Is it possible to merge video files using `cat`

catmultimediavideo editing

I wonder if it's possible to merge video files using the cat command? I mean will the resultant file play seamlessly?

Best Answer

Yes, it is possible. But not all formats support it.

ffmpeg FAQ:

A few multimedia containers (MPEG-1, MPEG-2 PS, DV) allow to join video files by merely concatenating them.

When converting to RAW formats you also have a high chance that the files can be concatenated.

ffmpeg -i input1.avi -qscale:v 1 intermediate1.mpg
ffmpeg -i input2.avi -qscale:v 1 intermediate2.mpg
cat intermediate1.mpg intermediate2.mpg > intermediate_all.mpg
ffmpeg -i intermediate_all.mpg -qscale:v 2 output.avi

But using cat in this way created intermediate files, which are not necessary. This is a better approach to avoid creating those intermediate files:

ffmpeg -i input1.avi -qscale:v 1 intermediate1.mpg
ffmpeg -i input2.avi -qscale:v 1 intermediate2.mpg
ffmpeg -i concat:"intermediate1.mpg|intermediate2.mpg" -c copy intermediate_all.mpg
ffmpeg -i intermediate_all.mpg -qscale:v 2 output.avi
Related Question