Skip to content

GIF Howto

lolilolicon edited this page Oct 16, 2016 · 2 revisions

There are several ways to make a relatively high quality GIF screencast.

Why not ffcast rec a.gif? Because unfortunately FFmpeg produces very low quality GIF encodes by default.

Record to PNGs & convert

The best quality is achieved by recording to a series of PNG images, and post-process them using ImageMagick / GraphicsMagic.

First, use the rec sub-command to record to PNGs, e.g.:

mkdir -p /tmp/0; cd /tmp/0
ffcast -w rec -r 20 %04d.png

Take note, here we record at 20 fps, therefore, to match the speed, the GIF frame delay must be 50 ms.

Next, convert the PNG images to GIF:

convert -loop 0 -delay 5 *.png -layers Optimize a.gif

Note convert can have a lot of resource impact. Consider using -limit.

Record to video & convert

If you don't care too much about perfect quality, or if you've already recorded to a video, try this method.

First, use the rec sub-command to record a video, e.g.:

ffcast -w rec /tmp/a.mp4

Next, convert the video to a high quality GIF with FFmpeg:

ffmpeg -i a.mp4 -vf palettegen -f image2 -c:v png - |
ffmpeg -i a.mp4 -i - -filter_complex paletteuse a.gif

Or more conveniently, use v2gif.sh.

Post-process the GIF

Now we have the GIF, but what if you want to shave off some frames at the beginning or end, or to insert some other frames, or to slow down some frames, etc? The answer is to use convert or gifsicle. Go RTFM :)

See also

Clone this wiki locally