VideoHelp Forum
+ Reply to Thread
Page 1 of 5
1 2 3 ... LastLast
Results 1 to 30 of 122
Thread
  1. Hi (...)

    sorry I have a video clip that is 720x1280 pixel but my screen is 16:9 1920x1080

    can I tell you into avisynth to auto add the correct black borders to the source so that the image appear with the correct aspect ratio, but outputting alwais my target resolution 1920x1080? or is there a plugin for avisynth that auto-pad or add the black borders to a video that don't match a target aspect ratio?

    thanks
    Last edited by marcorocchini; 8th Oct 2017 at 16:32.
    Quote Quote  
  2. AddBorders(320,180,320,180) # left, top, right, bottom

    You can create a function like this to calculate the values automatically:

    Code:
    function AddBordersToMake(clip v, int width, int height)
    {
       left = ((width - v.width) / 4) * 2
       right = width - (v.width + left)
    
       top = ((height - v.height) / 4) * 2
       bottom = height - (v.height + top)
    
       AddBorders(v, left, top, right, bottom)
    }
    Then call it like:

    Code:
    AddBordersToMake(1920,1080)
    Last edited by jagabo; 8th Oct 2017 at 22:36.
    Quote Quote  
  3. Image
    [Attachment 43327 - Click to enlarge]


    wow, it works thanks.

    Jagabo please do you know if is there a way to make the same effect, but instead of the solid black, using the blurred borders with the source image and a soft color in background?
    Quote Quote  
  4. I don't know why you can't figure out simple things like this yourself. Make the blurry image then use Overlay to overlay the original. Something like:

    Code:
    function FuzzyBackground(clip v, int width, int height)
    {
        background = v.Tweak(sat=0.67).BilinearResize(32,32).Spline36Resize(width,height) # big fuzzy background
        left = ((width - v.width) / 4) * 2
        top = ((height - v.height) / 4) * 2
        Overlay(background,  v,  x=left, y=top)
    }
    call with:

    Code:
    FuzzyBackground(1920, 1080)
    Click image for larger version

