
===========================================
| ENCODING TIPS FOR MPEG TYPE COMPRESSION |
===========================================

Always do a 2 or 3-pass encode if you can
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The complexity (and thus the number of bits) required to
compress the frames of a movie can vary greatly from one
scene to another. Modern video encoders can adjust to these
needs as they go and vary the bitrate. However, they cannot
exceed the requested average bitrate for long stretches of
time, because they do not know the bitrate needs of future
scenes.

2-pass encoding solves this problem by encoding the movie
twice. During the first pass, statistics are generated regarding
the number of bits used by each frame and the quantization level
(quality) at which it was encoded. Then, when the second pass
begins, the encoder reads these statistics and redistributes the
bits from frames where they are in excess to frames that are
suffering from low quality.

In order for the process to work properly, the encoder should be
given exactly the same sequence of frames during both passes.
This means that the same filters must be used, the same encoder
parameters must be used (with the possible exception of bitrate),
and the same frame drops and duplications (if any) must take place.

Always crop the black borders of a DVD
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Due to the nature of MPEG-type compression, there are various 
constraints you should follow for maximal quality. MPEG splits the 
video up into 16x16 squares called macroblocks, each composed of 4 
8x8 blocks of luma (intensity) information and two half-resolution 
8x8 chroma (color) blocks (one for red-cyan axis and the other for the 
blue-yellow axis). Even if your movie width and height are not multiples
of 16, the encoder will use enough 16x16 macroblocks to cover the whole 
picture area, and the extra space will go to waste. So in the interests 
of maximizing quality at a fixed filesize, it is a bad idea to use
dimensions that are not multiples of 16.
Most DVDs also have some degree of black borders at the edges. Leaving 
these in place can hurt quality in several ways.

  - MPEG-type compression is also highly dependent on frequency domain 
    transformations, in particular the Discrete Cosine Transform (DCT), 
    which is similar to the Fourier transform. This sort of encoding is 
    efficient for representing patterns and smooth transitions, but it has 
    a hard time with sharp edges. In order to encode them it must use many 
    more bits, or else an artifact known as ringing will appear.

  - The frequency transform (DCT) takes place separately on each macroblock 
    (actually each block), so this problem only applies when the sharp edge 
    is inside a block. If your black borders begin exactly at multiple-of-16 
    pixel boundaries, this is not a problem. However, the black borders on DVDs 
    rarely come nicely aligned, so in practice you will always need to crop to 
    avoid this penalty.

In addition to frequency domain transforms, MPEG-type compression uses motion 
vectors to represent the change from one frame to the next. Motion vectors 
naturally work much less efficiently for new content coming in from the edges 
of the picture, because it is not present in the previous frame. As long as 
the picture extends all the way to the edge of the encoded region, motion vectors 
have no problem with content moving out the edges of the picture. However, in the 
presence of black borders, there can be trouble:

 - For each macroblock, MPEG-type compression stores a vector identifying which
   part of the previous frame should be copied into this macroblock as a base for 
   predicting the next frame. Only the remaining differences need to be encoded. 
   If a macroblock spans the edge of the picture and contains part of the black 
   border, then motion vectors from other parts of the picture will overwrite the 
   black border. This means that lots of bits must be spent either re-blackening 
   the border that was overwritten, or (more likely) a motion vector will not be 
   used at all and all the changes in this macroblock will have to be coded 
   explicitly. Either way, encoding efficiency is greatly reduced.

Again, this problem only applies if black borders do not line up on multiple-of-16 
boundaries.

 - Finally, suppose we have a macroblock in the interior of the picture, and an 
   object is moving into this block from near the edge of the image. MPEG-type 
   coding cannot say "copy the part that is inside the picture but not the black 
   border." So the black border will get copied inside too, and lots of bits will 
   have to be spent encoding the part of the picture that is supposed to be there.

   If the picture runs all the way to the edge of the encoded area, MPEG has special 
   optimizations to repeatedly copy the pixels at the edge of the picture when a 
   motion vector comes from outside the encoded area. This feature becomes useless 
   when the movie has black borders. Unlike problems 1 and 2, aligning the borders at 
   multiples of 16 does not help here.

 - Despite the borders being entirely black and never changing, there is at least a 
   minimal amount of overhead involved in having more macroblocks.

For all of these reasons, it is recommended to fully crop black borders. Further, 
if there is an area of noise/distortion at the edge of the picture, cropping this 
will improve encoding efficiency as well. Videophile purists who want to preserve 
the original as close as possible may object to this cropping, but unless you plan 
to encode at constant quantizer, the quality you gain from cropping will considerably 
exceed the amount of information lost at the edges.

Do not scale down too much
~~~~~~~~~~~~~~~~~~~~~~~~~~

Scaling is always been an issue in MPEG compression. One might want to scale down 
a movie for different reasons, to lower the bitrate or file size of the encode. 
However, the MPEG compression does not like scaling down too much. If you scale 
down the original source to, lets say, 512x208, then you'll get the annoying stair 
steps in red colors, though this is not really MPEG's fault but has also to do with 
software scaling. Every time you see a bright/full red color in the movie, it will 
have lines (stair steps) in it. Another point in favour of not trying to scale down
too much is that the MPEG compression has to compress high frequencies much more than
low frequencies and it doesn't like that at all.

Choose your software scaler
~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you do need to scale down the source, then make sure to choose the right software scaler. 
For example, if you're going to scale down a lot, I found out that a more blurry image will 
look much better than a more sharper one. The Bilinear software scaler is very good for hard 
scaled down content because it will produce much less noise and ringing around objects. 
Sharp scalers that preserve a lot of image details, like the Bicubic or Bicubic Spline, will
produce much more noise/ringing when used in conjunction with a (very) low bitrate and low
resolution. Also those scalers will require much more bits to preserve their sharpness/details, 
thus they are not really recommended when doing low bitrate/hard scaled down encodes.

--------------------------------------------------------------------

NOTE: some content is taken directly from the MPlayer documentation.
      Copyright goes to the author(s) who wrote it