Write Large Video Files
10 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!