Record video frames directly to file, screen traversal

I am making a video from a sequence of graphs using VideoWriter

. It works mostly OK (following the next tip, this SO answer ). However, it looks like Matlab is trying to display all 3000 frames to the screen sequentially after it has done the animation, which makes my window manager jittery and the computer freezes for a few minutes.

Is there a way to record video frames directly to disc without going through the screen display? It seems that getframe

in writeVideo(vid, getframe(f))

necessarily makes the figure visible; is there a way to avoid this?

+2


source to share


3 answers


If you only have 3000 frames, you can save them as images and make video from images using something like ffmpeg. Remember to use a lossless format for images like PNG.



+2


source


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);

      

+1


source


Using avifile and addframe will allow you to create a video and not display it on screen. This seems to be a slower way of doing things, though.

Here's an example based on the position indicated:

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.

0


source







All Articles