MATLAB movie2avi cannot made video

  • Context: MATLAB 
  • Thread starter Thread starter kelvin490
  • Start date Start date
  • Tags Tags
    matlab movie video
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
4 replies · 3K views
kelvin490
Gold Member
Messages
227
Reaction score
3
I am trying to test the function movie2avi using simple codes in R2014a as follows:

clear; close all;
figure;
Z = peaks;
surf(Z);
axis tight manual;
ax = gca;
ax.NextPlot = 'replaceChildren';

loops = 40;
F(loops) = struct('cdata',[],'colormap',[]);
for j = 1:loops
X = sin(j*pi/10)*Z;
surf(X,Z);
drawnow;
F(j) = getframe(gcf);
end

movie(F);

movie2avi(F, 'myPeaks.avi', 'compression', 'None');

It seems the movie(F) works well but the avi file created contains the toolbar and background instead of just showing the graph. Also the avi file just show stationary picture as follow:

https://www.dropbox.com/s/otgnhc9ucfehqwk/a.png?dl=0

Another version of the program produce the same result:
clc;clear; close all;

figure;

Z = peaks;

surf(Z);

axis tight manual;

ax = gca;

ax.NextPlot = 'replaceChildren';v = VideoWriter('newfile2.avi','Uncompressed AVI');open(v);
loops = 40;

F(loops) = struct('cdata',[],'colormap',[]);

for j = 1:loops

X = sin(j*pi/10)*Z;

surf(X,Z);

drawnow;

F = getframe(gcf);

writeVideo(v,F);

end

close(v);There is also a warning:

Warning: Struct field assignment overwrites a value with class "double". See MATLAB R14SP2 Release Notes, Assigning Nonstructure
Variables As Structures Displays Warning, for details.

Please help. Thanks.
 
Physics news on Phys.org
The movie2avi function is not recommended. There is a note in the documentation saying to use VideoWriter instead.

Try this code out instead of calling movie2avi:

Code:
v = VideoWriter('newvid.avi');
open(v)
writeVideo(v,F)
close(v)

More info here: http://www.mathworks.com/help/matlab/ref/videowriter-object.html
 
  • Like
Likes   Reactions: kelvin490
kreil said:
The movie2avi function is not recommended. There is a note in the documentation saying to use VideoWriter instead.

Try this code out instead of calling movie2avi:

Code:
v = VideoWriter('newvid.avi');
open(v)
writeVideo(v,F)
close(v)

More info here: http://www.mathworks.com/help/matlab/ref/videowriter-object.html

I have tried writeVideo, for simple codes like this:
clc;clear; close all;
Z = peaks; surf(Z);
vid = VideoWriter('myPeaks2.avi');
vid.Quality = 100;
vid.FrameRate = 15;
open(vid);
for k = 1:20
surf(sin(2*pi*k/20)*Z,Z);
writeVideo(vid, getframe(gcf));
end
close(vid);
winopen('myPeaks2.avi')

it works for R2015a in my win8 computer, avi file is produced normally, but doesn't work for R2014a in a win10 computer, only stationary picuture with unnecessary background in the screen is shown in the avi (just like the picture I posted above). I don't know why there is such a difference...
 
Not at a computer to test this but my first guess would be that the graphics system had a major overhaul in 14b. So the behavior of some graphics functions changed, in particular I would double check that getframe(gcf) has the behavior you expect in both releases.
 
  • Like
Likes   Reactions: kelvin490
kreil said:
Not at a computer to test this but my first guess would be that the graphics system had a major overhaul in 14b. So the behavior of some graphics functions changed, in particular I would double check that getframe(gcf) has the behavior you expect in both releases.

Update: I added a command "set(gcf,'Renderer','zbuffer');" when I use R2014a and the problem is solved. It is just like using writeVideo in R2015a without that command. Thank you.
 
  • Like
Likes   Reactions: kreil