Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

share|improve this question
1  
Have you tried? –  Mr Lister Jul 25 '12 at 7:10
3  
I did actually. But somehow the result did not contain the second file although the file size was sum of both. –  Hamed Momeni Jul 25 '12 at 7:14

4 Answers 4

up vote 14 down vote accepted

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
share|improve this answer
1  
Nice answer. Thanks a lot. –  Hamed Momeni Jul 26 '12 at 7:40

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.

share|improve this answer

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 
share|improve this answer

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).

share|improve this answer
7  
Not 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
1  
How come I just did it successfully with DV files then? –  Pithikos Mar 17 '13 at 16:05
    
@Pithikos no idea. maybe you practice magic :) –  BЈовић Mar 18 '13 at 7:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.