How to make an animated gif from an video in Linux

First you will want to trip your video to the length you need, best to do this in openshot or something. More than a few seconds of video will end up being much larger gif than most will watch 🙂


# Make sure the right tools are installed
apt-get install ffmpeg imagemagick gifsicle # or the equivalent yum/etc
# make a temp directory/folder
mkdir /tmp/gifconvert
# dump 10 frames a second to a temp folder (you can change the size output here too)
ffmpeg -i toycars.mp4  -r 10  /tmp/gifconvert/out%04d.gif 
# Recombine them into a gif
gifsicle --delay=10 --loop /tmp/gifconvert/*.gif > animation.gif

animated gif
If you want to have it go forwards, then reverse, so it appears to be continuous you can change the gifsicle line to go like this (ignore the black border, exported the video wrong from openshot :))

ls -v /tmp/gifconvert/*.gif >/tmp/gif-list
ls -vr /tmp/gifconvert/*.gif >>/tmp/gif-list
gifsicle --delay=10 --loop `cat /tmp/gif-list` >testani.gif

shortanirev gif

All images and the original video come from this amazingly awesome vine video

  • Pingback: Animated gif from an video in Linux by terminal | - Slightly geeky but I love coffee()

  • Mustafa Gokay

    Hey. Awesome tutorial. But watch out for the first command. You wrote “ffmepg” but it has to be like “ffmpeg”

    • doh, will fix 🙂

  • Swapnil Chitnis

    Or just use this: mplayer input.mp4 -vo gif89a:fps=10:output=output.gif -vf scale=640:480 -ss 21:42 -endpos 22:08

    Makes a gif at 10fps at 640×480 resolution in the given start and end point.

    • Linux – 100 ways to skin a cat? 🙂
      I prefer this way so i can weed out odd frames – in the example case i had a pure black frame for some reason, not so obvious when playing video, but on a 10 frame gif it totally was..