MATLAB MATLAB movie2avi cannot made video

Click For Summary
SUMMARY

The discussion centers on issues with the MATLAB function movie2avi in R2014a, where the generated AVI file displays a stationary image with unnecessary background instead of the intended animation. Users are advised to transition to the VideoWriter function, which is recommended in the documentation. A solution was found by adding the command "set(gcf,'Renderer','zbuffer');" in R2014a, which resolved the rendering issue. The VideoWriter function was successfully tested in R2015a, producing the expected output without additional background elements.

PREREQUISITES
  • Familiarity with MATLAB programming environment
  • Understanding of MATLAB graphics rendering
  • Knowledge of the VideoWriter function in MATLAB
  • Basic experience with creating animations in MATLAB
NEXT STEPS
  • Explore the MATLAB VideoWriter documentation at MathWorks
  • Learn about graphics rendering options in MATLAB, specifically the 'Renderer' property
  • Investigate differences in graphics systems between MATLAB R2014a and R2015a
  • Experiment with various compression settings in VideoWriter for optimal video quality
USEFUL FOR

MATLAB users, data visualization specialists, and anyone involved in creating animations or video outputs in MATLAB, particularly those working with different versions of the software.

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 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 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 kreil

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
4K