Write Large Video Files

조회 수: 11 (최근 30일)
Dan Griffiths
Dan Griffiths 2018년 11월 5일
댓글: Dan Griffiths 2018년 11월 6일
Hi,
I am trying to read, process and write behavior video files. I am able to successfully save my video files if I plot the image (imshow), capture the images (getframe), and later write the video file. However, I would like to speed up the process by not plotting my images, and saving the images directly... however, when I do this I am unable to later write the video... I have received a variety of errors... The most common error is, "The ' cdata' field of FRAME must not be empty." I am able to plot the entire image sequence in Matlab. What am I doing wrong? Why is it telling me that CDATA is empty when I can see the images? Any help is greatly appreciated.
Thanks, Dan
Old Code:
i=1;
while hasFrame(vidObj)
RGB = readFrame(vidObj);
imshow(RGB)
hold on
plot(x(i),y(i), 'r+')
pause(.1)
hold off
Frame=getframe(gcf);
F(i)=im2frame(uint8(Frame.cdata));
end
video = VideoWriter(OutputName,'MPEG-4');
open(video)
writeVideo(video,F)
close(video)
New Code:
i=1;
while hasFrame(vidObj)
RGB = readFrame(vidObj);
Frame = insertMarker(RGB,[x(i) y(i)],'+','color','red','size',12);
F(i)=im2frame(uint8(Frame));
i=i+1;
end
video = VideoWriter(OutputName,'MPEG-4');
open(video)
writeVideo(video,F)
close(video)

채택된 답변

YT
YT 2018년 11월 6일
You could've clarified on which lines your error(s) occured, but like the error says, it's most likely that that one of your frames is empty. You could try to debug your code with the help of the following answer.
  댓글 수: 1
Dan Griffiths
Dan Griffiths 2018년 11월 6일
I'm sorry, the error occurs when I try to write the video. You are right, there are a few dropped frames in the middle of the video that cause the error. When I played the frames in the figure window and it did not error, I assumed that I had no dropped frames and that it was a writing/format error.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

제품


릴리스

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by