Thursday, July 10, 2008

Rip DVDs To H.264 AAC/AVC Or Extremely High Quality XVID Under Linux

I wanted to be able to rip a DVD to play back on my PS3. To do this I chose two different encoding schemes. One of them will create a will create a 690MB file that will fit on a CD, and the other one a roughly 1.2 GB file that looks and sounds about as good as the original - both with surround that will sound great on a stereo setup.

I assume that these rips will work on most devices that support H.264 AVC/AAC such as XBOX 360 and Apple TV, but I haven't tried them.

Let's get started.

The Small Encode
Here, I use Handbrake. This GPL Open Source video encoder is perfect for several reasons, most notably: it handles DVD decryption, all of the major codecs and the MP4 container, and it can downmix surround sound to Dolby Pro Logic II surround (which takes up 1/3 as much space as standard surround with only a minor loss of spacial positioning and a front center channel). It decrypts copy protected DVDs under all platforms except windows. Windows users will want to also install this tool to make handbrake work properly.

This is the command I use to rip an H.264 AVC/AAC file usually around 500 MB that will play on the PS3 and looks extremely good. It will produce a stereo AAC file with a bitrate of 128. Nearly every surround sound receiver will properly decode the audio and play back surround sound.
HandBrakeCLI --longest -i /dev/dvd -o outputFile.mp4 -e x264 --vb 600 -E faac --ab 128 -f mp4 -m -2 -T --subtitle-scan --subtitle-forced --native-language eng -p -x frameref=5:bframes=16:b_pyramid:direct_pred=auto:weight_b:partitions=all:8x8dct:me=umh:mixed_refs:brdo:bime:trellis=1:nopsnr:nossim:subq=6:level_idc=41

The Alternate Quality Encode

Here's another method that will produce better quality audio. Personally, I prefer to use the H.264 setup with AAC dolby surround. The video quality is already about as good as you can get out of a DVD, but if you do see artifacts you could simply bump up the video bitrate. If you want better audio, just bump the audio bitrate. But, if you want to keep th 5.1 dolby digital audio track, here's how.

Most machines already have mencoder installed (it comes with mplayer). And, the PS3 can also ready MPEG4 files in an AVI container. So, here we are going to use mencoder to create an MPEG4 file that contains XVID encoded video and just copies the original AC3 Dolby Digital sound into the resulting file. The audio takes up quite a bit more space than the AAC encodes above because AC3 is not nearly as good at compressing audio and we are getting 6 descrete channels instead of two. In fact, a typical AC3 dolby digital track consumes a bit over 400 k/sec. And, because we're interested in quality, we're going to use some very aggressive parameters to get extremely high quality in a fairly small amount of space. The bonus is that any receiver with optical inputs will take the pure digital signal in and play the 5.1 track as if it were the original movie (make sure the PS3 is set up to output bitstream dolby digital). A 2 hour movie will be about 1.2 GB. On my dual core laptop, it takes 5 hours to encode 1 hour of video.

(Just change the first two lines to properly set your input and output file names)
mencoder "$INPUT" -ffourcc XVID -ovc lavc -lavcopts vpass=1:turbo:$OPTIONS -oac copy -channels 6 -o /dev/null
mencoder "$INPUT" -ffourcc XVID -ovc lavc -lavcopts vpass=2:$OPTIONS -oac copy -channels 6 -o "$OUTPUT"

One final note, if you are using a nice big TV to watch the videos, you will likely see blocks. This is because DVDs have film grain and noise that cover up a lot of the blocky artifacts in especially dark scenes. Handbrake will clean out the noise, and leave the blocks.

No comments:

Post a Comment


Bookmark and Share