JaggyGauran

Freelance developer, and designer

Converting Videos to GIFs

Dependencies

  • ffmpeg
  • imagemagick | gifsicle

Dissect the video

ffmpeg -i convert.webm -r 10 -f image2 -y /tmp/gifs/%03d.png

First step is to disect the video into frames.

  • -i convert.webm - input file to convert
  • -r 10 - frame rate
  • -f image2 - format
  • -y - force overwrite the files
  • /tmp/gifs/%03d.png - This will generate a series of images in the destination folder.

Stitch the images into a single GIF

convert -delay 1x10 `seq -f /tmp/gifs/%03g.png 1 24` -coalesce -layers OptimizeTransparency output.gif

Now this is a two part command, let's start off with seq

seq -f /tmp/gifs/%03g.png 1 24
  • -f /tmp/gifs/%03g.png - The format on how image patterns, I guess %03g is equivalent to ffmpeg's %03d
  • 1 24 - Start and finish
# Output
/tmp/gifs/001.png
/tmp/gifs/002.png
...
/tmp/gifs/024.png

Now with the imagemagick command.

  • -delay 1x10 - The delay set per image
  • -coalesce - Merge the images from the seq command
  • -layers OptimizeTransparency - Okay this, I have no clue
  • output.gif - File to output

Try playing around with the settings to get the smoothness that you need. Take note though, the more images you split, the longer it takes.

Also, you can try using Gifsicle for GIF generation or optimization.