I seem to be having an error using movie2avi (even using the example shown in Matlab Help) What could be the issue?

3 views (last 30 days)
I am using matlab R2008a. I am attempting to run the following code from the movie2avi example. When running, the Figure changes as I would expect the movie to. When I type movie(mov) Figure 1 seems to zoom in but freeze on the first figure in the movie. Also when I view the .avi file created, all that is shown is a short wide gray bar that isn't changing. Could my system not have the capability to create the avi file?
scrsz = get(0,'ScreenSize') nFrames = 20;
% Preallocate movie structure. mov(1:nFrames) = struct('cdata', [],... 'colormap', []);
% Create movie. Z = peaks; surf(Z); axis tight manual set(gcf,'position',[1 35 scrsz(3)/1.2 scrsz(4)/1.2],'color','white') set(gca,'nextplot','replacechildren'); for k = 1:nFrames surf(sin(2*pi*k/20)*Z,Z) mov(k) = getframe(gcf); pause(0.05) end
% Create AVI file. movie2avi(mov, 'myPeaks.avi', 'compression', 'None','fps',5);

Accepted Answer

Geoff Hayes
Geoff Hayes on 7 Oct 2014
Edited: Geoff Hayes on 7 Oct 2014
Matt - the zooming in of the figure that occurs when you execute movie(mov) may be due to the fact that the figure that the movie is being played on has not been resized to the frame size. You could try
[h,w,p] = size(mov(1).cdata); % use 1st frame to get dimensions
hf = figure;
% resize figure based on frame's w x h, and place at (150, 150)
set(hf, 'position', [150 150 w h]);
axis off
movie(hf,mov,1,30,[0 0 0 0]);
to see if the above prevents the zooming.
As for only observing the first frame, I tried your code on a 32-bit R2014a version of MATLAB (Windows Vista), and I observed the same results. Even when I used the VideoWriter class to write the frames to file, all frames were identical to the first one (and had what appeared to be other artifacts from my desktop mixed in with the image).
A similar question was raised at stackoverflow: problems with movie file creation, and one solution was to change the figure renderer property to zbuffer (the default renderer is OpenGl for my PC). I added the middle line of code
set(gcf,'position',[1 35 scrsz(3)/1.2 scrsz(4)/1.2],'color','white')
set(gcf,'renderer','zbuffer'); % <---- New line of code
set(gca,'nextplot','replacechildren');
and created the avi. Both the movie(mov) and the avi worked - all frames were shown (none appeared to be identical). I tried this with your above code, and the VideoWriter alternative.

More Answers (0)

Categories

Find more on Animation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!