Write Large Video Files

10 ビュー (過去 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