File Exchange

image thumbnail

Movie to GIF Converter

version 1.5 (2.98 KB) by

Convert a matlab movie to a GIF

13 Ratings



View License


Matlab movie to GIF Converter.

Syntax: movie2gif(mov, gifFile, prop, value, ...)

The list of properties is the same like for the command 'imwrite' for the
file format gif:

'BackgroundColor' - A scalar integer. This value specifies which index in
                    the colormap should be treated as the transparent
                    color for the image and is used for certain disposal
                    methods in animated GIFs. If X is uint8 or logical,
                    then indexing starts at 0. If X is double, then
                    indexing starts at 1.

'Comment' - A string or cell array of strings containing a comment to be
            added to the image. For a cell array of strings, a carriage
            return is added after each row.

'DelayTime' - A scalar value between 0 and 655 inclusive, that specifies
              the delay in seconds before displaying the next image.

'DisposalMethod' - One of the following strings, which sets the disposal
                   method of an animated GIF: 'leaveInPlace',
                   'restoreBG', 'restorePrevious', or 'doNotSpecify'.

'LoopCount' - A finite integer between 0 and 65535 or the value Inf (the
              default) which specifies the number of times to repeat the
              animation. By default, the animation loops continuously.
              For a value of 0, the animation will be played once. For a
              value of 1, the animation will be played twice, etc.

'TransparentColor' - A scalar integer. This value specifies which index
                    in the colormap should be treated as the transparent
                    color for the image. If X is uint8 or logical, then
                    indexing starts at 0. If X is double, then indexing
                    starts at 1

Comments and Ratings (19)

Wendy Lin

Awesome function! Helped me a lot with the presentation. Thank you so much!!!


kammo (view profile)

Works like a charm.

Aidin Razavi

Is there a way to include the axes, ticks and labels as well?

Aidin Razavi


Ashkan (view profile)

great script. I had to modify the last line.


Ki (view profile)

great script. Just have one question, seems that the gil will not record anything in the frame title or xlabel or ylabel.


Ming (view profile)

This is the best best best best one.

Abi mehranian

 Great code!

matt dash

matt dash (view profile)

Nolan Conaway

Gets the job done!

I don't understand why this code hasn't got 5 stars yet. It does what it has to do and is very simple. Very good work!


Søren (view profile)

Very useful - with Keith's and Scott's recommendations.


Kye (view profile)

nevermind, misread documentation

Eric T

Eric T (view profile)

Doesn't work for me get the following error:
??? Error using ==> reshape
To RESHAPE the number of elements must not change.

Error in ==> aRGB2IND at 12
        RGBij = double(reshape(RGB(i,j,:), 1, 3)./255);

Error in ==> movie2gif at 75
        [IND, map] = aRGB2IND(RGB);

Scott Burnside

Useful code. I too had to make Keith's mod to initialize the waitbar. Btw, since .gif is 8-bit color you can use [IND, map] = rgb2ind(RGB,256);.

john chavez

whoops, i just realized that I was playing the gifs in quicktime. They play fine with firefox or some other web-browser.

john chavez

nice code, but I am having trouble with the color in the gifs that are being created. The movie images I am using have a lot of different colors in them, but the gifs that are created only have shades of white, light blue, dark blue, and black. I am using a bunch of fill3 commands with lighting effects to create the images, so maybe its a problem with the colormap?

Evan Variano

Thank you - This is a useful piece of code. To make it work, I had to make the change suggested by Keith Brodie (thanks Keith!). Also, when switching to the internal function rgb2ind, I had to supply an additional input, namely 128. In other words, this line shows up twice in my final code:

[IND, map] = rgb2ind(RGB,128);

Keith Brodie

Thanks - worked for me. I had to add one line to the movie2gif.m to initialize the waitbar handle in the case of nargin==2.

if (nargin == 2)
    h = waitbar(0, 'Generate GIF file...');



Some small bug fixes and ameliorations.


This new version fixed some small bugs.

MATLAB Release
MATLAB 7.8 (R2009a)
Tags Add Tags

Inspired: gif_add_frame

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video