Xinn.org

Security and Sanity Solutions.

 

Linux DVD Ripping Guide

Using Mplayer and Mencoder

 

So you want to rip some DVD's to your hard drive, it's not very hard, but takes time. I caught on pretty fast

so it shouldn't be much of a problem for others.  

I am using Fedora Core2 for all examples, 2 GHz p4 generic DVD drive.

Please Visit: http://www.mplayerhq.hu/homepage/ to DL the rpm's or you can build it from source if you feel so inclined.  Or from the GreySector site which has the latest rpm's for various linux iterations. http://luna.cs.ccsu.edu/dominik/mplayer/

Installation (one line):

rpm -Uvh mplayer-common-1.0pre6-1.i386.rpm mplayer-gui-1.0pre6-1.i386.rpm mplayer-skin-default-1.0-2.noarch.rpm lame-libs-3.96.1-1.i386.rpm

NOTE: There are circular dependencies, so you must install them all at once

http://ftp.icm.edu.pl/pub/linux/mplayer-rpms/mplayer.html This page had the mencoder if you can't find it elsewhere.

Also links to the codec's and other plug-ins you may desire. I installed an optimized version of Mencoder here: http://ftp.icm.edu.pl/pub/linux/mplayer-rpms/apt/7.3/RPMS.testing/

You will need the following also installed:

Libavcodec

Win32 codec's

DivX4/DivX5 http://www.divx.com/divx/linux/

XviD

Those are the best of the best in my opinion, but we'll be working with Divx almost exclusively in this lesson. You'll need Libavcodec

and DivX4 or DivX5 and XviD. http://www.mplayerhq.hu/DOCS/HTML/en/install.html for complete details. 

Ok, I'll assume the RPM's installed, and you have the codec's above installed fine.

Some of the tutorials I've seen on the net have you copying the files (*.vob) to the HD, and then ripping them, it's not much faster in my experience, scripting the rips is really the only benefit, so we'll rip direct off the DVD. In addition the vob files are divided up into 2 gig chunks, so your left with 4 DVD-NAME#.vob files. If you wanted to do very high quality rip's, I can see the benefit of having 50 or 60 minutes on a CD but the quality isn't of the greatest concern to me. I don't need a DVD quality CD, or avi file' I want something small, and that still looks very good, but I can deal with a little grainy-ness, I have the DVD already! If I want DVD quality, I'll play the DVD my laptop doesn't have a DVD drive, and I am poor, so a burned avi of a DVD is fine by me.  

There are a few things you may need to consider, if your DVD is widescreen with the 16x9 aspect ratio (or similar aspect), or if you're using the full screen. Typically DVD's are 2 sided for that purpose, full or widescreen. 

The first pass will encode the audio and video to an avi file, or you can set the output to /dev/null since the second pass will be a much better quality

The first pass writes the divx2pass.log file, which is a bunch of info for the second pass to use- to help it encode motion and other places the video is complex. 

mencoder dvd://1  -ofps 23.976 -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell:vbitrate=1000:vpass=1 -oac copy -o /dev/null

Dvd://1 is the first track

Ofps 23.976 is a typical framerate of NTSC dvd's

Out put video codec is lavc and it's options are use mpeg4 with a variable bit rate that equals 850 at very high quality (mbd=2) and this video pass is the first.

Output audio codec copy output to /dev/null (the bit bucket, nothingness) 

Now once that is done, you'll have the divx2pass.log created.

mencoder dvd://1  -ofps 23.976 -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell:vbitrate=1000:vpass=2 -oac copy -o movie.avi

Everything is the same except the Pass=2 and the output is a real filename of your choosing (movie.avi for example).

That's it! You should have a nice movie all set. 

EXAPMLES:

Lord OF The Rings- The Two Towers Special Edition (the 4 cd box set)

This DVD was wide screen, and so I wanted to chop off the black bars at the top and bottom, and make it more full screen,

So I played the DVD with this command to find the crop I should use. Make sure you play any DVD that has the full screen black bars for a few minutes, and make sure you will use the right ratio through-out. Because the first minute or more may just be a full screen PARAMOUNT PICTURES, NEW-LINE CINEMA intro.

Mplayer -vop cropdetect dvd://1

If cropping off the black bars is desired on a widescreen dvd, be sure you use the crop when extracting the audio, it actually helps so sync up video and audio, it took me a long time to figure that out dozens of dvd's were ripped and the sound was off, except on the dvd that I didn't crop so I finally figured it out.

 

Disc1

mplayer -vop cropdetect dvd://1 -v (crop detect, and show verbose output)

