Write Large Video Files
10 views (last 30 days)
Show older comments
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)
0 Comments
Accepted Answer
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.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!