1
votes

I am trying to use the movie2avi function in MATLAB. I simply copy the sample program in my MATLAB R2015a:

nFrames = 20;

% Preallocate movie structure.
mov(1:nFrames) = struct('cdata', [],...
                        'colormap', []);

% Create movie.
Z = peaks; surf(Z); 
axis tight manual
set(gca,'nextplot','replacechildren');
for k = 1:nFrames 
   surf(sin(2*pi*k/20)*Z,Z)
   mov(k) = getframe(gcf);
end

% Create AVI file.
movie2avi(mov, 'myPeaks.avi', 'compression', 'None');

But an error message appears:

Error using avi Unexpected Error. Reason: Failed to open file.

Error in audiovideo.internal.aviwriter (line 168) aviobj.FileHandle = avi('open',filename);

Error in movie2avi (line 63) avimov = audiovideo.internal.aviwriter(filename,varargin{:});

Error in MakeMovie (line 36) movie2avi(mov, 'myPeaks.avi', 'compression', 'None');

What's wrong here? Please help.

1
do you have write permision in the fodler you work on? I copy pasted that code and works very goo din my computer - Ander Biguri
I think yes, I am the administrator. - Kelvin S
@AnderBiguri I'm suggesting that the file be exported in some format that FFmpeg can read, and create the avi that way. Remember that "avi" is not a format: it's a container. How you build a movie depends on the codecs selected. - Carl Witthoft
Actually, the VideoWriter class is the way to go. As the documentation states, movie2avi is deprecated. - horchler
Also make sure you don't have myPeaks.avi open somewhere else. - Navan

1 Answers

0
votes

I have the same Problem,Just delete history of previous Object before use movie2avi to create new movie,And My Problem Solved.In your code:

    nFrames = 20;

    % Preallocate movie structure.
    mov(1:nFrames) = struct('cdata', [],...
                    'colormap', []);

    % Create movie.
    Z = peaks; surf(Z); 
    axis tight manual
    set(gca,'nextplot','replacechildren');
    for k = 1:nFrames 
    surf(sin(2*pi*k/20)*Z,Z)
    mov(k) = getframe(gcf);
    end

    if(isobject(aviobj))
    clear mov % if mov exist
    end

   % Create AVI file.
   movie2avi(mov, 'myPeaks.avi', 'compression', 'None');

    clear mov