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 22nd December 2005, 13:25   #1  |  Link
Raithmir
Registered User
 
Join Date: Dec 2003
Posts: 51
SAR - Just checking I understand this right

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.
Raithmir is offline   Reply With Quote
Old 22nd December 2005, 13:58   #2  |  Link
buzzqw
HDConvertToX author
 
Join Date: Nov 2003
Location: Cesena,Italy
Posts: 6,552
i think (and i hope) you must retain full height. So in calculation you cannot take off crop


BHH
__________________
HDConvertToX: your tool for BD backup
MultiX264: The quick gui for x264
AutoMen: The Mencoder GUI
AutoWebM: supporting WebM/VP8
buzzqw is offline   Reply With Quote
Old 22nd December 2005, 14:46   #3  |  Link
Sharktooth
Mr. Sandman
 
Sharktooth's Avatar
 
Join Date: Sep 2003
Location: Haddonfield, IL
Posts: 11,768
Q17 on http://forum.doom9.org/showthread.ph...689#post696689
use full height and width.
Sharktooth is offline   Reply With Quote
Old 22nd December 2005, 16:06   #4  |  Link
Raithmir
Registered User
 
Join Date: Dec 2003
Posts: 51
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 is offline   Reply With Quote
Old 22nd December 2005, 20:58   #5  |  Link
Raithmir
Registered User
 
Join Date: Dec 2003
Posts: 51
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?
Raithmir is offline   Reply With Quote
Old 23rd December 2005, 06:12   #6  |  Link
charleski
Registered User
 
charleski's Avatar
 
Join Date: Jul 2004
Posts: 383
Quote:
Originally Posted by Raithmir
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.
Quote:
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.
charleski is offline   Reply With Quote
Old 23rd December 2005, 10:27   #7  |  Link
Raithmir
Registered User
 
Join Date: Dec 2003
Posts: 51
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 is offline   Reply With Quote
Old 23rd December 2005, 10:31   #8  |  Link
Raithmir
Registered User
 
Join Date: Dec 2003
Posts: 51
Ah using the avisynth creator and using custom 2.35 it gives, 720 : 511 is that right?
Raithmir is offline   Reply With Quote
Old 23rd December 2005, 11:26   #9  |  Link
SeeMoreDigital
Life looks better in UHD
 
SeeMoreDigital's Avatar
 
Join Date: Jun 2003
Location: Notts, UK
Posts: 11,455
Quote:
Originally Posted by Raithmir
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
__________________
| I've been testing hardware media playback devices and software A/V encoders and decoders since 2001 | My Network Layout & A/V Gear |
SeeMoreDigital is offline   Reply With Quote
Old 23rd December 2005, 11:55   #10  |  Link
charleski
Registered User
 
charleski's Avatar
 
Join Date: Jul 2004
Posts: 383
Quote:
Originally Posted by Raithmir
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.
Quote:
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.

Quote:
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.
charleski is offline   Reply With Quote
Old 23rd December 2005, 12:08   #11  |  Link
Raithmir
Registered User
 
Join Date: Dec 2003
Posts: 51
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 is offline   Reply With Quote
Old 23rd December 2005, 12:11   #12  |  Link
Raithmir
Registered User
 
Join Date: Dec 2003
Posts: 51
Quote:
Originally Posted by charleski
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?
Raithmir is offline   Reply With Quote
Old 23rd December 2005, 15:22   #13  |  Link
charleski
Registered User
 
charleski's Avatar
 
Join Date: Jul 2004
Posts: 383
Quote:
Originally Posted by Raithmir
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.

Last edited by charleski; 23rd December 2005 at 15:24.
charleski is offline   Reply With Quote
Old 23rd December 2005, 16:12   #14  |  Link
Raithmir
Registered User
 
Join Date: Dec 2003
Posts: 51
"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?
Raithmir is offline   Reply With Quote
Old 23rd December 2005, 17:12   #15  |  Link
charleski
Registered User
 
charleski's Avatar
 
Join Date: Jul 2004
Posts: 383
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.
charleski is offline   Reply With Quote
Old 23rd December 2005, 19:31   #16  |  Link
Raithmir
Registered User
 
Join Date: Dec 2003
Posts: 51
So my original post was in fact correct? (apart from getting the aspect ratio wrong, 16:9 instead of 2.35:1)

Last edited by Raithmir; 23rd December 2005 at 19:50.
Raithmir is offline   Reply With Quote
Old 23rd December 2005, 19:58   #17  |  Link
charleski
Registered User
 
charleski's Avatar
 
Join Date: Jul 2004
Posts: 383
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.
charleski is offline   Reply With Quote
Old 23rd December 2005, 20:14   #18  |  Link
SeeMoreDigital
Life looks better in UHD
 
SeeMoreDigital's Avatar
 
Join Date: Jun 2003
Location: Notts, UK
Posts: 11,455
Quote:
Originally Posted by charleski
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
__________________
| I've been testing hardware media playback devices and software A/V encoders and decoders since 2001 | My Network Layout & A/V Gear |
SeeMoreDigital is offline   Reply With Quote
Old 23rd December 2005, 20:30   #19  |  Link
charleski
Registered User
 
charleski's Avatar
 
Join Date: Jul 2004
Posts: 383
Quote:
Originally Posted by SeeMoreDigital
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.
charleski is offline   Reply With Quote
Old 23rd December 2005, 21:52   #20  |  Link
Raithmir
Registered User
 
Join Date: Dec 2003
Posts: 51
Quote:
Originally Posted by charleski
Yes
Thank god for that!

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.
Raithmir 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 21:34.


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