Monday, February 15, 2010

Using Mencoder to Rip DVD into AVI/MKV/MP4 movies

Since I compiled MPlayer and Mencoder, I can use the programs for ripping DVD's as well as watching movies. Usually, I use SMPlayer frontend to play movies. Here I summarize how to make AVI, Matroska (.MKV) or MP4 files containing H.264 video and AAC audio.



First, download my Mplayer/Mencoder builds for Windows. MKVtoolnix is also needed.




Finding the Main DVD Title


In most cases, the first DVD title is the movie you want. Often, you can watch the feature title with the following command (Assuming D: is the DVD drive):


mplayer dvd://1 -dvd-device D:\ -ao dsound -vo directx:accel

For Windows Vista and Windows 7, direct3d is recommended as video output:


mplayer dvd://1 -dvd-device D:\ -ao dsound -vo direct3d

However, some DVD's have a feature title on a track other than the first. For such DVD's, trying each track can be tedious. The following command will help identify the main title on the DVD and also find information on available chapters and subtitles.


mplayer dvd://1 -dvd-device D:\ -identify -vf cropdetect > log.txt

Stop the movie after a moment (pressing q) and you'll get the log file log.txt. In the log.txt file, you'll find the main title to be the longest:


ID_DVD_TITLE_15_LENGTH=12.000
ID_DVD_TITLE_16_LENGTH=5513.533
ID_DVD_TITLE_17_LENGTH=0.500

Here, you find that the 16th title is the feature film.



Dumping the Feature Film from DVD


You can use MPlayer to save a DVD title on hard drive:


mplayer dvd://1 -dvd-device D: -v -dumpstream -dumpfile movie.vob

Now you can put aside your DVD. From now on, you can work with the VOB file saved on your hard drive. Alternatively, you can use VLC to dump a DVD title.



Finding Crop Values


If your DVD is widescreen (not fullscreen), look for the crop values from the log.txt file obtained above:


[CROP] Crop area: X: 0..719  Y: 60..417  (-vf crop=720:352:0:64).

In this example, the crop value will be 720:352:0:64. Note that the first two values (here 720 and 352) have to be divisible by 16.



Encoding DVD to an AVI file containing H.264 video and AAC audio


The following command actually creates an AVI file encoded in H.264:


mencoder dvd://1 -dvd-device E:\ -o movie.avi -oac faac -faacopts object=2:br=128 -vf pp=lb,filmdint,crop=704:464:6:10,scale=720:480,harddup -sws 8 -ofps 24000/1001 -ovc x264 -x264encopts crf=20:8x8dct:frameref=4:bframes=3:b_pyramid=normal:weight_b

The -vf scale= filter is used to resize the video stream. The output refresh rate will be 24000/1001=23.976 frames per second. If you're concerned with encoding speed, set bframes=2.



Encoding DVD to an AVI file containing DIVX video and MP3 audio


The following example shows how to create an AVI file encoded in MPEG-4. In the example below, the encoding bitrate is moderately 768 kilobits per second. The crop filter is only for widescreen titles.:


set VENCOPTS=vcodec=mpeg4:vbitrate=896:vmax_b_frames=2:mbd=2:v4mv:last_pred=3:trell:cbp
mencoder dvd://1 -dvd-device E:\ -o NUL -nosound -vf yadif=0,crop=704:464:6:10,scale=720:480,harddup -ovc lavc -lavcopts %VENCOPTS%:autoaspect:vpass=1
mencoder dvd://1 -dvd-device E:\ -o movie.avi -aid 128 -oac mp3lame -lameopts preset=128,aq=2,vol=8 -vf yadif=0,crop=704:464:6:10,scale=720:480 -ovc lavc -lavcopts %VENCOPTS%:autoaspect:vpass=2


Encoding Additional Sound Tracks


The following example command encodes the English sound track (aid 128) to +8dB-amplified 96kbps MP3:


mencoder dvd://1 -dvd-device D:\ -o audio-en.mp3 -of rawaudio -ovc frameno -aid 128 -oac mp3lame -lameopts preset=96,aq=2,vol=8

The following example encodes an AAC file:


