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 > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 22nd June 2020, 20:16   #41  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,934
There's a link for an updated version of CropResize in the opening post, containing fixes for a couple of obscure aspect ratio bugs when specifying an Output DAR. The new version is dated 2020-06-23.

Another link:
CropResize 2020-06-23.zip
hello_hello is offline   Reply With Quote
Old 12th September 2020, 05:43   #42  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,934
There's a link for an updated CropResize in the opening post dated 2020-09-11. There's a summary of changes above the link.
hello_hello is offline   Reply With Quote
Old 28th October 2020, 17:07   #43  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,934
There's a link for an updated CropResize in the opening post dated 2020-10-28. It fixes a minor color conversion gremlin. Details in the "Changes" text file.
hello_hello is offline   Reply With Quote
Old 30th October 2020, 04:52   #44  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,934
Sorry about an update so soon. It was just to fix some obsolete information in the help file, but I changed the version date to 2020-10-30.
There be a link in the opening post.
hello_hello is offline   Reply With Quote
Old 5th November 2020, 11:28   #45  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,934
Mainly a little more fiddling with the color correction. New version dated 2020-11-05.
hello_hello is offline   Reply With Quote
Old 24th December 2020, 00:49   #46  |  Link
Danette
Registered User
 
Join Date: Apr 2013
Posts: 346
Quote:
Originally Posted by hello_hello View Post
Edit: Sorry about the essay, but hopefully this will help makes things clearer.

The script simply uses the supplied InDAR to base the calculations on. If no InDAR/InSAR is specified, it assumes the source is non anamorphic (square pixels). If you were to do the following, it wouldn't crop at all as the InDAR and output DAR (resolution) are the same. Info=true will show you what it's doing.
CropResize(640,480, 0,0,0,0, InDAR=4.0/3.0, Info=true)
For the following it barely crops as the output dimensions almost match the InDAR.
CropResize(652,480, 0,0,0,0, InDAR=15.0/11.0, Info=true)
For the next example, the shape of objects in the picture will be exactly the same after resizing as for the previous one, but because the output width is narrower this time, it has to crop the sides.
CropResize(640,480, 0,0,0,0, InDAR=15.0/11.0, Info=true)
So it's not agreeing about the AR, or auto-cropping in the traditional sense, it's just preventing an aspect error based on the InDAR and output dimensions. It just happens that InDAR=15.0/11.0 requires 16 pixels to be cropped from the width if you want a 4:3 output. If you want to use that InDAR (which I think we decided is correct), but don't want to crop, you can increase the output width a bit.

Think of any specified cropping as the minimum cropping, but the script will increase it as required to prevent aspect error. To see what's being cropped, enable a cropping preview. The yellow lines are the specified cropping and any blue lines are the additional script cropping. The video isn't resized while the cropping preview is enabled.
CropResize(640,480, 10,4,-6,-4, InDAR=15.0/11.0, CPreview=1, Info=true)

For a 16:9 DVD the equivalent InDARs are (and specifying 16:9 output dimensions for resizing).
CropResize(768,432, 0,0,0,0, InDAR=16.0/9.0) - generic DAR
CropResize(768,432, 0,0,0,0, InDAR=20.0/11.0) - mpeg4 DAR

The main idea of CropResize is to crop and resize without having to calculate aspect error and adjust the cropping or resizing manually to prevent it. An example might be cropping a 1080p source and resizing to 720p. If you don't specify a height (use zero instead), the script will apply your cropping and then pick the appropriate height for you. Because it's free to pick the height, any additional cropping to prevent aspect error will be fairly minimal. You can do exactly the same thing with a DVD source as long as you use the correct InDAR
(cropping a 1080p source like this would mean you have a video with a 2.40:1 aspect ratio after cropping the black).
CropResize(1280,0, 4,140,-2,-142)
If you were to specify the same cropping as above with 4:3 output dimensions (still a 1080p source), it'd apply the specified cropping, then crop a huge amount from each side to give you a 4:3 output without distorting the picture.
CropResize(720,540, 4,140,-2,-142)

I find it very handy when working with video where the amount of black varies quite a bit (usually old DVDs), but I'm OCD about cropping it all. So I can do something like the following, specifying enough cropping to remove the black, without having to worry about distorting the picture, because CropResize won't let me.

Trim(0,1596).CropResize(640,480, 8,0,-8,0, InDAR=15.0/11.0) ++ \
Trim(1597,1884).CropResize(640,480, 16,2,-8,-4, InDAR=15.0/11.0) ++ \
Trim(1885,2597).CropResize(640,480, 24,4,-12,-2, InDAR=15.0/11.0) ++ \
Trim(2598,0).CropResize(640,480, 8,0,-8,0, InDAR=15.0/11.0)

