Tuesday 15 November 2016

Video to GIF shell script

I like to capture my Xbox One gaming moments to share with friends and have been working on a shell script to quickly convert videos to animated GIFs, I've put together this fairly simple little shell script that takes an input video and uses ffmpeg to convert to an animated GIF.

The GIF file format has a colour limitation of 256 colours, so optimisation needs to be done to ensure a good quality output. The script utilises ffmpegs palettegen options to generate a pallete of colours to use in the second pass using the bayer dither option. This is what the pallete PNG file looks like (upscaled from 16x16):

The resulting animated GIF turns out quite nice, this was captured from my Xbox One in the Battlefield 1 beta, the file is 480x260 and 4.3MB at 15 frames per second:

More information on GIF optimisation and bayer dithering can be found here, this was also the basis of my original script:
http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html

Just a warning, keep the input videos short, GIFs can get very large very quickly.

The script is available on github or copy and paste from below: