# How to create an animated GIF from a video file

This is a note-to-future-self-how-to-do-things…

Creating a good looking gif-animation from a video via the command line is fairly easy once you know how to do it…
You need ffmpeg and the convert tool from ImageMagick.

Let’s say you have a video file named video.mp4, then this creates a bunch of single frame PNGs with a width of 320 pixels and a proportional height in the current directory:

ffmpeg -i video.mp4 -vf scale=320:-1 -r 10 frame%03d.png

The -r option sets the framerate. In the example we used 10. So if the source framerate was 30, then every third frame will be rendered as a PNG.

Now we use the convert tool from ImageMagick to convert the PNG files into an animated gif:

convert -delay 10 -loop 0 frame*.png output.gif

The -delay option defines how many 1/100 seconds each frame should be delayed. If you set the frame rate to 10 when exporting the PNGs, you should set the delay to 1/10 of a second = to 10. This setting in the final animated gif is not exact, so you may need to experiment a bit.

Voila, that’s it!

I learned most of this from this answer on superuser.com