Name:	sample.jpg
Views:	231
Size:	78.3 KB
ID:	43330
    Quote Quote  
  5. Originally Posted by jagabo View Post
    I don't know why you can't figure out simple things like this yourself.

    because I'm a Cat : very low intelligence - big softness

    but please I need a help: in your image Image
    [Attachment 43336 - Click to enlarge]
    the image of the cat results "reframed" inside the screen. For example, I have another source that is 854x480: if I apply the AddBordersToMake(1920,1080) the source image appear as your example: re-framed.

    Is the a way to tell to avisynth that it have to keep the source the largest possible in the screen, while respecting the aspect ratio?




    THANKS THANKS
    Last edited by marcorocchini; 10th Oct 2017 at 13:39.
    Quote Quote  
  6. Member DB83's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Search Comp PM
    Originally Posted by jagabo View Post
    I don't know why you can't figure out simple things like this yourself.

    Simple explanation.

    The OP is a domestic cat. A wild cat will always find its own food. A domestic cat must have everything served up on a plate.
    Quote Quote  
  7. Originally Posted by marcorocchini View Post
    Is the a way to tell to avisynth that it have to keep the source the largest possible in the screen, while respecting the aspect ratio?
    Of course.
    Quote Quote  
  8. There is at least few ways different of dealing with borders - http://avisynth.nl/index.php/FillMargins or non-linear (my fav) scaling http://avisynth.nl/index.php/SimpleResize .
    Quote Quote  
  9. Thankcats but I need to "stretch"and expand the original source when this is < 1920x1080 of widh/hight but alwais keeping the original aspect ratio. And "fill" the "uncovered" with black or mirrored blur same-image as background.

    In the case of a source that is 720x 1280, using AddBordersToMake I get this result very well.

    But, in the case of a source image that is - e.g.- 900x500 or 854x480 or a format that have witdh or height < 1920x1080 I get a result like this

    Image
    [Attachment 43349 - Click to enlarge]


    Image
    [Attachment 43350 - Click to enlarge]


    so I wonder if there is a way to collate at least one of the two edges between witdh or height to maximize the screen occupied by the source
    Quote Quote  
  10. using, possibly, avisynth 64bit
    Quote Quote  
  11. Code:
    Import("v:\automazioneclip\avisynth\plugins\IResize.avsi")
    Import("v:\automazioneclip\AviSynth\plugins\AddBordersToMake.avsi")
    Import("v:\automazioneclip\AviSynth\plugins\FuzzyBackground.avsi")
    LoadPlugin("v:\automazioneclip\AviSynth\Lsmash64perVirtualDub64\LSMASHSource.dll")
    LoadCPlugin("v:\automazioneclip\avisynth\plugins64\yadif.dll")  
    LSMASHVideoSource("C:\INPUT.MP4")
    
    x = float(width) / float(height)
    LanczosResize(round(x * 1080.0),1080)        
    FuzzyBackground(1920,1080)
    
    ConvertToYUY2(interlaced=false)
    OH maybe I have found the solution
    Quote Quote  
  12. That's half the solution. Now you need the other half: when the image AR is wider than the output AR
    Quote Quote  
  13. While I was perusing the marcorocchini help forum, it occurred to me a fuzzy background might be an interesting addition to my CropResizeBorder script. I'm in the middle of creating a new version at the moment that should be faster, easier to use, and will do sub-pixel cropping (the current one is limited to mod2 cropping), so for the moment I replaced the current script's ability to add borders with an ability to add a fuzzy background instead (stealing jagabo's method).

    Temporary version of the script: CropResizeBorder Fuzzy.avsi
    jagabo's FuzzyBackground function is at the very end of the script if you want to tweak the brightness or colour etc.

    Either of these methods will give you a 1280x720 resolution while adding a fuzzy background instead of borders as required (you can resize to whatever resolution you like).

    CropResizeBorder(1280, 720, Cmode="RB")
    or
    CRB(1280, 720)

    Using a 4:3 image as an example:

    Last edited by hello_hello; 11th Oct 2017 at 11:59.
    Quote Quote  
  14. Member DB83's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Search Comp PM
    I have seen this effect on a certain tv channel that broadcasts 4:3 video in 16:9.

    What they do is add thin black bars to the vertical to prevent any 'bleeding'.
    Quote Quote  
  15. I hate that type of fill. I'd much rather see black borders.
    Quote Quote  
  16. I generally don't like coloured borders either, so I tried to make them less offensive.

    This version only uses a few pixels to create the borders, but not the edge ones, because that seems to suck, but close to the edge, and the borders are more washed out. If I had to have coloured borders, something like this would be better. It's easy enough to adjust the brightness and contrast in the functions at the end of the script (there's two of them now).

    CropResizeBorder_LessFuzzy.avsi

    Quote Quote  
  17. Code:
    /*
    The following are wrapper functions for running the script with different default settings.
    They all begin with "CR". If "B" is included in the function name, add borders mode is enabled.
    If the function name ends with an "A" the auto-cropping of black borders is enabled.
    All options are exactly the same as for CropResizeBorder(). Only the defaults are different.
    
    CR() - Resizing with auto-cropping of black disabled.
    Picture/black only cropped as required for minimum aspect error when resizing.
    Same as CropResizeBorder(Cthresh=0)
    
    CRA() - Resizing with auto-cropping of black enabled.
    Extra picture is cropped as required for minimum aspect error when resizing.
    Same as CropResizeBorder()
    
    CRB() - Script operating in Add Borders mode with auto-cropping of black disabled.
    Picture/black only cropped as required for minimum aspect error when resizing.
    Same as CropResizeBorder(Cmode="RB", Cthresh=0)
    
    CRBA() - Script operating in Add Borders mode with auto-cropping of black enabled.
    Extra picture is cropped as required for minimum aspect error when resizing.
    Same as CropResizeBorder(Cmode="RB")
    
    CRVA() - Resizing with auto-cropping of black for video sources (threshold increased).
    Extra picture is cropped as required for minimum aspect error when resizing.
    Same as CropResizeBorder(Cthresh=100, Csample=20)
    
    CR169() - Intended for cropping a 4:3 image to 16:9 with auto-cropping of black disabled.
    The top and bottom of the picture are cropped.
    Assuming the 4:3 picture has no black borders top or bottom, the bottom cropping is increased by roughly 33% and the top cropping reduced accordingly.
    Only the width can be specified. The PicDAR is always 16:9.
    Extra picture is cropped as required for minimum aspect error.
    Same as CropResizeBorder(OutHeight=0, CB=round(c.height/12.121212), PicDAR=16.0/9.0, Cthresh=0)
    
    CRA169() - Same as CR169() with auto-cropping of black enabled.
    Assumes the 4:3 picture has no black borders top or bottom but pillarboxing needs to be cropped.
    Same as CropResizeBorder(OutHeight=0, CB=round(c.height/12.121212), PicDAR=16.0/9.0)
    */
    
    # ========== CR Wrapper Function =====================================================
    
    function CR(clip c, int "OutWidth", int "OutHeight", int "CL", int "CT", int "CR", int "CB", int "Cthresh", int "Cstart", int "Csample", val "PicDAR", int "Mod", val "InDAR", int "Cpreview", string "Cmode", val "Bcolor")
    {
       Cmode = default(Cmode, """R""")
       OutWidth = (Cmode == """RW""") ? (0) : default(OutWidth, 0)
       OutHeight = (Cmode == """RW""") ? (0) : default(OutHeight, 0)
       CL = default(CL, 0)
       CT = default(CT, 0)
       CR = default(CR, 0)
       CB = default(CB, 0)
       Cthresh = default(Cthresh, 0)
       Cstart = default(Cstart, 0)
       Csample = default(Csample, 5)
       PicDAR = default(PicDAR, float(0))
       Mod = default(Mod, 4)
       InDAR = default(InDAR, float(c.width) / float(c.height))
       Cpreview = default(Cpreview, 0)
       Bcolor = default(Bcolor, $000000)
    
    return c.CropResizeBorder(OutWidth, OutHeight, CL, CT, CR, CB, Cthresh, Cstart, Csample, PicDAR, Mod, InDAR, Cpreview, Cmode, Bcolor)
    }
    
    # ========== CRA Wrapper Function ====================================================
    
    function CRA(clip c, int "OutWidth", int "OutHeight", int "CL", int "CT", int "CR", int "CB", int "Cthresh", int "Cstart", int "Csample", val "PicDAR", int "Mod", val "InDAR", int "Cpreview", string "Cmode", val "Bcolor")
    {
       Cmode = default(Cmode, """R""")
       OutWidth = (Cmode == """RW""") ? (0) : default(OutWidth, 0)
       OutHeight = (Cmode == """RW""") ? (0) : default(OutHeight, 0)
       CL = default(CL, 0)
       CT = default(CT, 0)
       CR = default(CR, 0)
       CB = default(CB, 0)
       Cthresh = default(Cthresh, 30)
       Cstart = default(Cstart, 0)
       Csample = default(Csample, 5)
       PicDAR = default(PicDAR, float(0))
       Mod = default(Mod, 4)
       InDAR = default(InDAR, float(c.width) / float(c.height))
       Cpreview = default(Cpreview, 0)
       Bcolor = default(Bcolor, $000000)
    
    return c.CropResizeBorder(OutWidth, OutHeight, CL, CT, CR, CB, Cthresh, Cstart, Csample, PicDAR, Mod, InDAR, Cpreview, Cmode, Bcolor)
    }
    
    # ========== CRB Wrapper Function =====================================================
    
    function CRB(clip c, int "OutWidth", int "OutHeight", int "CL", int "CT", int "CR", int "CB", int "Cthresh", int "Cstart", int "Csample", val "PicDAR", int "Mod", val "InDAR", int "Cpreview", string "Cmode", val "Bcolor")
    {
       Cmode = default(Cmode, """RB""")
       OutWidth = (Cmode == """RW""") ? (0) : default(OutWidth, 0)
       OutHeight = (Cmode == """RW""") ? (0) : default(OutHeight, 0)
       CL = default(CL, 0)
       CT = default(CT, 0)
       CR = default(CR, 0)
       CB = default(CB, 0)
       Cthresh = default(Cthresh, 0)
       Cstart = default(Cstart, 0)
       Csample = default(Csample, 5)
       PicDAR = default(PicDAR, float(0))
       Mod = default(Mod, 4)
       InDAR = default(InDAR, float(c.width) / float(c.height))
       Cpreview = default(Cpreview, 0)
       Bcolor = default(Bcolor, $000000)
    
    return c.CropResizeBorder(OutWidth, OutHeight, CL, CT, CR, CB, Cthresh, Cstart, Csample, PicDAR, Mod, InDAR, Cpreview, Cmode, Bcolor)
    }
    
    # ========== CRBA Wrapper Function ====================================================
    
    function CRBA(clip c, int "OutWidth", int "OutHeight", int "CL", int "CT", int "CR", int "CB", int "Cthresh", int "Cstart", int "Csample", val "PicDAR", int "Mod", val "InDAR", int "Cpreview", string "Cmode", val "Bcolor")
    {
       Cmode = default(Cmode, """RB""")
       OutWidth = (Cmode == """RW""") ? (0) : default(OutWidth, 0)
       OutHeight = (Cmode == """RW""") ? (0) : default(OutHeight, 0)
       CL = default(CL, 0)
       CT = default(CT, 0)
       CR = default(CR, 0)
       CB = default(CB, 0)
       Cthresh = default(Cthresh, 30)
       Cstart = default(Cstart, 0)
       Csample = default(Csample, 5)
       PicDAR = default(PicDAR, float(0))
       Mod = default(Mod, 4)
       InDAR = default(InDAR, float(c.width) / float(c.height))
       Cpreview = default(Cpreview, 0)
       Bcolor = default(Bcolor, $000000)
    
    return c.CropResizeBorder(OutWidth, OutHeight, CL, CT, CR, CB, Cthresh, Cstart, Csample, PicDAR, Mod, InDAR, Cpreview, Cmode, Bcolor)
    }
    
    # ========== CRVA Wrapper Function ===================================================
    
    function CRVA(clip c, int "OutWidth", int "OutHeight", int "CL", int "CT", int "CR", int "CB", int "Cthresh", int "Cstart", int "Csample", val "PicDAR", int "Mod", val "InDAR", int "Cpreview", string "Cmode", val "Bcolor")
    {
       Cmode = default(Cmode, """R""")
       OutWidth = (Cmode == """RW""") ? (0) : default(OutWidth, 0)
       OutHeight = (Cmode == """RW""") ? (0) : default(OutHeight, 0)
       CL = default(CL, 0)
       CT = default(CT, 0)
       CR = default(CR, 0)
       CB = default(CB, 0)
       Cthresh = default(Cthresh, 100)
       Cstart = default(Cstart, 0)
       Csample = default(Csample, 20)
       PicDAR = default(PicDAR, float(0))
       Mod = default(Mod, 4)
       InDAR = default(InDAR, float(c.width) / float(c.height))
       Cpreview = default(Cpreview, 0)
       Bcolor = default(Bcolor, $000000)
    
    return c.CropResizeBorder(OutWidth, OutHeight, CL, CT, CR, CB, Cthresh, Cstart, Csample, PicDAR, Mod, InDAR, Cpreview, Cmode, Bcolor)
    }
    
    # ========== CR169 Wrapper Function ===================================================
    
    function CR169(clip c, int "OutWidth", int "OutHeight", int "CL", int "CT", int "CR", int "CB", int "Cthresh", int "Cstart", int "Csample", val "PicDAR", int "Mod", val "InDAR", int "Cpreview", string "Cmode", val "Bcolor")
    {
       Cmode = default(Cmode, """R""")
       OutWidth = (Cmode == """RW""") ? (0) : default(OutWidth, 0)
       OutHeight = 0
       CL = default(CL, 0)
       CT = default(CT, 0)
       CR = default(CR, 0)
       CB = default(CB, round(c.height/12.121212))
       Cthresh = default(Cthresh, 0)
       Cstart = default(Cstart, 0)
       Csample = default(Csample, 5)
       PicDAR = (16.0/9.0)
       Mod = default(Mod, 4)
       InDAR = default(InDAR, float(c.width) / float(c.height))
       Cpreview = default(Cpreview, 0)
       Bcolor = default(Bcolor, $000000)
    
    return c.CropResizeBorder(OutWidth, OutHeight, CL, CT, CR, CB, Cthresh, Cstart, Csample, PicDAR, Mod, InDAR, Cpreview, Cmode, Bcolor)
    }
    
    # ========== CRA169 Wrapper Function ==================================================
    
    function CRA169(clip c, int "OutWidth", int "OutHeight", int "CL", int "CT", int "CR", int "CB", int "Cthresh", int "Cstart", int "Csample", val "PicDAR", int "Mod", val "InDAR", int "Cpreview", string "Cmode", val "Bcolor")
    {
       Cmode = default(Cmode, """R""")
       OutWidth = (Cmode == """RW""") ? (0) : default(OutWidth, 0)
       OutHeight = 0
       CL = default(CL, 0)
       CT = default(CT, 0)
       CR = default(CR, 0)
       CB = default(CB, round(c.height/12.121212))
       Cthresh = default(Cthresh, 30)
       Cstart = default(Cstart, 0)
       Csample = default(Csample, 5)
       PicDAR = (16.0/9.0)
       Mod = default(Mod, 4)
       InDAR = default(InDAR, float(c.width) / float(c.height))
       Cpreview = default(Cpreview, 0)
       Bcolor = default(Bcolor, $000000)
    
    return c.CropResizeBorder(OutWidth, OutHeight, CL, CT, CR, CB, Cthresh, Cstart, Csample, PicDAR, Mod, InDAR, Cpreview, Cmode, Bcolor)
    }
    
    # ================================================================================
    # ========== CropResizeBorder Function =================================================
    
    function CropResizeBorder(clip c, int "OutWidth", int "OutHeight", int "CL", int "CT", int "CR", int "CB", int "Cthresh", int "Cstart", int "Csample", val "PicDAR", int "Mod", val "InDAR", int "Cpreview", string "Cmode", val "Bcolor")
    {
       Cmode = default(Cmode, """R""")
       OutWidth = (Cmode == """RW""") ? (0) : default(OutWidth, 0)
       OutHeight = (Cmode == """RW""") ? (0) : default(OutHeight, 0)
       CL = default(CL, 0)
       CT = default(CT, 0)
       CR = default(CR, 0)
       CB = default(CB, 0)
       Cthresh = default(Cthresh, 30)
       Cstart = default(Cstart, 0)
       Csample = default(Csample, 5)
       PicDAR = default(PicDAR, float(0))
       Mod = default(Mod, 4)
       InDAR = default(InDAR, float(c.width) / float(c.height))
       Cpreview = default(Cpreview, 0)
       Bcolor = default(Bcolor, $000000)
    
    assert(CropResizeBorder_IsReallyFloat(PicDAR), """  CropResizeBorder: "PicDAR" must be floating point (4.0/3.0 or 1.7777 etc)  """ + chr(10))
    assert(CropResizeBorder_IsReallyFloat(InDAR), """  CropResizeBorder: "InDAR" must be floating point (4.0/3.0 or 1.7777 etc)  """ + chr(10))
    assert((Mod == 2)||(Mod == 4)||(Mod == 8)||(Mod == 16)||(Mod == 32), """  CropResizeBorder: "Mod" must be 2, 4, 8, 16 or 32  """ + chr(10))
    assert((Cpreview == 0)||(Cpreview == 1)||(Cpreview == 2), """  CropResizeBorder: "Cpreview" must be 0, 1 or 2  """ + chr(10))
    assert(Csample != 0, """  CropResizeBorder: "Csample" can't be zero  """ + chr(10))
    assert((Cmode == """R""")||(Cmode == """RB""")||(Cmode == """RW""")||(Cmode == """NR""")||(Cmode == """B"""), \
    """  CropResizeBorder: """" + string(Cmode) + """" is not a valid Cmode   """ + chr(10) + chr(10) + \
    """  "R" - (Default Mode) Crop & Resize  """ + chr(10) + \
    """  "RB" - Crop & Resize & Add Borders  """ + chr(10) + \
    """  "RW" - Crop & Resize Width Only  """ + chr(10) + \
    """  "NR" - No Resizing, Cropping Only  """ + chr(10) + \
    """  "B" - Clean Up Borders (No Resizing)  """ + chr(10))
    
    ACpreview = (Cpreview == 2) ? (0) : (Cpreview)
    
    Source_Width = c.width
    Source_Height = c.height
    Float_Source_Width = float(Source_Width)
    Float_Source_Height = float(Source_Height)
    
    Source_Storage_Aspect_Ratio = Float_Source_Width / Float_Source_Height
    Source_Picture_Aspect_Ratio = (InDAR > 0) ? (InDAR) : (Source_Storage_Aspect_Ratio)
    Source_Pixel_Aspect_Ratio = Float_Source_Height / Float_Source_Width * Source_Picture_Aspect_Ratio
    Anamorphic_AR = (PicDAR > 0) ? (PicDAR / Source_Pixel_Aspect_Ratio) : (0)
    
    Source_Resized_WidthA = Float_Source_Width * Source_Pixel_Aspect_Ratio
    Source_Resized_WidthB = round(Source_Resized_WidthA)
    Source_Resized_Width_Adjust = Source_Resized_WidthB - (floor(Source_Resized_WidthB / 2) * 2)
    Final_Source_Resized_Width = (Source_Resized_Width_Adjust == 0) ? (Source_Resized_WidthB) : \
    (Source_Resized_WidthA >= Source_Resized_WidthB) ? (Source_Resized_WidthB + 1) : (Source_Resized_WidthB - 1)
    
    Cropped_Source = autocrop(c, mode=0, samples=Csample, wMultOf=2, hMultOf=2, threshold=Cthresh, samplestartframe=CStart, leftadd=CL, topadd=CT, rightadd=CR, bottomadd=CB, aspect=0)
    
    CS_Width = width(Cropped_Source)
    CS_Height = height(Cropped_Source)
    Float_CS_Width = float(CS_Width)
    Float_CS_Height = float(CS_Height)
    
    CS_Resized_WidthA = Float_CS_Width * Source_Pixel_Aspect_Ratio
    CS_Resized_WidthB = round(CS_Resized_WidthA)
    CS_Resized_Width_Adjust = CS_Resized_WidthB - (floor(CS_Resized_WidthB / 2) * 2)
    Final_CS_Resized_Width = (CS_Resized_Width_Adjust == 0) ? (CS_Resized_WidthB) : \
    (CS_Resized_WidthA >= CS_Resized_WidthB) ? (CS_Resized_WidthB + 1) : (CS_Resized_WidthB - 1)
    
    Height_Mod_Cropped = autocrop(c, mode=ACpreview, samples=Csample, wMultOf=2, hMultOf=Mod, threshold=Cthresh, samplestartframe=CStart, leftadd=CL, topadd=CT, rightadd=CR, bottomadd=CB, aspect=Anamorphic_AR)
    
    HMC_Width = width(Height_Mod_Cropped)
    HMC_Height = height(Height_Mod_Cropped)
    Float_HMC_Width = float(HMC_Width)
    Float_HMC_Height = float(HMC_Height)
    HMC_Aspect = Float_HMC_Width / Float_HMC_Height
    
    HMC_Resized_WidthA = Float_HMC_Width * Source_Pixel_Aspect_Ratio
    HMC_Resized_WidthB = round(HMC_Resized_WidthA)
    HMC_Resized_Width_Adjust = HMC_Resized_WidthB - (floor(HMC_Resized_WidthB / 2) * 2)
    Final_HMC_Resized_Width = (HMC_Resized_Width_Adjust == 0) ? (HMC_Resized_WidthB) : \
    (Anamorphic_AR > HMC_Aspect) ? (HMC_Resized_WidthB + 1) : (HMC_Resized_WidthB - 1)
    
    HMC_Width_Resized = Height_Mod_Cropped.Spline36Resize(Final_HMC_Resized_Width, HMC_Height)
    HMC_Width_Resized_Cropped = \
    HMC_Width_Resized.autocrop(mode=0, samples=Csample, wMultOf=Mod, hMultOf=2, threshold=0, samplestartframe=CStart, leftadd=0, topadd=0, rightadd=0, bottomadd=0, aspect=0)
    
    Mod_Cropped = autocrop(c, mode=ACpreview, samples=Csample, wMultOf=Mod, hMultOf=Mod, threshold=Cthresh, samplestartframe=CStart, leftadd=CL, topadd=CT, rightadd=CR, bottomadd=CB, aspect=Anamorphic_AR)
    
    MC_Width = width(Mod_Cropped)
    MC_Height = height(Mod_Cropped)
    Float_MC_Width = float(MC_Width)
    Float_MC_Height = float(MC_Height)
    MC_Aspect = Float_MC_Width / Float_MC_Height
    
    MC_Resized_WidthA = Float_MC_Width * Source_Pixel_Aspect_Ratio
    MC_Resized_WidthB = round(MC_Resized_WidthA)
    MC_Resized_Width_Adjust = MC_Resized_WidthB - (floor(MC_Resized_WidthB / 2) * 2)
    Final_MC_Resized_Width = (MC_Resized_Width_Adjust == 0) ? (MC_Resized_WidthB) : \
    (Anamorphic_AR > MC_Aspect) ? (MC_Resized_WidthB + 1) : (MC_Resized_WidthB - 1)
    
    Output_Width = (Cmode == """NR""")||(Cmode == """B""") ? (MC_Width) : \
    (Source_Pixel_Aspect_Ratio == 1) && (OutWidth == 0) && (OutHeight == 0) ? (MC_Width) : \
    (OutWidth == 0) ? (width(HMC_Width_Resized_Cropped)) : \
    (OutWidth)
    Output_Height = (Cmode == """NR""")||(Cmode == """B""") ? (MC_Height) : \
    (Source_Pixel_Aspect_Ratio == 1) && (OutWidth == 0) && (OutHeight == 0) ? (MC_Height) : \
    (OutHeight == 0) ? (HMC_Height) : \
    (OutHeight)
    
    Float_Output_Width = float(Output_Width)
    Float_Output_Height = float(Output_Height)
    
    Cropped_Picture_Aspect_Ratio = Float_CS_Width / Float_CS_Height * Source_Pixel_Aspect_Ratio
    Output_Picture_Aspect_Ratio = (PicDAR > 0) ? (PicDAR) : (Cropped_Picture_Aspect_Ratio)
    Output_Storage_Aspect_Ratio = Float_Output_Width / Float_Output_Height
    Final_Picture_Aspect_Ratio = \
    (Cmode == """RB""") && (OutWidth > 0) && (OutHeight > 0) ? (Output_Picture_Aspect_Ratio) : \
    (OutWidth > 0) && (OutHeight > 0) ? (Output_Storage_Aspect_Ratio) : \
    (Output_Picture_Aspect_Ratio)
    
    One_Quarter_Mod = ceil(float(Mod) / 4.0 * 1.0)
    Three_Quarter_Mod = ceil(float(Mod) / 4.0 * 3.0)
    
    Intermediate_Width = round(Float_Output_Height * Final_Picture_Aspect_Ratio)
    Width_Adjust = Intermediate_Width - (floor(Intermediate_Width / Mod) * Mod)
    Width_Adjust_Up = Intermediate_Width + Mod - Width_Adjust
    Width_Adjust_Down = Intermediate_Width - Width_Adjust
    New_Width1 = Output_Width
    New_Width2 = (Width_Adjust > One_Quarter_Mod) ? (Width_Adjust_Up) : (Width_Adjust_Down)
    New_Width3 = (Width_Adjust >= Three_Quarter_Mod) ? (Width_Adjust_Up) : (Width_Adjust_Down)
    New_Width4 = (Cmode == "RB") && (Width_Adjust_Up > OutWidth) && (OutWidth > 0) ? (Width_Adjust_Down) : (Final_Picture_Aspect_Ratio < (16.0 / 9.0)) ? (New_Width2) : (New_Width3)
    
    New_Cropping_Aspect1h = float(New_Width1) / Float_Output_Height / Source_Pixel_Aspect_Ratio
    New_Cropping_Aspect4h = float(New_Width4) / Float_Output_Height / Source_Pixel_Aspect_Ratio
    
    Cropped_Video1h = autocrop(c, mode=ACpreview, samples=Csample, wMultOf=2, hMultOf=2, threshold=Cthresh, samplestartframe=Cstart, leftadd=CL, topadd=CT, rightadd=CR, bottomadd=CB, aspect=New_Cropping_Aspect1h)
    Cropping_Resizing1h = Cropped_Video1h.Spline36Resize(New_Width1, Output_Height)
    
    Cropped_Video4h = autocrop(c, mode=ACpreview, samples=Csample, wMultOf=2, hMultOf=2, threshold=Cthresh, samplestartframe=Cstart, leftadd=CL, topadd=CT, rightadd=CR, bottomadd=CB, aspect=New_Cropping_Aspect4h)
    Cropping_Resizing4h = Cropped_Video4h.Spline36Resize(New_Width4, Output_Height)
    
    Intermediate_Height = round(Float_Output_Width / Final_Picture_Aspect_Ratio)
    Height_Adjust = Intermediate_Height - (floor(Intermediate_Height / Mod) * Mod)
    Height_Adjust_Up = Intermediate_Height + Mod - Height_Adjust
    Height_Adjust_Down = Intermediate_Height - Height_Adjust
    New_Height1 = Output_Height
    New_Height2 = (Height_Adjust > One_Quarter_Mod) ? (Height_Adjust_Up) : (Height_Adjust_Down)
    New_Height3 = (Height_Adjust >= Three_Quarter_Mod) ? (Height_Adjust_Up) : (Height_Adjust_Down)
    New_Height4 = (Cmode == "RB") && (Height_Adjust_Up > OutHeight) && (OutHeight > 0) ? (Height_Adjust_Down) : (Final_Picture_Aspect_Ratio > (16.0 / 9.0)) ? (New_Height2) : (New_Height3)
    
    New_Cropping_Aspect1w = Float_Output_Width / float(New_Height1) / Source_Pixel_Aspect_Ratio
    New_Cropping_Aspect4w = Float_Output_Width / float(New_Height4) / Source_Pixel_Aspect_Ratio
    
    Cropped_Video1w = autocrop(c, mode=ACpreview, samples=Csample, wMultOf=2, hMultOf=2, threshold=Cthresh, samplestartframe=Cstart, leftadd=CL, topadd=CT, rightadd=CR, bottomadd=CB, aspect=New_Cropping_Aspect1w)
    Cropping_Resizing1w = Cropped_Video1w.Spline36Resize(Output_Width, New_Height1)
    
    Cropped_Video4w = autocrop(c, mode=ACpreview, samples=Csample, wMultOf=2, hMultOf=2, threshold=Cthresh, samplestartframe=Cstart, leftadd=CL, topadd=CT, rightadd=CR, bottomadd=CB, aspect=New_Cropping_Aspect4w)
    Cropping_Resizing4w = Cropped_Video4w.Spline36Resize(Output_Width, New_Height4)
    
    Final_Cropped_Video = \
    (Cmode == """RB""") && (Source_Pixel_Aspect_Ratio == 1) && (OutWidth == 0) && (OutHeight == 0) ? (Mod_Cropped) : \
    (Cmode == """RB""") && (OutWidth == 0) && (OutHeight == 0) ? (Height_Mod_Cropped) : \
    (Cmode == """RB""") && (OutWidth == 0) && (OutHeight > 0) ? (Cropped_Video4h) : \
    (Cmode == """RB""") && (OutWidth > 0) && (OutHeight == 0) ? (Cropped_Video4w) : \
    (Cmode == """RB""") && (Output_Storage_Aspect_Ratio >= Final_Picture_Aspect_Ratio) ? (Cropped_Video4h) : \
    (Cmode == """RB""") ? (Cropped_Video4w) : \
    (Cmode == """NR""")||(Cmode == """B""") ? (Mod_Cropped) : \
    (Source_Pixel_Aspect_Ratio == 1) && (OutWidth == 0) && (OutHeight == 0) ? (Mod_Cropped) : \
    (OutWidth == 0) && (OutHeight == 0) ? (Height_Mod_Cropped) : \
    (OutWidth == 0) && (OutHeight > 0) ? (Cropped_Video4h) : \
    (OutWidth > 0) && (OutHeight == 0) ? (Cropped_Video4w) : \
    (Cropped_Video1w)
    
    Final_Cropping_Resizing = \
    (Cmode == """RB""") && (Source_Pixel_Aspect_Ratio == 1) && (OutWidth == 0) && (OutHeight == 0) ? (Mod_Cropped) : \
    (Cmode == """RB""") && (OutWidth == 0) && (OutHeight == 0) ? (HMC_Width_Resized_Cropped) : \
    (Cmode == """RB""") && (OutWidth == 0) && (OutHeight > 0) ? (Cropping_Resizing4h) : \
    (Cmode == """RB""") && (OutWidth > 0) && (OutHeight == 0) ? (Cropping_Resizing4w) : \
    (Cmode == """RB""") && (Output_Storage_Aspect_Ratio >= Final_Picture_Aspect_Ratio) ? (Cropping_Resizing4h) : \
    (Cmode == """RB""") ? (Cropping_Resizing4w) : \
    (Cmode == """NR""")||(Cmode == """B""") ? (Mod_Cropped) : \
    (Source_Pixel_Aspect_Ratio == 1) && (OutWidth == 0) && (OutHeight == 0) ? (Mod_Cropped) : \
    (OutWidth == 0) && (OutHeight == 0) ? (HMC_Width_Resized_Cropped) : \
    (OutWidth == 0) && (OutHeight > 0) ? (Cropping_Resizing4h) : \
    (OutWidth > 0) && (OutHeight == 0) ? (Cropping_Resizing4w) : \
    (Cropping_Resizing1w)
    
    New_Picture_Width = width(Final_Cropping_Resizing)
    New_Picture_Height = height(Final_Cropping_Resizing)
    New_Picture_Aspect_Ratio = float(New_Picture_Width) / float(New_Picture_Height)
    
    Total_Width = \
    (Cmode == """RB""") && (OutWidth == 0) && (OutHeight >= 0) ? (New_Picture_Width) : \
    (Cmode == """RB""") && (OutWidth >= 0) && (OutHeight == 0) ? (New_Picture_Width) : \
    (Cmode == """RB""") && (Output_Storage_Aspect_Ratio > New_Picture_Aspect_Ratio) ? (Output_Width) : \
    (Cmode == """B""") ? (Source_Width) : \
    (New_Picture_Width)
    
    Total_Height = \
    (Cmode == """RB""") && (OutWidth == 0) && (OutHeight >= 0) ? (New_Picture_Height) : \
    (Cmode == """RB""") && (OutWidth >= 0) && (OutHeight == 0) ? (New_Picture_Height) : \
    (Cmode == """RB""") && (Output_Storage_Aspect_Ratio < New_Picture_Aspect_Ratio) ? (Output_Height) : \
    (Cmode == """B""") ? (Source_Height) : \
    (New_Picture_Height)
    
    Total_Picture_Aspect_Ratio = float(Total_Width) / float(Total_Height)
    
    Half_Width_Border = (Total_Width - New_Picture_Width) / 2
    Half_Height_Border = (Total_Height - New_Picture_Height) / 2
    Border_Width_Adjust = Half_Width_Border - (floor(Half_Width_Border / 2) * 2)
    Border_Height_Adjust = Half_Height_Border - (floor(Half_Height_Border / 2) * 2)
    Left_Border = Half_Width_Border - Border_Width_Adjust
    Top_Border = Half_Height_Border - Border_Height_Adjust
    Right_Border = Total_Width - New_Picture_Width - Left_Border
    Bottom_Border = Total_Height - New_Picture_Height - Top_Border
    
    AddingBorders = \
    Final_Cropping_Resizing.AddBorders(Left_Border, Top_Border, Right_Border, Bottom_Border, color=Bcolor)
    Final_Output = \
    ((Cmode == """RB""")||(Cmode == """B""")) && (Total_Picture_Aspect_Ratio < New_Picture_Aspect_Ratio) ? \
    CropResizeBorder_FuzzyBackground1(Final_Cropping_Resizing, Total_Width, Total_Height) : \
    ((Cmode == """RB""")||(Cmode == """B""")) && (Total_Picture_Aspect_Ratio > New_Picture_Aspect_Ratio) ? \
    CropResizeBorder_FuzzyBackground2(Final_Cropping_Resizing, Total_Width, Total_Height) : \
    (Final_Cropping_Resizing)
    
    ST_A1 = """Crop & Resize"""
    ST_B1 = """CRB (OutWidth=?, OutHeight=?, Cmode="R")"""
    ST_C1 = """Normal cropping & resizing mode (square pixel dimensions).\nIf OutWidth = 0 & OutHeight = 0, only the width is resized for anamorphic sources\n& PicDAR can adjust the cropping (same as Cmode="RW").\nIf Outwidth > 0 & OutHeight > 0, they determine the cropping & resolution (PicDAR has no effect).\nIf Outwidth > 0 & OutHeight = 0, OutWidth sets the width and PicDAR can adjust the cropping / height.\nIf Outwidth = 0 & OutHeight > 0, OutHeight sets the height and PicDAR can adjust the cropping / width."""
    
    ST_A2 = """Crop & Resize & Add Borders"""
    ST_B2 = """CRB (OutWidth=?, OutHeight=?, Cmode="RB")"""
    ST_C2 = """PicDAR adjusts the cropping & display aspect ratio of the picture itself.\nBorders are added to the sides or top / bottom according to the specified OutWidth & OutHeight.\nTherefore, OutWidth & OutHeight determine the overall resolution\nand cropping / PicDAR determine the picture resolution."""
    
    ST_A3 = """Crop & Resize Width Only"""
    ST_B3 = """CRB (Cmode="RW")"""
    ST_C3 = """This mode is intended to ensure only the width is resized for anamorphic sources,\nalthough for non-anamorphic sources it will only crop and resizing is disabled.\nFor anamorphic sources, the height is cropped to the specified mod,\nthe width is resized for square pixel dimensions, then the width is also cropped.\nNon-anamorphic sources are simply cropped (same as Cmode="NR")."""
    
    ST_A4 = """No Resizing, Cropping Only"""
    ST_B4 = """CRB (Cmode="NR")"""
    ST_C4 = """Resizing is disabled so the pixel aspect ratio is unchanged.\nPicDAR adjusts the cropping & display aspect ratio of the picture itself.\nMod overcrops as required for final picture width & height.\nOutWidth & OutHeight have no effect."""
    
    ST_A5 = """Clean Up Borders (No Resizing)"""
    ST_B5 = """CRB (Cmode="B")"""
    ST_C5 = """Borders are cropped and always added back for the original resolution\n(for both anamorphic and non-anamorphic sources).\nResizing is disabled so the pixel aspect ratio is unchanged.\nMod / PicDAR adjusts the cropping as required for final picture width & height.\nOutWidth & OutHeight have no effect."""
    
    ST_Dw = """Width = """ + string(width(AddingBorders)) + \
    """, Left Border = """ + string(Left_Border) + """, Right Border = """ + string(Right_Border)
    ST_Dh = """Height = """ + string(height(AddingBorders)) + \
    """, Top Border = """ + string(Top_Border) + """, Bottom Border = """ + string(Bottom_Border)
    
    ST_Ew = """Picture Width = """ + string(New_Picture_Width)
    ST_Eh = """Picture Height = """ + string(New_Picture_Height)
    
    ST_F = string(Final_MC_Resized_Width) + """ x """ + string(MC_Height)
    ST_G = string(Final_HMC_Resized_Width) + """ x """ + string(HMC_Height)
    ST_H = string(Total_Width) + """ x """ + string(Total_Height)
    ST_I = string(Final_Source_Resized_Width) + """ x """ + string(Source_Height)
    
    st01 = """Resolution set by cropping & PicDAR"""
    st02 = """Resolution set by cropping"""
    ST_J01 = (PicDAR > 0) ? st01 : st02
    st03 = """Cropped Height x PicDAR = Width"""
    st04 = """Cropped Height x Cropped DAR = Width"""
    ST_J02 = (PicDAR > 0) ? st03 : st04
    st05 = """OutHeight x PicDAR = Width"""
    st06 = """OutHeight x Cropped DAR = Width"""
    ST_J03 = (PicDAR > 0) ? st05 : st06
    st07 = """OutWidth x PicDAR = Height"""
    st08 = """OutWidth x Cropped DAR = Height"""
    ST_J04 = (PicDAR > 0) ? st07 : st08
    ST_J05 = (Source_Pixel_Aspect_Ratio == 1) && (OutWidth == 0) && (OutHeight == 0) ? ST_J01 : \
    (OutWidth == 0) && (OutHeight == 0) ? ST_J02 : \
    (OutWidth == 0) && (OutHeight > 0) ? ST_J03 : \
    ST_J04
    
    st09 = """OutHeight x PicDAR = Width + Borders"""
    st10 = """OutHeight x Cropped DAR = Width + Borders"""
    ST_J06 = (PicDAR > 0) ? st09 : st10
    st11 = """OutWidth x PicDAR = Height + Borders"""
    st12 = """OutWidth x Cropped DAR = Height + Borders"""
    ST_J07 = (PicDAR > 0) ? st11 : st12
    ST_J08 = (Source_Pixel_Aspect_Ratio == 1) && (OutWidth == 0) && (OutHeight == 0) ? ST_J01 : \
    (OutWidth == 0) && (OutHeight == 0) ? ST_J02 : \
    (OutWidth == 0) && (OutHeight > 0) ? ST_J03 : \
    (OutWidth > 0) && (OutHeight == 0) ? (ST_J04) : \
    (Output_Storage_Aspect_Ratio >= Final_Picture_Aspect_Ratio) ? ST_J06 : \
    ST_J07
    
    st13 = """Anamorphic Display Size\n(set by cropping & PicDAR)\n""" + ST_F
    st14 = """Anamorphic Display Size\n(set by cropping)\n""" + ST_F
    ST_J09 = (PicDAR > 0) ? st13 : st14
    st15 = """Anamorphic Picture Display Size\n(set by cropping & PicDAR)\n""" + ST_F
    st16 = """Anamorphic Picture Display Size\n(set by cropping)\n""" + ST_F
    ST_J10 = (PicDAR > 0) ? st15 : st16
    
    ST_K = """Total Resolution\n""" + ST_H
    ST_L = """Total Display Size (including borders)\n""" + ST_I
    ST_M = """Both OutWidth & OutHeight must be greater than zero to add borders."""
    ST_N = """OutWidth & OutHeight have no effect\nPicDAR adjusts the cropping and therefore the output resolution"""
    
    Subtitle_ColourA = (Final_Cropping_Resizing == Cropping_Resizing1w) || (Final_Cropping_Resizing == Cropping_Resizing4w) ? (color_paleturquoise) : (color_aquamarine)
    Subtitle_ColourB = (Final_Cropping_Resizing == Cropping_Resizing1w) || (Final_Cropping_Resizing == Cropping_Resizing4w) || (Final_Cropping_Resizing == Mod_Cropped) ? (color_aquamarine) : (color_paleturquoise)
    Subtitle_ColourC = (Subtitle_ColourA == color_paleturquoise) || (Subtitle_ColourB == color_paleturquoise) ? (color_paleturquoise) : (color_aquamarine)
    
    Fsize1 = (Total_Width / 39)
    Fsize2 = (Total_Width / 45)
    Fsize3 = (Total_Width / 49)
    Fsize4 = (Total_Width / 52)
    Fsize5 = (width(Final_Cropped_Video) / 49)
    
    Float_Total_Width = float(Total_Width)
    Y01 = round(Float_Total_Width / 38.0)
    Y02 = round(Float_Total_Width / 20.5)
    Y03 = round(Float_Total_Width / 14.2)
    Y04 = round(Float_Total_Width / 5.15)
    Y05 = round(Float_Total_Width / 4.55)
    Y06 = round(Float_Total_Width / 3.9)
    Y07 = round(Float_Total_Width / 3.55)
    Y08 = round(Float_Total_Width / 3.2)
    Y09 = round(Float_Total_Width / 2.78)
    Y10 = round(Float_Total_Width / 2.6)
    
    Cpreview1_Info = \
    (Final_Cropped_Video == Height_Mod_Cropped) ? \
    Final_Cropped_Video\
    .subtitle("""When OutWidth & OutHeight are zero (or unspecified) and the source is anamorphic and\nbeing resized to square pixels, the height is cropped before the width is resized, then\nthe width is resized and cropped to the specified mod (the source is cropped twice).\nThis ensures width and height conform to the specified mod and the height is not resized.\n\nThe cropping preview is the cropping before the width is resized, therefore\nsome additional picture "may" be cropped from the width after it's resized.""", lsp=10, x=-1, y=Y05, size=Fsize5, text_color=color_white) : \
    Final_Cropped_Video
    
    Cpreview2_Info = \
    \
    [* Crop & Resize *] \
    (Cmode == """R""") ? \
    (Final_Output\
    .subtitle(ST_A1, x=-1, y=Y01, size=Fsize2, text_color=color_aquamarine)\
    .subtitle(ST_B1, x=-1, y=Y02, size=Fsize4)\
    .subtitle(ST_C1, lsp=10, x=-1, y=Y03, size=Fsize4, text_color=color_azure)\
    .subtitle(ST_Ew, x=-1, y=Y06, size=Fsize1, text_color=Subtitle_ColourA)\
    .subtitle(ST_Eh, x=-1, y=Y07, size=Fsize1, text_color=Subtitle_ColourB)\
    .subtitle(ST_J05, x=-1, y=Y09, size=Fsize2, text_color=Subtitle_ColourC)) : \
    \
    [* Crop & Resize & Add Borders - Without Borders *] \
    (Cmode == """RB""") && (Total_Picture_Aspect_Ratio == New_Picture_Aspect_Ratio) ? \
    (Final_Output\
    .subtitle(ST_A2, x=-1, y=Y01, size=Fsize2, text_color=color_aquamarine)\
    .subtitle(ST_B2, x=-1, y=Y02, size=Fsize4)\
    .subtitle(ST_C2, lsp=10, x=-1, y=Y03, size=Fsize4, text_color=color_azure)\
    .subtitle(ST_Ew, x=-1, y=Y06, size=Fsize1, text_color=Subtitle_ColourA)\
    .subtitle(ST_Eh, x=-1, y=Y07, size=Fsize1, text_color=Subtitle_ColourB)\
    .subtitle(ST_J08, x=-1, y=Y09, size=Fsize2, text_color=Subtitle_ColourC)\
    .subtitle(ST_M, lsp=10, x=-1, y=Y10, size=Fsize4, text_color=color_azure)) : \
    \
    [* Crop & Resize & Add Borders - With Borders *] \
    (Cmode == """RB""") ? \
    (Final_Output\
    .subtitle(ST_A2, x=-1, y=Y01, size=Fsize2, text_color=color_aquamarine)\
    .subtitle(ST_B2, x=-1, y=Y02, size=Fsize4)\
    .subtitle(ST_C2, lsp=10, x=-1, y=Y03, size=Fsize4, text_color=color_azure)\
    .subtitle(ST_Dw, x=-1, y=Y04, size=Fsize3)\
    .subtitle(ST_Dh, x=-1, y=Y05, size=Fsize3)\
    .subtitle(ST_Ew, x=-1, y=Y06, size=Fsize1, text_color=Subtitle_ColourA)\
    .subtitle(ST_Eh, x=-1, y=Y07, size=Fsize1, text_color=Subtitle_ColourB)\
    .subtitle(ST_K, lsp=10, x=-1, y=Y08, size=Fsize2)\
    .subtitle(ST_J08, x=-1, y=Y09, size=Fsize2, text_color=Subtitle_ColourC)) : \
    \
    [* Crop & Resize Width Only *] \
    (Cmode == """RW""") && (Source_Pixel_Aspect_Ratio == 1) ? \
    (Final_Output\
    .subtitle(ST_A3, x=-1, y=Y01, size=Fsize2, text_color=color_aquamarine)\
    .subtitle(ST_B3, x=-1, y=Y02, size=Fsize4)\
    .subtitle(ST_C3, lsp=10, x=-1, y=Y03, size=Fsize4, text_color=color_azure)\
    .subtitle(ST_Ew, x=-1, y=Y06, size=Fsize1, text_color=color_aquamarine)\
    .subtitle(ST_Eh, x=-1, y=Y07, size=Fsize1, text_color=color_aquamarine)\
    .subtitle(ST_J08, x=-1, y=Y09, size=Fsize2, text_color=color_aquamarine)\
    .subtitle(ST_N, lsp=10, x=-1, y=Y10, size=Fsize4, text_color=color_azure)) : \
    \
    [* Crop & Resize Width Only - Anamorphic Source *] \
    (Cmode == """RW""") ? \
    (Final_Output\
    .subtitle(ST_A3, x=-1, y=Y01, size=Fsize2, text_color=color_aquamarine)\
    .subtitle(ST_B3, x=-1, y=Y02, size=Fsize4)\
    .subtitle(ST_C3, lsp=10, x=-1, y=Y03, size=Fsize4, text_color=color_azure)\
    .subtitle(ST_Ew, x=-1, y=Y06, size=Fsize1, text_color=color_aquamarine)\
    .subtitle(ST_Eh, x=-1, y=Y07, size=Fsize1, text_color=color_paleturquoise)\
    .subtitle(ST_J01, x=-1, y=Y09, size=Fsize2, text_color=color_paleturquoise)\
    .subtitle(ST_N, lsp=10, x=-1, y=Y10, size=Fsize4, text_color=color_azure)) : \
    \
    [* No Resizing, Cropping Only *] \
    (Cmode == """NR""") && (Source_Pixel_Aspect_Ratio == 1) ? \
    (Final_Output\
    .subtitle(ST_A4, x=-1, y=Y01, size=Fsize2, text_color=color_aquamarine)\
    .subtitle(ST_B4, x=-1, y=Y02, size=Fsize4)\
    .subtitle(ST_C4, lsp=10, x=-1, y=Y03, size=Fsize4, text_color=color_azure)\
    .subtitle(ST_Ew, x=-1, y=Y06, size=Fsize1, text_color=color_aquamarine)\
    .subtitle(ST_Eh, x=-1, y=Y07, size=Fsize1, text_color=color_aquamarine)\
    .subtitle(ST_J01, x=-1, y=Y09, size=Fsize2, text_color=color_aquamarine)) : \
    \
    [* No Resizing, Cropping Only - Anamorphic Source *] \
    (Cmode == """NR""") ? \
    (Final_Output\
    .subtitle(ST_A4, x=-1, y=Y01, size=Fsize2, text_color=color_aquamarine)\
    .subtitle(ST_B4, x=-1, y=Y02, size=Fsize4)\
    .subtitle(ST_C4, lsp=10, x=-1, y=Y03, size=Fsize4, text_color=color_azure)\
    .subtitle(ST_Ew, x=-1, y=Y06, size=Fsize1, text_color=color_aquamarine)\
    .subtitle(ST_Eh, x=-1, y=Y07, size=Fsize1, text_color=color_aquamarine)\
    .subtitle(ST_J09, lsp=10, x=-1, y=Y09, size=Fsize2, text_color=color_aquamarine)) : \
    \
    [* Clean Up Borders (No Resizing) *] \
    (Cmode == """B""") && (Source_Pixel_Aspect_Ratio == 1) ? \
    (Final_Output\
    .subtitle(ST_A5, x=-1, y=Y01, size=Fsize2, text_color=color_aquamarine)\
    .subtitle(ST_B5, x=-1, y=Y02, size=Fsize4)\
    .subtitle(ST_C5, lsp=10, x=-1, y=Y03, size=Fsize4, text_color=color_azure)\
    .subtitle(ST_Dw, x=-1, y=Y04, size=Fsize3)\
    .subtitle(ST_Dh, x=-1, y=Y05, size=Fsize3)\
    .subtitle(ST_Ew, x=-1, y=Y06, size=Fsize1, text_color=color_aquamarine)\
    .subtitle(ST_Eh, x=-1, y=Y07, size=Fsize1, text_color=color_aquamarine)\
    .subtitle(ST_J01, x=-1, y=Y09, size=Fsize2, text_color=color_aquamarine)\
    .subtitle(ST_K, lsp=10, x=-1, y=Y10, size=Fsize2)) : \
    \
    [* Clean Up Borders (No Resizing) - Anamorphic Source *] \
    (Cmode == """B""") ? \
    (Final_Output\
    .subtitle(ST_A5, x=-1, y=Y01, size=Fsize2, text_color=color_aquamarine)\
    .subtitle(ST_B5, x=-1, y=Y02, size=Fsize4)\
    .subtitle(ST_C5, lsp=10, x=-1, y=Y03, size=Fsize4, text_color=color_azure)\
    .subtitle(ST_Dw, x=-1, y=Y04, size=Fsize3)\
    .subtitle(ST_Dh, x=-1, y=Y05, size=Fsize3)\
    .subtitle(ST_Ew, x=-1, y=Y06, size=Fsize1, text_color=color_aquamarine)\
    .subtitle(ST_Eh, x=-1, y=Y07, size=Fsize1, text_color=color_aquamarine)\
    .subtitle(ST_J10, lsp=10, x=-1, y=Y08, size=Fsize2, text_color=color_aquamarine)\
    .subtitle(ST_L, lsp=10, x=-1, y=Y10, size=Fsize2)) : \
    nop
    
    Video_Out = \
    (Cpreview == 1) ? (Cpreview1_Info) : \
    (Cpreview == 2) ? (Cpreview2_Info) : \
    (Final_Output)
    
    return Video_Out
    }
    
    # ========== IsReallyFloatCRB Helper Function =============================================
    
    function CropResizeBorder_IsReallyFloat(val v)
    {
        s = ""
        try { 
            s = Hex(v) [* fails on float arguments! *]
        }
        catch(err_msg) { 
            s = "true"
        }
        return (IsFloat(v)) 
        \ ? (s=="true") [* s<>"true" if Hex succeeds *]
        \ : false       [* eliminate clips, strings, booleans  *]
    }
    
    # ========== FuzzyBackground Helper Function =============================================
    
    function CropResizeBorder_FuzzyBackground1(clip v, int "Total_Width", int "Total_Height")
    {
        Background1 = v.crop(0, 32, 0, -(v.height-64))
        Background2 = v.crop(0, (v.height-64), 0, -32)
        Background3 = StackVertical(Background1, Background2)
        Background4 = \
        Background3.Tweak(sat=0.33, bright=75, Cont=0.1).\
        BilinearResize(32,32).BilinearResize(Total_Width, Total_Height).\
        Blur(1,1).Blur(1,0).Blur(1,0)
        Left = ((Total_Width - v.width) / 4) * 2
        Top = ((Total_Height - v.height) / 4) * 2
        Overlay(Background4, v, x=Left, y=Top)
    }
    
    
    function CropResizeBorder_FuzzyBackground2(clip v, int "Total_Width", int "Total_Height")
    {
        Background1 = v.crop(32, 0, -(v.width-64), 0)
        Background2 = v.crop((v.width-64), 0, -32, 0)
        Background3 = StackHorizontal(Background1, Background2)
        Background4 = \
        Background3.Tweak(sat=0.33, bright=75, Cont=0.1).\
        BilinearResize(32,32).BilinearResize(Total_Width, Total_Height).\
        Blur(1,1).Blur(0,1).Blur(0,1)
        Left = ((Total_Width - v.width) / 4) * 2
        Top = ((Total_Height - v.height) / 4) * 2
        Overlay(Background4, v, x=Left, y=Top)
    }
    thank you cat, probably I need some month to try this but usefull ^^
    Quote Quote  
  18. Or a dark fuzzy reflection?

    Click image for larger version

