Create Time-lapse from Image Sequence with FFmpeg
Creating a time-lapse video from a series of sequentially numbered images is a highly efficient process when using FFmpeg, a powerful command-line tool. This guide provides a straightforward, step-by-step tutorial on how to compile your sequential image files into a high-quality video, explaining the essential command-line arguments, frame rate adjustments, and output configurations needed to get the best results.
The Basic Command
To build a time-lapse video, open your terminal or command prompt, navigate to the folder containing your images, and run the following command:
ffmpeg -framerate 24 -i image_%04d.jpg -c:v libx264 -pix_fmt yuv420p output.mp4Command Breakdown
-framerate 24: This sets the input frame rate. In this case, FFmpeg will read 24 images per second to construct the video. You can increase or decrease this number to speed up or slow down your time-lapse.-i image_%04d.jpg: This specifies the input file pattern.image_represents the common prefix of your files.%04dis a placeholder for a 4-digit zero-padded sequential number (e.g.,0001,0002,0003). If your files are 3-digit padded (e.g.,001), use%03d. If they are not zero-padded (e.g.,1,2,3), use%d..jpgis the file extension. Change this to.pngor another format if necessary.
-c:v libx264: This selects the H.264 video codec, which offers excellent compression and compatibility.-pix_fmt yuv420p: This pixel format ensures that the output MP4 video plays correctly on almost all media players and web browsers.output.mp4: The name of your resulting time-lapse video file.
Advanced Adjustments
Adjusting Video Quality
By default, FFmpeg will choose a standard quality. If you want to
control the quality and file size, use the Constant Rate Factor
(-crf) flag. Values range from 0 to 51, where lower means
better quality (18–23 is recommended for a great balance):
ffmpeg -framerate 30 -i image_%04d.jpg -c:v libx264 -crf 18 -pix_fmt yuv420p output.mp4Scaling the Output Video
High-resolution camera images can make the video file unnecessarily large. You can scale down the images (for example, to 1080p) during the rendering process using the scale filter:
ffmpeg -framerate 24 -i image_%04d.jpg -vf "scale=1920:-2" -c:v libx264 -pix_fmt yuv420p output.mp4(Note: -2 tells FFmpeg to automatically calculate
the height relative to the width to maintain the original aspect ratio,
ensuring the dimension is divisible by 2, which is required by the H.264
codec).