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. |
25th November 2011, 04:17 | #1 | Link |
Registered User
Join Date: Aug 2008
Posts: 233
|
Determining Pixel Aspect Ratio (PAR)
This is a replacement for this discussion which was so zany and nonsensical. When scaling video to another size, it is essential to determine the pixel aspect ratio (PAR) of the source in order to do it properly.
If your source looks stretched or squeezed horizontally (objects look too fat or too skinny) then it most likely it has non-square pixels. If you don't know where your clip originated, determining PAR can be difficult. Fortunately, only certain dimensions tend to have non-square pixels and most sources of these sizes tend to follow one of the standards. If your image is not of the dimensions listed below, it is most likely square pixels (PAR = 1) and requires no special consideration. [such as 1920x1080, 1280x720, 1024x768, 640x480, 640x360, 480x360, etc.] In addition to common DVD formats, I have also included SVCD and a few oddball "internet" resolutions with decent guesses as to their possible PAR. Please remember that, unless your source comes directly from a DVD or some known standard format, these are only "educated guesses", but educated guesses can often be better than stabbing in the dark. For each resolution there are two possible PAR values listed: The "normal" (4:3) aspect, and "widescreen" (16:9) Common non-square pixel formats and their Pixel Aspect Ratio (PAR) Code:
NTSC =================================================================== 720x486 \ 720x480 \ image appears slightly stretched -----> PAR = (10/11) 704x480 / image appears squeezed ---------------> PAR = (40/33) 352x240 / ------------------------------------------------------------------- 480x480 \ 360x360 \ image appears squeezed ---------------> PAR = (15/11) 352x360 / image appears extremely squeezed -----> PAR = (60/33) / ------------------------------------------------------------------- 360x480 \ 352x480 \ image appears extremely squeezed------> PAR = (20/11) / image appears ridiculously squeezed --> PAR = (80/33) / Code:
PAL =================================================================== 720x576 \ 704x576 \ image appears slightly squeezed ------> PAR = (59/54) 352x288 / image appears extremely squeezed -----> PAR = (118/81) 360x288 / ------------------------------------------------------------------- 480x576 --- image appears extremely squeezed ------> PAR = (59/36) --- image appears ridiculously squeezed ---> PAR = (59/27) 480x384 --- image appears slightly squeezed -------> PAR = (59/54) --- image appears extremely squeezed ------> PAR = (118/81) ------------------------------------------------------------------- 360x576 \ 352x576 \ image appears ridiculously squeezed---> PAR = (118/54) / image appears insanely squeezed-------> PAR = (236/81) / Code:
HD (either NTSC or PAL) =================================================================== 1440x1080 \ 960x720 \ --------------------------------------> PAR = (4/3) 1280x1080 -----------------------------------------> PAR = (3/2) Last edited by vampiredom; 27th November 2011 at 20:41. Reason: corrected SVCD PARs, expanded tables |
25th November 2011, 04:24 | #2 | Link |
Registered User
Join Date: Aug 2008
Posts: 233
|
Converting non-square pixels to square pixels
To convert a non-square pixel image into square pixels without cropping, multiply its width by the PAR. The height does not change. So…
704x480 @ 10/11 PAR would be 640x480 because: 704 * (10/11) = 640 Likewise, 720x576 @ 118/81 PAR would be 1049x576 because: 720 * (118/81) = 1048.8888888888888888888888888889 Just because a particular PAR conversion is "correct", however, it does not always mean it is the best choice. Let's have a look at the example above, which gave use 1048.8888888888888888888888888889x576 for a widescreen PAL DVD. Setting a decimal width is impossible - and setting an odd width such as 1049 will cause problems in YUY2 and YV12 colorspaces. For YUY2, it must be evenly divisible by 2, while YV12 requires mod4. Our example of 1048 will work fine for both. So, in the real world: 720 * (118/81) = 1048 In cases where a video is 720 pixels wide (like all DV and DVD formats), the actual 4:3 or 16:9 area is only 704 pixels wide. This how it is possible, for example, for 720x480 and 704x480 to have the same height and pixel aspect ratio. When converting to square pixels from such sources, it is usually best to crop 8 pixels off of each side and start with a 704x480 box. (Note: Some older professional NTSC formats may use 720x486. In which case, crop 4 pixels from the top and 2 from the bottom.) In AviSynth terms, that's: Code:
# assume a 720x576 source (PAL) Crop(8,0,-8,0) # assume a 720x480 source (NTSC) Crop(8,0,-8,0) # assume a 720x486 source (NTSC, like Matrox I-frame AVI files) Crop(8,4,-8,-2) 704x576 @ 118/81 PAR would be 1024x576 because: 704 * (118/81) = 1025.5802469135802469135802469136 = ~1024 So, why not 1025 or 1026? If you are doing RGB formats only (such as making still images) this may be an OK choice. However, with certain digital video formats, it is advantageous or requried for dimensions to be mod16. 1024 is also a standard computer monitor width, so it is a good choice for several reasons (and nobody will ever tell the difference). In these examples, we will assume the target it YV12 and use dimensions that are mod4 (evenly divisible by 4) for output. Code:
# We are assuming our input it NTSC 16:9 DVD in this example # Note the decimal point values so that AviSynth returns a float instead of an integer PAR = 40.0 / 33.0 # determine new width, make it mod4-safe for YV12 NewWidth = Round(width() * PAR) / 4 * 4 Spline36Resize(NewWidth, height()) Last edited by vampiredom; 25th November 2011 at 05:54. |
25th November 2011, 04:40 | #3 | Link |
Registered User
Join Date: Aug 2008
Posts: 233
|
Converting square pixels to non-square pixels
To convert a square pixel image to a different PAR is easy. Divide the width by the PAR like such:
640x480 @ 10/11 PAR 640 / (10/11) = 704 704x480 The above example is rather simplistic. In many cases, when converting from square pixels, we'll want to scale the image overall. First we need to determine the scaling factor. To accomplish this, divide the source height by the target height: Code:
SourceHeight / TargetHeight = ScalingFactor 480 / 720 = 0.66666666666666666666666666666667 Once we have the scaling factor, apply that to both width and height of the source. 1280 * 0.66666666666666666666666666666667 = 853.33333333333333333333333333333 720 * 0.66666666666666666666666666666667 = 480 Now, divide the source width by the target PAR: 853.33333333333333333333333333333 / (40/33) = 704 From this, we can see that 1280x720 transforms perfectly to 704x480 for widescreen NTSC. The same is true for widescreen PAL: 576/720 = 0.8 1280 * 0.8 / (118/81) = 702.9 720 * 0.8 = 576 Well, almost perfectly in the case of PAL… but 702.9 is more than close enough to 704 to call it 704x576. Sometimes, however. It is necessary or advantageous to crop or pad the source image when converting to from square pixels. Let's take the case of a 4928x3264 photograph that we want to format for 4:3 PAL DVD. First, determine if the image - when scaled proportionately - will be wider or taller than the destination. The destination in this case is 720x576 @ 59/54 PAR. Lets' turn this to square pixels (we don't want to round it yet) MaxWidth = 720 * (59/54) = 786.66666666666666666666666666667 MaxHeight = 576 From this, we'll get the effective Display Aspect Ratio of the target in square pixels: TargetDAR = MaxWidth / MaxHeight = 1.3657407407407407407407407407407 Let's now compare this with the photograph: SourceDAR = 4928/3264 = 1.5098039215686274509803921568627 From this, we can see that the DAR for the photo is larger, meaning it is wider than the Standard 720x576 4:3 PAL DVD. We have the choice of cropping from the sides or letterboxing it (putting bars on the top and bottom of the image.) Let's try it both ways: Cropping to fit another format To determine the cropping, let's get the closest PAL-sized box within that image, in round pixels. We'll use source image's height and the target format's DAR to determine that: 3264 * 1.3657407407407407407407407407407 = 4457.7777777777777777777777777776 = ~ 4458 Which gives us a cropped dimension of 4458x3264. Is is best that this number is evenly divisible by 2. In this case, it is. Were it not, we could have rounded up or down to the nearest 2. More than close enough for this kind of conversion. Letterboxing to fit another format Now, we'll do letterboxing instead of cropping. Width is easy here (Our target width will be 720) we only need to determine height. First, we'll determine our scaling factor. In this case, this will be determined by the target and source widths. Code:
TargetWidth / SourceWidth = ScalingFactor Now, multiply the height by the scaling factor: 3264 * 0.1461038961038961038961038961039 = 476.88311688311688311688311688313 At this point, we are still dealing with square pixel values for the image. We need to apply the PAR to our new height: 476.88311688311688311688311688313 * (59/54) = 521.03896103896103896103896103897 = ~ 520 In AviSynth, we would do something like this to fit our photo into letterboxed PAL 4:3 Code:
# load the 4928x3264 image ImageSource("bigphoto.jpg") # resize and add borders to fill 720x576 Spline36Resize(720, 520) AddBorders(0,28,0,28) Last edited by vampiredom; 25th November 2011 at 06:58. |
25th November 2011, 04:43 | #4 | Link |
Registered User
Join Date: Aug 2008
Posts: 233
|
Converting from one non-square pixel format to another
Most times, when converting from one non-square pixel format to another, we are converting PAL to NTSC or vice versa – or converting to/from a scaled format like SVCD. These types of standards conversions usually require only changing the height or width and leaving the other alone. Note: Any interlaced sources must be deinterlanced (or "bobbed") before scaling the height.
As far as scaling is concerned, these kinds of standards conversion are extremely easy and there really is no math required by the user: Code:
# Restore a 480x480 SVCD to full size for DVD output Spline36Resize(720,480) # Scale the image from 720x480 NTSC -> PAL Spline36Resize(720,576) # Scale the image from 704x576 PAL -> NTSC Spline36Resize(704,480) Let's look at one case where we are not doing NTSC <-> PAL and where some math is required for the conversion. Our source here will be HDV 1440x1080 @ PAR 4/3, which is widescreen. We will convert this to a 720x480 widescreen NTSC DVD two different ways; once with pillarboxing, and again with cropping. First, we'll set the basic parameters common to both versions: Code:
# Assume a 1440x1080 16:9 HDV source SourceWidth = width() SourceHeight = height() SourcePAR = 1.333333 TargetWidth = 720 TargetHeight = 480 TargetPAR = 1.212121 Since the DAR of 720x480 widescreen DVD is slightly wider, the pillarboxed version will resize the video to 704x480 and add 8 pixel borders on each side. Here is VersionA: Code:
# Scale factor based on heights = 0.444444 ScaleFactor = Float(TargetHeight) / Float(SourceHeight) # Determine the width to scale to (no need to determine height) ScaleWidth = Float(SourceWidth) * SourcePAR * ScaleFactor / TargetPAR # Round to mod4 -> 704 ScaleWidth = Round(ScaleWidth * 4) / 4 # Determine the border size PadX = (TargetWidth - ScaleWidth) / 2 VersionA = Spline36Resize(ScaleWidth, TargetHeight).AddBorders(PadX, 0, PadX, 0) Code:
# Scale factor based on widths = 0.5 ScaleFactor = Float(TargetWidth) / Float(TargetHeight) # Determine the cropped height relative to the source TargetDAR = Float(TargetWidth) * TargetPAR / Float(TargetHeight) CropHeight = Float(SourceWidth) * SourcePAR / TargetDAR # Round to mod2 -> 1056 CropHeight = Round(CropHeight * 2) / 2 # Determine the cropping amount for the top and bottom edges CropY = (SourceHeight - CropHeight) / 2 VersionB = Crop(0,CropY,0,-CropY).Spline36Resize(TargetWidth, TargetHeight) Last edited by vampiredom; 27th November 2011 at 07:05. Reason: Added text and examples |
25th November 2011, 06:28 | #5 | Link |
契約者
Join Date: Jun 2008
Posts: 1,576
|
Again this pure-math talks. Oh well, I'm not going to participate in such discussion again, just want to tell for those who hopefully will be able to read it below all this wall of text that there is plenty of dvds that are utilize full 720 pixels width and to get everything right needs to be resized like 720->853 without any cropping (and of course there is nothing to crop at all accept maybe ~2 semi-dark pixels which are normal and happens to be even on BD). Perhaps all american DVDs respect so called standards, I don't own any of such dvds so not sure, but this is not the case for other countries. And this is the case for pal-land too. So don't forget to use your eyes too, not pure math.
Last edited by Keiyakusha; 25th November 2011 at 06:43. |
25th November 2011, 07:23 | #6 | Link | |
Registered User
Join Date: Aug 2008
Posts: 233
|
Absolutely. This is very true. The stuff I put in here is meant to be a starting point and not a one-size-fits all solution. I hinted at that at the top of the post: That the pixel dimensions are not an absolute guarantee of the PAR for any given clip. (Though I state that DVDs adhere to standards, I guess I should have said that they should adhere to such standards).
Quote:
I appreciate your comments. If you or anyone finds an error in what I've written here, please let me know so I can correct it. I am trying to provide some clear guidance in an orderly fashion to newbies, so as to possibly avoid pointless discussions like the one I mentioned previously. |
|
25th November 2011, 08:27 | #8 | Link |
Registered User
Join Date: Mar 2009
Location: Germany
Posts: 5,772
|
There is a lot of misunderstanding (and because of that also lots of misinformation) concerning the aspect ratio in general.
While some of them may derive from notations (SAR) and others from changes in standards and official recommendations (EBU), I think the bulk of misunderstandings comes from a very simple yet overlook issue: the difference between the framesize and the image size (which generally is smaller than the framesize, due to overscan, blanking, and various "safe" settings), and this concerns mainly the people using only the PC that do reencodings, these people having only PC-background. There are only 2 DARs (FS and WS, 4:3 and 16 and 2 alternatives each (standard-analog, also called non-ITU, and ITU-R). However, since the material was processed maybe with a combination of digital (not necessarily ITU) and analog gear before editing (which also may influence the PAR), it is really difficult to find an one-for-all PAR/DAR solution. Depending on the source and its processing, all values may be correct, use your eyes and a PAR 1:1 display .
__________________
Born in the USB (not USA) |
25th November 2011, 10:29 | #9 | Link |
Registered User
Join Date: Dec 2007
Location: Germany
Posts: 632
|
Nice table!
There is however one point where I disagree with what the table states and that is the SVCD PAR. The table assumes the 480x576/480 pixels used in SVCD make up a 4:3 frame. I'm pretty sure though, and that's also what I have observed capturing the output of DVD-Players playing a 480x576 test video, that these 480 pixels are simply a downsized version of 720 which means it has the same characteristics as 720 (wider than 4:3, scanline length is 53.333µs). Therefore the PAR of PAL SVCD is 177/108 and the PAR of NTSC SVCD is 15/11. Edit: Those are for 4:3 video, 16:9 is as follows: PAL 177/81 NTSC 60/33 It's actually just the PAR for 720,704 multiplied by 1.5. Last edited by TheSkiller; 25th November 2011 at 10:41. |
25th November 2011, 11:48 | #10 | Link | |
Registered User
Join Date: Mar 2011
Posts: 4,921
|
Quote:
(Edit) Sorry, I noticed in a later post you modified "tend to" with "should". I don't think you can really generalise and say something like "crop to a width of 704 then use this pixel aspect ratio" etc. and know it'll be correct much of the time, because there's no way to know it will be. Admittedly if it's wrong it won't be out by much, but it can still be wrong. If only DVDs did all stick rigidly to some sort of standard..... Personally I think DVDs (at least) are less likely to follow one of the standards than they are to follow them. My usual way of resizing DVDs is to use a straight 16:9 or 4:3 resize (I can't remember the exact PARs off the top of my head) then crop off only the necessary crud (or crop to mod16), encode what's left and at least 9 times out of 10 that'll be correct. I think DVDs which use the "official" PARs are the exception, not the norm, and I've come to this conclusion after comparing many old DVD encodes with their Bluray equivalent. Anyway, being a GUI kind of guy I tend not to think about PAR all that much (I just choose non-ITU resizing, crop and encode) but for those times I do have to think about it, this resize calculator comes in quite handy as it'll let you choose between resize methods and it'll calculate the aspect ratio distortion for you as you crop. Yoda's Resize Calculator At least with the calculator handy it's not necessary to remember a table of PARs. Last edited by hello_hello; 25th November 2011 at 12:01. |
|
25th November 2011, 17:15 | #11 | Link | ||
Registered User
Join Date: Aug 2008
Posts: 233
|
Thank you!
Quote:
Quote:
More and more, however, I believe that discs will be sticking to the standard... because, finally, most editing software is using the same standard, digital TV broadcasts are using the same standards, etc. For many years, it was not this way (I still remember Adobe using 0.9000 for NTSC in version CS3, etc.) Heed Keiyakusha's words and you'll be fine: use your eyes, too! |
||
25th November 2011, 22:18 | #12 | Link | |
Registered User
Join Date: Dec 2007
Location: Germany
Posts: 632
|
Quote:
In conclusion, and that's my point, if you say a video of 720x... has those particular PARs mentioned in the table then you are ought say that a video of 480x... has those PARs I mentioned, otherwise it wouldn't be consistent. 720 is 1.5 times 480, so the PAR of 480 is also 1.5 times the PAR of 720. Last edited by TheSkiller; 25th November 2011 at 22:21. |
|
26th November 2011, 00:23 | #13 | Link | |
Registered User
Join Date: Aug 2008
Posts: 233
|
Quote:
** EDIT ** correct numbers now incorporated in the table ** EDIT ** Last edited by vampiredom; 26th November 2011 at 17:53. |
|
26th November 2011, 11:13 | #16 | Link | |
Registered User
Join Date: Dec 2007
Location: Germany
Posts: 632
|
Quote:
For example: (NTSC wide) 40/33 * 1.5 = 60/33 Now the test: 720 * 40/33 = 872.72 480 * 60/33 = 872.72 As you can see the 60/33 PAR is giving the same result for the 480 video as the 40/33 PAR does for the 720 video. PAL: 59/54 * 1.5 = 177/108 ...and so on. It should look like this: Code:
480x480 -------------------------------------------> PAR = (15/11) --- image appears extremely squeezed ------> PAR = (60/33) 480x576 -------------------------------------------> PAR = (177/108) --- image appears ridiculously squeezed ---> PAR = (177/81) Last edited by TheSkiller; 26th November 2011 at 11:21. |
|
26th November 2011, 18:26 | #19 | Link | |
Registered User
Join Date: Mar 2011
Posts: 4,921
|
Quote:
I'll admit I did some more thinking on this topic due to this thread, and I must admit that living in PAL-land there's a chance I'm making too quick an assumption the same thing also applies to NTSC DVDs. I have encoded quite a few of them, and I'm sure I've got a few lying around I'll be revisiting again due to this thread, but if the aspect ratio of Bluray discs can be taken as accurate, then in PAL-land at least, I'm absolutely certain by far the majority of discs use straight 16:9 or 4:3 resizing. PAL actually has "digital" pixel aspect ratios, which differ from those vampiredom posted, and if memory serves me correctly they resize to exactly 16:9 or 4:3, although I'm not sure I actually understand them fully yet (cause of the 720 vs 704 width thing). http://en.wikipedia.org/wiki/Pixel_a..._video_formats They also seem to be the same pixel aspect ratios used in digital PAL SD TV. http://en.wikipedia.org/wiki/Standar...ion#Resolution Now didn't vampiredom post something about DVDs, digital TV and editing software all using the same standard? For NTSC the PARs are always the same as those vampiredom posted so if NTSC discs do use straight 16:9 or 4:3 resizing the reason for it is something I'm still yet to learn.... maybe I'm just plain wrong about the way NTSC disc are resized. I'm very tired at the moment though, I'll have to think about this some more tomorrow. In the meantime, comments anyone? |
|
26th November 2011, 19:13 | #20 | Link |
Registered User
Join Date: Dec 2007
Location: Germany
Posts: 632
|
Yes, as stated on the wiki page you linked, those are the official Rec.601 and "common digital" PARs. They differ in less than or about 1 pixel, it is actutally the 702<->704 issue (702 no typo). 702 because that is the very exact active image area in analog PAL. The "digital" PARs assumes 704 which is fine as well, since the difference is too small for any practical application (however 720 generic 4:3/16:9 resizing vs. PAR/ITU based resizing is).
See: 720 * 59/54 = 786.66 720 * 12/11 = 785.45 and 720 * 118/81 = 1048.88 720 * 16/11 = 1047.27 Nothing to worry about imo. Last edited by TheSkiller; 26th November 2011 at 19:16. |
Tags |
conversion, par, pixel aspect ratio, standards |
Thread Tools | Search this Thread |
Display Modes | |
|
|