Is it possible to merge video files using `cat`?
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
There are two kinds of media files
streamable
non-streamable
The main difference is how the two file-formats embed meta-information. with non-streamable formats, the meta-informationc ("header") is stored at a specific position in the file, usually at the beginning, sometimes at the end. You cannot simply concatenate such files, as the meta-information from one of the files file will be in a non-standard location and thus be ignored.
OTOH, streamable formats need to be able to handle listeners that will start playing the file "somewhere in the middle". Therefore these formats keep re-sending the meta-information and even allow updating it within the file/stream. These formats can be simply concatenated.