What You Will Learn

Tested version: Verified with FFmpeg 6.1 (ubuntu-latest / CI-validated) Target OS: Windows / macOS / Linux


Comparing the Two concat Approaches

Criterionconcat demuxerconcat filter
SpeedFast (no re-encoding)Slow (re-encoding required)
Compatibility requirementSame codec and format requiredWorks with different formats
Number of input filesAny number supportedOne -i flag per input file required
File listRequires a text file (list.txt)Not required
Command complexitySimpleRequires filter_complex syntax

concat demuxer (Fast, Same-Format Files)

Overview

The concat demuxer lists file paths in a text file and joins them in order. It operates without re-encoding, making it very fast.

Creating the File List (list.txt)

The concat demuxer requires a dedicated text file. Create list.txt in the following format:

# Example list.txt (comment lines start with #)
file 'part1.mp4'
file 'part2.mp4'
file 'part3.mp4'

Creating it from the command line on Linux:

printf "file 'part1.mp4'\nfile 'part2.mp4'\nfile 'part3.mp4'\n" > list.txt

Creating it from Windows Command Prompt:

(echo file 'part1.mp4' & echo file 'part2.mp4' & echo file 'part3.mp4') > list.txt

Running the concat demuxer

ffmpeg -f concat -safe 0 -i list.txt -c copy output.mp4
OptionMeaning
-f concatUse the concat demuxer
-safe 0Disable safe path checking (required for absolute paths or special characters)
-i list.txtSpecify the file list as input
-c copyNo re-encoding (stream copy)

The concat demuxer command that uses list.txt is shown in a text block because it is skipped in automated CI testing.

Notes on Using concat demuxer


concat filter (Flexible, Supports Mixed Formats)

Overview

The concat filter in filter_complex can join files even when their formats or resolutions differ. Re-encoding is required, but it is a highly versatile approach.

Basic Command (Joining 2 Files)

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

Explaining the filter_complex Syntax

[0:v][0:a][1:v][1:a]concat=n=2:v=1:a=1[outv][outa]
PartMeaning
[0:v][0:a]Video and audio streams from the first input (index 0)
[1:v][1:a]Video and audio streams from the second input (index 1)
concat=n=2Join 2 segments (change to match the number of files)
v=1:a=1Output 1 video stream and 1 audio stream
[outv][outa]Output labels (referenced by -map)

Joining 3 Files

ffmpeg -i input1.mp4 -i input2.mp4 -i input.mkv -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

Set n=3 and list all stream pairs.

Joining with a Specified Codec

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]" -c:v libx264 -crf 23 -c:a aac output.mp4

Normalizing Resolution and Frame Rate

Even when using the concat filter, mismatched resolutions or frame rates can cause distortion in the joined video. It is recommended to normalize them beforehand using the scale and fps filters.

ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex "[0:v]scale=1280:720,fps=30[v0];[1:v]scale=1280:720,fps=30[v1];[v0][0:a][v1][1:a]concat=n=2:v=1:a=1[outv][outa]" -map "[outv]" -map "[outa]" -c:v libx264 -crf 23 -c:a aac output.mp4
Added FilterPurpose
scale=1280:720Normalize resolution
fps=30Normalize frame rate

Choosing the Right Method

Choose concat demuxer when:

Choose concat filter when:


Common Errors and Solutions

DTS ... out of order Error

Occurs when joining files with discontinuous timestamps using the concat demuxer. Change -c copy to -c:v libx264 -c:a aac.

Audio Goes Out of Sync

Occurs when frame rates or audio sample rates differ. Use the concat filter and normalize with the fps and aresample filters beforehand.

Specific Files Are Skipped

If file paths in list.txt contain spaces or special characters, verify that quoting is handled correctly.



Tested with: ffmpeg 6.1.1 / Ubuntu 24.04 (GitHub Actions runner) Primary sources: ffmpeg.org/ffmpeg-formats.html / ffmpeg.org/ffmpeg-filters.html / trac.ffmpeg.org/wiki/Concatenate