But anyway... what I was trying to explain in my previous post, is if you were to decide the source is 4:3 after you only crop 14 pixels from the sides, you can do it by specifying the appropriate InDAR, and that's the DAR the script will base it's calculations on. Use Info=true and you'll see it's only cropping 7 pixels each side here instead of 8.
CropResize(640,480, InDAR=1.35977, Info=true)

CropResize does have a "traditional" auto-cropping option. It requires the AutoCrop plugin (autocrop.dll). When it's enabled, the source is auto-cropped with autocrop.dll, any specified cropping is applied to the auto-cropped video, if necessary the script applies additional cropping to prevent aspect error, then it resizes. Try the following. Assuming auto-crop crops some or all of the black from the sides, the script will then crop 8 more pixels each side, and to prevent aspect error it'll crop a few pixels top and bottom before resizing to 4:3 dimensions.
CropResize(640,480, 8,0,-8,0, AutoC=true, InDAR=15.0/11.0, Info=true)
If you don't specify a height, you probably won't end up with a 4:3 output, but at the same time the script probably won't have to crop much extra picture to prevent aspect error.
CropResize(640,0, 8,0,-8,0, AutoC=true, InDAR=15.0/11.0, Info=true)
Thought it best to move this discussion here, since we are now focusing on this interesting ”CropResize” creation.

I’m trying to digest all of this and, after reading the above from the “Moire Effect & TFM(pp=0) Solution” thread and your initial post in this thread, I may be getting closer to understanding what this does and how I might prefer to use it.

As you may recall, I would accept borders, and even some edge video degradation, in order to retain as much content as possible. I think I’m becoming more interested in using the AutoCrop function in combination with cropping width only, as shown in one of your examples. So, trying to put it all together, I’ve come up with this as a way to meet my goals:

iCropResize(640,480,AutoC=true,InDAR=15.0/11.0,ResizeWO=true,Info=true)

Does it make sense? Would using CleanBorders=true, instead of ResizeWO=true, also crop width only? Is there any advantage to using one vs. the other?

After setting this for a an entire TV series, I suppose that I’ll have to try to find those one or two known circles/spheres and./or squares to verify correct AR as well as keeping an eye on those left and right crops to make sure I’m ok with what is going on there.
Danette is offline   Reply With Quote
Old 24th December 2020, 14:28   #47  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,934
Here's another essay for you.
For anyone else reading this post, we're talking about how to crop and resize a 4:3 NTSC DVD here, but specifying an mpeg4 DAR of 15:11 (1.36364) for the DVD instead of 4:3 (1.33333).

For the explanation of the different modes, I'll ignore auto-cropping for the moment. You're probably aware how anamorphic encoding works, so sorry if the "NoResize mode" explanation is stating the obvious.

When resizing is disabled completely (NoResize=true), the script only crops. So for an anamorphic source you need to set the correct sample aspect ratio when encoding, which would be -sar 10:11 in the encoder command line in this case. The sample aspect ratio isn't changed by cropping (only by resizing), so you can crop, set the SAR for the encoder, and the player will resize the encoded video to the correct aspect ratio on playback, just as it does for the DVD. The CropResize output dimensions are completely ignored when resizing is disabled (unless adding borders is enabled), so they might as well be zero.

CropResize(0,0, 8,0,-8,0, InDAR=15.0/11.0, NoResize=true) # Set -sar 10:11 for the encoder. The output will be 704x480.
The above is exactly the same as simply cropping, but for CropResize, Info=true will tell you the correct SAR to use for encoding, based on the specified DAR.
Crop(8,0,-8,0)
Reduce the cropping each side if 8 pixels crops picture, or don't crop at all, set -sar 10:11 for the encoder, and let the player resize the encoded video (if you specify InDAR=4.0/3.0, Info=true will tell you 8:9 is the SAR, and if don't crop, it would show the video would be resized to exactly 4:3 on playback).

CleanBorders also disables resizing, as it's purpose is only to replace the existing borders with clean ones. If the amount of cropping is uneven, CleanBorders centres the picture. The output dimensions are always the same as the source dimensions, so they might as well be zero. Whatever you crop/auto-crop is replaced with black borders.
CropResize(0,0, 8,2,-8,-2, InDAR=15.0/11.0, CleanBorders=true) # Set -sar 10:11 for the encoder and the output will be always be 720x480 with a 15:11 DAR.

