How to create a FFmpeg video from images in just 5 easy steps?
Public Space
4 minutes
How to Easily Create a Time-Lapse Video from Photo Sequences with FFmpeg
Are you wondering how to turn a photo sequence into a video effortlessly? In this guide, we'll show you how to convert image sequences into videos to make time-lapse using FFmpeg, a powerful command line tool for managing images and videos.
FFmpeg is an outstanding command line tool that helps you do plenty of things with images and videos. By using FFmpeg, you can convert an image sequence into a video file. If you are here to learn how to create a video from images with FFmpeg, let me help you.
It's an easy task to produce an FFmpeg output stream from a sequence of images. I'll detail how to do it easily, I'll simplify the process for your better understanding.
Shut down your worries and dive into how to create a video from images using FFmpeg.
Install FFmpeg
First things first: install FFmpeg. The easiest way is to use a Mac package manager named Homebrew to install it. However, if you don't have Homebrew, don’t worry, another option is to open up a terminal and then copy and paste the below text in the terminal window. Now press return.
bashCopier le code"/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
After that, Homebrew will start installing. Now you can easily install the FFmpeg file using Homebrew. Again, let's open up a terminal, copy and paste the below text, and then press return.
bashCopier le code brew install ffmpeg
Everything is okay, and the FFmpeg file will install in no time!
Preparing the Images
If you want to get the ultimate output file as you desire, it's more significant to have the input files ready very accurately. To recognize and line up image files you input, FFmpeg uses order matching. That's why it's essential that your images stay in the right order.
FFmpeg supports almost nearly three diverse patterns. Let’s take a look at these patterns below.
Filenames with preceding zeros, e.g., filename-%03d.png compares to images defined from filename-001.png to filename-999.png.
Filenames without preceding zeros, e.g., filename-%d.png compares to images defined from filename-1.png to filename-999.png.
Prefixed without a regular pattern, e.g., filename-*.png compares to all images that start with the prefix filename-.
You don't need to follow a regular numbering order. If you use this option, you will need to have an extra parameter for the images to video conversion. We will explain this in the following section.
Remember, if any filename contains a ‘%’ character, it's not a problem at all. Just add “%%” at the positioning of the ‘%’ character to avoid any issues!
If all the image files are ready to create a video stream with FFmpeg, let me show you how to create it.
Create a Video From Images
Once you have prepared the source image files with the correct order and name and placed them in the same directory, move ahead! You can run the below command in the terminal:
bashCopier le code ffmpeg -i img-%02d.png video_name.avi
FFmpeg looks for image files with filenames starting with ‘img-‘ followed by a two-digit number. In the command section, you will need to define a search pattern for the FFmpeg output file so that you can find the image sequence.
The search pattern depends on what name you set for the image files when you prepared them.
Setting The Frame Rate
While creating a video stream from a sequence of image files, the frame rate is an important consideration. Frame rate means the number of frames per second. Keep in mind that the most suitable frame rate will rely on the source image files you input.
For example, if you're thinking of stop-motion animation, the best option will be the default of 25 fps.
On the other hand, if you think of a slow-moving slide show, of course, you will want a slower frame rate like 2 fps. Here is a reminder for you — if you do not set the right frame rate, the output video file will not meet your expectations. You may find some strange results in the ultimate video file.
If you want to get an output video file with a 5 fps frame rate, you will need to paste the below command:
bashCopier le code ffmpeg -framerate 5 -i img-%02d.png video.avi
Changing the Video Format
In the above examples, I have shared the avi video format as the final output. For your convenience, FFmpeg supports a wide range of different types of video formats. Also, you can change the output video format by changing the file extension of the final output video file.
Here I share which output video setups are available:
bashCopier le code ffmpeg -encoders
You've learned how to create a video from a sequence of images with FFmpeg. In this write-up, I've discussed some options that enable you to convert image sequences into a video stream. By following these steps, you can produce high-quality videos that meet your expectations. The final output quality depends on the quality of your input files and their sequence.
Now that you’ve learned how to create a video from image sequences using FFmpeg, start converting your images into stunning time-lapse videos!
For more advanced time-lapse photography, consider using Enlaps' Tikee cameras. With their high-quality imaging capabilities, Tikee cameras ensure professional results for all your time-lapse projects. Visit Enlaps for more information.
Frequently Asked Questions
How to combine images into a video?
You can combine images into a video using FFmpeg by running the command ffmpeg -i img-%02d.png video_name.avi. This command searches for image files matching the pattern img-XX.png and combines them into a video file named video_name.avi.
How to overlay an image on a video in FFmpeg?
To overlay an image on a video using FFmpeg, use the following command: ffmpeg -i video.mp4 -i overlay.png -filter_complex "overlay=10:10" output.mp4. This command places the image overlay.png at coordinates (10,10) on the video video.mp4.
Can FFmpeg convert to MP4?
Yes, FFmpeg can convert videos to MP4 format. Simply use the command ffmpeg -i inputfile outputfile.mp4, replacing inputfile with your source video and outputfile.mp4 with your desired output filename.
How do I turn a picture into a moving video?
To turn a picture into a moving video using FFmpeg, you can apply filters such as zoom or fade. For example, use the command ffmpeg -loop 1 -i image.png -vf "zoompan=z='zoom+0.001':d=125" -t 5 output.mp4 to create a 5-second video where the image zooms slowly.
How do I insert an image into FFmpeg?
You can insert an image into a video in FFmpeg by using the overlay filter. The command ffmpeg -i video.mp4 -i image.png -filter_complex "overlay=0:0" output.mp4 places the image at the top-left corner of the video.
Does FFmpeg work on images?
Yes, FFmpeg is highly effective for working with images. It can convert, edit, and combine images into videos, as well as extract frames from videos, making it a versatile tool for image processing.
How to extract images from a video using FFmpeg?
To extract images from a video, use the command ffmpeg -i video.mp4 -vf fps=1 image-%03d.png. This extracts one frame per second from video.mp4 and saves them as a sequence of images named image-001.png, image-002.png, and so on.
Newsletter
Sign up for our newsletter
Get the latest news, exclusive offers, use cases, and expert advices by signing up now!
In need of a custom demonstration
To better understand the Tikee solution and to learn more before getting started, we offer you to schedule an individual appointment, via video conference.