This will create a video.avi file containing the video. You can play with the -x264encopts options and the -vf filters to improve the quality or reduce the file size. For example, a movie with a black border should be cropped with -vf crop=$X:$Y,scale=-1:-10,harddup with the proper values instead of $X and $Y (see cropdetect in the MEncoder manual). You may want to scale down the movie with -vf scale=$WIDTH:-10,harddup the width of the movie will become $WIDTH (keep $WIDTH a multiple of 16: 640, 480, or 320 are usually fine), the height will be correctly calculated in order to keep the aspect ratio.

You can also use any other of the filters MEncoder has to offer, like pullup,softskip or you can change the frame rate using -ofps. (If you do so, remember to use the same frame rate everywhere including in the commands to rip audio.)

It is important that you use harddup as the last filter: it will force MEncoder to write every frame (even duplicate ones) in the output. Also, it is necessary to use scale=$WIDTH,-10 with $WIDTH as -1 to keep the original width or a new, usually smaller, width: it is necessary since the H.264 codec uses square pixels and DVDs instead use rectangular pixels.

Ripping and encoding the audio

You can extract audio tracks as needed. Here we compress with the Vorbis algorithm, but you may want to check the MEncoder manual
in order to see alternatives.

You should repeat the command for every audio track you want, so we will have .avi files with the audio track.

You may also want to use -channels 6 to exact all the channels of a 5.1 DVD or changing the bit rate. As with the video, you can use audio filters via -af but it is not necessary.

Making the final .mkv file

Putting it all together in a single file is simple. Add other audio tracks if needed:

mkvmerge -D audio.avi -A video.avi -o mymovie.mkv

The .mkv file will contain everything, so you can store your movie keeping all the audio track you want. Even if you are not interested in keeping multiple sound tracks, the H.264/Vorbis format pair should ensure great quality.

Of course to make the work easier, you should write every command in a single file and execute it.

After the 2nd pass is done, copy the video.mp4 to nokia 5800 xm or n97's memory card and open the file using file manager of nokia after removing the device from the computer.

we need to run the above two commands in the folder where video.avi is present. play around with abitrate, vbitrate, and scale values to get video quality and size of your liking. alternate formatfactory is a mencoder gpl application for windows which runs in wine, can also convert all-to-mp4.

scale=640:-3 will try to keep the video width to 640 and resize the video height accordingly. Do use the "original" aspect in nokia's mp4 player "option->aspect" for 16:9 and 4:3 aspect ratio videos.

Encoding a multi audio / multi language MKV video to an MP4 with different audio streams

to encode multi-audio file to mp4 we need to use the "-aid <audio stream number>" like -map 0:1 in ffmpeg)