mencoder dvd://1 -dvd-device E: -o audio-en.aac -of rawaudio -ovc frameno -aid 128 -oac faac -faacopts object=2:br=128

Another way to encode DVD audio is to save the sound as .WAV file and encode it with LAME MP3 encoder. First, extract the audio as .WAV file. Then, encode the .WAV file to MP3.


mplayer dvd://1 -dvd-device D:\ -vo null -vc null -aid 128 -ao pcm:fast:file=audio-en.wav
lame --preset tape -h audio-en.wav audio-en.mp3

Later, you can mux AVI:


mencoder.exe -ffourcc DIVX -oac copy -ovc copy -o final_movie.avi -audiofile audio-en.mp3 movie.avi


Editing Chapters.txt


In the log.txt file, you'll find a section that looks like:


CHAPTERS: 00:00:00,00:03:37,00:05:42,00:09:12,00:11:24,00:16:18,00:20:21,00:22:56,00:26:14,00:29:31,00:32:26,00:35:13,00:38:13,00:42:14,00:43:47,00:48:25,00:51:45,00:53:52,00:57:32,01:00:04,01:05:44,01:08:29,01:10:45,01:13:53,01:18:21,01:21:10,01:24:45,01:28:53,01:31:32,01:33:36,01:35:36,01:38:57,01:41:44,

With a text editor, create a text file chapters.txt and put something like:


CHAPTER01=00:00:00.00
CHAPTER01NAME=My name is John Connor.
CHAPTER02=00:03:37.01
CHAPTER02NAME=Weight of the future.
CHAPTER03=00:05:42.16
CHAPTER03NAME=T-X arrives.


Extracting Subtitles from DVD


If you look at the log.txt file gotten above, you'll find information on subtitles.


subtitle ( sid ): 0 language: en
ID_SUBTITLE_ID=0
ID_SID_0_LANG=en
subtitle ( sid ): 1 language: fr
ID_SUBTITLE_ID=1
ID_SID_1_LANG=fr
subtitle ( sid ): 2 language: es
ID_SUBTITLE_ID=2
ID_SID_2_LANG=es

To extract DVD subtitles, I ran the following command in the Command Prompt:


mencoder movie.vob -nosound -ovc frameno -o nul -sid 0 -vobsubout subtitle-en -vobsuboutindex 0 -vobsuboutid en

mencoder movie.vob -nosound -ovc frameno -o nul -sid 1 -vobsubout subtitle-fr -vobsuboutindex 1 -vobsuboutid fr

mencoder movie.vob -nosound -ovc frameno -o nul -sid 2 -vobsubout subtitle-es -vobsuboutindex 2 -vobsuboutid es

The sid and vobsuboutindex number can be obtained from the log.txt file above. Do this for each subtitle but remember to name each output file uniquely.



Creating a Matroska file with Mkvmerge


Let's put together the video, audio and subtitles into a Matroska package. For this task, a command-line tool mkvmerge from MkvToolNix project is used.


mkvmerge
--title "Holiday Trip" --chapters CHAPTERS.TXT -o my_movie.mkv
--aspect-ratio 0:4/3
--track-name 1:"English AAC audio" --default-track 1 --language 1:en movie.avi
--track-name 0:"French AAC audio" --language 0:fr audio-fr-51.aac
--language 0:en en.idx --language 0:fr fr.idx --language 0:es es.idx

If there's a problem with audio/video synchronization, use the --sync option with mkvmerge. For example, the following command makes the audio track start at 13 seconds after the video starts:


mkvmerge -o movie.mkv video.264 --sync 0:13000 audio.mp3


Creating .MP4 files


Use MP4Box to create a .MP4 movie.


MP4Box -add video.h264 -add audio-en.mp3:lang=eng -add audio-fr.mp3:lang=fre -add en.idx -add fr.idx -add es.idx -fps 23.976 -chap CHAPTERS.TXT movie.mp4


Related Links


No comments:

Post a Comment

About This Blog

KBlog logo This blog seeks to provide a collection of interesting pictures found on the Web. Thanks for visiting the blog and posting your comments.

© Contents by KBlog

© Blogger template by Emporium Digital 2008

Followers

Total Pageviews

Powered By Blogger