[MEncoder-users] Aspect ratio arithmetuc (was: How to produce VCD\DVD content from a raw AVI video ?)

Nicolas George nicolas.george at normalesup.org
Tue Jul 1 10:42:57 CEST 2008


Le quartidi 14 messidor, an CCXVI, Ross Clement a écrit :
> When I play this DV file (as exported) in mplayer on the computer, it
> reports that the aspect ratio is 1.37:1 and that it's scaling to 786x576 to
> correct for it.(All this is from memory, but I think it's correct).

You should copy-paste exactly the output, to avoid mistakes.

>								      How
> could I modify the aspect ratio when I convert to mpeg2 so that it doesn't
> stretch the image and lose the sides?

I will take a slightly more generic example, where all fractions do not
simplify.

First of all, the actual resolution of the source content does not matter,
only its intended aspect ratio. For example, if the pixels are squares,
320×240 and 640×480 are perfectly equivalent for the following calculations.

Let us assume that the display aspect ratio of your content is 3/2 (this is
the standard aspect ratio for paper photos).

Let us assume that you want to play it on a wide-screen TV, and thus choose
a 16/9 DVD.

Let us assume that you have determined the size of the viewable area in this
configuration (probably by encoding a test pattern): 684×544.

First, let us compute the pixel aspect ratio of a 16/9 PAL DVD, because that
is the number that does not change when you crop tie image. The number 16/9
tells us that for some arbitrary unit, the size of the displayed image is 16
units wide times 9 units high. The actual value of the unit depends on the
size of the screen, but it does not matter, only the ratio matters.

Knowing that, we can compute the size of one pixel. Its width is 16 units
divided by 720 pixels, thus 16/720 units. For the same reason, the height of
one pixel is 9/576 units.

Finally, we can compute the display aspect ratio of one pixel, which is its
width divided by its height: (16/720) / (9/576) = (16/9) / (720/576), which
gives us 64/45, or approximatively 1.422. I suggest PARI/GP as a simple
calculator which handles fractions nicely.

Now, we must determine the pixel size for a 3/2 content. We do not know
whether the limiting factor will be the width or the height, so we try both,
and take the smallest.

First, let us try to fit the image in width. The width is therefore 684
pixels, we already know it. We also know that, for some unit (not the same
as before, and much smaller), the width of one pixel is 64, and its height
is 45. Therefore, in this unit, the width of the content is 684×64. Its
height must therefore be: 684×64 / (3/2). And to know the size
in pixels, we divide by 45: 684 × (64/45) / (3/2) = 648.53 approximatively.
The height must therefore be 649 pixels, which is bigger than 544. The
limiting factor is the height.

So let us try to fit the image in height. The height is 544, let us compute
the width. The height in small physical units is 544×45, so the width must
be 544×45 × (3/2). To get the width in pixels, we divide by 64:
544 × (45/64) × (3/2) = 544 × (3/2) / (64/45) = 573.75. The width must be
574 pixels, which fits in our 684.

Please note that I always tried to write the aspect ratios exactly as we
know them: 3/2, 64/45. The same calculation would work if we took
approximate values. For example, 3/2 = 1.5. One must just remember that 1.5
means 1.5/1.

Another point: we know that the aspect ratio of the content we want to
display is 3/2 = 1.5, and we want to display on something whose aspect ratio
is 16/9 = 1.78 approximatively. Since 1.78 > 1.5, the screen is wider than
the content, so we could have guessed that the limiting length would be the
height. The aspect ratio of the viewable area is not exactly 16/9, but the
difference is small, not enough to reach 1.5.

We can make the exact computation: the physical width of the viewable area
is 684×64, and its height is 544×45, so the aspect ratio is
(684×64) / (544×45) = (684/544) × (64/45) = 152/85, or approximatively 1.79.

Now, we know that we must scale our content to 574×544, and then add
720-574 = 146 black pixels on the left and right borders, and 576-544 = 32
black pixels on the top and bottom. There is a last, small point to decide:
how much on the left, how much on the right?

The black pixels we have to add can be split in two parts: first we add some
black pixels to totally fill the viewable area, and then we add black pixels
to pad the viewable area in the total area.

For the first part, we probably want the content centered on the visible
area. Our content is 574 pixels wide, the viewable area is 684, we need 110
pixels: 55 on each side. Vertically, the fit is perfect: 0 pixels.

For the second part, we have no choice, that is determined by the hardware.
Hopefully, we measured that back when we measured the size of the viewable
area. Let us assume that we lose 21 pixels on the left, 15 on the right, 18
on the top and 14 on the bottom.

The total is therefore: 55+21 pixels on the left, 55+15 pixels on the right,
0+18 pixels on the top, 0+14 pixels on the bottom.

(Note: I have been quite lengthy in this message, more than necessary, in
order to make it possible to quote it in a tutorial or as answer to a
similar question. I have no objection to have this text copied anywhere.)

(Note to Ross: in the previous message you top-posted. If you do it again,
you will make enemies on this list: avoid it. And if you do not know what
top-posting is, use Google or Wikipedia.)

Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/mencoder-users/attachments/20080701/bcb89852/attachment.pgp>


More information about the MEncoder-users mailing list