I attempt to create a movie by looping through frames in MATLAB.
Refering to mathworks.com documentation at http://www.mathworks.com/help/techdoc/ref/movie.html, I\'
I had this (well, a closely related) problem today. This stackoverflow topic was one of the top search engine results, so I thought I'd provide future searchers with some further info.
I was using a VideoWriter
object, and calling frame=getframe(fig_handle)
to save each frame to the video. As in the question to this topic, only 1 frame was saved. In addition, the background behind the figure could be seen through it, as if the figure was partially transparent.
Changing renders to painters or zbuffer worked. (set(gcf,'renderer','zbuffer')
for example.)
I needed openGL rendering though, since the movie used transparency. The key to making this work was to use
opengl('software')
This circumvented what was probably an issue with sending the graphics to and from the video card (I don't know for sure... it worked, and I moved on).
This works perfectly for me.
What if you tried putting a drawnow
in the loop after the surf
? (This flushes all the events and updates your graphics figure).
Could it perhaps be your movie player, or codecs? Could you try VLC/Windows Media Player/etc etc?
I also had the problem of only one frame being stored today. Changing the framerate from:
vid.FrameRate = round(0.2*fps/beatfreq);
which evaluated to 3, to simply:
vid.FrameRate = 10;
I can't see why this would make any difference, but it did promptly work after changing this.
EDIT: Turns out it was VLC that can't handle very low framerates. Windows Media Player played it fine no sweat.
Try the following:
f = figure();
Z = peaks; surf(Z);
a = axes('Parent',f);
axis(a,'tight');
set(a,'nextplot','replacechildren');
vid = VideoWriter('myPeaks2.avi');
vid.Quality = 100;
vid.FrameRate = 15;
open(vid);
for k = 1:20
surf(a,sin(2*pi*k/20)*Z,Z)
writeVideo(vid, getframe(f));
end
close(vid);
winopen('myPeaks2.avi')
It contains explicit handles using instead of implicit. Many chaos is caused in Matlab because people tend to use the implicit ones, like "gcf", "gca" which should have been removed completely from the language, IMHO.
Have you tried changing your monitor settings to 16 bit color? http://www.mathworks.com/matlabcentral/newsreader/view_thread/257389
I managed to get it to work by forcing the figure frames to be invisible, as per http://www.mathworks.com/support/tech-notes/1200/1204.html:
aviobj=avifile('test.avi'); %creates AVI file, test.avi
hf= figure('visible','off'); %turns visibility of figure off
hax=axes;
for k=1:10
image(k.*peaks,'parent',hax); %puts image in invisible axes
set(gca,'Zlim',[-20 20]);
aviobj=addframe(aviobj,hf); %adds frames to the AVI file
end
aviobj=close(aviobj); %closes the AVI file
close(hf); %closes the handle to invisible figure
At the end of the day, no compression was used, as I don't have Indeo5. Is it correct to to say we may rule out compression as the problem?