Convert video (.mp4 or other) to high quality animated gif
Alec Jacobson
September 12, 2011
You can do this directly with ffmpeg, but I had trouble with it and seem to remember the quality not being so good. Instead I convert my .mp4 video into an animated gif by first grabbing 10 frames every second and saving them to files using the following:
ffmpeg -i input.mp4 -r 10 output%05d.png
Then using imagemagick's convert tool insert each frame into an animated gif:
convert output*.png output.gif
This makes a rather large .gif file for even modest videos so probably you'll want to post process it (e.g. with Photoshop) to reduce the file size by compressing the .gif file or reducing the dimensions.
Clean up the png files using:
rm output*.png