FFmpeg concatenate video files

FFmpeg can losslessly (without reencoding) concatenate videos, even in different container formats, as long as the codec is the same. If the codec is different between files (H.264 vs. FFV1) then you would instead need to reencode.

This method can be used for YouTube video uploads, where you want to join small video files into one big file without bothering with a video editor.

Concatenate same codec videos

This example assumes you have MP4 videos to concatenate. If you’re on Windows, you will need Windows Subsytem for Linux.

Create a specially formatted file listing files to convert.

for f in ./*.mp4; do echo "file '$f'" >> flist.txt; done

Concatenate:

ffmpeg -f concat -safe 0 -i flist.txt -c copy out.mp4

This produces out.mp4, which will be close to the sum of the file sizes. It’s not precisely the same number of bytes as the sum of the files, perhaps due to timestamping and metadata differences.

Notes

  • -pattern_type glob -i '*.mp4' does NOT work because that’s for the input filter image2 ONLY!
  • FFmpeg concatenate