Tuesday, August 24, 2010

Creating animated gifs from movies

There are a lot of guides on explaining how to creating animated gifs by either creating them using various tools or by directly converting them from a movie. If you want to create an animated gif from scratch you can use Adobe Fireworks or Beneton Movie Gif. If you want to convert movie files (like WMV or FLV) to an animated gif, the best tool to use is ffmpeg.

The quick way

The easiest way to convert a  movie (in this example I will use a wmv, but it can also be any movie type) is using the internal function of ffmpeg. You can convert it by issuing the following command (which will create output.gif):

ffmpeg –i movie.wmv –r 5 –pix_fmt rgb24 –loop_output 0 –s 320x240 output.gif

Explanation of the switches (see also ffmpeg documentation):

-i determines the input file name (movie.wmv)

(put your filename between “ s if it contains spaces)
-r 5 tells ffmpeg to use a framerate of 5, which is a good setting when creating animated gif files (can be omitted if you want to use the original framereate)
-pix_fmt rgb24 required when converting to gif

(due to the max colors in a gif file)
-loop_output 0 Makes sure the gif animated forever, omit if this is not required
-s 320x240 Set the gif size to 320 by 240 to make the size of the animated gif smaller. Omit this if you don’t want this

This works perfect, however personally I am not so fond of how ffmpeg chooses the GIF color palette. I have not found anyway to improve this.

The better results way

As mentioned above, depending on your movie, the converted gif does not have an optimal color palette and you will see a lot dithering. The method I use most which gives the best results is exporting the frames using ffmpeg and importing them to your favorite animate gif tool (in my case Fireworks)

To export the frames of a movie using ffmpeg use:

ffmpeg –i movie.wmv –an –r 5 –y capture%d.png

Quick explanation: -an stands for no audio, –r specifies the framerate (change accordingly) and –y just tells ffmpeg to overwrite if files are existing. You export to any image format. I use PNG because this gives the best results.

The next step is to import your files in your favorite animator app. In Fireworks, select File – Open and select multiple the files you have generated with ffmpeg. Before pressing the Open button, make sure that the you check the “Open as animation” checkbox


Now Fireworks will create all the frames for you based on the image you have selected. Do your usual stuff and export it to animated gif.

Hope that this was useful and happy animating!

Souces: ahfr.org, noeckel,

No comments: