PDA

View Full Version : How to set aspect properly?


bur
23rd October 2007, 18:28
edit: After some more reading I found this formula: SAR = DAR * heigth/width. If I'm correct this would that for each video you had to set the aspect ratio individually, is that true? I never knew that was needed and certainly never did it with asp/avi encodings. So in my case I had to set it to 1 * (560/464) = 1.21? But is there no way to just have the video play at the given resolution and a DAR of 1:1 directly i.e. without the need to calculate and set --sar manually? I thought leaving --sar out had this effect and that was what I mostly read on the net. Just that in my case it produces a 4:3 video for whatever reason.


I'm a little desperate as this problem never occured before and I have no clue what to do:

I have a DVD source from which I made a d2v file and this avs:

LoadPlugin("d:\video\DGMPGDec\DGDecode.dll")
MPEG2Source("e:\DVD\dvd.d2v")
Crop(0,12,-2,-12)
LanczosResize(560,464)

I did a resize to 560x464 because after cropping the source had 696x574 resolution instead of going from the original 720x576. Was that okay?

Then I run x264:

x264 --pass 1 --stats "e:\dvd\pass1.stats" --output NUL "e:\dvd\dvd.avs"

x264 --sar 16:9 --pass 2 --stats "e:\dvd\pass1.stats" --bitrate 1600 --progress --no-ssim --no-psnr --threads auto --output "e:\dvd\Waechter.mkv" "E:\dvd\dvd.avs"

(I removed all the quality and zones related switches to keep it simple)

The resulting mkv looks a little too broad. And indeed MPC tells me it's 994x464 ... properly because he tries to get the 16:9 ratio. When leaving --sar out as I normally do the result is a 4:3 video (despite the resolution being 1:1.25 how does that come?).

What do I need to do, set --sar 6:5? But there should be a way to simply play the video at the given resolution. With the pixel ratio of 1:1 this should work fine.

It seems to me I don't get this aspect ratio thing right. So if anyone could shed some light... :) Or at least tell me if --sar 6:5 is okay (and maybe why I never set something like that before). Thanks.

