📄 menc-feat-dvd-mpeg4.html
字号:
If they are not, the chroma will no longer line up correctly with the
luma.
In theory, it is possible to crop with odd offsets, but it requires
resampling the chroma which is potentially a lossy operation and not
supported by the crop filter.
</p><p>
Further, interlaced video is sampled as follows:
</p><div class="informaltable"><table border="1" width="80%"><colgroup><col align="center"><col align="center"><col align="center"><col align="center"><col align="center"><col align="center"><col align="center"><col align="center"><col align="center"><col align="center"><col align="center"><col align="center"><col align="center"><col align="center"><col align="center"><col align="center"></colgroup><tbody><tr><td colspan="8" align="center">Top field</td><td colspan="8" align="center">Bottom field</td></tr><tr><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td></tr><tr><td colspan="2" align="center">C</td><td colspan="2" align="center">C</td><td colspan="2" align="center">C</td><td colspan="2" align="center">C</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td></tr><tr><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td></tr><tr><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td></tr><tr><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td colspan="2" align="center">C</td><td colspan="2" align="center">C</td><td colspan="2" align="center">C</td><td colspan="2" align="center">C</td></tr><tr><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td></tr><tr><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td></tr><tr><td colspan="2" align="center">C</td><td colspan="2" align="center">C</td><td colspan="2" align="center">C</td><td colspan="2" align="center">C</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td></tr><tr><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td></tr><tr><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td></tr><tr><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td colspan="2" align="center">C</td><td colspan="2" align="center">C</td><td colspan="2" align="center">C</td><td colspan="2" align="center">C</td></tr><tr><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">聽</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td><td align="center">L</td></tr></tbody></table></div><p>
As you can see, the pattern does not repeat until after 4 lines.
So for interlaced video, your y-offset and height for cropping must
be multiples of 4.
</p><p>
Native DVD resolution is 720x480 for NTSC, and 720x576 for PAL, but
there is an aspect flag that specifies whether it is full-screen (4:3) or
wide-screen (16:9). Many (if not most) widescreen DVDs are not strictly
16:9, and will be either 1.85:1 or 2.35:1 (cinescope). This means that
there will be black bands in the video that will need to be cropped out.
</p><p>
<span class="application">MPlayer</span> provides a crop detection filter that
will determine the crop rectangle (<tt class="option">-vf cropdetect</tt>).
Run <span class="application">MPlayer</span> with
<tt class="option">-vf cropdetect</tt> and it will print out the crop
settings to remove the borders.
You should let the movie run long enough that the whole picture
area is used, in order to get accurate crop values.
</p><p>
Then, test the values you get with <span class="application">MPlayer</span>,
using the command line which was printed by
<tt class="option">cropdetect</tt>, and adjust the rectangle as needed.
The <tt class="option">rectangle</tt> filter can help by allowing you to
interactively position the crop rectangle over your movie.
Remember to follow the above divisibility guidelines so that you
do not misalign the chroma planes.
</p><p>
In certain cases, scaling may be undesirable.
Scaling in the vertical direction is difficult with interlaced
video, and if you wish to preserve the interlacing, you should
usually refrain from scaling.
If you will not be scaling but you still want to use multiple-of-16
dimensions, you will have to overcrop.
Do not undercrop, since black borders are very bad for encoding!
</p><p>
Because MPEG-4 uses 16x16 macroblocks, you will want to make sure that each
dimension of the video you are encoding is a multiple of 16 or else you
will be degrading quality, especially at lower bitrates. You can do this
by rounding the width and height of the crop rectangle down to the nearest
multiple of 16.
As stated earlier, when cropping, you will want to increase the Y offset by
half the difference of the old and the new height so that the resulting
video is taken from the center of the frame. And because of the way DVD
video is sampled, make sure the offset is an even number. (In fact, as a
rule, never use odd values for any parameter when you are cropping and
scaling video.) If you are not comfortable throwing a few extra pixels
away, you might prefer instead to scale the video instead. We will look
at this in our example below.
You can actually let the <tt class="option">cropdetect</tt> filter do all of the
above for you, as it has an optional <tt class="option">round</tt> parameter that
is equal to 16 by default.
</p><p>
Also, be careful about "half black" pixels at the edges. Make sure you
crop these out too, or else you will be wasting bits there that
are better spent elsewhere.
</p><p>
After all is said and done, you will probably end up with video whose pixels
are not quite 1.85:1 or 2.35:1, but rather something close to that. You
could calculate the new aspect ratio manually, but
<span class="application">MEncoder</span> offers an option for <code class="systemitem">libavcodec</code> called <tt class="option">autoaspect</tt>
that will do this for you. Absolutely do not scale this video up in order to
square the pixels unless you like to waste your hard disk space. Scaling
should be done on playback, and the player will use the aspect stored in
the AVI to determine the correct resolution.
Unfortunately, not all players enforce this auto-scaling information,
therefore you may still want to rescale.
</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="menc-feat-dvd-mpeg4-resolution-bitrate"></a>14.1.5.聽Choosing resolution and bitrate</h3></div></div></div><p>
If you will not be encoding in constant quantizer mode, you need to
select a bitrate.
The concept of bitrate is quite simple.
It is the (average) number of bits that will be consumed to store your
movie, per second.
Normally bitrate is measured in kilobits (1000 bits) per second.
The size of your movie on disk is the bitrate times the length of the
movie in time, plus a small amount of "overhead" (see the section on
<a class="link" href="menc-feat-dvd-mpeg4.html#menc-feat-dvd-mpeg4-muxing-avi-limitations" title="14.1.12.2.聽Limitations of the AVI container">the AVI container</a>
for instance).
Other parameters such as scaling, cropping, etc. will
<span class="bold"><strong>not</strong></span> alter the file size unless you
change the bitrate as well!.
</p><p>
Bitrate does <span class="bold"><strong>not</strong></span> scale proportionally
to resolution.
That is to say, a 320x240 file at 200 kbit/sec will not be the same
quality as the same movie at 640x480 and 800 kbit/sec!
There are two reasons for this:
</p><div class="orderedlist"><ol type="1"><li><p>
<span class="bold"><strong>Perceptual</strong></span>: You notice MPEG
artifacts more if they are scaled up bigger!
Artifacts appear on the scale of blocks (8x8).
Your eye will not see errors in 4800 small blocks as easily as it
sees errors in 1200 large blocks (assuming you will be scaling both
to fullscreen).
</p></li><li><p>
<span class="bold"><strong>Theoretical</strong></span>: When you scale down
an image but still use the same size (8x8) blocks for the frequency
space transform, you move more data to the high frequency bands.
Roughly speaking, each pixel contains more of the detail than it
did before.
So even though your scaled-down picture contains 1/4 the information
in the spacial directions, it could still contain a large portion
of the information in the frequency domain (assuming that the high
frequencies were underutilized in the original 640x480 image).
</p></li></ol></div><p>
</p><p>
Past guides have recommended choosing a bitrate and resolution based
on a "bits per pixel" approach, but this is usually not valid due to
the above reasons.
A better estimate seems to be that bitrates scale proportional to the
square root of resolution, so that 320x240 and 400 kbit/sec would be
comparable to 640x480 at 800 kbit/sec.
However this has not been verified with theoretical or empirical
rigor.
Further, given that movies vary greatly with regard to noise, detail,
degree of motion, etc., it is futile to make general recommendations
for bits per length-of-diagonal (the analog of bits per pixel,
using the square root).
</p><p>
So far we have discussed the difficulty of choosing a bitrate and
resolution.
</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="menc-feat-dvd-mpeg4-resolution-bitrate-compute"></a>14.1.5.1.聽Computing the resolution</h4></div></div></div><p>
The following steps will guide you in computing the resolution of your
encode without distorting the video too much, by taking into account several
types of information about the source video.
First, you should compute the encoded aspect ratio:
<code class="systemitem">ARc = (Wc x (ARa / PRdvd )) / Hc</code>
</p><div class="itemizedlist"><p class="title"><b>where:</b></p><ul type="disc"><li><p>
Wc and Hc are the width and height of the cropped video,
</p></li><li><p>
ARa is the displayed aspect ratio, which usually is 4/3 or 16/9,
</p></li><li><p>
PRdvd is the pixel ratio of the DVD which is equal to 1.25=(720/576) for PAL
DVDs and 1.5=(720/480) for NTSC DVDs,
</p></li></ul></div><p>
</p><p>
Then, you can compute the X and Y resolution, according to a certain
Compression Quality (CQ) factor:
<code class="systemitem">ResY = INT(SQRT( 1000*Bitrate/25/ARc/CQ )/16) * 16</code>
and
<code class="systemitem">ResX = INT( ResY * ARc / 16) * 16</code>
</p><p>
Okay, but what is the CQ?
The CQ represents the number of bits per pixel and per frame of the encode.
Roughly speaking, the greater the CQ, the less the likelihood to see
encoding artifacts.
However, if you have a target size for your movie (1 or 2 CDs for instance),
there is a limited total number of bits that you can spend; therefore it is
necessary to find a good tradeoff between compressibility and quality.
</p><p>
The CQ depends on the bitrate, the video codec efficiency and the
movie resolution.
In order to raise the CQ, typically you would downscale the movie given that the
bitrate is computed in function of the target size and the length of the
movie, which are constant.
With MPEG-4 ASP codecs such as <code class="systemitem">Xvid</code>
and <code class="systemitem">libavcodec</code>, a CQ below 0.18
usually results in a pretty blocky picture, because there
are not enough bits to code the information of each macroblock. (MPEG4, like
many other codecs, groups pixels by blocks of several pixels to compress the
image; if there are not enough bits, the edges of those blocks are
visible.)
It is therefore wise to take a CQ ranging from 0.20 to 0.22 for a 1 CD rip,
and 0.26-0.28 for 2 CDs rip with standard encoding options.
More advanced encoding options such as those listed here for
<a class="link" href="menc-feat-enc-libavcodec.html#menc-feat-mpeg4-lavc-example-settings" title="14.3.4.聽Encoding setting examples"><code class="systemitem">libavcodec</code></a>
and
<a class="link" href="menc-feat-xvid.html#menc-feat-xvid-example-settings" title="14.4.4.聽Encoding setting examples"><code class="systemitem">Xvid</code></a>
should make it possible to get the same quality with CQ ranging from
0.18 to 0.20 for a 1 CD rip, and 0.24 to 0.26 for a 2 CD rip.
With MPEG-4 AVC codecs such as <code class="systemitem">x264</code>,
you can use a CQ ranging from 0.14 to 0.16 with standard encoding options,
and should be able to go as low as 0.10 to 0.12 with
<a class="link" href="menc-feat-x264.html#menc-feat-x264-example-settings" title="14.5.2.聽Encoding setting examples"><code class="systemitem">x264</code>'s advanced encoding settings</a>.
</p><p>
Please take note that the CQ is just an indicative figure, as depending on
the encoded content, a CQ of 0.18 may look just fine for a Bergman, contrary
to a movie such as The Matrix, which contains many high-motion scenes.
On the other hand, it is worthless to raise CQ higher than 0.30 as you would
be wasting bits without any noticeable quality gain.
Also note that as mentioned earlier in this guide, low resolution videos
need a bigger CQ (compared to, for instance, DVD resolution) to look good.
</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="menc-feat-dvd-mpeg4-filtering"></a>14.1.6.聽Filtering</h3></div></div></div><p>
Learning how to use <span class="application">MEncoder</span>'s video filters
is essential to producing good encodes.
All video processing is performed through the filters -- cropping,
scaling, color adjustment, noise removal, sharpening, deinterlacing,
telecine, inverse telecine, and deblocking, just to name a few.
Along with the vast number of supported input formats, the variety of
filters available in <span class="application">MEncoder</span> is one of its
main advantages over other similar programs.
</p><p>
Filters are loaded in a chain using the -vf option:
</p><pre class="screen">-vf filter1=options,filter2=options,...</pre><p>
Most filters take several numeric options separated by colons, but
the syntax for options varies from filter to filter, so read the man
page for details on the filters you wish to use.
</p><p>
Filters operate on the video in the order they are loaded.
For example, the following chain:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -