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.mp4Step-by-Step Breakdown
- Define the Inputs:
-i input1.mp4 -i input2.mp4loads the source files. In FFmpeg, the first input is index0, and the second is index1. - 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. - Configure the Concat Filter:
concat=n=2:v=1:a=1sets the parameters:n=2tells the filter there are two input segments.v=1specifies that each segment has 1 video stream, resulting in 1 combined video output stream.a=1specifies that each segment has 1 audio stream, resulting in 1 combined audio output stream.
- 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]). - Map to the Output File:
-map "[outv]"and-map "[outa]"instruct FFmpeg to select these specific filtered streams and write them tooutput.mp4. Without these mapping flags, FFmpeg may ignore the filtered streams or try to select default streams from the input files.