Name:	refl.jpg
Views:	250
Size:	19.5 KB
ID:	43359
    Quote Quote  
  19. Originally Posted by marcorocchini View Post
    thank you cat, probably I need some month to try this but usefull ^^
    The basics are in fact very simple. The idea is you can resize any video to any dimensions but instead of distorting the picture if the source/resize aspect ratios are different, the script automatically crops picture as required to make them the same. Specifying resizing and cropping is much the same as if you were using an Avisynth resizer. The included wrapper functions are effectively shortcuts for enabling options.

    This resizes to a width of 1280 while cropping 12 pixels from the top and bottom. The script automatically calculates the correct height.

    CR(1280, 0, 0, 12, 0, 12)

    The following would crop 10 pixels from each side and 50 from the height, then resize to 1280x720, but if the image isn't 16:9 after cropping (because 1280x720 is 16:9), the script will automatically crop it to 16:9 before resizing.

    CR(1280, 720, 10, 25, 10, 25)

    The following does much the same thing, except instead of cropping away picture in order to resize to 16:9 it'll add borders instead (which is what you asked about in your opening post).

    CRB(1280, 720, 10, 25, 10, 25)

    The CRA() and CRBA() functions are the same as above except they also auto-crop any black bars with autocrop.dll.

    The above functions are 99.9% of what I use the script for.

    I've been working on the new version sporadically and I'm close to finishing it. I can't imagine why I didn't think of creating a script like this years ago instead of a few months ago as it can be very tedious having to calculate and adjust cropping/resizing for every encode. The script still gives you as much control as you want over the output but you don't have to do the maths.
    Last edited by hello_hello; 19th Oct 2017 at 22:32.
    Quote Quote  
  20. jagabo, is there a plugin for applying changes to colour/brightness/stretch etc to a picture in a non uniform way? There's a word I'm looking for, but a description might be (for example) progressively darkening the image from the edges towards the centre.

    I ask, because my interest in creating borders that aren't completely black comes from owning a Plasma, but some sort of "3d depth effect" would probably make them more bearable. I saw quite a good example of it on a DVD a while back but I can remember what DVD it was at the moment. And the word I'm looking for.... I think I'm having a dumb day.
    Quote Quote  
  21. Originally Posted by hello_hello View Post
    jagabo, is there a plugin for applying changes to colour/brightness/stretch etc to a picture in a non uniform way? There's a word I'm looking for, but a description might be (for example) progressively darkening the image from the edges towards the centre.

    I ask, because my interest in creating borders that aren't completely black comes from owning a Plasma, but some sort of "3d depth effect" would probably make them more bearable. I saw quite a good example of it on a DVD a while back but I can remember what DVD it was at the moment. And the word I'm looking for.... I think I'm having a dumb day.
    For color/brightness - one way is with a gradient mask, with mt_merge or overlay

    But I'm guessing you want to use a procedural method , ideally without some pre-made physical mask or gradient file ?

    For stretch/resize, there is a non uniform resize function that was part of some plugin. But I can't recall the plugin...offhand. I'll have to look
    EDIT: it was warpedresize, part of simpleresize
    http://avisynth.nl/index.php/SimpleResize
    Quote Quote  
  22. This will create a 256x256 greyscale RGB ramp that increases from brightness 0 on the left to 255 on the right.

    Code:
    function GreyRamp()
    {
       black = BlankClip(color=$000000, width=1, height=256)
       white = BlankClip(color=$ffffff, width=1, height=256)
       StackHorizontal(black,white)
       BilinearResize(512, 256)
       Crop(128,0,-128,-0)
    }
    Name:  ramp.png
