Log in

View Full Version : Irregular Aspect Ratio question.


Logan9778
9th March 2017, 08:37
Hey guys (and gals!),

I've got a question for all you Guru's.

I'm trying to understand how to derive the correct Pixel Aspect Ratio for X264 (--sar ) from a 720x576 PAL DVD that I want to turn into a digital mkv file so I can play it in Plex.

I know that SAR x PAR = DAR. And PAR = DAR / SAR.

But does this work if you crop not only the sides, but the top and bottom as well?

Say, using Avisynth, I did Crop(16,10,-14,-12) to get rid of bars and bad areas. I'm making the crop a little extreme just to see if it keeps the Aspect Ratio or not. Does PAR = DAR / SAR still work? I've had various people tell me conflicting stuff and I can never find a circle I'm satisfied with on the DAR screen output to tell if its doing it right or not. Tons of Experimentation has kind of made my mind numb and now I'm really confused.

If so, my equation would be PAR = (4/3)/(690/554) to get the PAR value to put into --sar?

I've searched these forums, but never found an answer to this.

2 A.M. here, so I'll check this in the morning

Thanks!

ndjamena
9th March 2017, 09:17
If your source material was 768/720 before cropping, and you don't resize it at any point, it will still be 768/720 after cropping, no matter how much you've cropped off or from where.

As far as X264 is concerned cropping doesn't affect --sar.

Sharc
9th March 2017, 09:46
My advice:
1. Crop the annoying garbage off as you like. This doesn't change the pixel aspect ratio
2. Add clean black borders back such as to restore the original 720x576 frame
3. encode with x264: --sar 16:11 --tff (assuming your DVD is 16:9), or --sar 12:11 --tff if your DVD is 4:3

The maximum AR error (if any) should then be within 2.4%.

ndjamena
9th March 2017, 10:21
Crop(16,10,-14,-12)

That kind of cropping is only useful if you've already deinterlaced the video or if you've got one of those rare PAL DVDs encoded as progressive (W.I.T.C.H., I Dream of Jeannie etc.).

Interlaced YV12 needs to be cropped by four pixels vertically and two pixels horizontally, only progressive YV12 can be cropped by twos vertically because of the way the chroma information is shared.

The --SAR parameter x264 uses is actually the shape of the pixels and has nothing to do with the picture as a whole. 4:3 PAL is stored as 720 pixels but displayed as 768 pixels (4:3) or 1024 pixels (16:9), the --sar simply means for every 720 horizontal pixels in storage there are 768 horizontal pixels displayed (768/720 = --sar 1.0666666666666666666666666666667 or the pixels have a height to width ratio of 1.0666666666666666666666666666667:1), that doesn't change due to cropping since cropping doesn't change the shape of the pixels. According to ITU specs when captured from an analogue source the 4:3 picture is actually contained within a 704 aperture with the other 16 pixels left in reserve in case the capture was off centre. Video recorded as 4:3 from ITU equipment would be left with a --sar of 768/704 (1.0909090909090909090909090909091) or 12:11. There 16:9 videos captured in ITU as well (1024/704, 16:11 or --sar 1.4545454545454545454545454545455).

Videos from analogue captures tend to use ITU specs, while more recent discs tend to use the entire frame. Since you're cropping so drastically it's most likely the disc you're encoding is an ITU analogue capture which should use the 704 pixel aperture.

Ghitulescu
9th March 2017, 10:43
What kind of irregular AR are you talking about?

Anyway, cropping does not change the PAR as explained several time above. Just crop the margins, replace them if you want with black borders (a clever tip), then resize it to quadratic pixels (futureproof), encode it (back) to H.264 and let the player do the rest.

Unless the video comes from whatever strange source (like youtube or "censured" :) ), the PAR and DAR would be standardised, and there are plenty of guides to explain these - maybe too many :) . One of the most common source of confusion, also with these guides is that there are two identically named parameters, SAR, with two completely different meanings, depending on the context: Storage AR and Sample AR. In MPEG4 SAR is SampleAR and it replaces the PAR, whereas the StorageAR is renamed FrameAR. In the good old MPEG2, SAR is StorageAR.

Logan9778
9th March 2017, 11:32
Well, I couldn't sleep. Ndjamena - Where do you get the 768 in "--sar of 768/704" from? And so even though its 720x568, ITU would consider it 704?

I can see that (4/3)/(704/576) = 12/11 and (4/3)/(720/576) = 16/15. But even if its 720x576, you would still use --sar 12:11 because that is ITU standard?

I had thought you always calculated the SARs. Like if I cropped heavily to say, (4/3)/(630/420) = some weird SAR.

The DVD I'm trying to encode is Doctor Who - An Unearthly Child (first Doctor Who season). So, yeah, it's pretty old.

As for the crop, I just was making that up since you can learn more from a good exaggeration of a problem. At least IMO.

@Sharc - If I did crop it down to, say, the 630x420 as above, and left it like that without adding borders and such, I would still just leave the --sar at 12:11? The DVD is 4:3 DAR? according to MediaInfo.

@Ghitulescu - Could you recommend some of those guides?

ndjamena
9th March 2017, 11:51
(576/3)*4 = 768

768x576 = 4:3

720 pixels in storage, 768 pixels on display.

or with ITU padding

704 pixels in storage, 768 pixels on display.

Determining whether a video is ITU or not is difficult sometimes. Unearthly Child does seem to reach almost to the edges...

I think the master tapes for most of the early episodes were wiped and so the DVDs were likely taken from film but I don't know how that works or if it's even a factor.

The early Doctor Who borders are all over the place, they get more consistently ITU as you reach the later seasons. Someone on the forum might be able to explain how that happened.

Sharc
9th March 2017, 12:14
@Sharc - If I did crop it down to, say, the 630x420 as above, and left it like that without adding borders and such, I would still just leave the --sar at 12:11? The DVD is 4:3 DAR? according to MediaInfo.

Yes, leave the --sar 12:11. A SW player will normally read the --sar from the encoded stream and will play the picture undistorted. However, I would strongly recommend to add the borders back, because - depending on the playback scenario and the container - the --sar of the stream will not always be respected and the cropped picture will be stubbornly stretched to 4:3 (or 16:9), means distorted.

Ghitulescu
9th March 2017, 12:29
@Ghitulescu - Could you recommend some of those guides?

The obvious one =-> https://en.wikipedia.org/wiki/Pixel_aspect_ratio

Logan9778
9th March 2017, 21:39
The obvious one =-> https://en.wikipedia.org/wiki/Pixel_aspect_ratio

Lol, yeah, I've read all the wikipedia stuff on DAR/PAR/SAR and Aspect Ratio.

Thanks for all the info guys. I will continue to try to wrap my head about this. More questions to come! :thanks:

Yes, leave the --sar 12:11. A SW player will normally read the --sar from the encoded stream and will play the picture undistorted. However, I would strongly recommend to add the borders back, because - depending on the playback scenario and the container - the --sar of the stream will not always be respected and the cropped picture will be stubbornly stretched to 4:3 (or 16:9), means distorted.

And thanks for that Sharc! Yeah, I've seen it seem to mess up once.