Monday, April 8, 2019

Making animated gifs

Recently I wanted to make some animated gifs from a video.

First I used my video player (mpc-hc) to grab some frames and save them as .jpg's in a folder.

Then using ImageMagick, I cropped, resized, and created a gif:
$ convert -crop 1200x900+480+0 +repage -resize 480x480 -delay 8 -loop 0 *.jpg output.gif

The repage argument is necessary so that the output gif doesn't use a virtual canvas for the crop operation.

This was kinda big, though, so I looked at this gist and this forum thread to get some ideas on how to reduce the filesize. The source video is live-action footage with a stationary camera, and I settled on:
$ convert -fuzz 5% -ordered-dither o8x8,30 -layers Optimize +map output.gif output2.gif

This dropped the filesize from 1.9 MB to 0.6 MB without affecting the quality too much. The number of colors for posterizing the ordered dither (30) was chosen by some trial and error.