View difference between Paste ID: 38DuxqUS and XNBAbs7E
SHOW: | | - or go back to the newest paste.
1-
# Advanced Denoising and anime bob v1.24
1+
# Advanced Denoising and anime bob v1.25
2
3
# MotionThresh by mf
4
# Simple scenechange-proof motion threshold
5
# Tile outputs 16x16 clip for speed
6
# Use tile=true for conditional filtering, tile=false for masking
7
 
8-
function MotionThresh(clip input, float thresh, bool "tile") {
8+
function MotionThresh(clip input, float thresh, bool "tile", bool "fast") {
9-
tile = Default(tile, false)
9+
fast = Default(fast, false)
10
tile = Default(tile,  fast)
11-
black = BlankClip(input, width=16, height=16)
11+
12-
white = BlankClip(input, width=16, height=16, color=$FFFFFF)
12+
13
 
14
sislumaonly = !(VersionNumber() < 2.60) ? ssispmt ? input.isy() : input.isy8() : nop()
15
16
input = fast && !sislumaonly ? ssispmt ? input.converttoy() : input.converttoy8() : input
17
black = !fast ? BlankClip(input, width=16, height=16               ) : BlankClip(input, width=16, height=16, Color_yuv=color_black)
18
white = !fast ? BlankClip(input, width=16, height=16, color=$FFFFFF) : BlankClip(input, width=16, height=16, Color_yuv=color_white)
19
cond1 = ConditionalFilter(input, white, black, "YDifferenceFromPrevious()", "greaterthan", String(thresh))
20
cond2 = ConditionalFilter(input, white, black, "YDifferenceToNext()", "greaterthan", String(thresh))
21
Overlay(cond1, cond2, mode="darken")
22
tile ? last : PointResize(input.width, input.height)
23
}
24
25-
function MotionRamp(clip input, int thresh1, int thresh2, int thresh3, int thresh4, int thresh5, int "min", int "max", int "floor", int "ceil", int "radius", bool "tile") {
25+
26
######################################################################
27
# MotionRamp by mf
28
# Average motion soft-thresholding based on 5 thresholds
29
# Dependancies: MotionThresh, BlendMulti
30
 
31-
tile = Default(tile, false)
31+
function MotionRamp(clip input, int thresh1, int thresh2, int thresh3, int thresh4, int thresh5, int "min", int "max", int "floor", int "ceil", int "radius", bool "tile", bool "fast") {
32
min = Default(min, 0)
33
max = Default(max, 255)
34-
Interleave(MotionThresh(thresh3, tile=true), MotionThresh(thresh2, tile=true), MotionThresh(thresh4, tile=true), MotionThresh(thresh1, tile=true), MotionThresh(thresh5, tile=true)).ParameterisedBlend(0.20, 0.20, 0.20, 0.20, 0.20, gamma=1, scaleweights=false).SelectEvery(5,0)
34+
35
ceil  = Default(ceil, 255)
36-
Levels(floor, 1, ceil, min, max)
36+
37-
ColorYUV(levels="TV->PC")
37+
fast = Default(fast, false)
38
tile = Default(tile,  fast)
39
40
ssispmt   = Findstr(VersionString(), "AviSynth+") != 0 && Findstr(VersionString(), "r1576") == 0
41
 
42
sislumaonly = fast ? ssispmt ? input.isy() : input.isy8() : false
43
 
44
fast && !(VersionNumber() < 2.60) && !sislumaonly ? ssispmt ? input.converttoy() : input.converttoy8() : input
45
Interleave(MotionThresh(thresh3, tile=true, fast=fast), MotionThresh(thresh2, tile=true, fast=fast), MotionThresh(thresh4, tile=true, fast=fast), MotionThresh(thresh1, tile=true, fast=fast), MotionThresh(thresh5, tile=true, fast=fast)).ParameterisedBlend(0.20, 0.20, 0.20, 0.20, 0.20, gamma=1, scaleweights=false).SelectEvery(5,0)
46
TemporalSoften(radius,255,0,255,2)
47
fast ? last : Levels(floor, 1, ceil, min, max)
48
fast ? last : ColorYUV(levels="TV->PC")
49
tile ? last : PointResize(input.width, input.height)
50
}
51
52
53
##########
54
function admfilter(clip input, bool "mc", float "f", bool "DarkPreserve", float "rStr", float "amp", bool "lsb", bool "lsb_in", bool "lsb_out", bool "luma_rebuild", bool "u", bool "v", string "pp", string "dfttest_params", string "mcdfttest_params", string "custom_filter", clip "MotionRampadc") {
55
ssispmt   = Findstr(VersionString(), "AviSynth+") != 0 && Findstr(VersionString(), "r1576") == 0
56
d = default (DarkPreserve      , true)
57
mc = default (mc      , true)
58
f = Default(f, 16.0)
59
lsb = default (lsb, ssispmt ? input.BitsPerComponent() > 8 ? false : true : true)
60
lsb_in = default (lsb_in      , false)
61
lsb_out = default (lsb_out      , lsb_in)
62
lsb = lsb_in || lsb_out ? true : lsb
63
luma_rebuild = default (luma_rebuild      , true)
64-
MotionRampadc = defined(MotionRampadc) ? MotionRampadc : last.MotionRamp(5,10,15,20,25,Max=255,Tile=True)
64+
65
v = default (v      , true)
66
dfttest_params = default(dfttest_params, "")
67
mcdfttest_params = default(mcdfttest_params, "")
68
pp = default (pp, "blur(1.53)")
69
70
custom_filter = defined(custom_filter) ? custom_filter : \
71
                                                         mc ? "dfttestmc(pp=Eval(pp),lsb=lsb, Sigma=adSigma/f,rStr=rStr,amp=amp,lsb_in=lsb_in,luma_rebuild=luma_rebuild,u=u,v=v,dfttest_params=dfttest_params" + mcdfttest_params + ")" : \
72
                                                              "dfttest(lsb=lsb, Sigma=adSigma/f, lsb_in=lsb_in,u=u,v=v" + dfttest_params + ")"
73
74
input
75
MotionRampadc = defined(MotionRampadc) ? MotionRampadc : last.MotionRamp(5,10,15,20,25,Max=255,fast=True)
76
lsb_out && !lsb_in ? Dither_convert_8_to_16() : lsb_in && !lsb_out ? Ditherpost(mode=-1, y=1, u=1,v=1) : last
77
return GScriptClip("""
78
                     adSigma = AverageLuma(MotionRampadc)
79
                     (lsb_out && !lsb_in) || (lsb_in && !lsb_out) ? input : last
80
                     adden = Eval(custom_filter)
81
                     d ? DarkPreserve_function(filtered=adden, original=last, u=u ? 3 : 4, v=v ? 3 : 4, lsb=lsb, lsb_in=lsb_in, lsb_out=lsb_out) : adden
82
                     !d && !lsb_out && lsb ? Ditherpost(mode=7, slice=false) : last
83
                     """, args="MotionRampadc, f, d, rStr, amp, lsb_in, lsb_out, lsb, luma_rebuild, u, v,dfttest_params,mcdfttest_params,pp,input,custom_filter")
84
}
85
86
87
#######
88
function DarkPreserve_function(clip "filtered", clip "original", bool "merge16_8", int "u", int "v", bool "lsb", bool "lsb_in", bool "lsb_out") {
89
lsb_in    = default (lsb_in                       , false) #for original
90
F_lsb_in  = lsb_in ? (Height(filtered)) == (Height(original)) : (Height(filtered)) == (Height(original)*2)
91
lsb_out   = default (lsb_out         , F_lsb_in || lsb_in)
92
lsb       = default (lsb ,  lsb_in || lsb_out || F_lsb_in)
93
merge16_8 = default (merge16_8                     , true)
94
u         = default (u                                , 3)
95
v         = default (v                                , u)
96
chroma    = !(u != 3 && v != 3)
97
98
F_lsb_in        ? Assert(lsb,                          "16stacked filtered clip requires: lsb=true")                : nop()
99
lsb_in          ? Assert(lsb,                          "lsb_in  requires: lsb=true")                                : nop()
100
lsb_out         ? Assert(lsb,                          "lsb_out requires: lsb=true")                                : nop()
101
102
dp_lut = lsb_in ? original.Dither_lut16("x 4096 < 65535 x 19200 > 0 65535 x 4096 - 65535 19200 4096 - / * - ? ?",u=1,v=1) : original.mt_lut("x 16 < 255 x 75 > 0 255 x 16 - 255 75 16 - / * - ? ?",u=1,v=1)
103
104
dp_lut = lsb_in && merge16_8 ? dp_lut.Ditherpost(mode=6, slice=false, u=1, v=1) : dp_lut
105
106
dp_merge = lsb ? merge16_8 ? Dither_merge16_8(F_lsb_in ? filtered : filtered.Dither_convert_8_to_16(), lsb_in ? original : original.Dither_convert_8_to_16(), dp_lut, luma=chroma, u=u,v=v) : \
107
                             Dither_merge16(F_lsb_in ? filtered : filtered.Dither_convert_8_to_16(), lsb_in ? original : original.Dither_convert_8_to_16(), dp_lut, luma=chroma, u=u,v=v) : \
108
                             mt_merge(filtered, original, dp_lut, luma=chroma, u=u,v=v)
109
lsb ? lsb_out ? dp_merge : dp_merge.Ditherpost(mode=7, slice=false) : dp_merge
110
}
111
112
113
##########
114
#edge side bleed
115
##########
116
function edgesidebleed(clip input, float "w32", float "w16", float "w8", float "w4", float "w2", int "y", int "u", int "v") {
117
w2 = Default(w2, 0.001)
118
w4 = Default(w4, 0.055)
119
w8 = Default(w8, 0.015)
120
w16 = Default(w16, 0.02)
121
w32 = Default(w32, 0.001)
122
input
123
shift32 = Crop(Width()-32,0,32,0,true).StackHorizontal(Crop(0,0,-32,0,true))
124
w32==0 ? last : raveragew(last,1+w32,shift32,-w32,y=y,u=u,v=v)
125
shift16 = Crop(Width()-16,0,16,0,true).StackHorizontal(Crop(0,0,-16,0,true))
126
w16==0 ? last : raveragew(last,1+w16,shift16,-w16,y=y,u=u,v=v)
127
shift8 = Crop(Width()-8,0,8,0,true).StackHorizontal(Crop(0,0,-8,0,true))
128
w8==0 ? last : raveragew(last,1+w8,shift8,-w8,y=y,u=u,v=v)
129
shift4 = Crop(Width()-4,0,4,0,true).StackHorizontal(Crop(0,0,-4,0,true))
130
w4==0 ? last : raveragew(last,1+w4,shift4,-w4,y=y,u=u,v=v)
131
shift2 = Crop(Width()-2,0,2,0,true).StackHorizontal(Crop(0,0,-2,0,true))
132
w2==0 ? last : raveragew(last,1+w2,shift2,-w2,y=y,u=u,v=v)
133
}
134
135
136
###############
137
# Hqdn3d_2
138
139
function Hqdn3d_2(clip clip, float "ls", float "cs", float "lt", float "ct", int "UV", bool "lsb", bool "lsb_in", bool "i16") {
140
cs        = default (cs              , 3.0)
141
ct        = default (ct              , 4.5)
142
UV        = default (UV               , 3)
143
UV        = !(VersionNumber() < 2.60) ? isY8(clip) ? 1 : UV : UV
144
lsb_in    = default (lsb_in          , false)
145
i16       = default (i16             , false)
146
lsb_out   = default (lsb             , lsb_in)
147
148
i16b      = lsb_out || i16 || lsb_in
149
150
isrgb(clip) ? Assert(!i16b, "no 16bit for RGB, but you can use some trickes for that (see dither doc)") : nop()
151
152
yString = VersionNumber() < 2.60 ? "yv12" : "Y8"
153
154
pclip   = isYUV(clip) && i16b && isYUY2(clip) && !(VersionNumber() < 2.60) ? clip.ConvertToYV16() : clip
155
156
i16clip = isYUV(clip) ? i16b ? lsb_in ? pclip.Bitdepth(from=88, to=16) : i16 ? clip : pclip.Bitdepth(from=8, to=16) : nop() : nop()
157
158
	y = isYUV(clip) ? VersionNumber() < 2.60 ? i16b ? i16clip : clip : i16b ? ConvertToY8(i16clip) : ConvertToY8(clip) : nop()
159
	u = isYUV(clip) && UV != 1 ? VersionNumber() < 2.60 ? i16b ? UToY(i16clip) : UToY(clip) : i16b ? UToY8(i16clip) : UToY8(clip) : nop()
160
	v = isYUV(clip) && UV != 1 ? VersionNumber() < 2.60 ? i16b ? VToY(i16clip) : VToY(clip) : i16b ? VToY8(i16clip) : VToY8(clip) : nop()
161
	y = isYUV(clip) ? VersionNumber() < 2.60 ? isclip(i16clip) ? y.converttoyv12().Hqdn3d16Y(sp=ls, tp=lt) : y.converttoyv12().Hqdn3dY(sp=ls, tp=lt) : isclip(i16clip) ? y.Hqdn3d16Y(sp=ls, tp=lt) : y.Hqdn3dY(sp=ls, tp=lt) : nop()
162
	u = isYUV(clip) ? UV == 3 ? VersionNumber() < 2.60 ? isclip(i16clip) ? u.converttoyv12().Hqdn3d16Y(sp=cs, tp=ct) : u.converttoyv12().Hqdn3dY(sp=cs, tp=ct) : isclip(i16clip) ? u.Hqdn3d16Y(sp=cs, tp=ct) : u.Hqdn3dY(sp=cs, tp=ct) : u : nop()
163
	v = isYUV(clip) ? UV == 3 ? VersionNumber() < 2.60 ? isclip(i16clip) ? v.converttoyv12().Hqdn3d16Y(sp=cs, tp=ct) : v.converttoyv12().Hqdn3dY(sp=cs, tp=ct) : isclip(i16clip) ? v.Hqdn3d16Y(sp=cs, tp=ct) : v.Hqdn3dY(sp=cs, tp=ct) : v : nop()
164
	isYUV(clip) ? (VersionNumber() < 2.60) && isYUY2(clip) ? UV == 1 ? y : YToUV(u.converttoyuy2(),v.converttoyuy2(),y.converttoyuy2()) : UV == 1 ? y : YToUV(u,v,y) : nop()
165
        isYUV(clip) ? i16b && !i16 && lsb_out ? Bitdepth(from=16, to=88) : last : last
166
	isYUV(clip) ? !i16b || lsb_out || i16 ? last : Bitdepth(from=16, to=8) : last
167
	isYUY2(clip) ? VersionNumber() < 2.60 ? last : converttoyuy2() : last
168
169
	A = isrgb32(clip) ? clip.ShowAlpha(yString) : nop()
170
	r = isrgb(clip) ? clip.ShowRed(yString) : nop()
171
	g = isrgb(clip) ? clip.ShowGreen(yString) : nop()
172
	b = isrgb(clip) ? clip.ShowBlue(yString) : nop()
173
	A = isrgb32(clip) ? A.Hqdn3dY(sp=ls, tp=lt) : nop()
174
	r = isrgb(clip) ? r.Hqdn3dY(sp=ls, tp=lt) : nop()
175
	g = isrgb(clip) ? g.Hqdn3dY(sp=ls, tp=lt) : nop()
176
	b = isrgb(clip) ? b.Hqdn3dY(sp=ls, tp=lt) : nop()
177
	isYUV(clip) ? last : isrgb32(clip) ? MergeARGB(A,r,g,b) : MergeRGB(r,g,b,"RGB24")
178
}
179
180
181
###############
182
#motion adaptive by A.SONY
183
184
function smam(clip input, clip "prefilter", val "filter", int "pel", int "blksize", clip "motionmask", float "Str", float "Amp", bool "TV_range", bool "qtgmc_lsb", int "tr2", int "usedaa3mod") {
185
186
ssispmt   = Findstr(VersionString(), "AviSynth+") != 0 && Findstr(VersionString(), "r1576") == 0
187
qtgmc_lsb = default(qtgmc_lsb, ssispmt ? input.BitsPerComponent() > 8 ? false : true : true)
188
189
defined(filter) ? Assert((Isclip(filter) || IsString(filter)),        "'filter' only accepts clip or string") : nop()
190
191
Str             = default (Str, 1.5)
192
exfilclp        = isclip(filter)
193
sisbob          = round(framerate(input))==60 || framerate(input)==50
194
tr2             = default (tr2, sisbob ? 3 : 1)
195
usedaa3mod      = default (usedaa3mod, exfilclp ? 0 : sisbob ? 1 : 2)
196
197
infiltr = usedaa3mod == 1 ? input.daa3mod() : input
198
filclip = defined(filter) ? exfilclp ? filter : eval("infiltr." + filter) : infiltr.QTGMC(InputType=1, tr0=0, tr1=sisbob ? undefined : 1, tr2=tr2, lsb=qtgmc_lsb, rep1=sisbob ? undefined : 11, rep2=sisbob ? undefined : 11, Sharpness=0.0, TV_range=TV_range, Str=Str, Amp=Amp)
199
filclip = usedaa3mod == 2 ? filclip.daa3mod() : filclip
200
201
momask  = !defined(motionmask) ? input.smam_mask(prefilter,pel,blksize) : motionmask #if you deal with YUY2 then it should be Planar YUY2 in avs2.5 and yv16 in avs2.6
202
isyuy2(input) && VersionNumber() < 2.60 ? mt_merge(input.Interleaved2Planar(),filclip.Interleaved2Planar(),momask,u=3,v=3).Planar2Interleaved() : isyuy2(input) ? mt_merge(input.converttoyv16(),filclip.converttoyv16(),momask,u=3,v=3).converttoyuy2() : mt_merge(input,filclip,momask,u=3,v=3)
203
}
204
205
206
###############
207
#smam_mask
208
# if input is YUY2 the output will be Planar YUY2 in avs 2.5 and yv16 in avs 2.6
209
210
function smam_mask(clip input, clip "prefilter", int "pel", int "blksize", bool "chroma", int "dct") {
211
    ox = input.width()
212
    oy = input.height()
213
    HD = (ox > 1099 || oy > 599)
214
    sisbob  = round(framerate(input))==60 || framerate(input)==50
215
    pel = default( pel,     HD ? 1 : 2 )
216
    dct = default( dct, sisbob ? 0 : 2 )
217
    blksize = default(blksize,HD ? sisbob ? 8 : 16 : sisbob ? 4 : 8)
218
preclip= defined(prefilter) ? prefilter : (VersionNumber() < 2.60) && isyv12(input) ? input.HQdn3d().FFT3DFilter() : input.HQdn3d_2().FFT3DFilter()
219
sup    = preclip.MSuper(pel=pel,sharp=1)
220
fv1    = sup.MAnalyse(isb=false,delta=1,DCT=dct,Truemotion=false,blksize=blksize,chroma=chroma)
221
fv2    = sup.MAnalyse(isb=true,delta=1,DCT=dct,Truemotion=true,blksize=blksize,chroma=chroma)
222
223
momask1 = input.MMask(fv1, kind = 1, ml=2)
224
momask2 = input.MMask(fv2, kind = 1, ml=3)
225
momask1 =isyuy2(input) && VersionNumber() < 2.60 ? momask1.Interleaved2Planar() : isyuy2(input) ? momask1.converttoyv16() : momask1
226
momask2 =isyuy2(input) && VersionNumber() < 2.60 ? momask2.Interleaved2Planar() : isyuy2(input) ? momask2.converttoyv16() : momask2
227
mt_average(momask1,momask2,u=3,v=3)
228
}
229
230
231
##############
232
# sanimebob by A.SONY
233
234
function sanimebob(clip i, val "useqtgmc", val "bobpresmooth", float "Str", float "Amp", bool "TV_range", bool "qtgmc_lsb", bool "usedaa3mod", bool "usesmam", int "tr2") {
235
236
ssispmt   = Findstr(VersionString(), "AviSynth+") != 0 && Findstr(VersionString(), "r1576") == 0
237
qtgmc_lsb = default(qtgmc_lsb, ssispmt ? i.BitsPerComponent() > 8 ? false : true : true)
238
239
useq         = default (useqtgmc,                                                                                                           0)
240
Stringuseq   = IsString(useq                                                                                                                 )
241
bobpresmbool = default (isbool(bobpresmooth) ? bobpresmooth : !Stringuseq ? (useq==8 || defined(bobpresmooth)) : defined(bobpresmooth), false)
242
Str          = default (Str,                                                                                                              1.5)
243
tr2          = default (tr2,                                                                                !Stringuseq ? useq==8 ? 3 : 1 : 1)
244
usedaa3mod   = default (usedaa3mod,                                            !Stringuseq ? useq==4 || useq==5 || useq==7 || useq==9 : false)
245
usesmam      = default (usesmam,                                                       !Stringuseq ? !(useq==0 || useq==1 || useq==8) : false)
246
247
Assert(Isint(useq) || Stringuseq, "'useqtgmc' only accepts int or string")
248
249
prefiltered_i   = defined(bobpresmooth) ? isclip(bobpresmooth) ? bobpresmooth : IsString(bobpresmooth) ? Eval("i." + bobpresmooth) : undefined() : undefined()
250
251
iforbob   = bobpresmbool ? defined(prefiltered_i) ? prefiltered_i : i.QTGMC_bob(0,0.5).reduceflicker(strength=2).interlaced60or50(BFF=!(GetParity(i))) : i
252
iforbob   = bobpresmbool && !defined(prefiltered_i) ? isyuy2(i) ? iforbob.SeparateFields().Interleaved2Planar().Repair(i.SeparateFields().Interleaved2Planar(),Planar=true).Planar2Interleaved().weave() : iforbob.SeparateFields().Repair(i.SeparateFields()).weave() : iforbob
253
254
pyi       = i.pointresize(width(i),height(i)+8,0,-4,width(i),height(i)+8.0001)
255
pei       = i.eedi3(-2,sclip=iforbob.nnedi3(-2)).pointresize(width(i),height(i)+8,0,-4,width(i),height(i)+8.0001)
256
257
ymodclip  = VersionNumber() < 2.60 ? pyi.yadifmod(mode=3, edeint=pei).crop(0,4,-0,-4) : isyuy2(i) ? pyi.converttoyv16().yadifmod2(mode=3, edeint=pei.converttoyv16()).crop(0,4,-0,-4) : pyi.yadifmod2(mode=3, edeint=pei).crop(0,4,-0,-4)
258
yadifclip = isyuy2(i) ? VersionNumber() < 2.60 ? ymodclip.Interleaved2Planar().Repair(i.TDeint(1,emask=iforbob.tmm(1)).Interleaved2Planar(),Planar=true).Planar2Interleaved() : \
259
                                                 ymodclip.Repair(i.TDeint(1,emask=iforbob.tmm(1)).converttoyv16()).converttoyuy2() : \
260
                        ymodclip.Repair(i.TDeint(1,emask=iforbob.tmm(1)))
261
262
# for custom qtgmc, don't forget to put the input clip like this:- iforbob.QTGMC(... or yadifclip.QTGMC(... or i.QTGMC(...
263
QTGMCclip = isstring(useq) ? eval(useq) : \
264
                             useq==0 ? yadifclip : \
265
       useq==1 || useq==2 || useq==4 ? iforbob.QTGMC(SourceMatch=3, Lossless=2, EdiExt=yadifclip, tr0=1, tr1=1, tr2=tr2, lsb=qtgmc_lsb, rep0=11, rep1=11, rep2=11, Sharpness=0.1, TV_range=TV_range, Str=Str, Amp=Amp) : \
266
                  useq==3 || useq==5 ? yadifclip.QTGMC(InputType=1, tr0=1, tr1=1, tr2=tr2, lsb=qtgmc_lsb, rep0=11, rep1=11, rep2=11, Sharpness=0.1, TV_range=TV_range, Str=Str, Amp=Amp) : \
267
                  useq==6 || useq==7 ? yadifclip.QTGMC(InputType=1, tr0=0, lsb=qtgmc_lsb, Sharpness=usedaa3mod ? 0.0 : 0.1, TV_range=TV_range, Str=Str, Amp=Amp) : \
268
                                       i.QTGMC(SourceMatch=3, Lossless=2, EdiExt=yadifclip, useEdiExt=!(useq==9), tr0=useq==9 ? -1 : undefined(), rep0=useq==9 ? undefined() : 11, tr2=tr2, lsb=qtgmc_lsb, Sharpness=0.0, TV_range=TV_range, Str=Str, Amp=Amp)
269
270
daa3mclip = usedaa3mod ? QTGMCclip.daa3mod() : QTGMCclip
271
272
!usesmam ? daa3mclip : \
273
           yadifclip.smam(filter=QTGMCclip)
274
}