Write Large Video Files

11 views (last 30 days)
Dan Griffiths
Dan Griffiths on 5 Nov 2018
Commented: Dan Griffiths on 6 Nov 2018
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)

Accepted Answer

YT
YT on 6 Nov 2018
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 Comment
Dan Griffiths
Dan Griffiths on 6 Nov 2018
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.

Sign in to comment.

More Answers (0)

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!