How to merge video files under Linux

I generally dislike when movies are divided in two or more parts, although it’s just one more click to load 2nd or 3rd file, I prefer joining them together. Up until recently I was using avimerge tool fromtranscode package to do all of my merging, just because it was so simple to do with:

avimerge -i inputfile1.avi inputfile2.avi -o outputfile.avi

I’ve been doing this like so for a while, but more and more I keep getting out of sync audio, f.e. at some random point of the movie instead of normal audio I get audio from the 2nd CD so it’s completely out of sync and unfixable (if you don’t have the original files).

I found a better way of merging files, although a bit slower but it’s almost fail proof. Mencoder from the mplayer package was the best solution.

mencoder -oac copy -ovc copy inputfile1.avi inputfile2.avi -o outputfile.avi

This is the faster variant that works realy well, I’ve tested it on files thatavimerge could not join properly. But if you still get out of sync audio you can force mencoder to rebuild avi index like this:

mencoder -forceidx -oac copy -ovc copy inputfile1.avi inputfile2.avi -o outputfile.avi

Leave a Reply

Your email address will not be published. Required fields are marked *