How to concatenate two MP4 files using FFmpeg?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
With FFmpeg, concatenating MP4 files can be either fast and lossless or slower and more flexible. The right method depends on whether the input files are actually compatible. If the codec, resolution, frame rate, or audio layout differ, the simple copy-based method is likely to fail or produce broken playback.
Method 1: Concat Demuxer With No Re-encoding
Use the concat demuxer when the files already match.
Create a list file:
Then run:
This is the preferred method when it works because:
- it is fast
- it avoids quality loss
- it keeps CPU use low
The catch is that the streams must be compatible.
Check Compatibility First
Before assuming -c copy will work, inspect the inputs.
Compare at least:
- video codec
- resolution
- frame rate
- pixel format
- audio codec
- audio sample rate
If those differ, copy-based concatenation is the wrong tool.
Method 2: Concat Filter With Re-encoding
When the files differ, use the concat filter and encode a new output.
This is slower, but it handles mismatched inputs more safely because you are explicitly generating a new unified output stream.
Normalize Inputs When Needed
If one file has a different size or frame rate, normalize both first.
Then concatenate the normalized outputs.
This sounds like extra work, but it is often the cleanest way to avoid sync problems.
Watch Out for Missing Audio
If one clip has no audio track and the other does, concat commands that expect both audio streams can fail. In that case, either:
- add silent audio to the clip that lacks it
- or build a filter graph that matches the actual stream layout
Ignoring the mismatch is a common reason the command fails even when the video portion looks compatible.
Validate the Output
Do not assume success just because FFmpeg produced a file. Check duration and playback around the join.
Then test the boundary between clips in a media player. Seek there and verify:
- audio stays continuous
- there are no timestamp jumps
- the player does not freeze at the join
If the output is meant for web playback, you may also want a final remux step with -movflags +faststart so MP4 metadata is placed earlier in the file for progressive loading.
Common Pitfalls
- Using
-c copyon incompatible files and expecting FFmpeg to fix them automatically. - Forgetting to create the concat list file with the correct
file 'name'syntax. - Ignoring audio stream mismatches.
- Re-encoding with default settings and accidentally lowering output quality.
Summary
- Use the concat demuxer plus
-c copywhen the MP4 files are genuinely compatible. - Use the concat filter and re-encode when the inputs differ.
- Check stream properties with
ffprobebefore choosing the method. - Normalize inputs when needed instead of fighting mismatched streams.
- Always validate playback at the join point after concatenation.

