[MEncoder-users] ripping dvd to matroska and h.264
Matyas Sustik
mplayer.list at sustik.com
Sun Apr 19 03:32:05 CEST 2009
inbox at reinertson.com wrote:
> i'm trying to follow the instructions given in
>
> http://en.gentoo-wiki.com/wiki/Ripping_DVD_to_Matroska_and_H.264
>
> to rip a dvd to an mkv container. i think i've followed the
> instructions pretty carefully but two problems arise. first, the sound
> is not synced with the video and second, there are no subtitles. i've
> listed the sequence of commands below and i'd be grateful if someone
> would just review them to see if i've done anything obviously wrong.
Below is a script I used to reencode (for video compression research of
course) a movie. I used dvdbackup first, so the source is specified by using
-dvd-device. This was a progressive scan source and only needed cropping.
#!/bin/sh
SRC="-dvd-device YOUR_DVD dvd://5"
WORK=/scratch/encode/
NAME=YOUR_DVD_REENCODED
# You can encode a sample:
#SAMPLE="-ss 100 -endpos 180"
FILTER=softskip,crop=704:480:10:0,harddup
CHANNELS=2
BITS=800
# For different runs you may set TAG to mark them:
TAG=
FILE=$NAME$TAG
MSG=$WORK/$FILE.msg
NICE=10
echo "Running $0:" > $MSG
echo "###########" >> $MSG
cat $0 >> $MSG
echo "###########" >> $MSG
COMMON_OPTS=bitrate=$BITS:nr=300:subq=5:8x8dct:frameref=4:bframes=9:\
b_adapt=1:weight_b:b_pyramid:nointerlaced:nofast_pskip:trellis=1:\
mixed_refs:weight_b:me=umh:me_range=16:nodct_decimate:partitions=all:\
psy-rd=0.5,0.3:qcomp=0.7:direct_pred=auto:keyint=300:threads=auto:\
psnr:ssim:log=2
X264OPTS_PASS1=pass=1:$COMMON_OPTS:turbo=2
X264OPTS_PASS2=pass=2:$COMMON_OPTS
echo "First pass started on $(date)." >> $MSG
TIC=$SECONDS
nice -n $NICE \
time mencoder $SRC -cache 8192 $SAMPLE \
-o /dev/null \
-ofps 24000/1001 \
-vf $FILTER -sws 9 \
-ovc x264 -x264encopts $X264OPTS_PASS1 \
-oac pcm -channels $CHANNELS \
-passlogfile $WORK/passlog$TAG \
2>> $MSG
TOC=$SECONDS
let ET=$TOC-$TIC
echo "First pass done in $ET seconds." >> $MSG
echo "Second pass started on $(date)." >> $MSG
TIC=$SECONDS
nice -n $NICE \
time mencoder $SRC -cache 8192 $SAMPLE \
-o $WORK/$FILE.avi \
-ofps 24000/1001 \
-vf $FILTER -sws 9 \
-ovc x264 -x264encopts $X264OPTS_PASS2 \
-oac pcm -channels $CHANNELS \
-vobsubout $WORK/$FILE -slang en \
-passlogfile $WORK/passlog$TAG \
2>> $MSG
TOC=$SECONDS
let ET=$TOC-$TIC
echo "Second pass done in $ET seconds." >> $MSG
TIC=$SECONDS
mkfifo audio.wav
nice -n $NICE oggenc --ignorelength -q 6 audio.wav -o audio.ogg &
nice -n $NICE mplayer $WORK/$FILE.avi -vc null -vo null -nocache -channels
$CHANNELS -ao pcm:fast:file=audio.wav >/dev/null 2>&1
TOC=$SECONDS
let ET=$TOC-$TIC
echo "Extracted $CHANNELS audio channels in $ET seconds." >> $MSG
echo "Encoding finished on $(date)." >> $MSG
For the subtitles I used:
tccat -i <DVD source> -T <titleset number> -L | tcextract -x ps1 -t vob -a
0x20 | subtitle2pgm -o en-sub -c {0|255,0|255,0|255,0|255}
I note that the arguments for -c need to be adjusted depending on how the
subtitles appear on the DVD. (Some use hollow looking letters etc. just
try different variations of the 0 and 255 if the character recognition
software badly performs.)
The above creates a bunch of pgm files. Then pgm2txt can then be used to
create a bunch of txt files containing the actual subtitles. This is the
most error prone step. The character recognition software could be improved
a lot. I spell check with ispell and hand edit if other fixes are needed:
ispell -d american *txt
Then I create the srt file with:
srttool -s -w -i sub.srtx -o en-subs.srt
Finally, do not forget to merge in the srt file to the mkv container.
You need fairly recent mencoder, x264 library, oggenc for some of the above
options.
For example psy-rd did not yet make it into the stable debian release of
mencoder. Or you could drop that option, it is just what I ended up using.
The above encoding parms I consider medium quality and I use for movies which
are not eye candy (like Crouching Tiger..., Kurosawa Dreams) and not action
movies.
You need a recent oggenc to use the -ignorelength parm to overcome AVI format
size limitations (with 6 channels and close to 2 hours the pcm audio dump can
be larger than > 2GB).
Good luck.
Matyas
-
Every hardware eventually breaks. Every software eventually works.
More information about the MEncoder-users
mailing list