Maccara
23rd October 2007, 20:16
Taking into account this was probably a PAL 16:9 DVD + resizing aspect error (-0,47%), you should get original aspect by using --sar 85:58 (or just use original pal dvd par - that's close enough too, as the aspect error is so little anyway).

Or, you could resize just to, for example, 560x320 to have 1:1 par (with ~-1% aspect error).

This was just a quick calculation by ITU values and haven't re-checked, so hopefully calculated correctly. :)

bur
23rd October 2007, 20:24
But why 560x320? The original source was 720x576 (1.25:1) or after cropping 696x574 (1.21:1) - so I thought resizing to 560x464 with a ratio of 1.21:1 was the right thing to do.

And also why do I need to set --sar manually? Shouldn't it be clear for any player to just play the video at the given resolution?

The way it is now MPC gives two different values for height/width in the properties tab: 994x464 (where does it get those extra pixels - by interpolating? and why?) and also my original setting of 560x464 which it doesn't use probably because I set --sar 16:9


From what I get from here (http://trac.videolan.org/x264/browser/trunk/doc/vui.txt), I should set --sar to 16*464 and 9*560 or 1.47:1 - but that's more like a guess since I don't get the formula...

Maccara
23rd October 2007, 20:36
But why 560x320? The original source was 720x576 (1:1.25) or after cropping 696x574 (1:1.21) - so I thought resizing to 560x464 with a ratio of 1:21 was the right thing to do.

And also why do I need to set --sar manually? Shouldn't it be clear for any player to just play the video at the given resolution?


The original DVD most definitely does not have 1:1.25 aspect ratio, as the original DVD PAR is not 1:1. Cropping also changes the DVD aspect ratio (but not PAR!). Some further reading here (http://www.doom9.org/index.html?/capture/par.html).

If you do not want to use --sar, you have to encode at 1:1 pixel aspect ratio and you then have to take into account what the original par was to be able to calculate the correct resizing.

Or just use megui, as it does this for you automatically. ;)

Edit:
One way to calculate resizing is
X = Source_PAR/Target_PAR*Target_height/Source_height
Y = Source_height*Target_PAR/Source_PAR*Target_width/Source_width

Source height/width are after cropping. Target_PAR = 1, if you do not want to make an anamorphic encode (i.e., use --sar)

One way to calculate the original DAR of the DVD:
DAR = Source_PAR*Source_width/Source_height
(height/width after cropping, again)

I think you can derive the rest from here.

bur
24th October 2007, 19:24
Okay, thanks alot I never knew this. But why isn' it necessary to set this for xvid? Or does the vfw-interface do it automatically?

Just one thing, what is the DVD PAR? Is that a constant value or does it differ, and if so how do I get the exact value?

And if you have some time on your hands ;) ... why do DVDs not use a PAR of 1:1? And how are they played on a CRT/LCD with a PAR of 1:1? Who does the conversion there?

edit: Never mind, I just had a look at the link you posted. Good article.

bur
24th October 2007, 21:13
Though I have to admit I didn't get what I was doing (had a long day at the lab ;)) I used your formula and this gave me 560x422 to get from the PAR=1.094 PAL-DVD with 696x574 after cropping to my PAR=1 encode. But since 422 mod 16 isn't 0 I had to resort to 416. Does that mean my aspect will be 416/422=98.5% of the original value? Should be okay then I guess.

It seems this whole aspect ratio business is a lot more comlicated than I thought so far. For example what will happen if I play my PAR=1 encode on a TV? Or even more common a PAR=1.094 DVD on my CRT with PAR=1? Does the software player do the conversion on the fly? Or is the picture really a little off?


edit: Sorry, but somehow I failed with the calculation. The video now definetely looks a little squeezed in VD i.e. height seems to be too big. I played around with avs and it looks like something like 560x330 does the job. But why? Or is this just because I directly view the avs and the encode later will be correct even with 560x416?

I doublechecked and both going from 560 and 422 gives the correct number repectively. And the DAR of the DVD is the same as when using 56X422 with a PAR of 1. So it all really seems right. But still VDmod shows a squeezed picture... I'll let x264 run now and check the result tomorrow - maybe all will be well. :)

Maccara
25th October 2007, 00:15
bur, is your dvd PAL 4:3 or 16:9? I suspected 16:9 initially, but you're using 4:3 PAR in your calculations now...

Please check that first. If it is 4:3, PAR is 1.09402 and if 16:9 use 1.45869 in your calculations. (note, that these are again different for NTSC DVDs)

Maccara
25th October 2007, 00:25
Does the software player do the conversion on the fly?

Yes, providing info is in the stream (as it should be with DVDs or x264 encoded with --sar) and the player supports it (vlc most definitely does, as probably all dvd players do too).

bur
25th October 2007, 08:14
It's 16:9, but I couldn't find any numbers for the PAR on such DVDs. I checked this site (http://lipas.uwasa.fi/~f76998/video/conversion/#conversion_table) as well as the one you posted.

I found this site (http://encodingwissen.de/video/anamorph-quelle.html) (german) that says a 16:9 PAL DVD has PAR=1.4545 This would make the height smaller (since target_par/source_PAR shrinks) so I guess that value will be correct.

Thanks a lot for you time, I finally got how this whole PAR thing works. Not that difficult once you really get what's going on, but you have to find someone to explain. :)

Maccara
25th October 2007, 20:23
It's 16:9, but I couldn't find any numbers for the PAR on such DVDs. I checked this site (http://lipas.uwasa.fi/~f76998/video/conversion/#conversion_table) as well as the one you posted.

Ah, yes, that's true. :) They focus on analog conversions only and don't derive every possible value. I have also just calculated those myself.


I found this site (http://encodingwissen.de/video/anamorph-quelle.html) (german) that says a 16:9 PAL DVD has PAR=1.4545 This would make the height smaller (since target_par/source_PAR shrinks) so I guess that value will be correct.

I don't speak german myself, so I couldn't immediately discern how they got that value, but seems that they used DVD resolution 704x576 for those calculations & "generic par" which, IMO, is not exactly correct (would result in 13,54 MHz sampling rate, which is not correct for DVDs). But, I'm not 100% sure if this would be normal for some mastering (or if I made some mistake in calculation myself :)).

Thanks a lot for you time, I finally got how this whole PAR thing works. Not that difficult once you really get what's going on, but you have to find someone to explain. :)

I found it easiest for me to just think in analogue terms + ITU standards (for digitizing video) and then just derive everything from that domain to digital.

But you're right. It is much simpler than it first seems - you just have to get around to it. :) Glad I could help.

Brother John
26th October 2007, 15:44
Since I’m the author of that German site I can shed some light on the numbers shown there. Actually three different PAR tables exist. Read the chapter about how to calculate those numbers (http://encodingwissen.de/spezial/itur-bt601.html). (A Google translation (http://translate.google.com/translate?u=http%3A%2F%2Fencodingwissen.de%2Fspezial%2Fitur-bt601.html&langpair=de%7Cen&hl=de&ie=UTF-8&oe=UTF-8&prev=%2Flanguage_tools) might help.)

Exact PAR according to ITU-R BT.601
PAL NTSC
4:3 128/117 4320/4739
16:9 512/351 5760/4739


MPEG-4 PAR taken directly from the MPEG-4 standard documents.
Very similar to exact ITU figures and usually used for MPEG-4 encodings.
PAL NTSC
4:3 12/11 10/11
16:9 16/11 40/33


Generic PAR (i.e. ignoring ITU)
This leads to an exact 16:9 DAR for an uncropped 16:9 PAL frame.
PAL NTSC
4:3 16/15 8/9
16:9 64/45 32/27


Those three tables contain all the numbers you will ever need for any DVD source. Which table you use is mainly a matter of personal preference because you have virtually no chance to find out the real DVD PAR (i.e. the PAR used in the mastering process) for sure. It might be generic, it might be ITU. Black bars left/right are an indication for ITU, but you can’t be certain. Also the absence of bars might mean generic, but it’s no proof either.

I prefer the MPEG-4 values, for three reasons: 1) Imo you’re more likely to encounter an ITU DVD than a generic DVD. 2) MPEG-4 PARs are well defined in the MPEG-4 standard (which H.264 is a part of). Everything else than those four default values is an out-of-the-way custom PAR as far as the MPEG-4 bitstream is concerned. 3) The numbers are nice and easy to remember. :)


If you want a traditional, resized, square-pixel encoding:
Take your cropped picture (696×574) and calculate it’s proper playback resolution (PAR only affects horizontal value):
696 × 16/11 = 1012,
which gives you 1012×574.
Scale down both dimensions proportionally (i.e. by the same percentage). Example: Your desired width is 560, which is
560 / 1012 = 0,5534 (55.34%)
of the full 1012. Apply the same to the height:
574 × 0,5534 = 318.
Which gives you 560×318.
Make sure both dimensions are evenly divisible by 16. This will introduce some distortion commonly known as »aspect error«. For our example: 560 is already mod16, but 318 is not.
363 / 16 = 19,9.
As you can see, 20 × 16 = 320 is the nearest proper number, which gives you a final resolution of 560×320.

If you want an anamorphically encoded MPEG-4
Crop, do NOT resize.
The cropped picture should ideally be mod16.
Set the appropriate PAR in the encoder. --sar for x264, -par for Xvid_Encraw
Make sure your playback method is compatible. Today most software players/filters/decoders are. Standalone players are a different matter, as usual.

Some more info:
SAR is just a different name for PAR.
PAR defines the shape of a single pixel.
DAR defines the shape of the whole frame, usually including black bars.
PAR is never affected by cropping but might change with resizing (usually to 1:1).
DAR is always affected by cropping and usually by resizing as well.
For a DVD source, DAR has almost no meaning. So don’t worry about weird DARs (e.g. 560×320 is 1.75:1) because you’ll hardly ever get those nice »round« values of 1.33, 1.78, 1.85 or 2.35 anyway.

bur
26th October 2007, 17:45
Thanks for the additional info, but I'm german (auch bei gulli übrigens... :)) so I read all the info on your site about anamorphic video and now finally came up with keeping the PAR to keep more vertical resolution instead of using PAR=1 which would have left me with about 320y or only 60% of the source instead of the 464 I could use now.

And since H.264 isn't standalone-compatible anyway using anamorphic mpeg4 is always the better choice as opposed to the "old" way, I think.


Just for the records, if someone else might have the same problem:

Source: 720x576 PAL-DVD 16:9

Target:
(anamorphic) 560x464 --sar 16:11
(standard) 560x320 --sar 1:1

That did it for me.


Now I'm working on an excel table to get the correct values semi-automatically. For example you enter desired heigth and it gives you the proper width for both anamorphic and standard as well as source_DAR/target_DAR, bits/pixel*frame and the such. Or is there any program that does just this?

pdanpdan
26th October 2007, 19:21
you can try this:
http://mail.mercury.ro/www/dan/AR Calculator.7z

bur
26th October 2007, 20:42
Thanks, but I already made my own. Since I also wanted the bits/(pixel*frames) and how wrong your target DAR is, i.e. target_DAR/source_DAR and also have the values mod 16 corrected. That way you can easily check which values are the best.

Though I got to admit your sheet looks more professional with the checkboxes and colors. Mine is a little crude... :)

Maccara
27th October 2007, 00:25
Since I’m the author of that German site I can shed some light on the numbers shown there.

Thank you very much for great explanation & reference.

I completely forgot myself the mpeg-4 standards, as I work mostly from analogue sources myself. Luckily, that does not end up with much difference anyway. :)

Brother John
27th October 2007, 02:00
@bur
You could just use good old Gordian Knot for the calculations. It can even switch between MPEG-4 and generic PAR.

@Maccara
Yep, that it’s three PAR tables and not only two really isn’t a too well known fact. Problem with the real ITU values: In an MPEG-4 ASP bitstream you couldn’t store most of them (except PAL 4:3) because custom PAR fields are unsigned 8-bit integers with a max value 255. No problem for H.264 though.

bur
28th October 2007, 00:47
You could just use good old Gordian Knot for the calculations.True, but I don't want to install GK just for the calculations. So I made an excel sheet that pretty much covers all the calculations GK makes.

Since this was only possible with the help of you too, maybe you want to have a look and if there are some features that could be added let me know: Excel sheet (http://forum.doom9.org/showthread.php?t=131206)