As my last post covered unshaking and stabilizing videos, this post now deals with converting those videos from mp4 to gif (to create stunning looped images).

first we need to run a command to export the frames from the mp4 file.

mkdir frames
ffmpeg -i vid.mp4 -vf scale=320:-1:flags=lanczos,fps=10 frames/ffout%06d.png

This will create a couple of files which we'll need in the next step to create the gif.

convert -loop 0 frames/ffout*.png out.gif

ImageMagick does the magic and we have our gif :) !

convert -layers Optimize out.gif out_opt.gif

Reduces the filesize a little and optimizes the gif.

To reduce file size adjust parameters when creating the gif. I got pretty good results with a setup like this

mkdir frames
ffmpeg -i vid.mp4 -vf scale=320:-1:flags=lanczos,fps=5 frames/ffout%03d.png
convert -delay 6 +dither -depth 8 -colors 128 -loop 0 frames/ffout*.png out.gif
convert -layers Optimize out.gif out_opt.gif