Here’s how you may convert .mkv (Matroska) files to avi files, generates pretty large files though so you may have to add some restrictions (bitrate etc.)

mencoder $input -oac mp3lame -ovc xvid -xvidencopts pass=1 -o $output

Wheres $input is the mkv file and $output is the avi file.