Joining multiple videos into one single video file:

mencoder -oac copy -ovc copy -o <Outputfilename.ext> <Video1> <Video2> …. <Videox>

Encoding a video with mencoder using xvid codec:
* First, rip the audio:
mencoder -oac mp3lame -lameopts mode=2:cbr:br=128:vol=0  -ovc frameno -o frameno.avi  QM.avi
Since a two-pass encoding is better, I have illustrated the same here:
* 1-st pass encoding:
mencoder -sws 2 -oac copy -ovc lavc  -lavcopts vcodec=mpeg4:vbitrate=700:vhq:vpass=1  -ffourcc XVID   QM.avi -o /dev/null
* 2nd pass encoding:
*mencoder -sws 2 -oac copy -ovc lavc  -lavcopts vcodec=mpeg4:vbitrate=700:vhq:vpass=2  -ffourcc XVID   QM.avi -o “QMech.avi”

A bitrate of 700kbps is suggested to get some good picture quality. It could vary depending on your choice. xvid is for now the best choice out there that is compatible with most of the players on the market. There is a more comprehensive webpage by Matt Sparks here which makes your job a cake-walk. The above process generates two extra files viz. divx2pass.log & frameno.avi. Delete these files so that they don’t interfere with your next project.
rm -rf divx2pass.log frameno.avi