Reputation: 13493
I am making a video out of a sequence of plots using VideoWriter
. It works mostly OK (after following advice in this SO answer). However, it seems that Matlab tries to render all 3000 frames to screen sequentially after it's done animating, which causes my window manager to freak out and the computer to freeze for a few minutes.
Is there a way to write the video frames directly to disk, bypassing screen rendering? It seems that getframe
in writeVideo(vid, getframe(f))
necessarily makes the figure visible; is there a way to avoid that?
Upvotes: 2
Views: 9345
Reputation: 11
Don't use get frame, but use im2frame instead
writerObj = VideoWriter('awesomeMovie.mp4', 'MPEG-4');
open(writerObj);
masterFrame = rand(10,10,3);
f = im2frame(masterFrame);
writeVideo(writerObj,f);
Upvotes: 1
Reputation: 129
Using avifile and addframe will allow you to create a video and not display it to the screen. This seems to be a slower way to do things though.
Here is an example based on the referred post:
mov = avifile('myPeaks2.avi','fps',15);
set(gcf, 'visible', 'off')
for k=1:20
surf(sin(2*pi*k/20)*Z,Z);
mov = addframe(mov, gcf);
end
mov = close(mov);
Of course, this method is deprecated, so eventually you won't be able to use it.
Upvotes: 0
Reputation: 1720
If you have only 3000 frames, you can save them as images and make a video out of images using something like ffmpeg. Remember to use lossless format for images, such as PNG.
Upvotes: 2