View Full Version : SAR - Just checking I understand this right
Raithmir
22nd December 2005, 13:25
Ok so I'm testing out x264 for the first time. I'm going to encode Star Wars Episode 1 using full resolution just cropping away the black borders.
720x576 crop 72 off the top and bottom... (to make sure height is divisible by 16, is this still needed these days?)
So thats 720x432
SAR_x DAR_x * height
----- = --------------
SAR_y DAR_y * width
So....
16 * 432 = 6912
9 * 720 = 6480
So I need to use --sar 6912:6480??? is that correct? If not then I've no idea lol.
buzzqw
22nd December 2005, 13:58
i think (and i hope) you must retain full height. So in calculation you cannot take off crop
BHH
Sharktooth
22nd December 2005, 14:46
Q17 on http://forum.doom9.org/showthread.php?p=696689#post696689
use full height and width.
Raithmir
22nd December 2005, 16:06
Ahhh so cropping makes no difference. I did read Q17, and the linked thread, but didn't see anything about cropping. The thread also confused me as people were posting all kinds of different numbers.
So it should be...
16 * 576 = 9216
9 * 720 = 6480
which I can see is the same as SeeMoreDigital's post saying "PAL 16:9 DAR = 64:45". StephanV's post is different though, and I'm sure there was a different one yet again somewhere in that or another post I looked at.
Raithmir
22nd December 2005, 20:58
So why does MeGUI get it so wrong then as well? That confused me as well, just got back and confirmed that when using the avisynth creator, if I don't crop it and click the retain anamorphic box and set to 720x576 then it says...
# Set SAR in encoder to 720 : 506
which is close, but not the same as 64:45. If I crop then it changes it to...
# Set SAR in encoder to 720 : 675
Which is certainly not right? I also have to click on the suggest resolution checkbox a couple of times before it works properly. Is it just my machine playing up or is it like this for other people too? I'll report it in the MeGUI thread if it's a bug?
charleski
23rd December 2005, 06:12
So why does MeGUI get it so wrong then as well? That confused me as well, just got back and confirmed that when using the avisynth creator, if I don't crop it and click the retain anamorphic box and set to 720x576 then it says...
# Set SAR in encoder to 720 : 506
which is close, but not the same as 64:45.
720/506=1.422924901
64/45=1.4222recurring
The difference is a result of rounding errors in the integer arithmetic (necessary to accomodate different sizes and ARs) and is less than 0.05%... Don't lose sleep over it.
If I crop then it changes it to...
# Set SAR in encoder to 720 : 675
Which is certainly not right?Well, maybe it is. Can you explain exactly what you do to produce that figure? I know there's still a small bug somewhere in the flow for the resolution calculations but haven't hunted it down yet (there are a few areas where user input isn't caught correctly). Basically, if you select the right DAR, tick the 'maintain anamorphic resolution' box and then crop and select the desired output size (which is determined by the width), you have no problems. Exactly what do you click on and in what order to produce the SAR you quoted?
BTW, star wars films are 2.35:1, so you should set a custom DAR of 2.35 and crop away the black borders at top and bottom.
Raithmir
23rd December 2005, 10:27
Open d2v file, click auto-crop, click retain anamorpic (leaving resolution set to 640*...), if I click on edit now it has the SAR as -1:-1. Then increase the resolution to 720*... and it changes to 720:675.
You're completely right about the 2.35 aspect, I didn't think about that. What should I set the SAR to for that? I don't know how to work it out from that.
Raithmir
23rd December 2005, 10:31
Ah using the avisynth creator and using custom 2.35 it gives, 720 : 511 is that right?
SeeMoreDigital
23rd December 2005, 11:26
You're completely right about the 2.35 aspect, I didn't think about that. What should I set the SAR to for that? I don't know how to work it out from that.Okay.... try this: -
Crop away all the mattes to leave you with an 720x432 image frame size. Then add a custom SAR of 24:17
Cheers
charleski
23rd December 2005, 11:55
Open d2v file, click auto-crop, click retain anamorpic (leaving resolution set to 640*...), if I click on edit now it has the SAR as -1:-1.Yeah, this is what I need to fix, the calculation of the SAR is only invoked when you change the size.
Then increase the resolution to 720*... and it changes to 720:675.Which is actually right. You've cropped away the black borders, but the DAR (which is all that really matters) is still set to 16:9, so meGUI works out what it needs to do to unsquish the skinny picture you now have to a 16:9 aspect ratio.
You're completely right about the 2.35 aspect, I didn't think about that. What should I set the SAR to for that? I don't know how to work it out from that.No need to work anything out. Load the d2v, set the Input DAR to Custom and type 2.35 in the box next to it. Then tick the 'Retain anamorphic' box, click autocrop and then resize to 720 width.
If you're still worried, just open the avs in Notepad and add Trim(0,25) to the end then run a test encode - this will encode a 1 second sample which you can play back to check you have the right aspect ratio at the end of the process.
Raithmir
23rd December 2005, 12:08
Thanks guys, getting my head around it now I think.
Just kicking off an encode now using 24:17, is that the non-ITU calculation and the one MeGUI uses is ITU standard or something? I know it's very little difference and that you probably can't notice anyway, just curious.
SeeMore : How did you work that out? Interested in the math behind it so I could do it myself.
Raithmir
23rd December 2005, 12:11
Which is actually right. You've cropped away the black borders, but the DAR (which is all that really matters) is still set to 16:9, so meGUI works out what it needs to do to unsquish the skinny picture you now have to a 16:9 aspect ratio.
Hang on a minute, I thought cropping made no difference and I should still use the full original height when working it out?
So surely the 720:506 should be right and the same whether you're cropping or not?
charleski
23rd December 2005, 15:22
Hang on a minute, I thought cropping made no difference and I should still use the full original height when working it out?
So surely the 720:506 should be right and the same whether you're cropping or not?
No, because when you crop vertically you're altering the vertical height of your source input. Your full original height is only 432 lines (the rest of the area on the DVD is black matting bars, and you don't want to waste bitrate on them), so the aspect ratio calculations take that into account. The calculation looks at the DAR you've specified, then looks at the cropped picture that you give it and works out how to transform the cropped picture (resized to fit a 16x16 grid, yes that is still important) to the desired DAR.
As far as ITU goes: no, the calculations assume that the output device has square pixels (the Common Image Format standard) rather than the anachronistic values found in the ITU standard that are just a hold-over from the days of analog.
I've updated meGUI to catch user input more consistently in the resizing/SAR caluclations: version 0.2.3.1024 at the end of the meGUI development thread.
Raithmir
23rd December 2005, 16:12
"i think (and i hope) you must retain full height. So in calculation you cannot take off crop"
"use full height and width."
And now you say to use 432, which is after cropping. So which is it? Can anyone else see why I'm getting confused here?
charleski
23rd December 2005, 17:12
You want to use the full image height and width so that you keep all the information that is available from the DVD. The black matting is not part of the image and is only there because the DVD standard has a very rigid specification. You don't want to keep the black bars, so you can throw them away. You very definitely do need to apply the crop first before further calculations, otherwise you'd be including picture area that isn't going to be encoded and the calculations would be invalid.
There are, of course, times when you would want to resize the picture down, for instance if you're doing a 1CD encode of a longish movie, or are preparing something for a channel which needs smaller dimensions than the DVD standard.
The actual way meGUI calculates the SAR is as follows:
1) Apply the cropping and then determine the aspect ratio of the input video image (inputPixelCountRatio).
2) Scale the vertical resolution according to the horizontal resolution that's been specified (resizedVerticalResolution = horizontalResolution / inputPixelCountRatio)
3) Adjust the vertical resolution so that it matches the closest multiple of 16.
4) Set SARX to the horizontal resolution.
5) Set SARY to Round(HorizontalResolution^2 / (VerticalResolution * DAR)), this is then truncated to an integer.
Raithmir
23rd December 2005, 19:31
So my original post was in fact correct? (apart from getting the aspect ratio wrong, 16:9 instead of 2.35:1)
charleski
23rd December 2005, 19:58
Yes :)
There's a lot of confusing stuff around on the web about aspect ratios, but it's easy when you realise that the only aspect ratio that really matters is the DAR, the AR that you want to end up with. Everything else is just a transform (how do I get there from here). The whole thing isn't helped by the lingering analog embers of the ITU kludge that attempted to map digital pixels onto analog bandwidth, but as SeeMoreDigital points out on his website, the ITU standard for ARs is irrelevant nowadays.
SeeMoreDigital
23rd December 2005, 20:14
You want to use the full image height and width so that you keep all the information that is available from the DVD. The black matting is not part of the image and is only there because the DVD standard has a very rigid specification.This depends on your point of view!
It's probably more accurate to say that the matte has in-fact been encoded along with the image. So in reality it could just as well have been coloured grey instead black ;)
Thankfully the edge of the matte on most of todays DVD is much sharper than with earlier DVD transfers, so in some repects it's less important to crop them away.
Cheers
charleski
23rd December 2005, 20:30
This depends on your point of view!
It's probably more accurate to say that the matte has in-fact been encoded along with the image. So in reality it could just as well have been coloured grey instead black ;)
Well whatever colour it is, it's still true that it represents data which carries no useful information and so should be thrown away. The flexible playback transform capabilities written into the mp4 standard do away with the need to waste bitrate on the garbage mattes required by MPEG-2.
Raithmir
23rd December 2005, 21:52
Yes :)
Thank god for that! :D
Thanks for the help guys.
One thing I'd like in the avisynth creator bit is a tick box for resize, the same as there is for crop. Not that it matters much cause I just go into the edit tab and remove the resize line anyway if I'm keeping full res.
charleski
24th December 2005, 02:36
One thing I'd like in the avisynth creator bit is a tick box for resizeThere's no disable option for resize because resizing is pretty much mandatory for everything. The number of DVDs I've come across that were properly encoded without garbage mattes that needed to be cut away and resized can be counted on one hand.
Raithmir
24th December 2005, 10:36
I crop away, but why bother resize, unless it's a 1cd backup.
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.