Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
Have you tried? – Mr Lister Jul 25 '12 at 7:10
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
up vote 17 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
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
For example, ogg: stackoverflow.com/questions/27980960/… – BlackShift Mar 8 at 7:42

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

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

Your Answer


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.