Help - Search - Members - Calendar
Full Version: Mencoder Dvd To Divx
Darkside_RG > Technical Discussions > Guides/How To > Video
syn-ack
DIVX/LAVC

mEncoder is a multipurpose encoding tool that comes with mplayer.


I have been playing about with mEncoder and have some options I am reasonably happy with.

I have been experimenting with both lvac and mEncoder.

These options are for a high quality DVD rip, which will fit on 2 cds.
Below are the steps I have taken to rip a dvd and encode it using mEncoder and the XviD codec.


(Optional)
Rip vobs to Hard disk
CODE
mplayer dvd://  -dumpstream -dumpfile dvd.vob



CROPPING

Run mplayer with the cropdetect option this gives us the values needed for cropping the movie.
The command below will seek to 360 seconds into the film and stop after 15 seconds so we are seeing the crop values for the movie.
CODE
mplayer dvd:// -vf cropdetect -ss 360 -endpos 15



A list of crop values for the movie are printed to the terminal so we can then pass to mEncoder.

EXAMPLE
CODE
[CROP] Crop area: X: 4..714  Y:  74..508 (-vf crop=704:432:8:76).0
[CROP] Crop area: X: 4..714  Y:  74..508 (-vf crop=704:432:8:76).0
[CROP] Crop area: X: 4..714  Y:  74..508 (-vf crop=704:432:8:76).0
[CROP] Crop area: X: 4..714  Y:  74..508 (-vf crop=704:432:8:76).0


The important values are the *:*:*:* values in brackets

EXAMPLE
CODE
704:432:8:76



These will change per dvd so you need to run this with every dvd.
Make a note of these values.


2 PASS LAVC

1ST PASS
CODE
mencoder -v "$input" -vf crop="$crop",scale="$scale" -ffourcc DX50 -ovc lavc -lavcopts \ vcodec=mpeg4:trell:psnr:vhq:mbd=2:qpel:v4mv:vlelim=-2:vcelim=-5:vpass=1:vbitrate="$bitrate":autoaspect \
-force-avi-aspect "$aspect" -alang en -ofps 25 -fps 25 -oac mp3lame -lameopts abr:br=128:vol=9 -o /dev/null


2ND PASS
CODE
mencoder -v "$input" -vf crop="$crop",scale="$scale" -ffourcc DX50 -ovc lavc -lavcopts \ vcodec=mpeg4:trell:psnr:vhq:mbd=2:qpel:v4mv:vlelim=-2:vcelim=-5:vpass=2:vbitrate="$bitrate":autoaspect \
-force-avi-aspect "$aspect" -alang en -ofps 25 -fps 25 -oac mp3lame -lameopts abr:br=128:vol=9 -o "$output"









lsdvd is a nice little tool to list the contents of a dvd from the command line. It will be in most linux/unix repositories.

CODE
lsdvd





INPUT

mEncoder to use the largest title on the dvd
CODE
dvd://


or

mEncoder uses title one on the dvd.
CODE
dvd://1


you may use a file instead
CODE
movie.mpg






CROPPING AND SCALING

This is our crop values taken from the cropdetect output above.
CODE
crop=704:432:8:76



This is the resolution, I scale to around 704:304 for 16/9 or 640x480 for 4/3
CODE
scale=704:304


I have use -sws 2 bicubic, can be better at lower bitrates. I have experimented with lanczos scaling (can be sharper) but am not as happy as I am with the bicubic.
(I expect my options just need tweaking)
CODE
-sws 2



MAINTAINING COMPATIBILITY

This sets our header to DIVX5 and not the default FMP4,
lavc is not compatible with divx4 so we use DX50 for avi header so it can be played under windows players (not vlc)using more exotic options(b-frames, qpel etc)

CODE
-ffourcc=DX50




LAVC OPTIONS



This tells mEncoder to use lavc and the options follow (seperated by a colon)
CODE
-ovc lavc -lavcopts




uses the mpeg4 codec
CODE
vcodec=mpeg4




Optimizes quantization process
CODE
trell




Print the PSNR (peak signal to noise ratio) for the whole video after encoding.
CODE
psnr




From the man page
"vhq tries to find a motion vector that minimizes the difference between the reference frame and the encoded frame
With this setting activated, Xvid will also use the frequency domain (DCT) to search for a motion vector that minimizes not only the spatial difference but also the encoding length of the block"
Clever searching to me :wink and recomeded in all documents I have read.
CODE
vhq




This encodes each macroblock multiple ways and chooses the best one, it improved visual quality noticeably and added to encoded time
(mbd=1 is the same as vhq)
CODE
mbd=2




Use four motion vectors per macroblock also increases quality, selects more precise motion estimation and works well with mbd.
CODE
v4mv




These options deal with heurstics when encoding blocks (recomended for live movies, remove for animation.)
Other possible recomended values to try are -3 -6 and -4 and 9
CODE
vlelim=-2

CODE
vcelim=-5




