Create FFmpeg Time-Lapse Video with Specific FPS
This guide provides a straightforward walkthrough on how to compile a sequence of images into a high-quality time-lapse video using FFmpeg. You will learn the exact command-line arguments needed to control both the speed at which your source images are read (input frame rate) and the final playback frame rate (output FPS) of the video file.
The Standard Time-Lapse Command
If your images are sequentially named (e.g.,
img_0001.jpg, img_0002.jpg, etc.), you can
merge them into a video with a specific frame rate using the following
command:
ffmpeg -framerate 30 -i img_%04d.jpg -c:v libx264 -pix_fmt yuv420p output.mp4Parameter Breakdown
-framerate 30: This defines the input frame rate. FFmpeg will read 30 images per second of video. Adjust this number to speed up or slow down your time-lapse.-i img_%04d.jpg: Specifies the input files.%04dis a placeholder for a four-digit zero-padded sequence. If your files have three digits (e.g.,001), use%03d.-c:v libx264: Uses the H.264 video codec, which ensures high quality and wide compatibility across devices.-pix_fmt yuv420p: Sets the pixel format to YUV 420p, which is required for the video to play properly on standard media players and web browsers.output.mp4: The name of the resulting time-lapse video file.
Adjusting Input vs. Output FPS
Sometimes you want to process a low number of images per second (e.g., 5 frames per second) but want the actual output video container to run at a standard smooth rate (e.g., 29.97 or 30 FPS) to prevent compatibility issues on certain players.
To achieve this, use the -framerate option for the input
and the -r option for the output:
ffmpeg -framerate 5 -i img_%04d.jpg -r 30 -c:v libx264 -pix_fmt yuv420p output.mp4-framerate 5: FFmpeg reads 5 unique images per second.-r 30: FFmpeg duplicates frames to output a standard 30 FPS video file, keeping the visual speed at 5 unique frames per second.
Using Wildcards (For Non-Sequential Filenames)
If your images are not sequentially numbered (for example, if they
have timestamped filenames) and you are using a Unix-based system
(Linux/macOS), you can use the glob pattern type:
ffmpeg -framerate 24 -pattern_type glob -i '*.jpg' -c:v libx264 -pix_fmt yuv420p output.mp4