Resize Width Only mode defaults to resizing to square pixel dimensions, and both the output width and height are ignored (unless you set an OutDAR or enable adding borders), so once again they might as well be zero.
CropResize(0,0, 8,0,-8,0, InDAR=15.0/11.0, ResizeWO=true) # Based on the specified cropping and InDAR, the output will be 640x480.
The following would output 640x476.
CropResize(0,0, 8,2,-8,2, InDAR=15.0/11.0, ResizeWO=true)
If you cropped a little more from the sides, you'd end up with 636x476.
CropResize(0,0, 10,2,-10,2, InDAR=15.0/11.0, ResizeWO=true)

As far as auto-cropping goes, you don't know how much it'll crop from the sides if the amount of black varies, or if there's sometimes black top or bottom, so as per the above examples, there's no guarantee the output dimensions will be the same every time for either ResizeWO or NoResize, whereas full resizing mode can do whatever it likes to always output the specified dimensions.
Although keep in mind ResizeWO might still have to crop an extra pixel or three after auto-cropping so it can resize the width without distorting the picture. That's partly because by default, both ResizeWO and NoResize output mod4 dimensions (width and height both evenly divisible by 4). I don't necessarily recommend it, but you can change that to mod2 so ResizeWO has a little more freedom when resizing the width, and therefore any extra cropping would be quite minimal. For NoResize mode, mod2 means it'll never crop more than was cropped by auto-crop, unless you specify manual cropping too.
CropResize(0,0, AutoC=true, InDAR=15.0/11.0, Mod=2, ResizeWO=true)

So there's no perfect answer if you auto-crop. It depends if you want the same output dimensions each time. As you'd rather not crop picture, if you're happy to keep a little of the black, I'd consider forgetting about auto-cropping and resize to square pixel dimensions this way:
CropResize(0,0, 3,0,-3,0, InDAR=15.0/11.0, ResizeWO=true)
Or in this case, the following does exactly the same thing:
CropResize(648,480, 3,0,-3,0, InDAR=15.0/11.0)
The total cropping each side will always be 3.6 pixels, it'll probably never be enough to crop picture (even if it doesn't crop all the black), the height will never be cropped or resized, and the output will always be 648x480.

Hopefully that made things a little easier to understand rather than more confusing.

Last edited by hello_hello; 25th December 2020 at 18:46.
hello_hello is offline   Reply With Quote
Old 29th December 2020, 07:15   #48  |  Link
bruno321
Registered User
 
Join Date: Oct 2018
Posts: 133
Thanks for this, I've been using it really often, only for resizing according to SAR or DAR though, no cropping.

Something I noticed is: if I use CropResize(InSAR=8.0/9.0) to emulate a generic NTSC "4:3" situation, it resizes from 720x480 to 640x480. I'd prefer it resized it to 720x540 -- upsizing, not downsizing, as happens when playing back a DVD encode with 8:9 SAR. Why does CropResize downsize in this case, and can I make it always upsize instead?
bruno321 is offline   Reply With Quote
Old 29th December 2020, 23:47   #49  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,934
It only does that for 4:3 NTSC DVDs, as the default output dimensions are the source height (after any cropping), and the width resized to square pixel dimensions (after any cropping). Without increasing the height, 4:3 NTSC DVDs are the only DVDs that require the width to be resized down.

You can specify any 4:3 output dimensions you like though.
CropResize(720,540, InSAR=8.0/9.0)
CropResize(624,468, InSAR=8.0/9.0)

Keep in mind if the output dimensions (for square pixel resizing) don't match the source display aspect ratio, the script will crop whatever is required to prevent aspect error, so if in doubt only specify a width, or only the height, and the script will choose the appropriate height or width for you.
CropResize(720,0, InSAR=8.0/9.0)
CropResize(0,540, InSAR=8.0/9.0)

It's a good idea to resize that way if there's a fair bit of black to be cropped and you don't know what the output dimensions should be. For example, if you cropped a 16:9 NTSC DVD like this, you could pick the width (I chose 868 for no particular reason) and the script would take care of the height based on the InSAR or InDAR.

CropResize(868,0, 2,42,-2,-42, InSAR=32.0/27.0) # the output would be 868x404

One other thing to keep in mind, if you were to crop before resizing with CropResize, you'd have to specify the sample/pixel aspect ratio, not the original display aspect ratio, as cropping changes the display aspect ratio. For an NTSC 16:9 DVD, this would produce exactly the same result as above.

Crop(2,42,-2,-42)
CropResize(868, InSAR=32.0/27.0)

Whereas this would resize incorrectly.
Crop(2,42,-2,-42)
CropResize(868, InDAR=16.0/9.0)

For non-anamorphic sources it doesn't matter, because there's no InSAR/InDAR required.

Last edited by hello_hello; 30th December 2020 at 00:06.
hello_hello is offline   Reply With Quote
Old 30th December 2020, 07:16   #50  |  Link
bruno321
Registered User
 
