View License

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

» Watch video

Highlights from
Movie to GIF Converter

4.5 | 13 ratings Rate this file 41 Downloads (last 30 days) File Size: 2.98 KB File ID: #17463 Version: 1.5
image thumbnail

Movie to GIF Converter


Nicolae Cindea (view profile)


09 Nov 2007 (Updated )

Convert a matlab movie to a GIF

| Watch this File

File Information


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


This file inspired Gif Add Frame.

MATLAB release MATLAB 7.8 (R2009a)
Other requirements If you have Image Processing Toolbox you can replace my function aRGB2IND with the function rgb2ind.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (19)
30 Nov 2016 Wendy Lin

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

26 Mar 2015 kammo

kammo (view profile)

Works like a charm.

16 Mar 2015 Aidin Razavi

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

Comment only
16 Mar 2015 Aidin Razavi

18 Mar 2014 Ashkan

Ashkan (view profile)

great script. I had to modify the last line.

18 Jan 2014 Ki

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.

Comment only
29 Aug 2013 Ming

Ming (view profile)

This is the best best best best one.

19 Jul 2013 Abi mehranian

Great code!

07 Mar 2013 matt dash

matt dash (view profile)

20 Jul 2012 Nolan Conaway

Gets the job done!

19 Nov 2011 bart Blockmans

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!

17 Apr 2011 Søren

Søren (view profile)

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

20 May 2010 Kye

Kye (view profile)

nevermind, misread documentation

Comment only
10 Sep 2009 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);

27 Feb 2008 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);.

22 Feb 2008 john chavez

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

Comment only
22 Feb 2008 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?

Comment only
20 Feb 2008 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);

Comment only
30 Nov 2007 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...');

10 Oct 2011 1.3

This new version fixed some small bugs.

22 Apr 2013 1.5

Some small bug fixes and ameliorations.

Contact us