MATLAB movie2avi cannot made video

In summary, when using R2014a, the function movie2avi does not work as expected. The avi file produced contains the toolbar and background instead of just showing the graph. Also, the avi file just shows stationary picture. The code that works correctly is to use theVideoWriter function.
  • #1
kelvin490
Gold Member
228
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
  • #2
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
  • #3
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...
 
  • #4
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
  • #5
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

Related to MATLAB movie2avi cannot made video

1. Why am I getting an error message when trying to use the movie2avi function in MATLAB?

There could be several reasons for this error message. One common reason is that the file name or path you are providing for the output video is incorrect or inaccessible. Another reason could be that the video file you are trying to convert is not in a compatible format. Make sure to check the documentation for the movie2avi function and ensure that your input and output files are in the correct format.

2. How can I fix the issue of my video being cut off or distorted when using movie2avi?

This issue can occur when the video resolution and frame rate of your input and output files do not match. To fix this, make sure to specify the correct frame rate and resolution in the movie2avi function and check that your input video is in the correct format.

3. Can I convert a series of images into a video using movie2avi?

Yes, you can use the movie2avi function to convert a series of images into a video. Simply use the 'frame' input argument to specify the images you want to include in the video and make sure to set the correct frame rate and resolution.

4. Is there a limit to the length of the video that can be created using movie2avi?

The length of the video created using movie2avi is limited by the available memory on your computer. If you are trying to create a long video, it is recommended to split it into smaller segments and then combine them using a video editing software.

5. Can I add audio to the video created using movie2avi?

No, the movie2avi function does not support adding audio to the video. However, you can use a video editing software to combine the video created using movie2avi with an audio file.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
633
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
4K
Back
Top