Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

MATLAB movie2avi cannot made video

  1. Oct 28, 2015 #1

    kelvin490

    User Avatar
    Gold Member

    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.
     
  2. jcsd
  3. Oct 29, 2015 #2

    kreil

    User Avatar
    Gold Member

    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 (Text):

    v = VideoWriter('newvid.avi');
    open(v)
    writeVideo(v,F)
    close(v)
     
    More info here: http://www.mathworks.com/help/matlab/ref/videowriter-object.html
     
  4. Oct 29, 2015 #3

    kelvin490

    User Avatar
    Gold Member

    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...
     
  5. Oct 29, 2015 #4

    kreil

    User Avatar
    Gold Member

    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.
     
  6. Oct 30, 2015 #5

    kelvin490

    User Avatar
    Gold Member

    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: MATLAB movie2avi cannot made video
  1. MATLAB Video Glitch (Replies: 0)

  2. Matlab: movie2avi() (Replies: 1)

Loading...