Pregunta

I have a simulation running in MATLAB and I want to make a movie from the frames. There are more than 4000 frames at least 1600x1600 in size. Each frame is a 2D matrix. I can visualize them with pcolor and make a movie using getframe. But as the size is huge and the simulation is running overnight, I will run into alot of problems with screen savers, etc. Is there any better way to do this in MATLAB? Solutions with other softwares is also OK.

¿Fue útil?

Solución 2

Using the link provided in @Bee answer and some tinkering the problem is solved like this:

aviobj=VideoWriter(filename);
open(aviobj);
hFig=figure('Visible','Off');

for loop comes here
    cla

    %All Drawing stuff    

    img = hardcopy(hFig, '-dzbuffer', '-r0');
    writeVideo(aviobj, im2frame(img));
end
close(aviobj)

Note that it is using the VideoWriter instead of deprecated avifile and addframe and it does the rendering in memory not on disk so it's reasonably fast.

Otros consejos

Right before drawing the picture with pcolor(), try creating a figure that is invisible using h = figure('visible', 'off'); and use addframe(avi_file, h); to add a frame to the avi coming from the invisible figure. More detailed discussions can be found at Render MATLAB figure in memory

Update: it seems that there is no way to get a frame using getframe() inside a headless Matlab so options using VideoWriter and movie2avi will not work. If somebody has been successful with this, please correct me in the comments section.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top