How to use ffmpeg to combine multiple videos to one

Oh Dear! monitors your entire site, not just the homepage. We crawl and search for broken pages and mixed content, send alerts when your site is down and notify you on expiring SSL certificates.

Start your free 10 day trial! »

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.