View Full Version : Is there an on-line tutorial about SAR?
Gilgamesh-au
10th July 2016, 06:13
Hello,
As the title says I'm looking for an on-line tutorial/guide on using SAR properly. After having read that I should be able to come back here and ask some "intelligent" questions.
Searching on SAR in the forums didn’t return anything for me, probably because the search parameter was too small. Searching on google returned http://forum.doom9.org/showthread.php?t=127232 but that was answers to a specific question whereas mine is more general.
Some background on my reasons for the request.
I used to encode XviD using Gordian Knot and the guide I had for that said after trimming the black lines to continue trimming until the aspect error value was less than 1%. I assume they wanted the pixel aspect ratio to be 1:1 for display purposes. This had the issue that a little bit of the picture was lost.
I have heard elsewhere that using SAR on my x264 encodes would ensure that the display was correct. Then I wouldn’t need to lose any of the picture with extra trimming for a 1:1 PAR.
Thank You
hello_hello
14th July 2016, 21:24
Generally video was resized to square pixels for Xvid encoding as that's all most AVI capable DVD players supported. The output was also generally mod16 (width and height evenly divisible by 16), which meant often a bit of picture needed to be cropped in order not to distort it when resizing. These days mod4 is fine (I've never had a problem with a hardware player playing even mod2) which helps cut down on any extra cropping required when resizing to square pixels.
Edit: Most of what I've written below assumed you were referring to encoding anamorphic video such as DVDs. For a source with square pixels you can still change the SAR when resizing rather than crop extra picture to prevent distortion, but due to mod4 resizing being the norm I think most people just keep the SAR 1:1.
Support for anamorphic h264 (non square pixels) in an MKV/MP4 is pretty good these days, but not universal. The media player in the TV in this house assumes square pixels so I always resize to square pixels for encoding myself. Although I resize "up" as there's no 720 width restriction given we live in a HD world. ie 1024x576 for a PAL 16:9 DVD or 854x480 for NTSC etc.
In a perfect world though, you'd crop away the crud and encode what's left using the same pixel aspect ratio (sample aspect ratio) as the source, no resizing involved. For complete piece of mind, you'd probably crop so it's mod4, but that's at worst only an extra couple of pixels. Then it's just a matter of telling the x264 encoder which PAR you prefer.
There's a list of PARs here (chances are Gordian Knot used the "almost exact ITU" pixel aspect ratios for calculating resizing).
https://www.doom9.org/showthread.php?p=1058927#post1058927
My rule of thumb is to use the mpeg4 PARs for 4:3 DVDs (they're almost identical to the official ITU PARs but easier to remember) and to use the generic PARs for 16:9 DVDs. There's no way to know for sure which is correct but in my opinion that'll be right far more than it's wrong. The generic PARs give you an exact 4:3 or 16:9 display aspect ratio (assuming no cropping) while the ITU/mpeg4 aspect ratios are a little wider (about 2.5%). Anyway... for a 16:9 PAL DVD and anamorphic encoding that'd mean cropping and adding --sar 64:45 to the x264 command line.
Mind you I tend to still do some picture cropping much of the time anyway, as I'm a bit OCD about aspect ratio. My minimum is 4:3, which sometimes means after cropping a 4:3 DVD, cropping a bit more picture top and bottom is required to make it 4:3 again, and if it's quite close to 16:9 after cropping I keep cropping until it is 16:9. But that's just me....
Most encoder GUI's these days have an anamorphic encoding mode, and you can use strict anamorphic or resize to square pixels or anamorphic with resizing etc.... and they'll take care of the SAR for you. I use MeGUI myself. If you've not used it before, open a vob file via the File/Open menu, add the indexing job to the queue when it asks, run the indexing job and when it's done the script creator will open with a preview. It creates a basic script for you but you're free to modify it yourself.
If you're familiar with GK and AVisynth, MeGUI and the tools is uses shouldn't be completely foreign.
I think I ended up writing a guide of sorts......
an3k
19th July 2016, 15:30
Maybe this helps? http://forum.doom9.org/showpost.php?p=1318656&postcount=1
Or use this, it's a better one http://forum.doom9.org/showpost.php?p=1360932&postcount=12
However, this is from the old ages. With H.264 / MKV you actually don't need it anymore as long as you do NOT use anamorph encoding. Nobody does this because it there is no use for it anymore.
The whole Aspect Ratio fiasco and anamorph encoding was caused by the DVD specification not being able to store videos in 4:3 or 16:9 aspect ratio but only 5:4 (720x576).
The second url links to a post in a thread where we discussed SAR, PAR, DAR and I think it's clear that the different consortiums making the different specifications had not a real clue what they are doing in regards of Aspect Ratios. Same goes for the DVD resolution "We want to pack 4:3 or 16:9 onto a disc. Ok, lets squeeze everything into 5:4."
The best thing was when ITU released their own aspect ratios. These are different to the previously used ones. For example: 16:9 PAL is 1,778. But ITU thought 16:9 is 1,823361. Same goes for 4:3 PAL which is 1,333 but for ITU 4:3 is 1,367521.
"Experts"
EDIT: Sorry, I was too fixated on finding my old posts and (trying) to explain PAR that I didn't read what you want to do.
If you do not want to either 1) squeeze the video at least a tiny bit or 2) crop off any pixels of the actual video but instead just want to crop off eg. letterboxing or overscan and set the correct AR you can do that if you are fine with "weird" resolutions like 1916x878 (AR 2,40) or 762x570 (AR 4:3).
I never worked with Gordian Knot but I'll take a look and do some examples to see what you can set regarding Aspect Ratios. If you still need help :)
EDIT 2: What is your source? DVD with anamorph encoded video? What is your target container? Xvid AVI? To mux my encodes I use MKVToolNix GUI. There I can set at what Aspect Ratio the video should be shown in (eg. 1,333 - 1,778 - 1,850 - 2,200 - 2,350 - 2,400) and the tool does the rest.
hello_hello
21st July 2016, 22:49
an3k,
I'd be tempted to disagree with some of your information.
Most people here would recommend using anamorphic encoding for DVDs if possible because the video can be encoded without resizing. It's resized to the correct aspect ratio on playback as the original DVD would be. Assuming your player supports anamorphic video correctly. Anamorphic support is far more common now than it was for Xvid/Divx AVIs (AVI doesn't officially support anamorphic video) so it was less common to use anamorphic encoding then as it is for h264 video in an MP4 or MKV.
DVDs were designed to be backwards compatible with analogue NTSC and PAL. For analogue signals there are no pixels, just scanlines, and the number of scanlines were already set for NTSC and PAL. The issue then became the frequency with which to sample those scanlines, which gives you a number of pixels.
http://lurkertech.com/lg/video-systems/#480i
The ITU spec was based on sampling an analogue signal and the assumption the active picture isn't the full width, which is why they result in slightly wider aspect ratios than 4:3 and 16:9. The assumption is only 704 pixels is picture area. ie 704x480 = 4:3 or 16:9 and 704x576 is 4:3 or 16:9 (for PAL I think it's 702x576 but it's rounded to 704). The extra 8 pixels each side aren't picture. I'm not sure I've ever seen one, but 704x480 or 704x576 are legal resolutions for 4:3 DVDs.
Given NTSC and PAL are originally 4:3 analogue formats (you won't find a 16:9 VHS tape) the ITU spec seems to apply to most 4:3 DVDs, if not all of them.
At some stage it seems for 16:9 DVDs, the ITU method of 704 pixels containing the picture area transitioned to the entire 720 width containing the picture area, but if anything ITU came first. That changed the pixel aspect ratio though, and for 16:9 PAL it became 64/45, or 1.42222 as apparently GSpot was showing you. There's no way to know for sure which is correct as it's not specified anywhere, so a program or player (including GSpot) has to pick which PAR it's going to use.
If you look at the PARs from this link (https://www.doom9.org/showthread.php...27#post1058927) you'll see the PARs used by DivX you referred to in one of your links, such as 16/11, are the mpeg4 equivalents of the ITU aspect ratios. They're almost identical.
The rule of thumb I go by is all 4:3 DVDs use an ITU PAR (or mpeg4 as they're virtually the same). The majority of them have a considerable amount of crud down each side which indicates only 704 pixels of the width is active picture, and some of that normally wasn't seen in the analogue days due to overscanning (https://en.wikipedia.org/wiki/Overscan).
For 16:9 DVDs if they're old and have a similarly large amount of crud down each side it's an indication they might be ITU, but there's still no guarantee. I'm fairly sure most 16:9 DVDs (when it comes to PAL at least) use the generic PARs for exact 16:9 resizing.
Whether you resize to square pixels or use anamorphic encoding you've still got to assume your source DVD uses a particular PAR.
Most equipment with analogue connections seem to display DVDs using an ITU aspect ratio while digital connections (ie HDMI) use exact 4:3 or 16:9 resizing. Most software players use exact 4:3 or 16:9 resizing too.
If you're going to use anamorphic encoding I'd recommending specifying the PAR (or SAR - sample aspect ratio as it's now called) for the x264 encoder. If not and you remux with MKVToolNix while setting an aspect ratio, you end up with a video stream with no specified aspect ratio, or maybe a video stream with a 1:1 PAR, and a different aspect ratio written to the container. Then a player has to pick which one to use and it won't always be the correct one. If you specify a PAR when encoding, the video stream and container aspect ratios should be the same.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.