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 11th March 2021, 19:37   #1  |  Link
Arx1meD
Registered User
 
Arx1meD's Avatar
 
Join Date: Feb 2021
Posts: 103
Stab_Light - deshaker

This script will be useful for stabilizing video from shaking.
The script is based on Stab3 (found on real.finder's Avisynth Stuff). It is simplified and can fix large borders. It is also faster.

Code:
# Stab_Light() v1.2  -  deshaker
#
# v1.0 : - first release
# v1.1 : - adapted for use in all versions of AviSynth (by StainlessS)
#        - added motion search method
# v1.2 : - added Pre_Clip function for better search of motion vectors

/*
Needed plugins:
    MVTools2       https://github.com/pinterf/mvtools/releases
    DePan          DePan and DePanEstimate are bundled as a package with MVTools2
    DePanEstimate
    RgTools        https://github.com/pinterf/RgTools/releases
    MaskTools2     https://github.com/pinterf/masktools/releases/
    FillBorders    https://github.com/Asd-g/AviSynth-FillBorders/releases
    AVSInpaint     https://github.com/pinterf/AvsInpaint/releases
    GRunT          https://github.com/pinterf/GRunT/releases
    GScript        for AviSynth v2.60 only  https://forum.doom9.org/showthread.php?t=147846

External dependencies: 
    fftw3.dll (or renamed to libfftw3f-3.dll) from http://www.fftw.org/ (http://www.fftw.org/install/windows.html)
    Copy the file fftw3.dll to the folder C:\Windows\System32 for Win32. For Win64 copy 32-bit version in C:\Windows\SysWOW64
    and copy 64-bit version in C:\Windows\System32.
    Or use LoadDLL (http://avisynth.nl/index.php/LoadDLL)


Stab_Light(clip, ts, range, dxmax, dymax, zoom, rotation, PAR, mirror,
           MaxBorders, FixBorders, FixFalPos, MethodMS, debug)

ts          Default: 7           - Frames to temporal average for better motion estimation (max. 7)
range       Default: 1           - Frames before/after to estimate motion
dxmax       Default: autodetect  - Maximum deviation in pixels
dymax       Default: autodetect  - x, and y should be the same
zoom        Default: 1.0         - Maximum zoom factor (1 disabled). When zoom > 0 borders can be large
rotation    Default: false       - Rotation estimation for MethodMS=2 only. If rotation=true black borders can be curved.
                                   To fix them set mirror=true 
PAR         Default: 1.0         - Pixel Aspect Ratio of your source
mirror      Default: false       - Depan it self fill empty borders with mirrored from frame edge pixels
MaxBorders  Default: autodetect  - Maximum of black borders in pixels
FixBorders  Default: true        - Fix black borders
FixFalPos   Default: true        - Fixes borders of MaxBorders more pixels wide
MethodMS    Default: 1           - Method of motion search: 1 - DePan is used to search for motion
                                                                in many cases better and faster
                                                            2 - MVTools is used to search for motion
                                                                slower, bad border fix, recommended to set mirror=true
debug       Default: false       - Show black borders if mirror=false and FixBorders=true


This script can be Import()'ed under AviSynth+, OR, under AviSynth v2.60 Standard [ONLY IF GScript is installed].
Can also be GImport()'ed when GScript Installed.
Can also be auto Loaded by AviSynth if in Plugins directory. [Needs GScript installed if not AviSynth+].
Can also be dumped in AvsInit()'s GIMPORT directory for auto loading by AvsInit().

GScript needs to be installed BEFORE attempting to AviSynth v2.60 std Import()/GImport() "Stab_Light.avsi".
Either by Plugins AutoLoad, or Manual LoadPlugin() loading.


Example:
    for AviSynth v2.60 :  LoadPlugin("C:\AVS\plugins\GScript_26_32.dll")
                          Import("C:\AVS\scripts\Stab_Light.avsi")

    for AviSynth+      :  Import("C:\AVS\scripts\Stab_Light.avsi")

Stab_Light(ts=7, zoom=1.0, mirror=false, rotation=false, FixFalPos=true, FixBorders=true, MethodMS=1, debug=false)


Thread in Doom9's forum: https://forum.doom9.org/showthread.php?t=182532
*/

Function Fb2FnNameEx(string Fn) {
Try{
    Eval(Fn+"()")B = true
} Catch (e) {
    Assert(e.FindStr("syntax") == 0, "Fb2FnNameEx: Error in Function Name '"+Fn+"'")
    B = (e.FindStr("no function named") == 0)
}
return B
}

Fb2IsPlus     = (FindStr(VersionString,"AviSynth+") != 0)
Fb2HasGScript = Fb2FnNameEx("GScipt")

Fb2_GS_S = """
    Function FindBorders(clip c, int edge, float thr, int MaxB, int pad, int w, int h) {
    # edge: 0=left, 1=right, 2=top, 3=bottom
    result=0
    for(i = 1, MaxB) {
        crpd = c.Crop(edge==1?w-i:0, edge==3?h-i:0, edge==0?i:0, edge==2?i:0)
        if(crpd.AverageLuma <= thr) { result = i + pad } else { i = MaxB }
    }
    return result
    }
"""

/*
If this avsi script is not in plugins, then HasGScript [Fb2HasGScript] can be FALSE, even if using GImport() from GScript dll.
Not sure why this occurs, so even if Fb2HasGScript==FALSE and is NOT AviSynth+, then we use GScript's GEval instead of Eval to
install above FindBorders() function.
We use Eval() to install the function, ONLY if GScript not installed and is AviSynth+.
*/

Try {
    Fb2HasGScript || !Fb2IsPlus ? GEval(Fb2_GS_S) : Eval(Fb2_GS_S)
} Catch (msg) {
    Assert(false, ScriptFile+": Need GScript or AviSynth+ or GScript mast be loaded before the script"+Chr(10)+
        \ "IsPlus="+String(Fb2IsPlus)+"; HasGScript="+String(Fb2HasGScript)+Chr(10)+
        \ "SysErr="+Msg)
}

Function Stab_Light(clip clp, int "ts", int "range", int "dxmax", int "dymax", float "zoom", bool "rotation", float "PAR",
                  \ bool "mirror", int "MaxBorders", bool "FixBorders", bool "FixFalPos", int "MethodMS", bool "debug") {
ts         = Default(ts, 7)
range      = Default(range, 1)
dxmax      = Default(dxmax, Round(clp.Width()/180.0))
dymax      = Default(dymax, dxmax)
zoom       = Default(zoom, 1.0)
rotation   = Default(rotation, false)
PAR        = Default(PAR, 1.0)
mirror     = Default(mirror, false)
MaxBorders = Default(MaxBorders, Max(Round(clp.Width()/60.0), 20))
FixBorders = Default(FixBorders, true)
FixFalPos  = Default(FixFalPos, true)
MethodMS   = Default(MethodMS, 1)
debug      = Default(debug, false)

Assert(MethodMS == 1 || MethodMS == 2, "Stab_Light: Motion search method should be 1 or 2")

temp    = TemporalSoften(clp, ts, 255, 255, 25, 2)  # SC thr to 25 otherwise pans will stutter
rep     = Repair(temp, TemporalSoften(clp, 1, 255, 255, 25, 2))
inter   = Interleave(rep, clp)  # temporal stable (better subpixel detection)
pre_clp = inter.Pre_Clip(blur=1.0, contrast=0.7, brightness=100).RemoveGrain(mode=17)

vectors = MethodMS == 2 ? pre_clp.MSuper(hpad=8, vpad=8, pel=1, sharp=2, chroma=false)
                               \ .MAnalyse(isb=false, blksize=Height(clp)<=720?8:16, overlap=Height(clp)<=720?2:4,
                                         \ chroma=false, truemotion=false, global=true, search=5, dct=7)
                      \ : Undefined

mdata = MethodMS == 1 ? DePanEstimate(pre_clp, range=range, pixaspect=PAR, trust=0, dxmax=dxmax, dymax=dymax, zoommax=zoom)
                    \ : pre_clp.MDepan(vectors, zoom=zoom>1, rot=rotation, thSCD1=400)

dp    = DePan(inter, data=mdata, offset=-1, mirror=mirror?15:0, pixaspect=PAR, matchfields=false, subpixel=2)
stab  = SelectEvery(dp, 2, 0)

w = Width(clp)
h = Height(clp)
thr = 10.0
pre = stab.ConvertToY8()#.ColorYUV(off_y=-15)

stab = !mirror && FixFalPos ? \
gScriptClip(stab, "
    AverageLuma(Crop(pre, 0, 0, -w+MaxBorders+1, 0)) < thr ? clp : \
    AverageLuma(Crop(pre, w-MaxBorders-1, 0, 0, 0))  < thr ? clp : \
    AverageLuma(Crop(pre, 0, 0, 0, -h+MaxBorders+1)) < thr ? clp : \
    AverageLuma(Crop(pre, 0, h-MaxBorders-1, 0, 0))  < thr ? clp : Last
    return Last
", args="clp, pre, MaxBorders, w, h, thr",Local=true) : stab

return !mirror && FixBorders ? FillBorders2(stab, thr=thr, pad=1, MaxBorders=MaxBorders, debug=debug) : stab
}

Function FillBorders2(clip c, float "thr", int "pad", int "MaxBorders", bool "debug") {
thr   = Default(thr, 5.0) # Threshold for black borders
pad   = Default(pad, 0)   # Extra padding for borders
MaxB  = Default(MaxBorders, Max(Round(c.Width()/60.0), 20)) # Maximum of black borders in pixels
debug = Default(debug, false) # Show black borders

w = Width(c)
h = Height(c)
pre   = c.ConvertToY8()#.ColorYUV(off_y=-15)
blank = c.mt_lut("0", chroma="-128")

gScriptClip(c, """
    x1 = FindBorders(pre, 0, thr, MaxB, pad, w, h) # left
    x2 = FindBorders(pre, 1, thr, MaxB, pad, w, h) # right
    y1 = FindBorders(pre, 2, thr, MaxB, pad, w, h) # top
    y2 = FindBorders(pre, 3, thr, MaxB, pad, w, h) # bottom
    
    PreBlur  = 0 # If > 0 then there may be an error
    PostBlur = 0 # Max(x1, x2, y1, y2, 4) # If > 0 then there may be an error
    b_fix    = (x1 + x2 + y1 + y2) > 0
    max_fix  = Max(x1, x2, y1, y2)
    
    msk = b_fix && max_fix >= 8	? blank.ConvertToY8().LetterBox(y1, y2, x1, x2, color=$ffffff).ConvertToYV12() : blank
    
    fixed = !b_fix ? Last
                 \ : max_fix < 8 ? FillBorders(left=x1, top=y1, right=x2, bottom=y2, mode=0, y=3, u=3, v=3)
                               \ : InpaintLogo(mask=msk, Radius=Max(x1,x2,y1,y2,5)*1.5, PreBlur=PreBlur, PostBlur=PostBlur)
    
    debug ? mt_merge(fixed, 
                   \ blank.ConvertToRGB().LetterBox(y1, y2, x1, x2, color=$ff3333).ConvertToYV12(),
                   \ blank.ConvertToY8().LetterBox(y1, y2, x1, x2, color=$ffffff).ConvertToYV12(), 
                   \ luma=true)
                   \ .Subtitle("Black borders:\n     "+string(y1)+"\n  "+string(x1)+"     "+string(x2)+"\n     "+ string(y2), 
                             \ lsp=0, text_color=$ff3333, font="Courier New", x=MaxB+5, y=MaxB+5)
        \ : fixed
    
    return Last
""", args="pre, blank, thr, pad, MaxB, debug, w, h") 
}

function Pre_Clip(clip clp, float "blur", float "contrast", float "brightness"){
blur       = Default(blur, 1.0)
contrast   = Default(contrast, 1.2)
brightness = Default(brightness, 10.0)

v = clp.mt_lut(expr="x 20 1 x 127.5 / - 21 ^ pi x * 255 / cos 21 ^ - * 1.05 * -", Y=3, U=2, V=2, scale_inputs="allf", use_expr=2)

mask_1 = clp.Tweak(sat=0).Blur(blur).mt_edge(mode="min/max", thY1=0, thY2=255, Y=3, U=2, V=2)

pre_1 = v.Tweak(cont=contrast, bright=brightness)
pre_2 = mt_merge(v, pre_1, mask_1, Y=3, U=2, V=2)
pre_3 = pre_2.Tweak(sat=0).mt_invert().Blur(1.58).Blur(1.58).Blur(1.58)
pre_4 = mt_lutxy(pre_2, pre_3, expr="x 127.5 > y 255 x - 127.5 / * x 255 x - - + y x 127.5 / * ? ", Y=3, U=2, V=2, scale_inputs="allf", use_expr=2)

# s = clp.vsTCanny().mt_binarize(threshold=0, chroma="-128")
# Overlay(pre_4, s, mask=s, opacity=0.5)

return pre_4
}
Old version for AviSynth+ only
Code:
# Needed plugins: DePan, DePanEstimate, GRunT, RgTools, MaskTools2, FillBorders, AVSInpaint
function Stab_Light(clip clp, int "ts", int "range", int "dxmax", int "dymax", float "zoom", float "PAR", \
                bool "mirror", int "MaxBorders", bool "FixBorders", bool "FixFalPos", bool "debug") {
ts         = Default(ts, 7)        #frames to temporal average for better motion estimation (max. 7)
range      = Default(range, 1)     #frames before/after to estimate motion
dxmax      = Default(dxmax, Round(clp.Width()/180.0)) #maximum deviation in pixels
dymax      = Default(dymax, dxmax) #x, and y should be the same
zoom       = Default(zoom, 1)      #maximum zoom factor (1 disabled)
PAR        = Default(PAR, 1.0)     #PAR of your source
mirror     = Default(mirror, false) #Edge filling
MaxBorders = Default(MaxBorders, Max(Round(clp.Width()/60.0), 20))
FixBorders = Default(FixBorders, true)
FixFalPos  = Default(FixFalPos, true) #Fixes borders of MaxBorders more pixels wide
debug      = Default(debug, false)

temp    = TemporalSoften(clp, ts, 255, 255, 25, 2) # SC thr to 25 otherwise pans will stutter
rep     = Repair(temp, TemporalSoften(clp, 1, 255, 255, 25, 2))
inter   = Interleave(rep, clp) # temporal stable (better subpixel detection)
pre_clp = inter.mt_lut(expr="x 20 1 x 127.5 / - 21 ^ pi x * 255 / cos 21 ^ - * 1.05 * -", Y=3, U=2, V=2).RemoveGrain(mode=17) #ColorYUV(levels="PC->TV")

mdata = DePanEstimate(pre_clp, range=range, pixaspect=PAR, trust=0, dxmax=dxmax, dymax=dymax, zoommax=zoom)
dp    = DePan(inter, data=mdata, offset=-1, mirror=mirror?15:0, pixaspect=PAR, matchfields=false, subpixel=2)
stab  = SelectEvery(dp, 2, 0)

w = Width(clp)
h = Height(clp)
thr = 10

stab = mirror == false && FixFalPos == true ? gScriptClip(stab, """
pre = ConvertToY8()#.ColorYUV(off_y=-15)
AverageLuma(Crop(pre, 0, 0, -w+MaxBorders+1, 0)) < thr ? clp : \
AverageLuma(Crop(pre, w-MaxBorders-1, 0, 0, 0)) < thr ? clp : \
AverageLuma(Crop(pre, 0, 0, 0, -h+MaxBorders+1)) < thr ? clp : \
AverageLuma(Crop(pre, 0, h-MaxBorders-1, 0, 0)) < thr ? clp : stab
""", args="clp, stab, MaxBorders, w, h, thr") : stab

mirror == false && FixBorders ==true ? FillBorders2(stab, thr=thr, pad=1, MaxBorders=MaxBorders, debug=debug) : stab
}

function FillBorders2(clip c, int "thr", int "pad", int "MaxBorders", bool "debug") {
thr   = Default(thr, 5)
pad   = Default(pad, 0)
MaxB  = Default(MaxBorders, Max(Round(c.Width()/60.0), 20))
debug = Default(debug, false)

w = width(c)
h = height(c)

gScriptClip(c, """
pre = ConvertToY8()#.ColorYUV(off_y=-15)

x1 = 0
x2 = 0
y1 = 0
y2 = 0
for(i = 1, MaxB, 1) {
	if (AverageLuma(Crop(pre, 0, 0, -w+i, 0)) < thr) {x1 = i + pad} else {break}
}
for(i = 1, MaxB, 1) {
	if (AverageLuma(Crop(pre, w-i, 0, 0, 0)) < thr) {x2 = i + pad} else {break}
}
for(i = 1, MaxB, 1) {
	if (AverageLuma(Crop(pre, 0, 0, 0, -h+i)) < thr) {y1 = i + pad} else {break}
}
for(i = 1, MaxB, 1) {
	if (AverageLuma(Crop(pre, 0, h-i, 0, 0)) < thr) {y2 = i + pad} else {break}
}

PreBlur  = 0 #If > 0 then there may be an error 
PostBlur = 0 #Max(x1, x2, y1, y2, 4) #If > 0 then there may be an error 
b_fix    = (x1 + x2 + y1 + y2) > 0
max_fix  = Max(x1, x2, y1, y2)

msk = b_fix && max_fix >= 8 ? pre.mt_lut("0", chroma="-128").LetterBox(y1, y2, x1, x2, color_yuv=$ffffff).ConvertToYV12() : \
                              pre.mt_lut("0", chroma="-128")

fixed = b_fix ? max_fix < 8 ? FillBorders(left=x1, top=y1, right=x2, bottom=y2, mode=0, y=3, u=3, v=3) : \
                              InpaintLogo(mask=msk, Radius=Max(x1,x2,y1,y2,5)*1.5, PreBlur=PreBlur, PostBlur=PostBlur) : \
                c

debug == true ? mt_merge(fixed, \
                         c.mt_lut("0", chroma="-128").ConvertToRGB().LetterBox(y1, y2, x1, x2, color=$ff3333).ConvertToYV12(), \
                         pre.mt_lut("0", chroma="-128").LetterBox(y1, y2, x1, x2, color_yuv=$ffffff).ConvertToYV12(), \
                         luma=true)\
                        .Subtitle("Black borders:\n     "+string(y1)+"\n  "+string(x1)+"     "+string(x2)+"\n     "+ string(y2), \
                                  lsp=0, text_color=$ff3333, font="Courier New", x=MaxB+5, y=MaxB+5) : \
                fixed
""", args="c, thr, pad, MaxB, debug, w, h")
}
Example:
Stab_Light(zoom = 1.00, mirror = false, FixFalPos = true, FixBorders = true, debug = false)
or
Stab_Light(ts=7, zoom=1.0, mirror=false, rotation=false, FixFalPos=true, FixBorders=true, MethodMS=1, debug=false)

Original and stabilized clip

Last edited by Arx1meD; 24th June 2021 at 09:38.
Arx1meD is offline   Reply With Quote
Old 12th March 2021, 20:25   #2  |  Link
manono
Moderator
 
Join Date: Oct 2001
Location: Hawaii
Posts: 7,405
Hi,
Your filter has arrived at the right time as I've just begun work on an especially jumpy video. It seems to work fine but there's a line imprinted at the top of the entire video:

Script error: Syntax error
([Script Clip], line 8 column 21)

Would you happen to know anything about that?

Thank you.

Last edited by manono; 13th March 2021 at 02:02.
manono is offline   Reply With Quote
Old 12th March 2021, 20:57   #3  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,158
Avs+ ? [Uses for/next loop - OR, if not Avs+, use GScript's GImport() on OP script]
and all requirements fulfilled ? # DePan, DePanEstimate, GRunT, RgTools, MaskTools2, FillBorders, AVSInpaint

Quote:
Script error: Syntax error
([Script Clip}, line 8 column 21)
There are 2 instances of gScriptclip in that script, 1st instance only 7 lines, so must be 2nd instance, ie
Code:
gScriptClip(c, """
pre = ConvertToY8()#.ColorYUV(off_y=-15)

x1 = 0
x2 = 0
y1 = 0
y2 = 0
for(i = 1, MaxB, 1) {  # <<<<< Line 8, coloumn 21 is @ the curly brace thing '{' : looks like need Avs+ or GScript for for/next loop
	if (AverageLuma(Crop(pre, 0, 0, -w+i, 0)) < thr) {x1 = i + pad} else {break}
}
for(i = 1, MaxB, 1) {
	if (AverageLuma(Crop(pre, w-i, 0, 0, 0)) < thr) {x2 = i + pad} else {break}
}
for(i = 1, MaxB, 1) {
	if (AverageLuma(Crop(pre, 0, 0, 0, -h+i)) < thr) {y1 = i + pad} else {break}
}
for(i = 1, MaxB, 1) {
	if (AverageLuma(Crop(pre, 0, h-i, 0, 0)) < thr) {y2 = i + pad} else {break}
}

PreBlur  = 0 #If > 0 then there may be an error
PostBlur = 0 #Max(x1, x2, y1, y2, 4) #If > 0 then there may be an error
b_fix    = (x1 + x2 + y1 + y2) > 0
max_fix  = Max(x1, x2, y1, y2)

msk = b_fix && max_fix >= 8 ? pre.mt_lut("0", chroma="-128").LetterBox(y1, y2, x1, x2, color_yuv=$ffffff).ConvertToYV12() : \
                              pre.mt_lut("0", chroma="-128")

fixed = b_fix ? max_fix < 8 ? FillBorders(left=x1, top=y1, right=x2, bottom=y2, mode=0, y=3, u=3, v=3) : \
                              InpaintLogo(mask=msk, Radius=Max(x1,x2,y1,y2,5)*1.5, PreBlur=PreBlur, PostBlur=PostBlur) : \
				c

debug == true ? mt_merge(fixed, \
	                     c.mt_lut("0", chroma="-128").ConvertToRGB().LetterBox(y1, y2, x1, x2, color=$ff3333).ConvertToYV12(), \
			             pre.mt_lut("0", chroma="-128").LetterBox(y1, y2, x1, x2, color_yuv=$ffffff).ConvertToYV12(), \
						 luma=true)\
			             .Subtitle("Black borders:\n      "+string(y1)+"\n  "+string(x1)+"       "+string(x2)+"\n      "+
                                     \ string(y2), lsp = 10, text_color=$ff3333, font="Courier New", x=MaxB+5, y=MaxB+5) : \
                fixed
""", args="c, thr, pad, MaxB, debug, w, h")
Script works ok for me [avs+], but using defaults, what are the args you are using ?
Code:
AviSource("d:\Parade.avi")

Stab_Light()
EDIT: below seems to work ok too [as OP example].
Code:
AviSource(".\stab_example.mkv.AVI")  # OP's sample, After ffmpeg conversion to UT_Video AVI
W=width/2
crop(0,0,W,0)   # only unstable half
ORG=Last
Stab_Light(zoom = 1.00, mirror = false, FixFalPos = true, FixBorders = true, debug = false)
D=Last.Subtract(ORG)
T=StackHorizontal(ORG,Last)
B=StackHorizontal(D,D)
StackVertical(T,B)
just to show its doing something [and no error message]
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 12th March 2021 at 22:12.
StainlessS is offline   Reply With Quote
Old 13th March 2021, 03:26   #4  |  Link
manono
Moderator
 
Join Date: Oct 2001
Location: Hawaii
Posts: 7,405
Thanks for taking the time to have a look, StainlessS.
Quote:
Avs+ ?
Regular AviSynth 2.60 32bit.
Quote:
...use GScript's GImport() on OP script
Tried it but no change.
Quote:
...and all requirements fulfilled ?
I have them all loaded explicitly in the script, but I can't vouch for them all being the latest versions.
Quote:
...what are the args you are using ?
The same as his example. Mine jumps similarly to his before-and-after, and I first wanted to get it going before I experimented. This is the complete script at the moment:

LWLibavVideoSource("EK Do Teen.mp4")
Stab_Light(zoom = 1.00, mirror = false, FixFalPos = true, FixBorders = true, debug = false)
Return Last


Even with no arguments (Stab_Light()), same thing. Maybe Arx1meD will have an idea. Thanks again.

Last edited by manono; 13th March 2021 at 07:47.
manono is offline   Reply With Quote
Old 13th March 2021, 05:04   #5  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,158
OK, I'm gettin' same error message as you now with 2.6 std.
I'll play a bit more but may not do it tonite if takes very long, its after 04:00 am here.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 13th March 2021, 06:05   #6  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,158
Well I've had a bit more play, and not sure whats going on (maybe I need sleep badly or something, things just dont add up).

this thing
Code:
        for(i = 1, MaxB, 1) {
        	if (AverageLuma(Crop(pre, 0, 0, -w+i, 0)) < thr) {x1 = i + pad} else {break}
        }
I dont think there is a break keyword in GScript, but it dont cause a problem under AVS+.
I think I once asked for Gavino to implement break and Do {} Until (), he was non too keen, he likes the easy life.

Does anybody know if Pinterf impemented break, and if it was documented somewhere ?
[Break seems to be the prob, but it somehow flags the error earlier in script].

I'll try fix it [to work under GScript].

EDIT:
Fixed as below, but still gives pretty much same error.
Code:
        for(i = 1, MaxB, 1) {
        	if (AverageLuma(Crop(pre, 0, 0, -w+i, 0)) < thr) {x1 = i + pad} else { i = MaxB }
        }
EDIT: I'll come back to this tomorrow if Arx1meD aint fixed it.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 13th March 2021 at 06:28.
StainlessS is offline   Reply With Quote
Old 13th March 2021, 08:32   #7  |  Link
Arx1meD
Registered User
 
Arx1meD's Avatar
 
Join Date: Feb 2021
Posts: 103
manono I am using AVS + and I have no errors.
Earlier I used the borders search method written in FillBorders_stabi. In FillBorders_stabi, the maximum borders is 4 px. I increased the search for the borders to 16 px.

Old version of my FillBorders2. See the modified version in post #27

Code:
function FillBorders2(clip c, int "thr", int "pad", int "MaxBorders", bool "debug") {
thr   = Default(thr, 5)
pad   = Default(pad, 0)
MaxB  = Default(MaxBorders, 16)
debug = Default(debug, false)

w = width(c)
h = height(c)

gScriptClip(c, """
pre = ConvertToY8()#.ColorYUV(off_y=-15)

x1 = AverageLuma(crop(pre, 0, 0, -w+1, 0)) < thr ? \
    (AverageLuma(crop(pre, 0, 0, -w+2, 0)) < thr ? \
    (AverageLuma(crop(pre, 0, 0, -w+3, 0)) < thr ? \
    (AverageLuma(crop(pre, 0, 0, -w+4, 0)) < thr ? \
    (AverageLuma(crop(pre, 0, 0, -w+5, 0)) < thr ? \
    (AverageLuma(crop(pre, 0, 0, -w+6, 0)) < thr ? \
    (AverageLuma(crop(pre, 0, 0, -w+7, 0)) < thr ? \
    (AverageLuma(crop(pre, 0, 0, -w+8, 0)) < thr ? \
    (AverageLuma(crop(pre, 0, 0, -w+9, 0)) < thr ? \
    (AverageLuma(crop(pre, 0, 0, -w+10, 0)) < thr ? \
    (AverageLuma(crop(pre, 0, 0, -w+11, 0)) < thr ? \
    (AverageLuma(crop(pre, 0, 0, -w+12, 0)) < thr ? \
    (AverageLuma(crop(pre, 0, 0, -w+13, 0)) < thr ? \
    (AverageLuma(crop(pre, 0, 0, -w+14, 0)) < thr ? \
    (AverageLuma(crop(pre, 0, 0, -w+15, 0)) < thr ? \
    (AverageLuma(crop(pre, 0, 0, -w+16, 0)) < thr ? 16 : 15) : 14) : 13) : 12) : 11) : 10) : 9) : 8) : 7) : 6) : 5) : 4) : 3) : 2) : 1) : 0

x2 = AverageLuma(Crop(pre, w-1, 0, 0, 0)) < thr ? \
    (AverageLuma(Crop(pre, w-2, 0, 0, 0)) < thr ? \
    (AverageLuma(Crop(pre, w-3, 0, 0, 0)) < thr ? \
    (AverageLuma(Crop(pre, w-4, 0, 0, 0)) < thr ? \
    (AverageLuma(Crop(pre, w-5, 0, 0, 0)) < thr ? \
    (AverageLuma(Crop(pre, w-6, 0, 0, 0)) < thr ? \
    (AverageLuma(Crop(pre, w-7, 0, 0, 0)) < thr ? \
    (AverageLuma(Crop(pre, w-8, 0, 0, 0)) < thr ? \
    (AverageLuma(Crop(pre, w-9, 0, 0, 0)) < thr ? \
    (AverageLuma(Crop(pre, w-10, 0, 0, 0)) < thr ? \
    (AverageLuma(Crop(pre, w-11, 0, 0, 0)) < thr ? \
    (AverageLuma(Crop(pre, w-12, 0, 0, 0)) < thr ? \
    (AverageLuma(Crop(pre, w-13, 0, 0, 0)) < thr ? \
    (AverageLuma(Crop(pre, w-14, 0, 0, 0)) < thr ? \
    (AverageLuma(Crop(pre, w-15, 0, 0, 0)) < thr ? \
    (AverageLuma(Crop(pre, w-16, 0, 0, 0)) < thr ? 16 : 15) : 14) : 13) : 12) : 11) : 10) : 9) : 8) : 7) : 6) : 5) : 4) : 3) : 2) : 1) : 0

y1 = AverageLuma(Crop(pre, 0, 0, 0, -h+1)) < thr ? \
    (AverageLuma(Crop(pre, 0, 0, 0, -h+2)) < thr ? \
    (AverageLuma(Crop(pre, 0, 0, 0, -h+3)) < thr ? \
    (AverageLuma(Crop(pre, 0, 0, 0, -h+4)) < thr ? \
    (AverageLuma(Crop(pre, 0, 0, 0, -h+5)) < thr ? \
    (AverageLuma(Crop(pre, 0, 0, 0, -h+6)) < thr ? \
    (AverageLuma(Crop(pre, 0, 0, 0, -h+7)) < thr ? \
    (AverageLuma(Crop(pre, 0, 0, 0, -h+8)) < thr ? \
    (AverageLuma(Crop(pre, 0, 0, 0, -h+9)) < thr ? \
    (AverageLuma(Crop(pre, 0, 0, 0, -h+10)) < thr ? \
    (AverageLuma(Crop(pre, 0, 0, 0, -h+11)) < thr ? \
    (AverageLuma(Crop(pre, 0, 0, 0, -h+12)) < thr ? \
    (AverageLuma(Crop(pre, 0, 0, 0, -h+13)) < thr ? \
    (AverageLuma(Crop(pre, 0, 0, 0, -h+14)) < thr ? \
    (AverageLuma(Crop(pre, 0, 0, 0, -h+15)) < thr ? \
    (AverageLuma(Crop(pre, 0, 0, 0, -h+16)) < thr ? 16 : 15) : 14) : 13) : 12) : 11) : 10) : 9) : 8) : 7) : 6) : 5) : 4) : 3) : 2) : 1) : 0

y2 = AverageLuma(Crop(pre, 0, h-1, 0, 0)) < thr ? \
    (AverageLuma(Crop(pre, 0, h-2, 0, 0)) < thr ? \
    (AverageLuma(Crop(pre, 0, h-3, 0, 0)) < thr ? \
    (AverageLuma(Crop(pre, 0, h-4, 0, 0)) < thr ? \
    (AverageLuma(Crop(pre, 0, h-5, 0, 0)) < thr ? \
    (AverageLuma(Crop(pre, 0, h-6, 0, 0)) < thr ? \
    (AverageLuma(Crop(pre, 0, h-7, 0, 0)) < thr ? \
    (AverageLuma(Crop(pre, 0, h-8, 0, 0)) < thr ? \
    (AverageLuma(Crop(pre, 0, h-9, 0, 0)) < thr ? \
    (AverageLuma(Crop(pre, 0, h-10, 0, 0)) < thr ? \
    (AverageLuma(Crop(pre, 0, h-11, 0, 0)) < thr ? \
    (AverageLuma(Crop(pre, 0, h-12, 0, 0)) < thr ? \
    (AverageLuma(Crop(pre, 0, h-13, 0, 0)) < thr ? \
    (AverageLuma(Crop(pre, 0, h-14, 0, 0)) < thr ? \
    (AverageLuma(Crop(pre, 0, h-15, 0, 0)) < thr ? \
    (AverageLuma(Crop(pre, 0, h-16, 0, 0)) < thr ? 16 : 15) : 14) : 13) : 12) : 11) : 10) : 9) : 8) : 7) : 6) : 5) : 4) : 3) : 2) : 1) : 0

x1 = x1 > 0 ? x1+pad : x1
x2 = x2 > 0 ? x2+pad : x2
y1 = y1 > 0 ? y1+pad : y1
y2 = y2 > 0 ? y2+pad : y2

PreBlur  = 0 #If > 0 then there may be an error 
PostBlur = 0 #Max(x1, x2, y1, y2, 4) #If > 0 then there may be an error 
b_fix    = (x1 + x2 + y1 + y2) > 0
max_fix  = Max(x1, x2, y1, y2)

msk = b_fix && max_fix >= 8 ? pre.mt_lut("0", chroma="-128").LetterBox(y1, y2, x1, x2, color=$ffffff).ConvertToYV12() : \
                              pre.mt_lut("0", chroma="-128")

fixed = b_fix ? max_fix < 8 ? FillBorders(left=x1, top=y1, right=x2, bottom=y2, mode=0, y=3, u=3, v=3) : \
                              InpaintLogo(mask=msk, Radius=Max(x1,x2,y1,y2,5)*1.5, PreBlur=PreBlur, PostBlur=PostBlur) : \
				c

debug == true ? mt_merge(fixed, \
	                     c.mt_lut("0", chroma="-128").ConvertToRGB().LetterBox(y1, y2, x1, x2, color=$ff3333).ConvertToYV12(), \
			             pre.mt_lut("0", chroma="-128").LetterBox(y1, y2, x1, x2, color=$ffffff).ConvertToYV12(), \
						 luma=true)\
			             .Subtitle("Black borders:\n      "+string(y1)+"\n  "+string(x1)+"       "+string(x2)+"\n      "+string(y2), lsp = 10, text_color=$ff3333, font="Courier New", x=MaxB+5, y=MaxB+5) : \
                fixed
""", args="c, thr, pad, MaxB, debug, w, h")
}
Use it with MaxBorders = 16
Stab_Light(zoom = 1.00, mirror = false, MaxBorders=16, FixFalPos = true, FixBorders = true, debug = false)

Last edited by Arx1meD; 14th March 2021 at 07:43. Reason: Changed color_yuv to color in LetterBox
Arx1meD is offline   Reply With Quote
Old 13th March 2021, 08:46   #8  |  Link
manono
Moderator
 
Join Date: Oct 2001
Location: Hawaii
Posts: 7,405
Hi,

And thank you for taking a look. I'm not entirely sure I understand you correctly, but if change the filter settings to:

Stab_Light(zoom = 1.00, mirror = false, MaxBorders=16, FixFalPos = true, FixBorders = true, debug = false)

I still get the same error message. Should this filter be used only with AviSynth+?
manono is offline   Reply With Quote
Old 13th March 2021, 09:05   #9  |  Link
Arx1meD
Registered User
 
Arx1meD's Avatar
 
Join Date: Feb 2021
Posts: 103
Thank you for taking the time to test this script.
Have you replaced the FillBorders2 function?
Can you write what kind of error? As before: [Script Clip], line 8 column 21 ?

Try using Stab3 until I find the error.
Perhaps you are right and my FillBorders2 works correctly only in AVS+.

Last edited by Arx1meD; 13th March 2021 at 09:40.
Arx1meD is offline   Reply With Quote
Old 13th March 2021, 15:20   #10  |  Link
Arx1meD
Registered User
 
Arx1meD's Avatar
 
Join Date: Feb 2021
Posts: 103
manono, I checked my old version of the FillBorders2 function in AviSynth 2.6 and there was no error.
Whatever I do I have failed to fix a bug in gScriptClip ([Script Clip], line 8 column 21). I guess I'm using "for(i = 1, MaxB, 1)..." incorrectly.

Last edited by Arx1meD; 13th March 2021 at 15:31.
Arx1meD is offline   Reply With Quote
Old 13th March 2021, 15:23   #11  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,158
I dont think Manono quite understood that you intended for him to replace posted Fillborders2 with your older one in post #7.
I'll try with both old and new and see if I can find solution more like your inital posted Fillborders2.

EDIT: OK, you just beat me with your post.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 13th March 2021, 15:59   #12  |  Link
Arx1meD
Registered User
 
Arx1meD's Avatar
 
Join Date: Feb 2021
Posts: 103
After many attempts to understand the cause of the error, I am inclined to believe that AviSynth 2.6 does not support "{" "}" inside a function.

Last edited by Arx1meD; 13th March 2021 at 16:17.
Arx1meD is offline   Reply With Quote
Old 13th March 2021, 16:23   #13  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,158
It should with GScript installed. [ so long as used with eg for(){} : If/Else, or While(){} ].

EDIT: If below GG() function is held in eg GG.avsi, and GImport'ed instead of inline with GSCript(""" ... """) would work OK.
Code:
GScript("""
    Function GG() {
        t=0
        for(i=0,10,1) {
            t=t+i
            if(i==5) { 
                i=10 # Break
            }      
        }
        return t
    }
""")

blankclip
x = GG()

Subtitle(String(x))
return last
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 13th March 2021 at 16:29.
StainlessS is offline   Reply With Quote
Old 13th March 2021, 16:35   #14  |  Link
Arx1meD
Registered User
 
Arx1meD's Avatar
 
Join Date: Feb 2021
Posts: 103
Need to use this GScript (Function GG) for AviSynth 2.6 only or for any version?

Last edited by Arx1meD; 13th March 2021 at 16:56.
Arx1meD is offline   Reply With Quote
Old 13th March 2021, 17:18   #15  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,158
Sorry, that was just an example showing that can use '{' '}' using GScript with V2.60 Std.
Example can use as given in prev post, ie surrounded by GScript(""" ... """),
or without the GScript(""" ... """) thing if GImport'ed.
But of course you need GScript dll in plugins.

Avs+ has GScript functionality builtin, does not need the GScript(""" ... """) thing, nor GImport(), nor the plugin dll.

If we get a solution, then avs 2.60 std [with gscript dll loaded] needs to GImport the avsi, and Avs+ needs to Import, or have it in plugins dir.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 13th March 2021 at 17:22.
StainlessS is offline   Reply With Quote
Old 13th March 2021, 17:47   #16  |  Link
Arx1meD
Registered User
 
Arx1meD's Avatar
 
Join Date: Feb 2021
Posts: 103
And there is one more question left. Is it correct to use break?
Arx1meD is offline   Reply With Quote
Old 13th March 2021, 19:44   #17  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,158
Break is not implemented in GScript [despite my asking for it some years ago].
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 13th March 2021, 20:16   #18  |  Link
Arx1meD
Registered User
 
Arx1meD's Avatar
 
Join Date: Feb 2021
Posts: 103
It is strange that AVS+ did not cause an error. Probably break is implemented in AVS+.
StainlessS, do you think it is necessary to replace break with i = MaxB ?

Last edited by Arx1meD; 13th March 2021 at 20:56.
Arx1meD is offline   Reply With Quote
Old 13th March 2021, 20:18   #19  |  Link
manono
Moderator
 
Join Date: Oct 2001
Location: Hawaii
Posts: 7,405
Quote:
Originally Posted by Arx1meD View Post
Have you replaced the FillBorders2 function?
As I mentioned last time, I wasn't sure I understood your earlier post. Your list of required filters in your first post mentions only FillBorders. There's nothing about FillBorders2. Okay, I copied it from your post and added an Import line to the script.

Since the last time I ran an encode using other filters and now have a Lagarith AVI with which to work. The current script:

AVISource("Movie.avi")
Stab_Light(zoom = 1.00, mirror = false, MaxBorders=16, FixFalPos = true, FixBorders = true, debug = false)
Return Last


I opened it in VDub and got a different error message this time:

"_lut: unsupported colorspace, masktools only support planar YUV colorspaces (YV12, YV16, YV
([ScriptClip], line 83)"

The message appears to be cut off after the 'YV'. The AVI is already in YV12.
manono is offline   Reply With Quote
Old 13th March 2021, 20:40   #20  |  Link
Arx1meD
Registered User
 
Arx1meD's Avatar
 
Join Date: Feb 2021
Posts: 103
manono, which version of MaskTools2 are you using?
The problem in mt_lut. In http://avisynth.nl says that mt_lut supports the Y8 color format.

Code:
msk = b_fix && max_fix >= 8 ? pre.mt_lut("0", chroma="-128").LetterBox(y1, y2, x1, x2, color=$ffffff).ConvertToYV12() : \
                              pre.mt_lut("0", chroma="-128") # line 83
mt_lut uses clip:
Code:
pre = ConvertToY8()#.ColorYUV(off_y=-15)
Try updating to the latest version of MaskTools2.

Last edited by Arx1meD; 13th March 2021 at 21:08.
Arx1meD is offline   Reply With Quote
Reply

Tags
deshaker

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 08:42.


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