Making GIFs From Videos in Linux
I started making some .gif
s to embed in documentation and my notes as I
develop Rusty Nail. I always have to lookup how to
convert the images to gif
s. Every time I am also concerned with how big the
.gif
s 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:
ffmpeg
splits the video into a directory ofgif
sconvert
those images and stitches them together into onegif
.gifsicle
optimizes thegif
and allow a stage to resize it and also change the color. Thegiflossy
plug-in also can apply lossy compression to the gif video during the optimization step.
Read on for the script.
Requirements:
To use my make_gif.sh
script you will need the following applications:
- ffmpeg (I used version 3.1.5)
- Imagemagick (ImageMagick 6.9.3-0 Q16 x86_64 2016-05-14)
- gifsicle
- giflossy: Which you will need to install from source.
These should be installable from Ubuntu 16.04 or Fedora 25.
The Script
Usage
$ make_gif.sh -o my_new_image.gif input_file.mp4
You can get help information with:
$ make_gif.sh -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.
Conclusion
While gif
s 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.