This option disables some of the more cpu hungry options on the first pass, speeding things up a bit.
CODE
turbo




Tells mencoder the pass which pass it is working on, 3 passes and higher can be used but the noticeable quality difference above 3 pass is minimal.
CODE
vpass=1

CODE
vpass=2




BITRATE

Bitrate to be used
CODE
vbitrate=1250





ASPECT

This preserves the aspect of the dvd and writes the information to the header, only mplayer takes any notice of this.
To have windows media player,vlc or xine play our movie at the correct aspect ratio we need to scale (as above) to an appropriate 16/9 or 4/3 resolution.

CODE
autoaspect


To force a specific aspect and can be used with -ovc copy to change aspect.
CODE
force-avi-aspect 16/9



LANGUAGE AND AUDIO

This option specifies the language code to use for the audio (english) otherwise we may end up with the directors commentary.

CODE
-alang en



Encodes the audio with the given audio codec (mp3)

CODE
-oac mp3lame -lameopts



Use an average bitrate of 128 for the audio track and boosts the volume.

CODE
abr:br=128:vol=9





OUTPUTFILE 1st PASS

This sends the output of the first pass to /dev/null A file (divx2pass.log) is created on the first pass containing information
about the input video file (movements colour information etc), this is read on the 2nd pass.

CODE
-o /dev/null




OUTPUTFILE 2nd PASS

This is the output file to use

CODE
-o Finished_Movie.avi




SCRIPT


Usage

Extract script
CODE
gzip -d dvd2xvid.gz


add execute permission
CODE
chmod +x dvd2xvid


run script
CODE
./dvd2xvid







You will be asked a set of questions


INPUT

input device = enter the file or device to use as input

For the largest title on the dvd.

CODE
dvd://


or the 3rd title on the dvd.
CODE
dvd://3


or a filename

CODE
/home/synack/movies/movie.vob


CODE
/home/synack/movies/movie.mpg




OUTPUT

output file = enter the desired output filename without an extension.

CODE
New_Movie.




BITRATE OR FINAL FILE SIZE

bitrate or final filesize = as explained above, using a negative value specifies an approximate file size.
adding a positive value uses the specified bitrate
Bitrate
CODE
1200

or
Approx Final File Size
CODE
-1250000




ASPECT RATIO

aspect ratio = enter 16/9 or 4/3

CODE
16/9




CROPPING AND SCALING

resolution = enter scaled resolution seperated by colons.

CODE
704:304



cropdetect will now be run, enter the values in the brackets seperated by colons.

CODE
688:432:18:68





Sit back and wait ssmile.gif




RANDOM MENCODER STUFF




OTHER VIDEO FILTERS

Deinterlace

for interlaced content,
I have used the -kerndeint and -lavcdeint on a dvb-t source and have found lavcdeint option a lot smoother.

CODE
-kerndeint
-lavcdeint
-pp=lb



noise filter (good for grainy source)
CODE
hqdn3d=2:1:2.



Optimize mencoder for cartoons.
CODE
cartoon



Global Motion Compensation for help with movies with lots of panning, zooming and rotating images.
CODE
gmc







MENCODER COMMAND LINES

Joining 2 files
CODE
mencoder -ovc copy -oac copy -o Joinedfilm.avi filmCD1.avi filmCD2.avi


Splitting a large file
CODE
mencoder large_file.avi -ss 0 -endpos 700mb -ovc copy -oac copy -o cut_file_Part1.avi

CODE
mencoder large_file.avi -ss 700mb -ovc copy -oac copy -o cut_file_Part2.avi



Fixing broken index and interleaving
CODE
mencoder -idx broken_file.avi -ovc copy -oac copy -o fixed_file.avi



Watch movie in ascii art
CODE
mplayer -vo aa:width=***:height=*** movie.avi



TESTING


These options are good for test encoding/playing part of a movie.

seek to 10 minutes into the input file

CODE
-ss 10:00


seek to 120 seconds into the input file

CODE
-ss 120



seek to 100mb into the film

CODE
-ss 100mb





end after 10 minutes

CODE
-endpos 10:00


end after 120 seconds

CODE
-endpos 120


end after 100 MB

CODE
-endpos 100mb






Verbose output

CODE
mencoder -v


CODE
mplayer -v



Another cool thing about this tool is that some of the options/switches are interchangable
for example

Will play track 1 on the dvd at a scaled resolution of 704x304, staring after 10 minutes and ending after 120 seconds.
CODE
mplayer dvd://1 -vf scale=704:304 -ss 10:00 -endpos 120


Will encode track 1 on the dvd at a scaled resolution of 704:304, staring after 10 minutes and ending after 120 seconds. (extra options needed)
CODE
mencoder dvd://1 -vf scale=704:304 -ss 10:00 -endpos 120








Have fun drinks.gif
syn-ack
Changed lots of options and updated explanations (may change a few more over the next few days)
Added basic script
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.