I wonder if it's possible to merge video files using the cat command? I mean will the resultant file play seamlessly?
- 441
- 2
- 7
- 14
-
1Have you tried? – Mr Lister Jul 25 '12 at 07:10
-
3I did actually. But somehow the result did not contain the second file although the file size was sum of both. – 2hamed Jul 25 '12 at 07:14
4 Answers
Yes, it is possible. But not all formats support it.
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
- 33,188
- 10
- 112
- 146
-
1Aren't you still creating intermediate files in the second version? – John Gowers Apr 13 '19 at 21:55
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.
- 6,300
- 1
- 24
- 48
-
For example, ogg: http://stackoverflow.com/questions/27980960/how-to-lossless-concatenate-ogg-vorbis-files – BlackShift Mar 08 '16 at 07:42
As BЈовић said, in general, each file has its own header. Try with this example from Ubuntu How To's:
mencoder -ovc copy -oac copy video1.avi video2.avi -o completevideos.avi
- 121
- 5
No, it is not possible, because every video file has a header. To merge videos you need to use a tool (like for example ffmpeg or mencoder).
- 600
- 1
- 8
- 20
-
9Not quite correct. There are video formats without header, e.g. rawvideo or yuv4mpegpipe which output raw data. That's why you have to provide the frame size when reading those formats, since the size is unknown due to the missing header. – Marco Jul 25 '12 at 13:24
-
2
-
1