Join Date: Oct 2018
Posts: 133
Hmm, I guess the advantage of CropResize for me is precisely that I can quickly preview how the final encode is going to look, without having to do the math manually each time. But I'm not seeing how to do that here, given that I typically like to CropResize after manually cropping the black bars out. If I cropped on both height and width, then how can I input to CropResize a SAR of 8/9 and have it give me an upsized result, without manually specifying to it what width or height I wish it to have (like you did with the 868 above)?

If that doesn't exist, perhaps an extra option "Upsize=true" that would always prevent downsizing would be called for? I'd be grateful for it
bruno321 is offline   Reply With Quote
Old 30th December 2020, 13:45   #51  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,934
An option to upsize isn't out the question. You can't specify output dimensions manually? If not, this does it easily enough.

Code:
# ========== UpSizeMe ===========================================================
#
#  For automatically resizing NTSC 4:3 DVDs based on
#  the cropped width, rather than the cropped height.
#
#  Crop(10,4,-6,-6)
#  CropResize(UpSizeMe(), InSAR=8.0/9.0)
#
#  "Mod" adjusts the width to be used for resizing to a particular mod.
#  The default is mod 4.
#
#  When "Up" is true, if the cropped width isn't a "Mod" width, 
#  it's increased to the next mod width up, otherwise it's
#  reduced to the next mod width down.
#  The default is true.
#
# ===============================================================================

   function UpSizeMe(clip Source, int "Mod", bool "Up")   {
   Mod = default(Mod, 4)
   Up = default(Up, true)
   CroppedWidth = width(Source)
   OutWidth = Up ? ceil(float(CroppedWidth) / float(Mod)) * Mod : \
   floor(float(CroppedWidth) / float(Mod)) * Mod
   return OutWidth   }

# ===============================================================================
Crop(10,4,-6,-6)
CropResize(UpSizeMe(), InSAR=8.0/9.0)

CropResize will resize using the cropped width as the OutWidth. It's output will be 704x528 for the example above, rather than 624x468.
If you want the output to be 4:3 each time (even if it requires cropping a little extra picture), use the CropDAR argument.

CropResize(UpSizeMe(), CropDAR=4.0/3.0, InSAR=8.0/9.0)

The output dimensions will be as close to 4:3 as the mod option allows, which for CropResize defaults to mod4 for the width and height. It's only used when CropResize has to choose one or both of them. When you specify output dimensions, you get what you asked for.

CropResize(UpSizeMe(), CropDAR=4.0/3.0, InSAR=8.0/9.0, Mod=4)

Last edited by hello_hello; 31st December 2020 at 07:10.
hello_hello is offline   Reply With Quote
Old 31st December 2020, 13:53   #52  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,934
bruno321,
I had another idea, so here's a couple of functions. The one you'll want for your 4:3 NTSC DVDs is NCrop().
Simply add your cropping to a script, then add "N" to the beginning of "Crop".

Add the cropping to a script.
Crop(10,4,-6,-6)

Change the function name to NCrop.
NCrop(10,4,-6,-6)

NCrop hands the cropping to CropResize. The cropped video width becomes the output width, 8:9 is used for the sample aspect ratio, and the output is 4:3.

