Encoding DVDs to Matroska + x264

From FedoraJunkies

Jump to: navigation, search

The following is a how to backup a DVD to a high quality x264 encased in the Matroska container:

Contents

Extract Audio

Determine what audio source you would like to rip, I recommend the ac3 5.1 source as often as possible for the best sound quality.

mplayer -v -frames 0 dvd://1 2> /dev/null |grep aid

Which should output a list of the audio channels on your DVD:

audio stream: 0 format: ac3 (5.1) language: en aid: 128.
audio stream: 1 format: dts (5.1) language: en aid: 137.
audio stream: 2 format: ac3 (stereo) language: es aid: 130.
audio stream: 3 format: ac3 (stereo) language: fr aid: 131.
audio stream: 4 format: ac3 (stereo) language: en aid: 132.
audio stream: 5 format: ac3 (stereo) language: en aid: 133.

As mentioned above, ac3 is the best source (in my opinion) so let's grab that (aid = the corresponding aid above):

mplayer -dvd-device "/dev/sr0" dvd://1 -aid 128 -dumpaudio -dumpfile audio_0

Determine Crop Rate

To remove the black bars around the movie we need to determine the crop rate:

mencoder -nosound -nocache -ovc lavc -vf cropdetect -o /dev/null dvd://1

The above should output your crop settings, e.g.

[CROP] Crop area: X: 90..629  Y: 60..414  (-vf crop=528:352:96:62).371:0]

Encode video, pass #1

Run the first pass of ripping the DVD - Title #1 is assumed, however if you have a multi title dvd make sure you select the appropriate title you want to rip:

mencoder dvd://1 -ovc x264 -nosound -sws 2 -vf crop=528:352:96:62,pullup,softskip,harddup -x264encopts bitrate=5000:threads=4:pass=1 -o /dev/null

Change crop=xxx:xxx:xx:xx to whatever your crop rate was detected as

Encode video, pass #2

mencoder dvd://1 -ovc x264 -nosound -sws 2 -vf crop=528:352:96:62,pullup,softskip,harddup -x264encopts bitrate=5000:threads=4:pass=2 -o video.mp4

Extract Subtitles

mencoder -dvd-device "/dev/sr0" dvd://1 -nosound -ovc copy -o /dev/null -vobsubout sub_0 -vobsuboutindex 0 -sid 0

Mux Audio + Video into Matroska

mkvmerge --title "Movie Title" --language 0:eng sub_0.idx --language 0:eng audio_0 -A video.mp4 -o "Movie.Title.mkv"
Personal tools