Making GIFS with FFMPEG

Raw gif

ffmpeg can now make gifs in a single step, no longer do you have to generate frames then pass them into ImageMagick. For most of the videos I have tried the initial gif from ffmpeg hasn't been very good.

I found a stackoverflow post that describes a two step process for generating gifs with ffmpeg that has great results. The first step generates a palette from the source video, then this palette is used as a filter when converting the video into a gif.

ffmpeg -i -vf fps=10,scale=320:-1:flags=lanczos,palettegen palette.png

Output the GIF using the palette:

ffmpeg  -i -i palette.png -filter_complex "fps=10,scale=320:-1:flags=lanczos[x];[x][1:v]paletteuse" output.gif

Plaette gif

The improvement is more evident if you click and watch the full size gifs side by side. The stackoverflow post links a blog post with even more information on generating high quality gifs from video.


if [ "$#" -ne 1 ]; then
    echo "usage: makegif filename.mp4"
    exit 1


ffmpeg -y -i $input -vf fps=10,scale=320:-1:flags=lanczos,palettegen palette.png
ffmpeg -y -i $input -i palette.png -filter_complex "fps=10,scale=0:-1:flags=lanczos[x];[x][1:v]paletteuse" $filename.gif