How to Convert a Video to an Animated GIF in Linux

fmpeg-logo

The Animated gifs They have taken the web by storm, something that in recent times is more noticeable than ever but if we start to analyze it comes from the early days of the web, even though at that time they were small animated icons and today it is almost videos of a few seconds long.

Let's see, then, how to convert a video into an animated GIF in Linux, something for which we are going to based on FFmpeg and in ImageMagick, two veteran tools in the world of free software and available in all Linux distros, so as a first step we must install them both.

Once this is done, and assuming that we are in a terminal window and positioned in the folder in which we have the video file from which we want to create the GIF, we are going to base ourselves on something like the following:

ffmpeg -t <duración en segundos> -ss <posición de inicio en formato hh:mm:ss> -i < nombre del archivo de vídeo> salida%04d.gif

So if we want create an animated GIF that begins 5 seconds after a video called 'Birthday.MP4' and lasts for 15 seconds, we do:

ffmpeg -t 15 -ss 00:00:05 -i cumpleaños.mp4 salida%04d.gif

If we then list the files in that folder we will see that there are a few that end with something like 'output [\ d +]. Gif': these are the frames, or frames, that FFmpeg has obtained from the video.

Now we join them in the animated GIF, for which we are going to use ImageMagick, as follows:

convert -delay -loop 0 salida*gif

For example, to create an animated GIF called 'cumple.gif' that contains 20 frames per second and repeats infinitely, we do:

convert -delay 1x20 -loop 0 salida*gif cumple.gif

If instead of that we want it to be repeated 4 times, we modify the 0 after the 'loop' to a 4. Now we can use an ImageMagick tool called GIF Optimizer, which allows us reduce animation size:

convert -layers Optimize cumple.gif cumple-final.gif

That's it, you can start creating your own animated GIFs and share them with the world.

More information - ffmpeg: record your Linux desktop without problems


The content of the article adheres to our principles of editorial ethics. To report an error click here!.

Be the first to comment

Leave a Comment

Your email address will not be published.

*

*

  1. Responsible for the data: AB Internet Networks 2008 SL
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.