Making GIFs From Videos in Linux

Chris Woodall | 2016-12-23

I started making some .gifs to embed in documentation and my notes as I develop Rusty Nail. I always have to lookup how to convert the images to gifs. Every time I am also concerned with how big the .gifs are so after doing some looking around I made a little script which uses ffmpeg, convert, and gifsicle (with giflossy) to take an input mp4, webm, or any video that ffmpeg can decode.

The process is this:

  1. ffmpeg splits the video into a directory of gifs
  2. convert those images and stitches them together into one gif.
  3. gifsicle optimizes the gif and allow a stage to resize it and also change the color. The giflossy plug-in also can apply lossy compression to the gif video during the optimization step.

Read on for the script.


To use my script you will need the following applications:

  1. ffmpeg (I used version 3.1.5)
  2. Imagemagick (ImageMagick 6.9.3-0 Q16 x86_64 2016-05-14)
  3. gifsicle
  4. giflossy: Which you will need to install from source.

These should be installable from Ubuntu 16.04 or Fedora 25.

The Script


$ -o my_new_image.gif input_file.mp4

You can get help information with:

$ -h

This was my first time using the POSIX getopts which made it pretty easy to add new options to the script. I far prefer the style of clap-rs (for Rust), or click for Python.


While gifs are a pretty useful format for adding video content to documentation. I realize that the .webm format might be a better alternative, in the long run. With less effort, you can get higher compression rates and smaller file sizes, all with better quality and the option for integrating audio.