mencoder dvd://1 -ofps 23.976 -ovc lavc -lavcopts vcodec=mpeg4:trell:vbitrate=700:mbd=2:vpass=1 -vf crop=716:362:2:58 -oac mp3lame -lameopts vbr=3 -o /dev/null

mencoder dvd://1 -ofps 23.976 -ovc lavc -lavcopts vcodec=mpeg4:trell:vbitrate=700:mbd=2:vpass=2 -vf crop=716:362:2:58 -oac mp3lame -lameopts vbr=3 -o LOTR-TT-d1.avi

(total rip time for the DVD was 4 hrs, start to finish, the next disc was about the same)

Love Hena (the 3 cd box set)

My friend brought this to me, wanting to brush up on his Japanese he asked if it could be done, I told him yes, and ripped them. What he wanted was English subtitles, but the Japanese voices. It was pretty simple, and no cropping was needed.

mencoder dvd://2 -ofps 23.976 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=900:mbd=2:vpass=1 -slang jp -sid 2 -oac mp3lame -lameopts vbr=3 -o /dev/null

mencoder dvd://2 -ofps 23.976 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=900:mbd=2:vpass=2 -slang jp -sid 2 -oac mp3lame -lameopts vbr=3 -o Love-Hena-D1.avi

(total rip time for the first DVD was 3.5 hrs, start to finish, the next two disc's were about the same) This DVD actually defaulted to English as the language, as it was a region 1 dvd, made for the US market. If audio track 0 was Japanese, I wouldn't of used the -slang jp (or I could of used -aid 129 instead of slang) Another thing to note, the first track wasn't the main video track for the first DVD, track 1 was a short preview clip, and track 2 was the video I needed, but the other disc's track 1 (dvd://1) was the video it's always something. Worth noting, there are Closed Caption (CC) subtitles on many Region1 DVD's, they are encoded in the VOB userdata streams on some DVD's, use the -subcc switch to view them, the verbose switch cannot detect these as they are in a stream, not stored separately.

In Living Color (Season 1- 3 Disc's)

I noticed that this video was interlaced, so you have to rip these using the -vf pp=md options. This is also an example of how to rip raw VOB files. I used vobcopy from this site:

http://lpn.rnbhq.org/projects/c/c.shtml

Vobcopy /mnt/dvd /dir-of-your-choosing (vobcopy /dev/dvd . or vobcopy /mnt/dvd . or even vobcopy /dev/dvd /home/user) (you may have to be root to use vobcopy)

That will grab the raw VOB data and store it in the directory of your choosing. It created the following files for me:

INLIVINGCOLOR_S1_D11-1.vob (inlivingcolor season 1 disc 1, vob 1)

INLIVINGCOLOR_S1_D11-2.vob (inlivingcolor season 1 disc 1, vob 2)

INLIVINGCOLOR_S1_D11-3.vob (inlivingcolor season 1 disc 1, vob 3)

Now you have to CAT the files, and pipe them through mencoder- the real difference is you don't specify dvd://1 anymore, and you HAVE TO PLACE A DASH at the end of the command.

cat INLIVINGCOLOR_S1_D11*.vob | mencoder -vf pp=md -ovc lavc -lavcopts vcodec=mpeg4:trell:vbitrate=840:mbd=2:vpass=2 -oac mp3lame -lameopts vbr=3 -o InLivingColor-S1-D1.avi

Something I hadn't mentioned before was the trell option- it's in all the examples, but I didn't define it for you

Trell= Trellis searched quantization. This will find the optimal en-coding for each 8x8 block. Trellis searched quantization is quite simple a optimal quantization in the PSNR vs bitrate sense (assuming that there would be no rounding errors introduced by the IDCT, which is obviously not the case) it simply finds a block for the minimum of error and da*bits.

Trell should be used even in regular dvd rips. This site has some great research on mencoder and it's different tweaks:

http://www.ee.oulu.fi/~tuukkat/mplayer/tests/

Invader Zim:

This DVD was setup very weird also Track 4, chapter 8 starts this one off- the other stuff was Director Comentary and behind the Scenes stuff. Also this was very interlaced, as many TV shows that are ported to DVD are, espically cartoons.

I did the following to start grabbing this DVD rip:

mencoder dvd://4 -aid 128 -chapter 8-9 -vf pp=md -ovc lavc -lavcopts vcodec=mpeg4:v4mv:trell:vbitrate=780:mbd=2:vpass=1 -oac mp3lame -lameopts vbr=3 -o Bestest-Friend.avi

mencoder dvd://4 -aid 128 -chapter 10-11 -vf pp=md -ovc lavc -lavcopts vcodec=mpeg4:v4mv:trell:vbitrate=780:mbd=2:vpass=1 -oac mp3lame -lameopts vbr=3 -o NanoZim.avi

I actually only did one pass on each of these since it looked pretty good after the one pass.

http://www.ee.oulu.fi/~tuukkat/mplayer/tests/deinttest2/readme.html

Problems I've run into and their corrections:

 The first audio track (track 0, typically called -aid 128) on the DVD is the director or commentary track. This is easy to get around, but can be frustrating if you do not listen the dvd before ripping. Play the dvd with Mplayer and specify -aid 128 first before ripping.

If you need or want a different audio track, use Mplayer to find the correct one by using the verbose mode

Mplayer -v dvd://1

Mplayer will list a very verbose list of what it's doing and seeing, the audio track listing will look like this:

DVD successfully opened.

[open] audio stream: 0 audio format: ac3 (5.1) language: en aid: 128 (while mplayer can't tell you which track is which, the Directors commentary can be on the first audio track 128 that is.)

[open] audio stream: 1 audio format: ac3 (stereo) language: en aid: 129 (English)

[open] audio stream: 2 audio format: ac3 (stereo) language: fr aid: 130 (French)

[open] audio stream: 3 audio format: ac3 (stereo) language: en aid: 131

[open] audio stream: 4 audio format: ac3 (stereo) language: en aid: 132

[open] number of audio channels on disk: 5.

[open] subtitle ( sid ): 0 language: en

[open] subtitle ( sid ): 1 language: es

[open] subtitle ( sid ): 1 language: fr

[open] number of subtitles on disk: 3

 

To listen/rip the correct audio, add the -aid xxx to the command. For instance

To play:   mplayer -aid 129 dvd://1         

To rip fullscreen do:    mencoder dvd://1 -ovc frameno -aid 129 -oac mp3lame -lameopts abr=128 -o frameno.avi

Remember if cropping, to get the audio right, run the crop on both pass's.

To rip and crop do:    mencoder dvd://1 -vf crop=XXX:XXX:X:X -aid 129 -ovc frameno -oac mp3lame -lameopts abr=128 -o frameno.avi (remember to replace XXX:XXX:X:X with your detected crop)

The director commentary popped up on a few dvd's as track 0 (aka aid 128) for me, Dusk Til Dawn, Desperado and Donnie Darko maybe it's just the Dvd's that use D's a lot in the tittle J

 

ERROR

-ratecontrol.c:XXX :ff_rate_estimate_qscale picture_number<rcc->num_entries

XXX being some number that varies from error to error.

This was due to me using the wrong or corrupt divx2pass.log, only occurred on the second pass, as it should of.

 Audio out of sync using mencoder.

This one was a quick and easy fix. Avisync is part of the transcode tool set http://zebra.fh-weingarten.de/~transcode/

avisync -i Your-UnSynched.avi -o Synched.avi -n X (or -X)                     (X being a value of 1 or more, I've never used over 5 (5 frames out of sync that is)

Or

avisync -i Your-UnSynched.avi -o Synched.avi -n -X                     (Use the minus for sounds that happen before an action)

The -i = input file, the -o = output the -n number of frames to pad (positive number) or subtract (negative number)

Use a positive number if the lips are moving for a few frames, and then the audio comes in looks sort of like a Kung-Fu movie that way.

With the minus, if the sound lags before an action, like the lips moving or a car door slamming, sound before the action- still looks like Kung-Fu.

 X is the amount of frames to shift the audio by. Don't erase the old out of sync avi until you're sure the new one is correct.

Again, the minus is when there is a sound before the action, and the positive number is when the action comes but the sound is lagging behind it.

 

Also, you may need to symlink dev/dvd so it's easier to play things

For example : ln -s /dev/hdd /dev/dvd

/dev/hdd is the dvd drive, and /dev/dvd is what Mplayer is looking for by default.

Splitting Videos using Mencoder

It's pretty simple really specify a start point if need be, and an end point use the -oac copy and -ovc copy command

Mencoder movie.avi -ss 00:04:36 -aoc copy -ovc copy -endpos 00:02:47 -o movie-out.avi

-ss Start at this position (given in hours:minutes:seconds 00:00:00)

-endpos End so many hours:minutes:seconds after start position (this number might be smaller than the start position, again it's the end position in time after the start position, so if your start position was 4minutes 36seconds, and your end position is 2minutes and 47 seconds after the start position, your number will look negative- well in my mind it did)

Other examples of splitting avi's:

Mencoder movie.avi -aoc copy -ovc copy -endpos 00:04:35 -o movie-out.avi

(This will begin where movie.avi begins, and end at 4:35)

Mencoder movie.avi -ss 00:04:36 -aoc copy -ovc copy -o movie-out.avi

(This will start at 4:36 and end when the movie.avi file ends)

Xinn.org

Security and Sanity Solutions.