How to merge video files

by levien on zo 26 oktober 2008 // Posted in misc // under

How to merge/join/combine/concatenate multiple video files

Say you have a collection of short video clips made with a telephone or digital camera, and you want to join them into a single video file. How can you do this without having to re-encode everything?

In Ubuntu Linux:

What you have to do depends somewhat on the format of the files you have (MPEG, AVI, or other). To merge MPEG-files, either use mencoder or mpgtx. You can install these using apt-get or Synaptic. Mpgtx does not always produce usable output.

  • For MPEG-1 using MEncoder: mencoder -oac copy -ovc copy -of mpeg -mpegopts format=mpeg1 -o output.mpg input1.mpg input2.mpg input3.mpg
  • For MPEG-2 using MEncoder: mencoder -oac copy -ovc copy -of mpeg -mpegopts format=mpeg2 -o output.mpg input1.mpg input2.mpg input3.mpg
  • For either MPEG-1 or MPEG-2 using mpgtx: mpgjoin -o output.mpg input1.mpg input2.mpg input3.mpg
  • To merge AVI-files without re-encoding, you can also use mencoder (provided they are the same size and have been encoded using the same codec!): mencoder -forceidx -oac copy -ovc copy -of avi -o output.avi input1.avi input2.avi input3.avi
  • An alternative is to use the avimerge tool from the transcode package: avimerge -o output.avi -i input1.avi input2.avi input3.avi

If you want to merge other types of files, such as QuickTime (.mov), MJPEG, MP4 or 3GP, you may need the help of some extra tools, such as ffmpeg, avidemux or mjpegtools. See also: FFmpeg FAQ

  • To join MP4, 3GP/3G2 or other so-called IsoMedia files (based on the MPEG-4 part 14 specification), you can use the mp4box tool from the gpac package: mp4box -cat inputfile1.mp4 -cat inputfile2.mp4 output.mp4 (Thanks to Janis Mussat on video.ffmpeg.user for this tip.)
  • For QuickTime movies you may need to merge the files into a single AVI-file using mencoder, and then convert them back to a QuickTime file using ffmpeg. Something like: mencoder -oac copy -ovc copy -of avi -o output.avi\ ffmpeg -i output.avi -vcodec copy -acodec copy -f mov I don’t know if this will work though, I don’t have many QuickTime files to try this with…

In Windows:

  • To merge AVI-files, use virtualdub
  • To merge MPEG-files, use the multiplexer of TMPGEnc. Select File->MPEG Tools->Merge & Cut, select the output stream type and output file, add the files to be merged, and presto!