What You Will Learn
- The differences between the two concat approaches (demuxer vs. filter) and how to choose
- Fast concatenation with the concat demuxer (text file method)
- Flexible concatenation with the concat filter (
filter_complex) - Things to watch out for when joining files with different frame rates or resolutions
Tested version: Verified with FFmpeg 6.1 (ubuntu-latest / CI-validated) Target OS: Windows / macOS / Linux
Comparing the Two concat Approaches
| Criterion | concat demuxer | concat filter |
|---|---|---|
| Speed | Fast (no re-encoding) | Slow (re-encoding required) |
| Compatibility requirement | Same codec and format required | Works with different formats |
| Number of input files | Any number supported | One -i flag per input file required |
| File list | Requires a text file (list.txt) | Not required |
| Command complexity | Simple | Requires 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
| Option | Meaning |
|---|---|
-f concat | Use the concat demuxer |
-safe 0 | Disable safe path checking (required for absolute paths or special characters) |
-i list.txt | Specify the file list as input |
-c copy | No re-encoding (stream copy) |
The concat demuxer command that uses list.txt is shown in a
textblock because it is skipped in automated CI testing.
Notes on Using concat demuxer
- All files must share the same codec, resolution, and frame rate
- Mismatched formats can cause audio/video desync or errors
- Without
-safe 0, files with non-relative paths will error
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]
| Part | Meaning |
|---|---|
[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=2 | Join 2 segments (change to match the number of files) |
v=1:a=1 | Output 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 Filter | Purpose |
|---|---|
scale=1280:720 | Normalize resolution |
fps=30 | Normalize frame rate |
Choosing the Right Method
Choose concat demuxer when:
- All files share the same codec and resolution
- You have many files and want fast concatenation without re-encoding
- You are joining homogeneous data such as split recording files
Choose concat filter when:
- Files have different codecs or resolutions
- You want to specify files dynamically in a script (no list file needed)
- You want to directly join trimmed results
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.
Related Articles
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