Views: 2809
Size:  1.9 KB

    You can then manipulate that as necessary (for use as a mask with Overlay(), etc.) This works with AviSynth 2.6 but may need to be changed for earlier versions where the exact behavior of BilinearResize may vary.
    Quote Quote  
  23. jagabo & poisondeathray,

    Thanks for the info. I have to spend time in the real world for the next couple of days but I'll try out those suggestions when I've escaped from it.

    Cheers.
    Quote Quote  
  24. Here's another one. I've only tried it on a few videos so far, but it seems to be sufficiently unobtrusive
    and not-unpleasant to look at (when not really looked at, if you know what I mean).
    I've added fixed noise and temporal softening to the mix.

    Image
    [Attachment 43381 - Click to enlarge]


    https://youtu.be/pvrjKZWFCmM
    (2 min preview) (updated)

    Code:
    # requires http://avisynth.nl/index.php/AddGrain
     
    <source>
    
    SuperSexyWidescreen(16, 9)
    return Last
    Code:
    # https://forum.videohelp.com/threads/385341-avisynth-how-to-add-borders#post2498883
    # requires http://avisynth.nl/index.php/AddGrain
    ##################################
    ### a nice Pillarbox effect - extends blurred source into left & right borders 
    ##  also known as /SoftPillarbox/
    ##
    ## NOTE: 
    ##  * padding is 24 pixels minimum (12 per side), in steps of 4
    ##  * if at least 24 pixels of padding is not needed, source is returned unchanged
    ##  * this filter looks best if source has had any minor black bars cropped off beforehand
    ##
    ## @ aspect_num, aspect_den 
    ##          - defines the output ASPECT RATIO; default 16, 9
    ##              (the ratio determines the new, padded width, given source video height)
    ##              Examples: 
    ##              | SuperSexyWidescreen()           ## expand to 16:9 aspect ratio (default)
    ##              | SuperSexyWidescreen(16, 9)      ## expand to 16:9 
    ##              | SuperSexyWidescreen(4, 3)       ## expand to 4:3 
    ##              | SuperSexyWidescreen(48, 9)      ## expand to 3 x 16:9 (triple monitors!)
    ##              | SuperSexyWidescreen(2560, 1080) ## expand to true 21:9 (21.3333:9)
    ##              | SuperSexyWidescreen(Width+32, Height) ## expand to explicit width
    ## @ edge  - amount of picture on left & right to be stretched over pillarbox; 
    ##              range 0.02_0.5; default 0.03 (3%)
    ## @ gain  - brightness of pillarbox portion; 
    ##              range 0.2_2.0; default 0.9 (slightly darker)
    ##              (bypass / substitute plain black borders if gain < 0.1)
    ## @ sat   - saturation of pillarbox portion; 
    ##              range 0.0_2.0; default 0.5 (50%)
    ## @ blue  - amount of pillarbox blue shift; 
    ##              range -32_32; default 2 (subtle)
    ## @ blur  - amount of pillarbox spatial blur; 
    ##              range 0_100; default 100 (very heavy)
    ## @ noise - amount of pillarbox fixed-pattern noise; 
    ##              range 0_50; default 3 (subtle)
    ## @ tblur - radius of pillarbox temporal blur; 
    ##              range 0_9; 0=off; default 4 (moderate)
    ## @ scene - pillarbox temporal blur scene change threshold
    ##              range 0_255; default 30
    ## @ xblend - amount of cross-blending for pillarbox symmetry
    ##              range 0_1; default 0.0 (off)
    ##
    ## @ version 2.3 (interface; add blend, scenechange; bypass if output too narrow)
    ## @ version 2.4 (AddGrain_DeepColor)
    ##
    function SuperSexyWidescreen(
    \               clip C, int "aspect_num", int "aspect_den", 
    \               float "edge", float "gain", float "sat",int "blue", 
    \               int "blur", int "noise", int "tblur", int "scene", 
    \               float "xblend")
    {
        C
        anum  = Default(aspect_num, 16)
        aden  = Default(aspect_den, 9)
        wid   = _mod(4, (Float(anum) / Float(aden) * Height))
    
        edge  = Min(Max(0.02, Default(edge,   0.06)), 0.5)
        gain  = Min(Max(0.0,  Default(gain,   0.9 )), 2.0)
        sat   = Min(Max(0.0,  Default(sat,    0.6 )), 2.0)
        blue  = Min(Max(-32,  Default(blue,   2   )), 32)
        blur  = Min(Max(0,    Default(blur,   100 )), 100)
        noise = Min(Max(0,    Default(noise,  3   )), 50)
        tblur = Min(Max(0,    Default(tblur,  4   )), 9)
        blend = Min(Max(0,    Default(xblend, 0.0 )),  1.0)
        scene = Default(scene, 32)
    
        test1 = C.Width > (wid-24)
        
        ## TEMPORAL SOFTEN (done first as it adds artifacts)
        (tblur==0 || test1) ? Last 
        \ : TemporalSoften(tblur, 255, 255, scene, 2)
    
        ### EXTRACT LEFT & RIGHT EDGES
        L = (test1) ? Last : Crop(          0,               0, _mod(2, edge*Width), 0) 
        R = (test1) ? Last : Crop(_mod(2, (1.0-edge)*Width), 0, _mod(2, edge*Width), 0)
    
        ## STRETCH
        ## p=19: softest w/o visible 'blockiness' 
        L = (test1) ? Last : L.GaussResize(_mod( 2, 0.5*(wid-C.Width)), Height, p=19)
        R = (test1) ? Last : R.GaussResize(_mod(-2, 0.5*(wid-C.Width)), Height, p=19)
    
        ## BLUR
        ## (almost can't have too much blur)
        L=(blur<0.5 || test1) ? L 
        \ : L.QGaussBlur(blur, blur).QGaussBlur(blur, blur)
        R=(blur<0.5) || test1 ? R 
        \ : R.QGaussBlur(blur, blur).QGaussBlur(blur, blur)
        StackHorizontal(L, R)
    
        ## SYMMETRY
        (blend<0.01 || test1) ? Last 
        \ : Overlay(FlipHorizontal, opacity=blend/2.0)
    
        ## DARKEN, DESATURATE, ADD BLUE SHIFT
        ## (differentiate from main program, but not too much)
        (test1) ? Last 
        \ : ColorYUV(gain_y=f2c(gain), off_u=blue, cont_u=f2c(sat), cont_v=f2c(sat))
    
        ## ADD FIXED NOISE ('FROSTED GLASS') 
        ## (enough to hide any banding from mega-blur)
        (noise==0 || test1) ? Last 
        \ : AddGrain(Float(noise), 0.22, 0.22, constant=1>0)
        
        return (test1) ? C
        \ : StackHorizontal(
        \       Crop(0, 0, _mod(2, 0.5*Width), 0), 
        \       C, 
        \       Crop(_mod(-2, 0.5*Width), 0, 0, 0))
    }
    
    ##################################
    ### quick & dirty Gaussian blur
    function QGaussBlur(clip C, float radx, float rady)
    {
        return C.BilinearResize(
        \           Max(16, _mod(2, Float(C.Width)/radx)), 
        \           Max(16, _mod(2, FLoat(C.Height)/rady)))
        \       .GaussResize(
        \           C.Width, C.Height, p=19)
    }
    
    ##################################
    ### return true if running in Avisynth+, false otherwise
    ##
    function IsAvsPlus()
    {
        sVer = LCase(VersionString) 
        return (FindStr(sVer, "avisynth+")    > 0)
        \   || (FindStr(sVer, "avisynthplus") > 0)
    }
    
    #######################################
    ### scale "normal" float arguments to 
    ### [[ColorYUV]]'s <gain_x>, <gamma_x> & <cont_x>  
    ##
    function f2c(float f) {
        return Round((f - 1.0) * 256.0) 
    }
    
    ##################################
    ### return argument <f> as integer and ensure it is modulo <m>
    ##
    ## @ m - mod value (round toward zero, unless m < 0)
    ## @ f - input (may be positive or negative)
    ##
    ## Examples
    ## | _mod( 2,  3.3) =  2 ## round toward zero
    ## | _mod(-2,  3.3) =  4 ## round away from zero
    ##
    function _mod(int m, float f)
    {
        x  = (m>0) ? -1 : 1
        m  = Max(1, Abs(m))
        sg = Sign(f)
        i  = Round(Abs(f))
        return sg * Max(0, i + x * (i % m))
    }
    EDIT added cross-blending for symmetry per hello_hello's suggestion below, and other minor changes
    Last edited by raffriff42; 21st Oct 2017 at 06:47. Reason: script version 2.4 (revert from 2.5)
    Quote Quote  
  25. raffriff42,

    That looks reasonably good for coloured borders, although it did occur to me when I was playing with the idea myself, that maybe part of what makes them distracting is the left and right borders can be quite different. I wondered if you took the pixels used for the left border and the pixels used for the right and blended them, then used the blended pixels for both sides, whether that might be less distracting. It works in my head, but in practice maybe it won't. I've grabbed your function, but I might have a play with that idea later anyway.

    Cheers.
    Quote Quote  
  26. Thanks hello_hello. I dunno, with what I've seen so far, I think the asymmetry actually helps.
    In this concert footage, one side of the screen is often brighter than the other:
    Image
    [Attachment 43389 - Click to enlarge]


    I've been watching a variety of things with it (live - no re-encoding), and it actually enhances the experience way more than it distracts.

    EDIT oh you want anime?
    Image
    [Attachment 43390 - Click to enlarge]
    Last edited by raffriff42; 16th Oct 2017 at 01:34.
    Quote Quote  
  27. I haven't played with it much yet, but I'm still leaning towards symmetry.
    They're still not completely symmetric, which I assume has something to do with the temporal softening and one side being offset a little, or something obvious I'm missing (I haven't had a close look at the script yet) and that's probably a good thing, but I did try sticking the following in between the "extract left and right edges" and "stretch" sections of the script. Just to see. Maybe they could be blended slightly unevenly as a compromise.

    L=overlay(L, R, opacity = 0.5)
    R=overlay(L, R, opacity = 0.5).FlipHorizontal()

    Without and with screenshots below. I haven't tried watching a video with the borders either way yet.
    Image Attached Thumbnails Click image for larger version

Name:	test.jpg
Views:	246
Size:	94.0 KB
ID:	43392  

    Quote Quote  
  28. hicats please does exist a 64bit version of autotocrop.dll?

    the raffiriff's works well also in 64bit. Please now I have a new wonder: I have a 4:3 source (old videos) to convert in 16:9 in crop/resize mode fullscreen (without borders). Does exist a function or a script in avisynth 64bit that do this? thanks
    Quote Quote  
  29. hello_hello, I'm coming around to your point of view. I added in a cross-blending argument to the script above.

    And now below, blurred borders for all 4 sides; it looks like post #4 but with added (optional) temporal blur & fixed pattern noise, as in the first script. It does not look as good as the first one (in my opinion) for the case of side borders only. BTW I'm growing less fond of temporal blur, depending on the source, but the noise is needed: without fixed pattern noise, heavy blurring has really nasty banding problems at times.
    Code:
    ##################################
    ### add soft borders
    ##
    ## @ gain  - brightness of pillarbox portion; 
    ##              range 0.2_2.0; default 0.9 (slightly darker)
    ##              (bypass / substitute plain black borders if gain < 0.1)
    ## @ sat   - saturation of pillarbox portion; 
    ##              range 0.0_2.0; default 0.6 (60%)
    ## @ blue  - blue shift of pillarbox portion; 
    ##              range -32_32; default 0 (none; subtle=2)
    ## @ blur  - amount of pillarbox blur; 
    ##              range 0_200; default 100 (strong)
    ## @ noise - amount of pillarbox fixed-pattern noise; 
    ##              range 0_50; default 3 (subtle)
    ## @ tblur - radius of temporal blur; 
    ##              range 0_9; default 0 (off)
    ## @ blend - amount of cross-blending for symmetry
    ##              range 0_1; default 0.5 (moderate)
    ##
    ## @ version 2.0
    ## requires http://avisynth.nl/index.php/AddGrain
    ##
    function BlurBorders(clip C, int left, int top, int right, int bottom, 
    \                    float "gain", float "sat", int "blue",
    \                    int "blur", float "noise", int "tblur",
    \                    float "blend")
    {
        C
        wid   = Width  + left + right
        hgt   = Height + top + bottom 
    
        gain  = Min(Max(0.0,  Default(gain,  0.9 )), 2.0)
        sat   = Min(Max(0.0,  Default(sat,   0.6 )), 2.0)
        blue  = Min(Max(-32,  Default(blue,  0   )), 32)
        blur  = Min(Max(0,    Default(blur,  100 )), 200)
        noise = Min(Max(0.0,  Default(noise, 3   )), 1.0)
        tblur = Min(Max(0,    Default(tblur, 0   )), 9)
        blend = Min(Max(0,    Default(blend, 0.5)), 1.0)
    
        ## TEMPORAL SOFTEN (if desired) (done first as it adds artifacts)
        (tblur==0) ? Last 
        \ : TemporalSoften(tblur, 255, 255, 255, 2).Slip(-(tblur/2-1))
    
        ## STRETCH + BLUR
        w = Max(16, _mod(4, Float(wid)/blur))
        h = Max(16, _mod(4, Float(hgt)/blur))
        BilinearResize(w, h)
        GaussResize(wid, hgt, p=19)
        ## p=19: softest w/o visible 'blockiness' 
    
        ## SYMMETRY
        Overlay(FlipHorizontal, opacity=blend/2.0)
    
        ## DARKEN, DESATURATE
        ColorYUV(gain_y=f2c(gain), off_u=blue, cont_u=f2c(sat), cont_v=f2c(sat))
    
        ## ADD FIXED NOISE ('FROSTED GLASS') 
        ## (enough to hide any banding from mega-blur)
        (noise==0) ? Last 
        \ : AddGrain(var=Float(noise), hcorr=0.33, vcorr=0.33, constant=1>0)
    
        return Last.Overlay(C, x=left, y=top)
    } 
    
    ##################################
    ### return argument <f> as integer and ensure it is modulo <m>
    ##
    ## @ m - mod value (round toward zero, unless m < 0)
    ## @ f - input (may be positive or negative)
    ##
    ## Examples
    ## | _mod( 2,  3.3) =  2 ## round toward zero
    ## | _mod(-2,  3.3) =  4 ## round away from zero
    ##
    function _mod(int m, float f)
    {
        x  = (m>0) ? -1 : 1
        m  = Max(1, Abs(m))
        sg = Sign(f)
        i  = Round(Abs(f))
        return sg * Max(0, i + x * (i % m))
    }
    Last edited by raffriff42; 19th Oct 2017 at 09:01.
    Quote Quote  
  30. While I'm not a fan of filling in the black pillar bars, some of these, especially raffriff's filling in with the average luma/chroma blur from the main video, look better than what I see on TV.

    However, the one thing that I still think makes it obtrusive is the hard line between the program material and the border. It seems to me that what is needed is some sort of transition so that there is no longer any sense of a vertical line of demarcation. My thought would be to create a stretch function for the video that stretches the edges about 10-15 pixels. The tricky part would be to then blend that into blurred side-bars to that you had a sense of a gradual transition from sharp to blurred. I did something like this about ten years ago, using various fX in Vegas, but was never able to quite tweak it so that it looked better than the black bars.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!