Easily Encode your Videos / DVDs with MPlayer/Mencoder

This entry will show you how to easily encode videos with MPlayer / Mencoder. MPlayer is a good, free, open-source, cross platform player / encoder that can make a local copy of your DVDs and transcode your videos to a format your embedded player (iPod, Cowon D2, ...) can read.

Video Codecs:

First, I have to talk a little bit about video codecs. In a nutshell, there are two main formats in which you should consider encoding your videos:

1. Xvid: Free and open source, widely used, your dvd player can probably read/play the transcoded video files.

2. H.264 ~30% more efficient than Xvid, but not yet widely spread. You should probably not use this format yet unless you do not care about being able to read the files on your dvd player. I do not recommend this format, but it is the one I use for my personnal video library :P.

You can get MPlayer/Mencoder for your platform here.


These commands will encode / rip the video files into the Xvid format. To use other formats, please refer to the Mencoder documentation.

[For Windows] Once Mplayer / Mencoder is installed, go into the directory that contains the Mencoder.exe binary.

The you can use the following commands:

Normal Encode:

resize video (fixed):
mencoder input.avi -o output.avi −vf scale=500:375 -oac copy -ovc xvid -xvidencopts bitrate=1500

encoding video using mencode:
mencoder input.avi -o output.avi -oac lavc -ovc xvid -xvidencopts bitrate=1500
mencoder input.avi -o output.avi -oac lavc -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1500
mencoder input.avi -o output.avi -oac copy -ovc lavc -lavcopts vcodec=mjpeg:vbitrate=4000

join multiples files:
mencoder -oac copy -ovc copy -idx -o output.avi *.avi
cat a.avi b.avi > all.avi
(and then:)
mencoder -forceidx -oac copy -ovc copy all.avi -o all_final.avi

build slideshow from .jpg:
mencoder "mf://*.jpg" -mf fps=0.2 -vf scale=640:480 -o output.avi -ovc xvid -xvidencopts bitrate=1500

Rip DVDs:

keep original (mpeg-2) encoding:
mencoder dvd://1 -dvd-device D: -o out.avi -oac copy -ovc copy

orig.size, with compression:
mencoder dvd://1 -dvd-device D: -o out.avi -oac lavc -ovc xvid -xvidencopts bitrate=1500

resizing, with keeping aspect ratio (572 x abc):
mencoder dvd://1 -dvd-device D: -o out.avi −vf scale −zoom −xy 572 -oac lavc -ovc xvid -xvidencopts bitrate=1500

resizing, with keeping aspect ratio and reducing framerate:
mencoder dvd://1 -dvd-device D: -ofps 23 -o out.avi -vf scale -zoom -xy 320 -oac lavc -ovc xvid -xvidencopts bitrate=2000
mencoder dvd://1 -dvd-device D: -ofps 23 -o out.avi −vf scale −zoom −xy 572 -oac lavc -ovc xvid -xvidencopts bitrate=1500

resizing, force 640x480:
mencoder dvd://1 -dvd-device D: -o out.avi −vf scale=640:480 -oac lavc -ovc xvid -xvidencopts bitrate=1500

If you get error messages about the audio compression, just replace "-oac copy" by "-oac lavc" or "-oac mp3ame"

No comments: