In this article, we look at how to create a GIF file from a bunch of images using FFmpeg, adjust the frames-per-second (fps), speed, and looping using FFmpeg. To learn more about FFmpeg, please explore all our FFmpeg articles on OTTVerse.com.
Install FFmpeg first
If you don’t have FFmpeg installed, then you can download it from here or install it using these instructions for Windows, Mac, and Linux. Once you have FFmpeg installed on your computer, you can proceed with this tutorial.
Generating Images from a Video
To generate a set of images from a video, you need to take periodic screenshots or thumbnails from the video. You can do this using FFmpeg easily and the process is explained in this tutorial: Thumbnails & Screenshots using FFmpeg – 3 Efficient Techniques. The basic command is as follows –
ffmpeg -i simpsons.mp4 -vf "select='not(mod(n,10))',setpts='N/(30*TB)'" -f image2 simpimgs%03d.jpg
To learn how the commandline parameters work, do read the article linked above.
Now that you have the necessary images to create the GIF, let’s proceed to the next step.
Creating a GIF from Images using FFmpeg
Here is the command line for creating a GIF file using a series of images and the FFmpeg tool.
ffmpeg -f image2 -framerate 1 -i simpimgs%03d.jpg -loop -1 simpson.gif
-i simpimgs%03d.jpg
– list of input images for the GIF file-framerate 1
means that FFmpeg will display each image for 1 second (frames/second).-loop -1
means that the GIF should not loop.0
= loop infinitely and this is the default value.1
= loop once (i.e. play two times)2
= loop two times (i.e. play thrice)
simpson.gif
– name of the output file.

FrameRate of the GIF created using FFmpeg
Now, let’s speed up the GIF by increasing the frame rate to 10 fps
as follows. You can see that the GIF completes much faster, right?
ffmpeg -f image2 -framerate 10 -i simpimgs%03d.jpg -loop -1 simpson_10fps.gif

Looping a GIF using FFmpeg
Now, let’s take a look at creating a GIF that loops infinitely. We do this by controlling the -loop
parameter and setting it to 0
. As we saw earlier, the loop
parameters are –
-1
= GIF should not loop.0
= loop infinitely and this is the default value.1
= loop once (i.e. play two times)2
= loop two times (i.e. play thrice)
By setting the loop
parameter to 0
, we get the following GIF that plays infinitely.

Conclusion
I hope this quick tutorial was useful to you and you know how to take a set of images and create a GIF out of it, and adjust the framerate, looping, etc. for the GIF.
Good luck, and happy streaming!
Thanks for this. You may want to explain what %03d does. It wasn’t obvious to me but I figured it out.
Thank you – we’ll update this in the article
The correct form is image%d.png in this case the program will grab all those images with the sequential numbers (n.n)
I enjoyed reading the article. Do you know how to set the frame rate for each frame when creating a gif from an image?