Code:
# ===============================================================================
# ========== NCrop ==============================================================
# ===============================================================================
#
#   NCrop is a CropResize wrapper function for automatically resizing NTSC 4:3 DVDs based on
#   the cropped width, rather than the cropped height.
#   All CropResize arguments can be used with NCrop, except OutWidth and OutHeight.
#
#   NCrop defaults to using InSAR=8.0/9.0 for CropResize. To disable 8:9 as the default input sample
#   aspect ratio, change the InSAR line in the NCrop function to the following:
#   InSAR = defined(InDAR) ? 0 : default(InSAR, 0)
#
#   NCrop also defaults to using CropDAR=4.0/3.0 for CropResize, to ensure the output has a 4:3 display
#   aspect ratio. To disable the forcing of 4:3 cropping and resizing by default, change the CropDAR line
#   in the NCrop function to the following:
#   CropDAR = default(CropDAR, 0)
#
#   The resized height will be mod4.
#
# -------------------------------------------------------------------------------
#
#   Useage:
#   
#   Add cropping to a script.
#   Crop(10,4,-6,-6)
#
#   Add an "N" to the Crop function's name and the NCrop wrapper function takes over.
#   NCrop(10,4,-6,-6)
#
#   After changing the function's name to NCrop, CropResize arguments can also be added.
#
#   Disable the default input SAR.
#   NCrop(10,4,-6,-6, InSAR=0)
#
#   Change the default input SAR and display CropResize info.
#   NCrop(10,4,-6,-6, InSAR=10.0/11.0, Info=true)
#
#   Disable the default input SAR with InDAR.
#   NCrop(10,4,-6,-6, InDAR=0)
#
#   Override the default input SAR with InDAR, set a new input DAR, and enable borders.
#   NCrop(10,4,-6,-6, InDAR=15.0/11.0, Borders=true)
#
# ===============================================================================

 function NCrop(clip Source, int "CL", int "CT", int "CR", int "CB", \
 val "CropDAR", int "CSplit", bool "CAlign", bool "AutoC", int "CThresh", int "CStart", int "CSample", \
 int "CPreview", int "CLine", val "InDAR", val "InSAR", val "OutDAR", val "OutSAR", bool "AutoAspect", \
 int "Mod", int "HMod", bool "NoResize", bool "ResizeWO", bool "Borders", bool "CleanBorders", \
 val "BColor", bool "Frosty", int "ColorCorrect", string "ColorMode", string "Resizer", int "GMode", \
 bool "RMode", int "PicDim", bool "Position", bool "Info")     {

    Try{  IsG1Function = G1_GFunction  }catch(err){  IsG1Function = false  }
    Try{  IsG2Function = G2_GFunction  }catch(err){  IsG2Function = false  }
    
    # Disable the use of GCropResize global variables, just in case....
    IsG2Function ? Eval("  global G2_GFunction = false  ") : nop()
    IsG1Function ? Eval("  global G1_GFunction = false  ") : nop()

    CropDAR = default(CropDAR, 4.0/3.0)
    InSAR = defined(InDAR) ? 0 : default(InSAR, 8.0/9.0)
    InDAR = default(InDAR, 0)
    Mod = default(Mod, 4)
    CroppedWidth = width(Crop(Source, CL, CT, CR, CB))
    OutWidth = ceil(float(CroppedWidth) / float(Mod)) * Mod

 Output = CropResize(Source, OutWidth, 0, CL, CT, CR, CB, CropDAR, CSplit, CAlign, AutoC, \
 CThresh, CStart, CSample, CPreview, CLine, InDAR, InSAR, OutDAR, OutSAR, AutoAspect, \
 Mod, HMod, NoResize, ResizeWO, Borders, CleanBorders, BColor, Frosty, ColorCorrect, ColorMode, \
 Resizer, GMode, RMode, PicDim, Position, Info)

    IsG1Function ? Eval(" global G1_GFunction = true ") : nop()
    IsG2Function ? Eval(" global G2_GFunction = true ") : nop()

 return Output     }

# ===============================================================================
# ===============================================================================

Last edited by hello_hello; 6th January 2021 at 08:01.
hello_hello is offline   Reply With Quote
Old 31st December 2020, 14:00   #53  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,934
GCrop is more generic than NCrop and requires the GCropResize function for specifying CropResize settings, but it's purpose is much the same.

Code:
# ===============================================================================
# ========== GCrop ==============================================================
# ===============================================================================
#
#   GCrop is a CropResize wrapper function, intended for use with the GCropResize function,
#   included with CropResize. "G" for "global", as GCropResize creates global Avisynth variables
#   for CropResize. It passes the video through untouched (unless it's auto-cropping).
#   The purpose of GCrop is to make it easier to apply standard cropping in a script, while still using
#   CropResize for the resizing.
#
#   All CropResize arguments can be used with GCropResize, while GCrop itself can only be used to
#   specify the cropping.
#   If you also specify cropping with GCropResize, it'll be added to GCrop's cropping and the total
#   will be applied by CropResize.
#
# -------------------------------------------------------------------------------
#
#   Useage:
#   
#   Add GCropResize to a script to configure any CropResize options.
#   Follow GCropResize with the cropping.
#
#   GCropResize(1280,720, Borders=true, Info=true)
#   Crop(10,44,-6,-42)
#
#   Add a "G" to the Crop function's name and the GCrop wrapper function takes over.
#
#   GCropResize(1280,720, Borders=true, Info=true)
#   GCrop(10,44,-6,-42)
#
# ===============================================================================

 function GCrop(clip Source, int "CL", int "CT", int "CR", int "CB")      {

    Try{  IsG1Function = G1_GFunction  }catch(err){  IsG1Function = false  }
    Try{  IsG2Function = G2_GFunction  }catch(err){  IsG2Function = false  }

    SourceWidth = width(Source)
    IsGMode = IsG1Function || IsG2Function

    L1 = default(CL, 0)
    T1 = default(CT, 0)
    R1 = default(CR, 0)
    B1 = default(CB, 0)
    R1 = (R1 == 0) ? 0 : (R1 < 0) ? R1 : R1 - Source_Width + L1
    B1 = (B1 == 0) ? 0 : (B1 < 0) ? B1 : B1 - Source_Height + T1

    L2 = IsGMode ? (IsG1Function ? G1_CL : G2_CL) : 0
    T2 = IsGMode ? (IsG1Function ? G1_CT : G2_CT) : 0
    R2 = IsGMode ? (IsG1Function ? G1_CR : G2_CR) : 0
    B2 = IsGMode ? (IsG1Function ? G1_CB : G2_CB) : 0
    R2 = (R2 == 0) ? 0 : (R2 < 0) ? R2 : R2 - Source_Width + L2
    B2 = (B2 == 0) ? 0 : (B2 < 0) ? B2 : B2 - Source_Height + T2

 return CropResize(Source, CL=L1+L2, CT=T1+T2, CR=R1+R2, CB=B1+B2)      }

