Create Video from Images using FFmpeg

In this tutorial, we will learn how to create a video from images using FFmpeg. FFmpeg can do this easily if the input is fed as a sequence of images that have been named in an appropriate and easy-to-parse manner.

Creating a video from images is very useful, especially when you indulge in stop-motion photography or into time-lapse movies. In time-lapse movies, you basically set up your camera to take a picture and then go to sleep for N seconds. It then wakes up and takes another picture, and goes back to sleep. You do process this long enough, and you have a 100s of images shot from a single position, and when you make a movie out of them, the result is spectacular.

If you are interested in making a time-lapse video, then take a look at this tutorial that shows you how to make a video from images using FFmpeg.

Step 0: Preparing the Images

As mentioned, for this method to work as desired, it is necessary to prepare the input correctly. FFmpeg uses string matching to identify and line up the input images — and so it is important that the input images are sequentially numbered.

FFmpeg provides support for approximately three different patterns. The patterns are as follows:

  1. Filenames with leading zeroes, e.g. filename-%03d.png corresponds to images named from filename-001.png to filename-999.png.
  2. Filenames without leading zeroes, e.g. filename-%d.png correspond to images named from filename-1.png to filename-999.png.
  3. Prefixed without a regular pattern, e.g. filename-*.png correspond to all images that start with the prefix filename- but do not strictly follow a sequential numbering order. If you use this option, then you need to provide an additional parameter for the image to video conversion and we’ll see this in a later section.

Note: If the filename contains the character ‘%’, it can be solved by adding “%%” at the positioning of the literal to “escape” this problem!

Now that we have the images prepared, let’s demonstrate how to create a video using these images.

For this demo, I used the previously published article Thumbnails & Screenshots using FFmpeg – 3 Efficient Techniques to generate the images required. As you can see from the screenshot below, the images are sequentially numbered which makes the images-to-video conversion much easier!

video from images using FFmpeg

Create a Video from Sequential Images using FFmpeg

The most basic form of the command to create a video from images using FFmpeg is as follows:

ffmpeg -framerate 10 -i filename-%03d.jpg output.mp4

If the -framerate parameter is not provided, FFmpeg selects the default rate of 25 fps. Depending on the format used to prepare the images, substitute the appropriate string matching pattern. 

Using glob for Pattern Matching When Sequential Input Is Not Provided

If a sequential order is not provided, but the input filenames are appropriately prefixed and follow a logical order, then you can use the glob parameter to create the video. For example, you might have input-00.png, input-10.png, and input-30.png, etc. Here is an example of the command line for creating a video from such images.

ffmpeg -framerate 10 -pattern_type  glob -i "filename-*.jpg" output.mp4

Note:

  1. It is necessary to quote the glob pattern, else the command will fail due to the command interpreting the files as multiple arguments. 
  2. Windows has a problem with globbing as it does not have access to glob.h. See here and here. The easiest way out is to actually ensure that the files are sequentially ordered.
Related:  VMAF in FFmpeg - Installation and Usage Guide for Ubuntu

Examples

Here are some examples of videos created from images using FFmpeg with different frame rates.

Framerate = 25 fps (default)

Notice how FAST the video progresses, which is because we have 25 frames every second. This is unwatchable, in my opinion! It could be a great option if you are making a stop motion movie, or a time lapse movie.

Framerate = 2 fps

Notice how slow the video progresses which is because we have only two frames every second.

Framerate = 10 fps

That’s it. I hope you were able to successfully create a video from images using FFmpeg from this tutorial. If you are interested in FFmpeg, please check out the rest of the FFmpeg tuorials on OTTVerse.com.

Akshay Rajeev
Akshay Rajeev

Akshay is a student at the NYU Tandon School of Engineering, completing his M.S. in Computer Engineering. His area of interest includes software system design, machine learning, and cybersecurity.

Akshay also serves as a Contributing Author on OTTVerse.com

1 Comment

  1. Hello, I congratulate you on this great job.

    I have a problem, I have a list of 50 images in ima-% 03d format that is to say .. ima-001 to ima-050. But FFMPEG only records up to picture 33.

    Show this on the screen: deprecated pixel format used, make sure you did set range correctly

Leave a Reply

Your email address will not be published.


*