8bit avatar

PRACTICAL PARANOID

It's in that place where I put that thing that time


1 min | snippet

Convert a video to an animated GIF using ffmpeg

Pixelated scene from the movie Hackers with the main cast posing against a wall

This is an uber-quick post on how to convert a short video to an animated GIF using ffmpeg. As a bonus tip, we will also use ffmpeg to trim the video.

Let’s start by trimming a video to a 5 sec clip using the following command:

ffmpeg -ss 00:01:25 -to 00:01:30 -i input.mp4 -c copy output.mp4

The output clip will include the 5 sec between 01:25 and 01:30 min.

Now that we have a short clip we can convert it to GIF using the following command:

ffmpeg -i output.mp4 -loop 0 animated.gif

You can tweak the loop option as follows:

  • -1 no loop
  • 0 infinite loop
  • 1 loop once (plays 2 times)
  • 2 loop twice (plays 3 times)

That’s all folks 👋😀