Map FFmpeg Concat Filter Outputs to Output File

When combining multiple video and audio streams using FFmpeg’s concat filter, you must explicitly map the resulting filtergraph outputs to your final output file. This guide explains how to define output labels within the concat filter and use the -map option to route those merged streams correctly, preventing common errors such as missing audio or video in your final export.

To map the outputs of the concat filter, you need to assign custom labels (called “pads”) to the end of your filter chain and then reference those labels using the -map option.

The Basic Syntax

Here is a standard command template for concatenating two files with video and audio:

ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex "[0:v][0:a][1:v][1:a] concat=n=2:v=1:a=1 [outv] [outa]" -map "[outv]" -map "[outa]" output.mp4

Step-by-Step Breakdown

  1. Define the Inputs: -i input1.mp4 -i input2.mp4 loads the source files. In FFmpeg, the first input is index 0, and the second is index 1.
  2. Specify Streams for the Filter: [0:v][0:a][1:v][1:a] tells the filter to take the video and audio from the first input, followed by the video and audio from the second input.
  3. Configure the Concat Filter: concat=n=2:v=1:a=1 sets the parameters:
    • n=2 tells the filter there are two input segments.
    • v=1 specifies that each segment has 1 video stream, resulting in 1 combined video output stream.
    • a=1 specifies that each segment has 1 audio stream, resulting in 1 combined audio output stream.
  4. Label the Outputs: [outv] [outa] are the custom names assigned to the resulting concatenated video and audio streams. You can name these anything you like (e.g., [v_merged] and [a_merged]).
  5. Map to the Output File: -map "[outv]" and -map "[outa]" instruct FFmpeg to select these specific filtered streams and write them to output.mp4. Without these mapping flags, FFmpeg may ignore the filtered streams or try to select default streams from the input files.