FFmpeg: Set Input Frame Rate of Image Sequence
When converting a series of sequential images into a video using
FFmpeg, defining the correct input frame rate is crucial to ensure the
output video plays at your intended speed. This guide provides a direct,
step-by-step explanation of how to use the -framerate
option to specify the input frame rate for an image sequence, preventing
issues like skipped frames or incorrect playback speeds.
The Correct Command Structure
To set the frame rate of an input image sequence, you must place the
-framerate option before the input flag
(-i).
Here is the basic command:
ffmpeg -framerate <fps> -i input_%04d.png output.mp4Step-by-Step Example
If you have a sequence of images named frame_0001.png,
frame_0002.png, etc., and you want to combine them into a
video at 30 frames per second (FPS), run the following command:
ffmpeg -framerate 30 -i frame_%04d.png output.mp4Key Components Explained
-framerate 30: Tells FFmpeg to read the input images at a rate of 30 frames per second.-i frame_%04d.png: Specifies the input path. The%04dplaceholder tells FFmpeg to look for a four-digit, zero-padded sequential numbering system (e.g., 0001, 0002).output.mp4: The resulting video file. By default, FFmpeg will match the output frame rate to the specified input frame rate.
Crucial Tip: Input vs. Output Frame Rate
It is a common mistake to place the frame rate option after the input
file, or to use the -r flag instead of
-framerate.
- Always use
-frameratebefore-i: If you do not specify an input frame rate, FFmpeg defaults to 25 FPS. - Avoid using
-rfor inputs: The-roption is older and less efficient for image demuxing. It can cause FFmpeg to drop or duplicate frames to match a default rate before applying your desired rate. - Changing Output FPS: If you want the input sequence
read at one speed (e.g., 10 FPS) but exported to a standard video format
container that requires a higher frame rate (e.g., 30 FPS), specify
-frameratebefore the input and-r(or-framerateagain) before the output:
ffmpeg -framerate 10 -i frame_%04d.png -r 30 output.mp4This command reads the images at 10 FPS but duplicates the frames smoothly to create a standard 30 FPS video file.