How to use ffmpeg to combine multiple videos to one

Tired of the privacy invasion of the Chrome webbrowser? Worried about the risk of seeing ads everywhere? Give the Brave Browser a try. It supports all the same Chrome extensions, with none of the telemetry. It auto-blocks ads and helps support content creators like me.

Give the Brave browser a try »

Profile image of Mattias Geniar

Mattias Geniar, November 09, 2019

Follow me on Twitter as @mattiasgeniar

Here’s a quick tip on how to combine multiple separate videos into a single one, using ffmpeg.

First, create a text file that has the filenames for all your different fragments.

$ cat files.txt
file 'file 1.mkv'
file 'file 2.mkv'
file 'file 3.mkv'
file 'file 4.mkv'

All the files in files.txt will be concatenated to a single output file. Add/remove lines as needed.

Now, use ffmpeg to combine them all.

$ ffmpeg -f concat -safe 0 -i files.txt -c copy output.mkv
[matroska,webm @ 0x7fc2cb800600] Auto-inserting h264_mp4toannexb bitstream filter/s speed= 450x
frame=103454 fps=11333 q=-1.0 Lsize=  460025kB time=01:08:58.30 bitrate= 910.6kbits/s speed= 453x
video:398150kB audio:59680kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.479438%

The end result, if this was successful, is an output.mkv file that has all fragments combined.

Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.