Code:
#Import("M:\temp2\source script2 Dr Paulo Pirej.avs")
# Plugins: - RemoveGrain
# - MaskTools2
# - Depan + DepanEstimate
# - MVTools2
SetMemoryMax(512)
SetMTMode(3)
LoadPlugin("M:\Temp2\RemoveGrain.dll")
LoadPlugin("M:\Temp2\MaskTools2-25.dll")
LoadPlugin("M:\Temp2\Depan.dll")
LoadPlugin("M:\Temp2\DepanEstimate.dll")
LoadPlugin("M:\Temp2\MVTools2.dll")
LoadPlugin("M:\Temp2\LSMASHSource.dll")
#LoadPlugin("M:\Temp2\RgTools.dll")
#mpeg2source("M:\Marcelo 27.5.20\1\01\01-1.d2v")
#mpeg2source("M:\Marcelo 999255703 - Fazer\01 ok 19m.d2v")
#DirectShowSource("M:\Flavio Itapema 4.11.20 Fazer\02 FI 4capt PanLG.mp4", fps = 25, ConvertFPS = True )
a = LSmashAudioSource("M:\Flavio Itapema 4.11.20 Fazer\02 FI 4capt PanLG.mp4")
v = LSmashVideoSource("M:\Flavio Itapema 4.11.20 Fazer\02 FI 4capt PanLG.mp4")
AudioDub(v,a)
#DirectShowSource("M:\Luis Tonini 14.1.20 - Fazer\01 V14ES10 e.mp4")
#DirectShowSource("E:\Tereza Soares 13.8.20 - Fazer\01 TS 8capt V17JVCES10.mp4", fps = 25, ConvertFPS = True ) # para AVI encapsulado AVI Xvid da Avermidia ou MP4 da Aple
#DirectShowSource("M:\Neogrid 5-10-17\090 4capt V13SVSDV.avi", fps = 25, ConvertFPS = True ) # para AVI encapsulado AVI Xvid da Avermidia
#AVISource("E:\Cleiton\Super 8mm\03\03 ok.avi")
#AVISource("E:\Luiz Itapema 23.9.20 - Fazer\18 LI SD8.avi", audio=true)
#AVISource("E:\Luiz Itapema 23.9.20 - Fazer\18 LI SD8.avi") # DV AVI
#AVISource("M:\Pedro 31-7-18\25 8capt V15ES10SDV.avi", audio=true)
SetMTMode(2)
#ConvertToYV12()
#ConvertToyv411()
#Crop(0,20,-0,-30,true)
#bob(0,0.5)
AssumeTFF()
SeparateFields()
a=last
clense(reduceflicker=false).merge(last,0.5).clense(reduceflicker=false)
mot=removegrain(11,0).removegrain(20,0).DepanEstimate(range=2)
take2=a.depaninterleave(mot,prev=2,next=2,subpixel=2)
clean1=take2.TMedian2().selectevery(5,2)
sup1 = clean1.minblur(1).removegrain(11,0).removegrain(11,0)
\ .mt_lutxy(clean1,"x 1 + y < x 2 + x 1 - y > x 2 - y ? ?",U=2,V=2)
\ .msuper(pel=2,sharp=0)
sup2 = a.msuper(pel=2,levels=1,sharp=2)
#bv23=sup1.manalyse(isb=true, truemotion=false,global=true,delta=3,blksize=16,overlap=8,search=5,searchparam=4,DCT=5)
bv22=sup1.manalyse(isb=true, truemotion=false,global=true,delta=2,blksize=16,overlap=8,search=5,searchparam=4,DCT=5)
bv21=sup1.manalyse(isb=true, truemotion=false,global=true,delta=1,blksize=16,overlap=8,search=5,searchparam=4,DCT=5)
fv21=sup1.manalyse(isb=false,truemotion=false,global=true,delta=1,blksize=16,overlap=8,search=5,searchparam=4,DCT=5)
fv22=sup1.manalyse(isb=false,truemotion=false,global=true,delta=2,blksize=16,overlap=8,search=5,searchparam=4,DCT=5)
#fv23=sup1.manalyse(isb=false,truemotion=false,global=true,delta=3,blksize=16,overlap=8,search=5,searchparam=4,DCT=5)
#a.mdegrain3(sup2,bv21,fv21,bv22,fv22,bv23,fv23,thSAD=499) # << this is the "2-fold" variant
interleave(a.mcompensate(sup2,fv22),a.mcompensate(sup2,fv21),a,a.mcompensate(sup2,bv21),a.mcompensate(sup2,bv22))
TMedian2().selectevery(5,2)
sup3 = last.msuper(pel=2,sharp=2)
bv33=sup3.manalyse(isb=true, truemotion=false,global=true,delta=3,blksize=8,overlap=4,search=5,searchparam=4,DCT=5)
bv32=sup3.manalyse(isb=true, truemotion=false,global=true,delta=2,blksize=8,overlap=4,search=5,searchparam=4,DCT=5)
bv31=sup3.manalyse(isb=true, truemotion=false,global=true,delta=1,blksize=8,overlap=4,search=5,searchparam=4,DCT=5)
fv31=sup3.manalyse(isb=false,truemotion=false,global=true,delta=1,blksize=8,overlap=4,search=5,searchparam=4,DCT=5)
fv32=sup3.manalyse(isb=false,truemotion=false,global=true,delta=2,blksize=8,overlap=4,search=5,searchparam=4,DCT=5)
fv33=sup3.manalyse(isb=false,truemotion=false,global=true,delta=3,blksize=8,overlap=4,search=5,searchparam=4,DCT=5)
last.mdegrain3(sup3,bv31,fv31,bv32,fv32,bv33,fv33,thSAD=499) # valor Original thSAD=499
LSFMod(strength=60)
Interleave()
Weave()
#stackvertical(a,last) # Alterado por mim.
return(last)
#--------------------------------------------------------------
# Helper functions
function MinBlur(clip clp, int r, int "uv")
{
uv = default(uv,3)
uv2 = (uv==2) ? 1 : uv
rg4 = (uv==3) ? 4 : -1
rg11 = (uv==3) ? 11 : -1
rg20 = (uv==3) ? 20 : -1
medf = (uv==3) ? 1 : -200
RG11D = (r==0) ? mt_makediff(clp,clp.sbr(),U=uv2,V=uv2)
\ : (r==1) ? mt_makediff(clp,clp.removegrain(11,rg11),U=uv2,V=uv2)
\ : (r==2) ? mt_makediff(clp,clp.removegrain(11,rg11).removegrain(20,rg20),U=uv2,V=uv2)
\ : mt_makediff(clp,clp.removegrain(11,rg11).removegrain(20,rg20).removegrain(20,rg20),U=uv2,V=uv2)
RG4D = (r<=1) ? mt_makediff(clp,clp.removegrain(4,rg4),U=uv2,V=uv2)
\ : (r==2) ? mt_makediff(clp,clp.medianblur(2,2*medf,2*medf),U=uv2,V=uv2)
\ : mt_makediff(clp,clp.medianblur(3,3*medf,3*medf),U=uv2,V=uv2)
DD = mt_lutxy(RG11D,RG4D,"x 128 - y 128 - * 0 < 128 x 128 - abs y 128 - abs < x y ? ?",U=uv2,V=uv2)
clp.mt_makediff(DD,U=uv,V=uv)
return(last)
}
# median of 5 clips from Helpers.avs by G-force
Function Median2(clip "input_1", clip "input_2", clip "input_3", clip "input_4", clip "input_5", string "chroma")
{
chroma = default(chroma,"process") #default is "process". Alternates: "copy first" or "copy second"
#MEDIAN(i1,i3,i5)
Interleave(input_1,input_3,input_5)
chroma == "process" ? Clense(reduceflicker=false) : Clense(reduceflicker=false,grey=true)
m1 = selectevery(3,1)
#MAX(MIN(i1,i3,i5),i2)
m2 = input_1.MT_Logic(input_3,"min",chroma=chroma).MT_Logic(input_5,"min",chroma=chroma).MT_Logic(input_2,"max",chroma=chroma)
#MIN(MAX(i1,i3,i5),i4)
m3 = input_1.MT_Logic(input_3,"max",chroma=chroma).MT_Logic(input_5,"max",chroma=chroma).MT_Logic(input_4,"min",chroma=chroma)
Interleave(m1,m2,m3)
chroma == "process" ? Clense(reduceflicker=false) : Clense(reduceflicker=false,grey=true)
selectevery(3,1)
chroma == "copy first" ? last.MergeChroma(input_1) : chroma == "copy second" ? last.MergeChroma(input_2) : last
Return(last)
}
function TMedian2(clip c) {
Median2( c.selectevery(1,-2), c.selectevery(1,-1), c, c.selectevery(1,1), c.selectevery(1,2) ) }