# ===============================================================================
# ===============================================================================

Last edited by hello_hello; 31st December 2020 at 15:55.
hello_hello is offline   Reply With Quote
Old 5th January 2021, 14:50   #54  |  Link
Danette
Registered User
 
Join Date: Apr 2013
Posts: 346
I’ve spent the last several weeks trying to find AR problems with CropResize on 12 different TV series (all NTSC) …and I can’t find any! So, at this point, I’m going to have to make it my default resizing approach.

I think that what I will do is to use one of your suggestions:
CropResize(0,0, 0,0,-0,0, InDAR=15.0/11.0, ResizeWO=true, Resizer=”Lanczos4Resize”) and add in the cropping (left and right borders only) following use of the auto-crop in AvsPMod’s crop editor. This way, I can quickly determine if the cropping is good. I have a macro that can perform all of this in seconds. Are there any potential pitfalls to which you think I should be alert?

Am I right that the InDAR function is actually changing the pixel size to “x” size, i.e.; the pixel is not square, in order to provide the AR adjustment?

Last edited by Danette; 5th January 2021 at 15:12.
Danette is offline   Reply With Quote
Old 5th January 2021, 20:55   #55  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,934
Quote:
Originally Posted by Danette View Post
I’ve spent the last several weeks trying to find AR problems with CropResize on 12 different TV series (all NTSC) …and I can’t find any! So, at this point, I’m going to have to make it my default resizing approach.

I think that what I will do is to use one of your suggestions:
CropResize(0,0, 0,0,-0,0, InDAR=15.0/11.0, ResizeWO=true, Resizer=”Lanczos4Resize”) and add in the cropping (left and right borders only) following use of the auto-crop in AvsPMod’s crop editor. This way, I can quickly determine if the cropping is good. I have a macro that can perform all of this in seconds. Are there any potential pitfalls to which you think I should be alert?

Am I right that the InDAR function is actually changing the pixel size to “x” size, i.e.; the pixel is not square, in order to provide the AR adjustment?
Yes, the InDAR effectively tells the script the shape of the pixels for the source video, so InDAR=15.0/11.0 and InSAR=10.0/11.0 achieve the same thing for a 4:3 NTSC DVD (InSAR meaning input sample or pixel aspect ratio). If you don't specify either it uses an InSAR and assumes InSAR=1.0.

ResizeWO mode first determines the resized video width after any cropping (otherwise the original width is resized).
For an InSAR (input sample/pixel aspect ratio) it's simply:
Cropped Width x InSAR
InDAR is converted to InSAR with:
(Original Height x InDAR / Original Width)
So for an InDAR the resized width after cropping is:
Cropped Width x (Original Height x InDAR / Original Width)
If there's no cropping the resized width is effectively:
Original Height x InDAR

From there the script works out how much the width needs to be reduced (if at all) to make it mod4, and then calculates how much extra needs to be cropped from the source width so there won't be any aspect error. The source sample aspect ratio is taken into account when calculating any extra cropping.
In ResizeWO mode, if the height after cropping isn't mod4, the script simply crops an extra couple of pixels from either the top or bottom to make it mod4.

