MATLAB movie2avi cannot made video

  • Context: MATLAB 
  • Thread starter Thread starter kelvin490
  • Start date Start date
  • Tags Tags
    matlab movie video
Click For Summary

Discussion Overview

The discussion revolves around issues encountered when using the MATLAB function movie2avi to create video files from graphical outputs. Participants explore alternative methods, particularly the VideoWriter function, and share experiences across different MATLAB versions.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant describes their attempt to use movie2avi and notes that the resulting AVI file contains unwanted elements like the toolbar and background, showing only a stationary image.
  • Another participant suggests that movie2avi is not recommended and proposes using VideoWriter instead, providing a code snippet for this approach.
  • A third participant confirms that they successfully used VideoWriter in a different MATLAB version (R2015a) but encountered issues with R2014a, where the output was also a stationary image.
  • One participant speculates that changes in the graphics system between MATLAB versions could affect the behavior of functions like getframe.
  • A later reply mentions that adding a specific command to set the renderer resolved their issue in R2014a, making the output behave like that in R2015a.

Areas of Agreement / Disagreement

Participants generally agree that movie2avi is problematic and that VideoWriter is a preferable alternative. However, there is disagreement regarding the behavior of these functions across different MATLAB versions, with no consensus on the underlying cause of the issues experienced.

Contextual Notes

Limitations include potential differences in graphics handling between MATLAB versions, which may affect the functionality of getframe and the resulting video output.

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

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