FFmpeg Concat Filter with Different Frame Rates
This article explains how to merge video files with different frame
rates using FFmpeg’s concat filter. Because merging videos
with mismatched frame rates directly can cause sync issues, dropped
frames, or playback errors, we will demonstrate how to standardize the
frame rate, resolution, and audio parameters within a single FFmpeg
command to ensure a seamless output.
The Problem with Different Frame Rates
The FFmpeg concat filter requires all input streams to
have identical properties, including width, height, pixel format, and
frame rate. If you attempt to concatenate videos with different frame
rates (for example, one at 24 fps and another at 60 fps) without
aligning them first, the command will either fail or produce a corrupted
output file with severe audio-video desynchronization.
To solve this, you must use a complex filtergraph
(-filter_complex) to normalize the frame rate of each input
stream before passing them to the concatenation filter.
The FFmpeg Command
The following command takes two input files (input1.mp4
and input2.mp4), standardizes their frame rates to 30 fps,
matches their resolutions to 1920x1080, and merges them into a single
output file.
ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex \
"[0:v]fps=fps=30,scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,format=yuv420p[v0]; \
[0:a]aresample=44100[a0]; \
[1:v]fps=fps=30,scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,format=yuv420p[v1]; \
[1:a]aresample=44100[a1]; \
[v0][a0][v1][a1]concat=n=2:v=1:a=1[outv][outa]" \
-map "[outv]" -map "[outa]" output.mp4How the Command Works
Here is a step-by-step breakdown of how the filtergraph processes the inputs:
fps=fps=30: This filter changes the frame rate of the input stream to a consistent 30 frames per second. It will duplicate or drop frames as necessary to achieve this rate without changing the speed of the video.scaleandpad: These filters resize the video to a uniform resolution (1920x1080) while preserving the original aspect ratio by adding black bars (letterboxing/pillarboxing) where needed.format=yuv420p: This ensures both videos use the same color space and pixel format, which is required for a successful concatenation.aresample=44100: This normalizes the audio sample rate to 44.1 kHz, preventing audio sync issues during the transition between clips.[v0][a0][v1][a1]concat=n=2:v=1:a=1[outv][outa]: This joins the normalized video and audio streams together. Then=2parameter specifies the number of input segments, whilev=1anda=1specify that each segment contains one video stream and one audio stream.-map "[outv]" -map "[outa]": Maps the final concatenated video and audio streams to the output fileoutput.mp4.