Using my earlier example of cropping 3 pixels from each side:
CropResize(0,0, 3,0,-3,0, InDAR=15.0/11.0, ResizeWO=true, Resizer="Lanczos4Resize")
The mod4 width is calculated to be 648 as the exact width would be 649.09.
714 x 480 x (15/11) / 720 = 649.09
or
714 x (10/11) (SAR) = 649.09
And it works out that a total of 3.6 pixels needs to be cropped from each side in order to resize to 648 with zero aspect error, so the end result is the script does this (Info=true will show you what's happening):

Crop(2,0,-2,0)
Lanczos4Resize(648,480, 1.6,0,-1.6,0)

720 - 3.6 - 3.6 = 712.8
712.8 x (10/11) = 648

If there's no cropping:
CropResize(InDAR=15.0/11.0, ResizeWO=true, Resizer="Lanczos4Resize")
The end result is:

Lanczos4Resize(652,480, 1.4,0,-1.4,0)

720 - 1.4 - 1.4 = 717.2
717.2 x (10/11) = 652

So yeah.... a different InDAR would change the result as the script is simply basing it's calculations on the InDAR (or InSAR) you tell it use.

The only difference I can see to cropping with AvsPmod after resizing, if that's what you mean, is resizing in this case reduces the width of the black, because you're resizing down, so if there were 8 pixels of black each side, they're cropped to 6.6 pixels (because CropResize cropped 1.4 pixels each side before resizing to 652x480) and after resizing...
6.6 x (10/11) = 6.
After resizing with CropResize, 8 pixels borders are now 6 pixel borders.
10 pixel borders would end up 7.82 pixels wide.
10 - 1.4 = 8.6
8.6 x (10/11) = 7.82

So you could do this and end up with 640x480
CropResize(0,0, 8,0,-8,0, InDAR=15.0/11.0, ResizeWO=true, Resizer="Lanczos4Resize")

Or you could end up with 640x480 this way.
CropResize(InDAR=15.0/11.0, ResizeWO=true, Resizer="Lanczos4Resize")
Crop(6,0,-6,0)

Whether cropping before or after CropResize crops less black, or more picture, would depend on the width of the black borders to begin with, and if they have mod2 dimensions. It's swings and roundabouts...

If you auto-crop with AvsPmod, it might be better to crop first, then let CropResize do it's thing, but if you do that you must specify the appropriate InSAR rather than a DAR, as cropping changes the DAR, and keep in mind CropResize might still crop a fraction more from the width to prevent any aspect error when resizing.

AutoCrop()
CropResize(InSAR=10.0/11.0, ResizeWO=true, Resizer="Lanczos4Resize")

Did any of that help?

Last edited by hello_hello; 7th January 2021 at 20:20.
hello_hello is offline   Reply With Quote
Old 5th January 2021, 21:37   #56  |  Link
Danette
Registered User
 
Join Date: Apr 2013
Posts: 346
Yes, it helps confirm my understanding.

I am analyzing (with AvsPmod's cropping editor) the width-cropping necessary BEFORE applying CropResize. I then place those AvsPmod cropping values into CropResize for processing.

I don't much care what the final picture width (640x480,652x480,etc.) is, so long as the AR is accurate.
Danette is offline   Reply With Quote
Old 6th January 2021, 07:18   #57  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,934
If you're doing that, here's a wrapper function for you. Similar to the one I posted earlier for bruno321.
This one's called DCrop (for Danette crop).

Edit: Also added Resizer="Lanczos4Resize" as the default resizing method.

The defaults are InDAR=15.0/11.0, ResizeWO=true, and Resizer="Lanczos4Resize".

Apply your cropping with AvsPmod.

Crop(6,0,-8,0)

Then switch to DCrop.

DCrop(6,0,-8,0)

And that's it. DCrop and CropResize take over from there.
The result would be the same as
CropResize(0,0, 6,0,-8,0, InDAR=15.0/11.0, ResizeWO=true, Resizer="Lanczos4Resize")

Code:
# ===============================================================================
# ========== DCrop ==============================================================
# ===============================================================================
#
#   DCrop is a CropResize wrapper function for automatically resizing (4:3 DVDs by default).
#   All CropResize arguments can be used with DCrop.
#
#   DCrop defaults to using InDAR=15.0/11.0 for CropResize. To disable 15:11 as the default
#   input display aspect ratio, change the InDAR line in the DCrop function to the following:
#   InDAR = defined(InSAR) ? 0 : default(InDAR, 0)
#
#   DCrop also defaults to ResizeWO=true. To disable ResizeWO=true as the default,
#   change the ResizeWO line in the DCrop function to the following:
#   ResizeWO = default(ResizeWO, false)
#
#   The default resizing of "Lanczos4Resize" can also be reverted to Spline36Resize by
#   changing the Resizer line in the function to this:
#   Resizer = default(Resizer, "")
#
# -------------------------------------------------------------------------------
#
#   Useage:
#   
#   Add cropping to a script.
#   Crop(6,0,-8,0)
#
#   Add "D" to the Crop function's name and the DCrop wrapper function takes over.
#   DCrop(6,0,-8,0)
#
#   After changing the function's name to DCrop, CropResize arguments can also be added.
#   Specifying a new InDAR or InSAR over-rides the default of InDAR=15.0/11.0.
#   DCrop(6,0,-8,0, InSAR=8.0/9.0, Info=true)
#
#   In order to use the function as intended, if you wish to add resizing to DCrop,
#   the OutWidth & OutHeight must be specified after the cropping, not before.
#   DCrop(6,0,-8,0, 640,480, InSAR=8.0/9.0, ResizeWO=false)
#
# ===============================================================================

 function DCrop(clip Source, int "CL", int "CT", int "CR", int "CB", int "OutWidth", int "OutHeight", \
 val "CropDAR", int "CSplit", bool "CAlign", bool "AutoC", int "CThresh", int "CStart", int "CSample", \
 int "CPreview", int "CLine", val "InDAR", val "InSAR", val "OutDAR", val "OutSAR", bool "AutoAspect", \
 int "Mod", int "HMod", bool "NoResize", bool "ResizeWO", bool "Borders", bool "CleanBorders", \
 val "BColor", bool "Frosty", int "ColorCorrect", string "ColorMode", string "Resizer", int "GMode", \
 bool "RMode", int "PicDim", bool "Position", bool "Info")     {

    Try{  IsG1Function = G1_GFunction  }catch(err){  IsG1Function = false  }
    Try{  IsG2Function = G2_GFunction  }catch(err){  IsG2Function = false  }
    
    # Disable the use of GCropResize global variables, just in case....
    IsG2Function ? Eval("  global G2_GFunction = false  ") : nop()
    IsG1Function ? Eval("  global G1_GFunction = false  ") : nop()

    InDAR = defined(InSAR) ? 0 : default(InDAR, 15.0/11.0)
    InSAR = default(InSAR, 0)
    ResizeWO = default(ResizeWO, true)
    Resizer = default(Resizer, "Lanczos4Resize")

 Output = CropResize(Source, OutWidth, OutHeight, CL, CT, CR, CB, CropDAR, CSplit, CAlign, AutoC, \
 CThresh, CStart, CSample, CPreview, CLine, InDAR, InSAR, OutDAR, OutSAR, AutoAspect, \
 Mod, HMod, NoResize, ResizeWO, Borders, CleanBorders, BColor, Frosty, ColorCorrect, ColorMode, \
 Resizer, GMode, RMode, PicDim, Position, Info)

    IsG1Function ? Eval(" global G1_GFunction = true ") : nop()
    IsG2Function ? Eval(" global G2_GFunction = true ") : nop()

 return Output     }

# ===============================================================================
# ===============================================================================

Last edited by hello_hello; 6th January 2021 at 08:34.
hello_hello is offline   Reply With Quote
Old 8th January 2021, 21:24   #58  |  Link
Danette
Registered User
 
Join Date: Apr 2013
Posts: 346
Well, thank you. You just made my life a little easier ...imagine that.
Danette is offline   Reply With Quote
Old 11th January 2021, 07:45   #59  |  Link
bruno321
Registered User
 
Join Date: Oct 2018
Posts: 133
Just got around to testing these. I've an NTSC (720x480 SAR) source, if I do

Crop(10, 2, -8, -0) I get 702x478.

If I do NCrop(10, 2, -8, -0) I get 704x528. There's this difference in width due to the script forcing mod4. Could you make a mod2 script?

Same with UpsizeMe() (which I personally prefer).

Thanks!
bruno321 is offline   Reply With Quote
Old 11th January 2021, 08:15   #60  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,934
Personally I'd avoid a mod2 width. These days it'd probably be okay, but you never know.. there might still be the odd player/device that won't be happy about it. You're resizing the height anyway, so resizing the width by a couple of pixels at the same time isn't likely to make a difference. Anyway.... I included the Mod argument so you can change the mod to whatever you want.

UpSizeMe(Mod=2)

The default for CropResize is still mod4 for the height though. The width will be whatever UpSizeMe tells CropResize to make it, but if you want to set mod2 for the height as well, you'll need to do this:

Crop(10,4,-6,-6)
CropResize(UpSizeMe(Mod=2), HMod=2, InSAR=8.0/9.0)

To make the default mod2 for UpSizeMe, just change the following line in the function I posted earlier.
Change:
Mod = default(Mod, 4)
to:
Mod = default(Mod, 2)

You'll still have to use Mod=2 or Hmod=2 for CropResize though. For CropResize, Hmod uses the same value as Mod unless you specify a value for HMod, so normally this would change both the width and height mod.

CropResize(640,480, Mod=2, InSAR=8.0/9.0)

You can modify the NCrop function the same way. Changing the Mod default will change the height mod for CropResize too.
To not have the script crop to 4:3 dimensions, as well as changing the Mod line, delete the CropDAR line or change it to the following.

CropDAR = default(CropDAR, 0.0)

Last edited by hello_hello; 11th January 2021 at 08:53.
hello_hello 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 17:55.


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