SysTutorials

How to Concatenate Multiple Video Files on Linux

· updated April 12, 2026

When you need to combine multiple video files (like video1.mp4, video2.mp4, and video3.mp4) into a single output file, FFmpeg is the standard tool on Linux. It’s faster, more reliable, and better maintained than older tools like mencoder.

Using FFmpeg with the Concat Demuxer

The most robust approach uses FFmpeg’s concat demuxer, which properly handles file sequences without re-encoding.

First, create a text file listing your videos (concat_list.txt):

file 'video1.mp4'
file 'video2.mp4'
file 'video3.mp4'

Then concatenate with:

ffmpeg -f concat -safe 0 -i concat_list.txt -c copy output.mp4

The -c copy option copies streams without re-encoding, preserving quality and speed.

Important notes:

Quick Concatenation with the Concat Protocol

For files with identical properties, you can use the concat protocol directly:

ffmpeg -i "concat:video1.mp4|video2.mp4|video3.mp4" -c copy output.mp4

This is faster but less reliable if files have any property differences.

Re-encoding When Necessary

If your source files have mismatched codecs or resolutions, you’ll need to re-encode:

ffmpeg -f concat -i concat_list.txt -c:v libx264 -preset fast -crf 23 -c:a aac output.mp4

This example uses H.264 video and AAC audio with moderate quality. Adjust -crf (0-51, lower is better) and -preset (ultrafast to veryslow) based on your needs.

Handling Different Container Formats

If you’re mixing formats (.avi, .mkv, .mp4), first convert them to a common format:

ffmpeg -i video1.avi -c copy video1.mp4
ffmpeg -i video2.mkv -c copy video2.mp4

Then concatenate the converted files using the concat demuxer.

Common Issues

Audio sync problems: Re-encoding both video and audio together usually resolves this:

ffmpeg -f concat -i concat_list.txt -c:v libx264 -c:a aac output.mp4

File path errors: Use absolute paths or -safe 0:

ffmpeg -f concat -safe 0 -i concat_list.txt -c copy output.mp4

Duration detection fails: Some formats need explicit re-encoding rather than stream copying, especially for certain AVI or MKV files.

Installation

FFmpeg is in all major Linux distributions:

# Debian/Ubuntu
sudo apt install ffmpeg

# RHEL/CentOS/Fedora
sudo dnf install ffmpeg

# Arch
sudo pacman -S ffmpeg

For best results with modern codecs and hardware acceleration, ensure you have a recent FFmpeg build (4.4+).

Troubleshooting Common Issues

When encountering problems on Linux systems, follow a systematic approach. Check system logs first using journalctl for systemd-based distributions. Verify service status with systemctl before attempting restarts. For network issues, use ip addr and ss -tulpn to diagnose connectivity problems.

Package management issues often stem from stale caches. Run dnf clean all on Fedora or apt clean on Ubuntu before retrying failed installations. If a package has unmet dependencies, try resolving them with dnf autoremove or apt autoremove.

These commands are frequently used alongside the tools discussed in this article:

Quick Verification

After applying the changes described above, verify that everything works as expected. Run the relevant commands to confirm the new configuration is active. Check system logs for any errors or warnings that might indicate problems. If something does not work as expected, review the steps carefully and consult the official documentation for your specific version.

← All posts