Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Video Encoding > MPEG-4 AVC / H.264

Reply
 
Thread Tools Search this Thread Display Modes
Old 23rd October 2007, 17:28   #1  |  Link
bur
Registered User
 
Join Date: Jul 2005
Posts: 103
How to set aspect properly?

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.

Last edited by bur; 23rd October 2007 at 19:18.
bur is offline   Reply With Quote
Old 23rd October 2007, 19:16   #2  |  Link
Maccara
Registered User
 
Join Date: Dec 2001
Posts: 145
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.
Maccara is offline   Reply With Quote
Old 23rd October 2007, 19:24   #3  |  Link
bur
Registered User
 
Join Date: Jul 2005
Posts: 103
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, 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...

Last edited by bur; 23rd October 2007 at 19:31.
bur is offline   Reply With Quote
Old 23rd October 2007, 19:36   #4  |  Link
Maccara
Registered User
 
Join Date: Dec 2001
Posts: 145
Quote:
Originally Posted by bur View Post
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.

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.

Last edited by Maccara; 23rd October 2007 at 19:48.
Maccara is offline   Reply With Quote
Old 24th October 2007, 18:24   #5  |  Link
bur
Registered User
 
Join Date: Jul 2005
Posts: 103
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 is offline   Reply With Quote
Old 24th October 2007, 20:13   #6  |  Link
bur
Registered User
 
Join Date: Jul 2005
Posts: 103
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.

Last edited by bur; 24th October 2007 at 20:40.
bur is offline   Reply With Quote
Old 24th October 2007, 23:15   #7  |  Link
Maccara
Registered User
 
Join Date: Dec 2001
Posts: 145
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 is offline   Reply With Quote
Old 24th October 2007, 23:25   #8  |  Link
Maccara
Registered User
 
Join Date: Dec 2001
Posts: 145
Quote:
Originally Posted by bur View Post
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).
Maccara is offline   Reply With Quote
Old 25th October 2007, 07:14   #9  |  Link
bur
Registered User
 
Join Date: Jul 2005
Posts: 103
It's 16:9, but I couldn't find any numbers for the PAR on such DVDs. I checked this site as well as the one you posted.

