[MPlayer-dev-eng] A DVD ripping example into docs?
Samuli Kärkkäinen
skarkkai at woods.iki.fi
Sun Sep 14 21:42:56 CEST 2003
My friend wrote what I consider a very good explanation of his process of
creating a high quality rip of a DVD movie. Because I believe in examples
and HOWTOs in documentation, I offer this (with his permission) as part of
chapter 7 "Encoding with MEncoder" of the documentation. The title could be
fe. "Making a high quality MPEG4 rip of a DVD movie".
The text below is a direct copy of the original email. Obviously to be
incorporated into documentation, the text must be reformatted and cleaned up
somewhat. I'm willing to do that. Shall I do the formatting and post this as
a patch against the manual?
--- snip ---
> Another thing, when you encode a DVD to your PC what setting do you use?
Well I use Linux software, but the settings should mostly translate to
any windows software you use, with the exception of the aspect ratio,
which windows software doesn't support at all or very well.
So you asked for it. It's not trivial. Basically I encode like this:
1. Play the DVD and run a crop detect filter on it. This gives me
a crop rectangle to use for encoding. The reason for this is
that many DVDs have a different aspect ratio than 1.779, which
is the aspect a DVD stream is in. So you want to crop out the
pointless black bars when you rip. A common aspect is 2.35,
which is cinescope. Most big blockbuster movies have this
aspect ratio.
2. With this new crop rectangle, calculate the aspect ratio for
this movie. We preserve the aspect rather than scaling the
video stream, because scaling just needlessly makes the video
bigger. Lots of people do this because the aspect tag in the
mpeg4 header is ignored by most/all windows players, but my
Linux player recognizes it just fine. Sometimes the crop area
requires manual tweaking. So say the crop area is 720:364:0:56
(that's the actual crop area for Harry Potter 2). That means
the raw video stream is 720x364, left offset 0, top offset 56.
How to calculate the new aspect ratio? (Remember the DVD aspect
ratio is 1.779, or 854/480). The aspect is not 720/364 because
DVD video stream is scaled up. NTSC DVD video stream is 720x480
but it is scaled to 854x480 when viewed to give the proper
aspect ratio. So the aspect ratio for this Harry Potter DVD is
really 720*(854/720)/364 or 2.346. Now I know aspect=2.346 for
ripping, when using that crop area.
3. Next I must pick the quality level. Normally I use constant
quantizing (aka constant quality, or variable bitrate). I don't
care how big the movie is, only that the quality is good. With
my encoder I use setting "vqscale=3" where 1 is the highest
quality. BUT, if the movie is long and the total movie size
will exceed 2GB, I suddenly care how big the movie is. The
movie must be less than 2GB because my media player (and many
others) can't index AVIs past 2GB which means no seeking in
movies that big. There's an extension for AVIs called ODML that
allows 64 bit indexing but mine doesn't support it yet, so I
have to make sure the movie doesn't exceed 2GB. If it would be
bigger than 2GB with constant quality, I go to step 4, otherwise
I go to step 5.
4. So I have to make sure the movie is less than 2GB which it would
be with vqscale=3. I could probably use vqscale=4 and make it
smaller, but then I lose on quality. I want to make the movie
the best possible quality that will fit in 2GB so I must use
average bitrate encoding, or ABR, which involves 2 pass
encoding. With ABR I must calculate the average video bitrate
to use. You may have heard of 3 pass encoding, but that's used
for ABR audio. I never ever ever compress my audio. I always
copy the audio stream raw from DVD, so I can get the AC3
stream. The AC3 stream, if it's DD5.1, is typically 448kbit.
So if my movie is, say, 3 hours long (LoTR was), and I need to
squeeze it into 2GB, and I know my audio bitrate is 448kbit/s,
you can see how it's possible to determine the bitrate to use
for a two pass.
5. At this point I figure out if the movie requires any filtering
like increasing gamma, sharpening, etc. I never deinterlace
video. I used to, but I now strongly believe that deinterlacing
belongs during playback, not during encoding. Although it's my
experience that most movies are not deinterlaced.
6. So now I know what filters I need to use, what my crop area and
aspect ratio is, what bitrate to use if it's an ABR encoding,
and I'm ready to go.
If you're going to be a DVD ripping aficionado you need to know about
telecine, aka 3-2/2-3 pulldown, and inverse telecine. The crux of it is
that movies are filmed at a framerate of 23.976 fps (yes, exactly that)
whereas NTSC video is 29.97 fps. If you rip a DVD at 29.97, you're really
wasting space because of the way telecine works, plus you'll find that when
the camera pans over some scene, it will look choppy. So for movies (i.e.
not TV shows like Buffy or Friends or something), you should force output
framerate to 23.976. And if your encoding software is any good, it will
recognize that the video stream had undergone a pulldown process, and will
apply inverse telecine to the video. This means your resulting rip will be
23.976 frames and will be the exact same frames used in the original film
(more or less).
So for my Harry Potter example above, I was able to use constant
quantizing and it fit in under 2GB. (With constant quality really the
only way to tell if it'll fit under 2GB is to rip it and find out.)
Here is the command line I would use to rip that movie. It won't be
much use to you, but you can see the settings I use, and maybe translate
those into your software:
mencoder -dvd 1 -oac copy -ovc lavc -lavcopts vcodec=mpeg4:vqscale=3:vhq:v4mv:keyint=250:aspect=2.346 -ofps 23.976 -vop crop=720:364:0:56 -o Harry_Potter_2.avi
"-oac copy" says copy the audio stream raw from the DVD. vhq and v4mv
are specific high quality settings for the mpeg4 codec I use. keyint
says to specify a key frame every 250 frames. Etc., etc. I didn't
apply any gamma or sharpening filters to this rip. Normally you don't
need to, except for maybe older movies, or B&W, or some cartoons.
A lot of this could be automated, but the whole process can't be. It's
very much a manual thing as each DVD is different and you need to
experiment sometimes to get the best results. More often than not,
though, the formula above works just fine for me (with different crop
area and aspect, of course).
There you go. Easy as pie, eh?
Jason.
--- snap ---
--
Samuli Kärkkäinen |\ _,,,---,,_
skarkkai at woods.iki.fi ---------ZZZzz /,`.-'`' -. ;-;;,_------
http://www.woods.iki.fi |,4- ) )-,_. ,\ ( `'-'
'---''(_/--' `-'\_)
More information about the MPlayer-dev-eng
mailing list