View Full Version : Getting the perfect aspect ratio without cropping pixels?
SnotRat
12th February 2003, 07:16
I'm trying to encode a 16:9 movie that doesn't have any black black borders at the perfect aspect ratio without having to crop any pixels. 496x272 gives me 0% error, but i'd like to go higher than that. If i added borders on the top and bottom how would i figure out if i have the right aspect or not?
manono
12th February 2003, 09:34
Hi-
Interesting question. I don't know if this is the fastest way, but it works. You didn't say, so I'll assume this is NTSC. Open the .d2v in GKnot. Set Input Pixel Aspect Ratio in the Resolution Tab to 1:1. Then set the W-Modul to 16 and adjust the resolution to 720x480. Then save that as an .avs with no cropping or resizing. Then knock out all the lines except the 2 below. You'll get something like this:
LoadPlugin("C:\DIVXST~1\GORDIA~1\mpeg2dec.dll")
mpeg2source("G:\Jeeves\18\JeevesTest18.d2v")
Open it in GKnot and make sure everything's OK. Then, as an example, add the AddBorders line to the script so it looks something like this:
LoadPlugin("C:\DIVXST~1\GORDIA~1\mpeg2dec.dll")
mpeg2source("G:\Jeeves\18\JeevesTest18.d2v")
AddBorders(0,8,0,8)
Save it and open the .avs in GKnot and you should see your movie, but with the added black bars on the top and bottom. The resolution should now be 720x496. Now, change the Input PAR to NTSC 16:9, and resize to your chosen resolution (I'd also set the W-Modul back to 32 at this point), and crop from the top and bottom to get a low Aspect Error. Then save that .avs (with a name different from the first .avs). It'll now say something like this:
LoadPlugin("C:\DIVXST~1\GORDIA~1\mpeg2dec.dll")
avisource("G:\Jeeves\18\JeevesTest18.avs")
crop(0,6,720,482)
BicubicResize(640,352,0,0.5)
Notice how the avisource line replaced the mpeg2 source line in the first script. It's now referring back to the first .avs. You can either leave it that way, or replace avisource with the original mpegsource line and put back the AddBorders line (I think I'd recommend this-probably faster encoding):
LoadPlugin("C:\DIVXST~1\GORDIA~1\mpeg2dec.dll")
mpeg2source("G:\Jeeves\18\JeevesTest18.d2v")
AddBorders(0,8,0,8)
crop(0,6,720,482)
BicubicResize(640,352,0,0.5)
And you should be on your way. But maybe hakko504 or TheWEF have a more elegant solution.
SnotRat
14th February 2003, 09:52
Thank you for the detailed explanation.
I was actually working from a PAL source but i have many borderless 16x9 NTSC to work on as well. I assume for PAL i would follow the same as above but with 720x576 instead?
I'd like to understand why this works. I would have thought adding borders would change the AR by trying to squeeze the picture between them.
hakko504
14th February 2003, 10:33
Adding borders expand the picture, leaving the active picture area intact.
And yes, I have a different solution. :D Not sure if it's better, but I think it will be faster when it comes to encoding.
In GKnot, contrary to all normal recommendations, set the W- and H-module to 2! Even with this method, NEVER EVER USE MOD-1! Find the exact resolution you want with the slider, i.e. the largest one that gives you 0.0% error.
Now we want to find out how much border should be added, so first you round the width up to nearest mod-32 and make a note of the difference [dw]. Now do the same thing for the height, but now round up to mod-16 and take note of the difference [dh].
Now let go to the save and encode part of GKnot and find the edit button. Find the resize line. Here we are going to add the AddBorder call, just after the resize, but before any filtering. I recommend a (tempo/)spatial-smoother like Convolution3D after addborder to reduce the impact of thesharp edges. The Addborder call should look like this AddBorder(dw/2,dh/2,dw/2,dh/2), rounding the first two numbers up to mod-2 and the last two numbers down to mod 2. Examples:#res=632x474 => dw=8, dh=6
BicubicResize(632,474)
Addborder(4,4,4,2) #dh/2=3, first time rounded up to 4, second time rounded down to 2
#res=482x310 dw=30,dh=10
BicubicResize(482,310)
AddBorder(16,6,14,4)
manono
14th February 2003, 12:09
Hi-
I would have thought adding borders would change the AR by trying to squeeze the picture between them.
It would have if the resolution was still 720x480, but as hakko504 said, the black bars were added to an unchanged video to make it 720x496.
I assume for PAL i would follow the same as above but with 720x576 instead?
Yep.
I think it will be faster when it comes to encoding.
OK, but the reason I didn't add a final faster step was because you said recently that AviSynth's crop adds next to no encoding time (see, I remember your posts). What I would also do is adjust the final AddBorders by the amount that was cropped, and cut out the crop line to make it like this:
LoadPlugin("C:\DIVXST~1\GORDIA~1\mpeg2dec.dll")
mpeg2source("G:\Jeeves\18\JeevesTest18.d2v")
AddBorders(0,2,0,0)
BicubicResize(640,352,0,0.5)
However, your solution is certainly faster to set up, and "cleaner" than mine. But SnotRag said he wanted to add black only to the top and bottom. So, with your solution, I guess you'd leave the W-Modul at 32 and change only the H-Modul to 2 initially. I like challenges like this, much more than all the "Error could not open log file" posts we get.
hakko504
14th February 2003, 12:32
I agree with you manono, this is the challenges we like, and not the routine questions that most of the time could be avoided by an advanced search.
And you're right the crop doesn't take any time: but resizing the added black pixels does, and this makes it faster to add the black borders after the resize, as there is fewer pixels to resize. On the other hand, resizing with the borders added will do the spatial smoothing I recommended, so it's not easy to choose. I do remember a thread in the general forum discussing wether to keep black border or not, and IIRC the results were that we could gain 3-8% in compressability by not encoding the black bars. This is not a problem if we do quality based encodings.
manono
14th February 2003, 21:53
Hi-
So it's the resizing that takes longer with the added black bars. Live and learn (as I also remember you saying recently).:)
...the results were that we could gain 3-8% in compressability by not encoding the black bars.
Yeah, I also wouldn't do it the way SnotRat wants. I have no hesitation about cropping some of the video, and avoid leaving black bars at all costs. But we aim to please. :p
SnotRat
18th February 2003, 01:34
Originally posted by manono
Yeah, I also wouldn't do it the way SnotRat wants. I have no hesitation about cropping some of the video, and avoid leaving black bars at all costs. But we aim to please. :p
I find myself psychologically better off when i know i'm viewing the whole uncropped video. :)
Manono, using your method does it matter what border values i add? Like instead of AddBorders(0,8,0,8) in theory would i be able to do something like AddBorders(1,8,3,4)? My understanding is that as long as you're adding borders to 1:1 it doesn't matter what the values are and the AR won't change. Am i correct?
hakko504
18th February 2003, 07:48
Yes, but never use odd values for horizontal resolution! Addborders(1,4,3,8) will fail! Use Addborders(2,4,2,8) instead. And to be on the safe side, the vertical resolution should also be even.
manono
18th February 2003, 08:44
Hi-
There were 3 reasons I chose AddBorders(0,8,0,8). You said you wanted to add black only above and below the video. Adding 8 pixels above and below should be enough to give you low Aspect Error when cropped (by low Aspect Error, I mean 0.5% or less-I don't worry much about getting it down to zero). And third and most importantly, If you add some pixels that aren't multiples of the W and H-Moduls (in this case, the H-Modul being 16), then you'll be changing the size of the video.
So if you add some other combination of numbers (and follow hakko504's advice about making them even numbers, which I second), then I would reset the W and H-modules to 2 temporarily (until the time comes to resize).
SnotRat
19th February 2003, 00:53
I am very confused. I have a NTSC 16:9 source which i got to 0% error at 576x320 by temporarily setting the W and H modules to 2, AddBorders(0,10,0,10) and then by cropping 9 off both the top and bottm.
***********************************************
LoadPlugin("C:\PROGRA~1\GORDIA~1\mpeg2dec.dll")
mpeg2source("E:\V original 1\Vo1.d2v")
AddBorders(0,10,0,10)
-----------------------------------------------
LoadPlugin("C:\PROGRA~1\GORDIA~1\mpeg2dec.dll")
avisource("E:\V original 1\Vo2.avs")
crop(0,9,720,482)
BicubicResize(576,320,0.333,0.333)
0% error
***********************************************
I thought I would get the same results by instead putting AddBorders(0,2,0,2) and then cropping 1 off both the top and bottom, but it resulted in a +1.7% error.
***********************************************
LoadPlugin("C:\PROGRA~1\GORDIA~1\mpeg2dec.dll")
mpeg2source("E:\V original 1\Vo1.d2v")
AddBorders(0,2,0,2)
-----------------------------------------------
LoadPlugin("C:\PROGRA~1\GORDIA~1\mpeg2dec.dll")
avisource("E:\V original 1\Vo1.avs")
crop(0,1,720,482)
BicubicResize(576,320,0.333,0.333)
1.7% error
***********************************************
Here's another example. I have a PAL 16:9 source which i got to 0% error by again setting W and H modules to 2 and AddBorders(6,0,6,0). After cropping 1 off both the top and the bottom, and then 6 off each side it resulted in 0% error at 576x320.
***********************************************
LoadPlugin("C:\PROGRA~1\GORDIA~1\mpeg2dec.dll")
mpeg2source("E:\New Ring Project\Ring 2\r2.d2v")
AddBorders(6,0,6,0)
-----------------------------------------------
LoadPlugin("C:\PROGRA~1\GORDIA~1\mpeg2dec.dll")
avisource("E:\New Ring Project\Ring 2\@@NEW R2\r2.avs")
crop(6,1,720,574)
BicubicResize(576,320,0.333,0.333)
0% Error
***********************************************
Since 6 got cropped off on each side I figured I wouldn't need to AddBorders(6,0,6,0) and could achieve the same result by just cropping 1 off both the top and bottom. It resulted in a 1.7% error.
***********************************************
LoadPlugin("C:\PROGRA~1\GORDIA~1\mpeg2dec.dll")
mpeg2source("E:\New Ring Project\Ring 2\r2.d2v")
-----------------------------------------------
LoadPlugin("C:\PROGRA~1\GORDIA~1\mpeg2dec.dll")
avisource("E:\New Ring Project\Ring 2\@@NEW R2\r2b.avs")
crop(0,1,720,574)
BicubicResize(576,320,0.333,0.333)
1.7% Error
***********************************************
I don't understand where i went wrong in either of these cases.
manono
19th February 2003, 05:47
Hi-
Try as I might, I can't reproduce your error. Maybe some pics will help. Here's the original .avs with the AddBorders:
LoadPlugin("E:\DIVXST~1\GKnot\mpeg2dec.dll")
mpeg2source("D:\Wasabi\Wasabi.d2v")
AddBorders(0,10,0,10)
I open this in GKnot, crop to get 0% Aspect Error and Resize and see this screen:
manono
19th February 2003, 06:16
That gives me this:
LoadPlugin("E:\DIVXST~1\GKnot\mpeg2dec.dll")
avisource("D:\Wasabi\Wasabi-Test.avs")
crop(0,6,720,486)
BicubicResize(576,320,0.333,0.333)
Then , since I don't need to add 10 pixels to the top and bottoms, I change the .avs to this:
LoadPlugin("E:\DIVXST~1\GKnot\mpeg2dec.dll")
mpeg2source("D:\Wasabi\Wasabi.d2v")
AddBorders(0,4,0,4)
I crop again to get 0% Aspect error, and save it to get this .avs:
LoadPlugin("E:\DIVXST~1\GKnot\mpeg2dec.dll")
avisource("D:\Wasabi\Wasabi-Test3.avs")
crop(0,0,720,486)
BicubicResize(576,320,0.333,0.333)
The pic below is of the second GKnot screen with the AddBorders values of 4 pixels above and below the video.
SnotRat
19th February 2003, 23:21
It's my mistake. I knew i was doing something wrong i just couldn't figure out what. The pics set me straight. Thanks. Here's what i was doing using AddBorders(0,4,0,4):
SnotRat
19th February 2003, 23:22
And the correct way i think:
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.