I found this site (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.

Last edited by bur; 25th October 2007 at 18:43.
bur is offline   Reply With Quote
Old 25th October 2007, 19:23   #10  |  Link
Maccara
Registered User
 
Join Date: Dec 2001
Posts: 145
Quote:
Originally Posted by bur View Post
It's 16:9, but I couldn't find any numbers for the PAR on such DVDs. I checked this site 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.

Quote:
I found this site (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 ).
Quote:
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.
Maccara is offline   Reply With Quote
Old 26th October 2007, 14:44   #11  |  Link
Brother John
(schein)heilig
 
Brother John's Avatar
 
Join Date: Jun 2003
Location: Germany
Posts: 512
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. (A Google translation might help.)

Exact PAR according to ITU-R BT.601
Code:
      PAL         NTSC
4:3   1150/1053  38800/42651
16:9  4600/3159  155200/127953
Almost exact and commonly used ITU-PAR according to Jukka Aho’s well-known article. However he did not account for the fact that the top and bottom half-lines of the analog image are only half-height.
Code:
      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.
Code:
      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.
Code:
      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:
  1. 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.
  2. 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.
  3. 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
  1. Crop, do NOT resize.
  2. The cropped picture should ideally be mod16.
  3. Set the appropriate PAR in the encoder. --sar for x264, -par for Xvid_Encraw
  4. 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.
__________________
Brother John

When lost in BeSweet's options, have a look at the Commandline Reference.
DVD nach MPEG-4 klappt nicht? Verzweifelt? Auf zum Encodingwissen!

Last edited by Brother John; 8th January 2014 at 23:39. Reason: added really exact ITU numbers
Brother John is offline   Reply With Quote
Old 26th October 2007, 16:45   #12  |  Link
bur
Registered User
 
Join Date: Jul 2005
Posts: 103
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?

Last edited by bur; 26th October 2007 at 16:50.
bur is offline   Reply With Quote
Old 26th October 2007, 18:21   #13  |  Link
pdanpdan
Registered User
 
Join Date: Apr 2005
Location: Bucharest, Romania
Posts: 145
you can try this:
http://mail.mercury.ro/www/dan/AR Calculator.7z
Attached Files
File Type: 7z AR Calculator.7z (4.5 KB, 332 views)

Last edited by pdanpdan; 26th October 2007 at 18:31.
pdanpdan is offline   Reply With Quote
Old 26th October 2007, 19:42   #14  |  Link
bur
Registered User
 
Join Date: Jul 2005
Posts: 103
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...
bur is offline   Reply With Quote
Old 26th October 2007, 23:25   #15  |  Link
Maccara
Registered User
 
Join Date: Dec 2001
Posts: 145
Quote:
Originally Posted by Brother John View Post
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.
Maccara is offline   Reply With Quote
Old 27th October 2007, 01:00   #16  |  Link
Brother John
(schein)heilig
 
Brother John's Avatar
 
Join Date: Jun 2003
Location: Germany
Posts: 512
@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.
__________________
Brother John

When lost in BeSweet's options, have a look at the Commandline Reference.
DVD nach MPEG-4 klappt nicht? Verzweifelt? Auf zum Encodingwissen!
Brother John is offline   Reply With Quote
Old 27th October 2007, 23:47   #17  |  Link
bur
Registered User
 
Join Date: Jul 2005
Posts: 103
Quote:
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
bur is offline   Reply With Quote
Old 2nd January 2014, 07:34   #18  |  Link
Overdrive80
Anime addict
 
Overdrive80's Avatar
 
Join Date: Feb 2009
Location: Spain
Posts: 673
Hi, I am wondering if my reasoning is correct for doing anamorphically encoded MPEG-4.

Knowing that DAR=SARxPAR. SAR (DVD, NTSC, AR-16:9)= 720x480 and after cropping is: 716x474
  • For generic PAR

    16/9=716/474*PAR

    If 716/474=358/237

    16/9=358/237*PAR

    Clearance values:

    PAR=16*237/9*358=3792/3222

    Would be correct value of parametre? --sar 3792:3222

  • ITU PAR

    DAR=(720/480)x(5760/4739)=(3/2)*(5760/4739)=17280/9478=8640/4739

    8640/4739=716/474x(PARx/PARy)

    If 716/474=358/237

    8640/4739=358/237*PAR

    Clearance values:

    PAR=8640*237/358*4739=2047680/1696562=1023840/848281

    Would be correct value of parametre? --sar 1023840:848281

Thanks in advance.
__________________
Intel i7-6700K + Noctua NH-D15 + Z170A XPower G. Titanium + Kingston HyperX Savage DDR4 2x8GB + Radeon RX580 8GB DDR5 + ADATA SX8200 Pro 1 TB + Antec EDG750 80 Plus Gold Mod + Corsair 780T Graphite
Overdrive80 is offline   Reply With Quote
Old 2nd January 2014, 12:41   #19  |  Link
Brother John
(schein)heilig
 
Brother John's Avatar
 
Join Date: Jun 2003
Location: Germany
Posts: 512
I’m not sure what exactly you want to achieve with your calculations.

If you just want to keep the original PAR you do not need to calculate anything. The PAR is not affected by cropping. --sar should be the appropriate value for NTSC 16:9 according to your PAR table of preference (see my post above).

If you want your cropped image to have an exact 16:9 DAR then your “for generic PAR” method is correct. Technically your “ITU PAR” method also seems sane (I didn’t check it in detail) but why would you want to force the final DAR to be the not-quite-16:9 ITU dimensions manually. You can achieve the same thing much simpler by just plugging the appropriate table values into --sar.
Edit: Strike that, it’s not quite the same. Forcing an ITU-ish DAR for a cropped image really does not make sense at all.

Note that the two SAR numbers in H.264 are 16bit fields, i.e. they cannot hold values greater than 65536. In old MPEG-4 Visual (Xivd, DivX) they were only 8bit, i.e. a max. value of 255.
__________________
Brother John

When lost in BeSweet's options, have a look at the Commandline Reference.
DVD nach MPEG-4 klappt nicht? Verzweifelt? Auf zum Encodingwissen!

Last edited by Brother John; 2nd January 2014 at 12:55.
Brother John is offline   Reply With Quote
Old 2nd January 2014, 16:33   #20  |  Link
Overdrive80
Anime addict
 
Overdrive80's Avatar
 
Join Date: Feb 2009
Location: Spain
Posts: 673
Quote:
Originally Posted by Brother John View Post
I’m not sure what exactly you want to achieve with your calculations.

If you just want to keep the original PAR you do not need to calculate anything. The PAR is not affected by cropping. --sar should be the appropriate value for NTSC 16:9 according to your PAR table of preference (see my post above).

If you want your cropped image to have an exact 16:9 DAR then your “for generic PAR” method is correct. Technically your “ITU PAR” method also seems sane (I didn’t check it in detail) but why would you want to force the final DAR to be the not-quite-16:9 ITU dimensions manually. You can achieve the same thing much simpler by just plugging the appropriate table values into --sar.
Edit: Strike that, it’s not quite the same. Forcing an ITU-ish DAR for a cropped image really does not make sense at all.

Note that the two SAR numbers in H.264 are 16bit fields, i.e. they cannot hold values greater than 65536. In old MPEG-4 Visual (Xivd, DivX) they were only 8bit, i.e. a max. value of 255.
Ok, then I will take value of PAR like constant. Thanks.
__________________
Intel i7-6700K + Noctua NH-D15 + Z170A XPower G. Titanium + Kingston HyperX Savage DDR4 2x8GB + Radeon RX580 8GB DDR5 + ADATA SX8200 Pro 1 TB + Antec EDG750 80 Plus Gold Mod + Corsair 780T Graphite
Overdrive80 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:26.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.