How to Configure FFmpeg Concat Filter Input Count

This article explains how to configure the input count in the FFmpeg concat video filter to merge multiple video and audio streams. You will learn the exact syntax for the n parameter, how it interacts with audio and video stream settings, and how to apply this in a practical command-line example.

To configure the input count in the FFmpeg concat filter, you must use the n parameter within the filter definition. The n parameter tells FFmpeg how many segments (or input files) you are joining together. By default, if you do not specify n, FFmpeg assumes a value of 2.

The Concat Filter Syntax

The basic syntax for the concat filter is as follows:

[input_streams] concat=n=NUMBER_OF_INPUTS:v=VIDEO_STREAMS:a=AUDIO_STREAMS [output_streams]

Step-by-Step Example

If you want to concatenate three separate video files (input1.mp4, input2.mp4, and input3.mp4), you have an input count of 3. Each file contains one video stream and one audio stream.

Here is how you configure the command:

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.mp4

Breakdown of the Command

  1. Input Files: -i input1.mp4 -i input2.mp4 -i input3.mp4 defines the three source files. FFmpeg indexes these inputs starting from zero (0, 1, and 2).
  2. Stream Selection: [0:v][0:a][1:v][1:a][2:v][2:a] tells FFmpeg to pull the video (v) and audio (a) streams from each of the three inputs in chronological order.
  3. Filter Configuration: concat=n=3:v=1:a=1 is where the input count is set.
    • n=3 explicitly tells the filter to expect exactly 3 input segments.
    • v=1 tells the filter that each segment has 1 video stream.
    • a=1 tells the filter that each segment has 1 audio stream.
  4. Output Mapping: [outv][outa] labels the resulting merged video and audio streams, which are then mapped to the final output file output.mp4 using the -map flags.