Howto: Encode video files with mencoder

Can you believe how hard it is to find a quick cheat sheet for using mencoder (included with mplayer) to encode various video formats? These should work on any platform that is supported by mplayer (*nix, windows, os x). I figured almost everyone will want to encode to some avi container-based format, and encoding to other formats is outside the scope of this article (there are far too many options for the different codecs to cover here). What this will help with, is encoding FROM any of those nonsense crazy formats to the very reasonable, and open source XviD codec. Most information will work with any other input format (simply change from big_file-worthless.mkv to big_file-worthless.mpg or big_file-worthless.asf, etc.) Extracting subtitles and different audio tracks is Matroska specific, but that's what I needed to do so that's the example you're getting!

Get a Sample (start at 5:00 and record until 13:00)
-------------------------------------------------------

mencoder movie.wmv -o movie.avi -ovc lavc -oac mp3lame -ss 5:00 -endpos 8:00

Matroska Video (.mkv) --> XviD (.avi)
-------------------------------------------------------

mencoder big_file-worthless.mkv -oac mp3lame -ovc xvid -xvidencopts pass=1 -alang en -slang en -sub subtitles.srt -o it's_a_good_size.avi
mencoder big_file-worthless.mkv -oac mp3lame -ovc xvid -xvidencopts pass=2:bitrate=800 -alang en -slang en -sub subtitles.srt -o it's_a_good_size.avi

Extract Subtitles/Audio (Track 4/3) from Matroska Video
-------------------------------------------------------

emerge mkvtoolnix (only on gentoo linux-based systems, figure it out for your own platform)
mkvmerge -i movie.mkv
mkvextract tracks movie.mkv 3:audio.ogg 4:subtitles.srt