Configure FFmpeg Concat Filter Inputs and Streams
This article explains how to configure the input count and stream
types using the FFmpeg concat filter. You will learn how to
use the n, v, and a parameters to
define the number of input segments, video streams, and audio streams,
allowing you to seamlessly merge multiple media files into a single
output.
To configure the concat filter in FFmpeg, you must
define its parameters inside a -filter_complex graph using
the syntax concat=n=X:v=Y:a=Z. These three parameters
dictate how FFmpeg processes your input files:
n(Segment Count): Specifies the number of input segments to join. The default value is2.v(Video Streams): Specifies the number of output video streams per segment. The default value is1.a(Audio Streams): Specifies the number of output audio streams per segment. The default value is0.
Understanding the Input Mapping
The concat filter requires you to explicitly feed it the
correct number of input streams based on your configuration. The total
number of input streams you must pass into the filter is calculated
as:
Total Inputs = n × (v + a)
The inputs must be ordered sequentially by segment. For each segment, you must specify the video stream(s) first, followed by the audio stream(s).
Example 1: Concatenating Video and Audio (1 Video, 1 Audio)
If you want to merge three separate video files, each containing one
video stream and one audio stream, your parameters will be
n=3, v=1, and a=1.
The total number of input streams needed is
3 × (1 + 1) = 6.
ffmpeg -i input1.mp4 -i input2.mp4 -i input3.mp4 -filter_complex \
"[0:v][0:a][1:v][1:a][2:v][2:a]concat=n=3:v=1:a=1[outv][outa]" \
-map "[outv]" -map "[outa]" output.mp4In this command: * [0:v][0:a] represent the video and
audio of the first file. * [1:v][1:a] represent the video
and audio of the second file. * [2:v][2:a] represent the
video and audio of the third file. * [outv] and
[outa] are the temporary labels assigned to the
concatenated video and audio outputs, which are then mapped to the final
output file.
Example 2: Concatenating Video Only (No Audio)
If you are merging two video files that do not have audio, set
a=0. Your parameters will be n=2,
v=1, and a=0.
The total number of input streams needed is
2 × (1 + 0) = 2.
ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex \
"[0:v][1:v]concat=n=2:v=1:a=0[outv]" \
-map "[outv]" output.mp4Important Requirements
When using the concat filter, all input segments must
share identical attributes. If the attributes do not match, the filter
may fail or produce corrupted output. Ensure your inputs have the same:
* Video resolution (width and height) * Frame rate (fps) * Pixel format
(e.g., yuv420p) * Audio sample rate * Audio channel layout (e.g., stereo
or mono)