Join multiple AVI or MPEG videos into a single file with mencoder

I have some videos I wish to concatenate into a single one, without re-encoding.

It’s very easy with mencoder.

If they are avi:

mencoder -forceidx -ovc copy -oac copy part1.avi part2.avi part3.avi -o total.avi

-forceidx forces to rebuild the index, for seeking.

But if they are MPG files i should use the MPEG container (mencoder uses avi as default, regardless of file extension)

mencoder -forceidx -of mpeg -noskip -mc 0 -ovc copy -oac copy part1.mpg part2.mpg part3.mpg -o total.mpg

The mencoder manual advises the use of -noskip -mc 0 when muxing mpeg files.
For MPEG1 format this has to be specified, because MPEG2 is the default:

mencoder -forceidx -of mpeg -noskip -mc 0 -mpegopts format=mpeg1 -ovc copy -oac copy part1.mpg part2.mpg part3.mpg -o -o total.mpg