def do_filter(): """Vapoursynth filtering""" def _nneedi3_clamp(clip: vs.VideoNode, strength: int = 1): bits = clip.format.bits_per_sample - 8 thr = strength * (1 >> bits) luma = get_y(clip) strong = TAAmbk(luma, aatype='Eedi3', alpha=0.4, beta=0.4) weak = TAAmbk(luma, aatype='Nnedi3') expr = 'x z - y z - * 0 < y x y {0} + min y {0} - max ?'.format(thr) clip_aa = core.std.Expr([strong, weak, luma], expr) return core.std.ShufflePlanes([clip_aa, clip], [0, 1, 2], vs.YUV) src = SRC_CUT interpolate = core.resize.Bicubic(src, src_left=3) f_1 = 1006 src = src[:EDSTART + f_1] + interpolate[EDSTART + f_1] + src[EDSTART + f_1:-1] src = depth(src, 16) blur = core.bilateral.Gaussian(src, [0.45, 0]) den = CoolDegrain(blur, tr=1, thsad=60, blksize=8, overlap=4, plane=4) dering = core.std.MaskedMerge(den, hvf.YAHR(den, 2, 32), muvf.AnimeMask(den, 0.2), 0) aa_a = core.std.MaskedMerge(dering, _nneedi3_clamp(dering), TAAmbk(dering, mtype=2, showmask=1)) aa_b = TAAmbk(src, aatype='Nnedi3', mtype=1, nns=4, qual=2, nsize=6) aa = lvf.rfs(aa_a, aa_b, [(OPSTART, OPEND), (EDSTART, EDEND)]) preden = core.knlm.KNLMeansCL(aa, a=2, h=2, d=0, device_type='gpu', channels='Y') diff = core.std.MakeDiff(aa, preden, 0) db_m = lvf.denoise.detail_mask(aa.std.Median(), brz_a=3000, brz_b=1500) db_a = dbs.f3kpf(aa, 17) db_b = core.placebo.Deband(preden, radius=17, threshold=5.5, iterations=1, grain=4, planes=1 | 2 | 4) db_b = core.std.MergeDiff(db_b, diff, 0) db = lvf.rfs(db_a, db_b, [(9729, 9845), (13652, 14048)]) db = core.std.MaskedMerge(db, aa, db_m) grain = mdf.adptvgrnMod_mod(db, 0.2, size=1.25, sharp=60, luma_scaling=8) final = depth(grain, 10) return final, src
def do_filter(): """Vapoursynth filtering""" def _nneedi3_clamp(clip: vs.VideoNode, strength: int = 1): bits = clip.format.bits_per_sample - 8 thr = strength * (1 >> bits) luma = get_y(clip) strong = TAAmbk(luma, aatype='Eedi3', alpha=0.4, beta=0.4) weak = TAAmbk(luma, aatype='Nnedi3') expr = 'x z - y z - * 0 < y x y {0} + min y {0} - max ?'.format(thr) clip_aa = core.std.Expr([strong, weak, luma], expr) return core.std.ShufflePlanes([clip_aa, clip], [0, 1, 2], vs.YUV) src = SRC_CUT src += src[-1]*2 interpolate = core.resize.Bicubic(src, src_left=3) f_1 = 1006 src = src[:EDSTART+f_1] + interpolate[EDSTART+f_1] + src[EDSTART+f_1:-1] src = depth(src, 16) blur = core.bilateral.Gaussian(src, [0.45, 0]) den = CoolDegrain(blur, tr=1, thsad=60, blksize=8, overlap=4, plane=4) dering = core.std.MaskedMerge(den, hvf.YAHR(den, 2, 32), muvf.AnimeMask(den, 0.2), 0) aa_a = core.std.MaskedMerge(dering, _nneedi3_clamp(dering), TAAmbk(dering, mtype=2, showmask=1)) aa_b = TAAmbk(src, aatype='Nnedi3', mtype=1, nns=4, qual=2, nsize=6) aa_c = TAAmbk(dering, aatype='Eedi3SangNom', mtype=2, cycle=2) aa_d = TAAmbk(dering, aatype='Eedi3', cycle=2) aa = lvf.rfs(aa_a, aa_b, [(OPSTART, OPEND), (EDSTART, EDEND)]) aa = lvf.rfs(aa, aa_c, [(6448, 6546)]) aa = lvf.rfs(aa, aa_d, [(5467, 5550)]) db_m = lvf.denoise.detail_mask(aa.std.Median(), brz_a=3000, brz_b=1500) db = dbs.f3kpf(aa, 17) db = core.std.MaskedMerge(db, aa, db_m) grain = mdf.adptvgrnMod_mod(db, 0.2, size=1.25, sharp=60, luma_scaling=8) final = depth(grain, 10) return final, src
def do_filter(): """Vapoursynth filtering""" def _nneedi3_clamp(clip: vs.VideoNode, strength: int = 1): bits = clip.format.bits_per_sample - 8 thr = strength * (1 >> bits) luma = get_y(clip) strong = TAAmbk(luma, aatype='Eedi3', alpha=0.4, beta=0.4) weak = TAAmbk(luma, aatype='Nnedi3') expr = 'x z - y z - * 0 < y x y {0} + min y {0} - max ?'.format(thr) clip_aa = core.std.Expr([strong, weak, luma], expr) return core.std.ShufflePlanes([clip_aa, clip], [0, 1, 2], vs.YUV) def _hell_deband(clip: vs.VideoNode): clip = depth(clip, 32) preden = vrf.knlmcl(clip, 2, 2, bits=32) diff = core.std.MakeDiff(clip, preden) deband = core.placebo.Deband(preden, radius=20, threshold=28, iterations=3, grain=8, planes=1|2|4) merge = core.std.MergeDiff(deband, diff) return depth(merge, 16) def _hell_mask(mask: vs.VideoNode, pand: int): mask = lvf.scale.iterate(mask, core.std.Median, 2) mask = hvf.mt_expand_multi(mask, 'ellipse', 0, sw=pand, sh=pand) mask = hvf.mt_inpand_multi(mask, 'ellipse', 0, sw=pand - int(pand/2), sh=pand - int(pand/2)) mask = core.std.Expr(mask, 'x 25000 < 0 x 6 * ?') return mask src = SRC_CUT interpolate = core.resize.Bicubic(src, src_left=3) f_1, f_2 = 1006, 2006 src = src[:EDSTART+f_1] + interpolate[EDSTART+f_1] + src[EDSTART+f_1:EDSTART+f_2] \ + interpolate[EDSTART+f_2] + src[EDSTART+f_2:-2] # Fix bandings in motion src = core.std.FreezeFrames(src, 29782, 29786, 29782) src = core.std.FreezeFrames(src, 29787, 29788, 29787) src = core.std.FreezeFrames(src, 29789, 29791, 29791) src = depth(src, 16) blur = core.bilateral.Gaussian(src, [0.45, 0]) den = CoolDegrain(blur, tr=1, thsad=60, blksize=8, overlap=4, plane=4) dering = core.std.MaskedMerge(den, hvf.YAHR(den, 2, 32), muvf.AnimeMask(den, 0.2), 0) aa_a = core.std.MaskedMerge(dering, _nneedi3_clamp(dering), TAAmbk(dering, mtype=2, showmask=1)) aa_b = TAAmbk(src, aatype='Nnedi3', mtype=1, nns=4, qual=2, nsize=6) aa = lvf.rfs(aa_a, aa_b, [(OPSTART, OPEND), (EDSTART, EDEND)]) db_m = lvf.denoise.detail_mask(aa.std.Median(), brz_a=3000, brz_b=1500) db_a = dbs.f3kpf(aa, 17) db_b = core.std.MaskedMerge(_hell_deband(aa), aa, _hell_mask(db_m, 60)) db_c = core.placebo.Deband(aa, radius=18, threshold=5, iterations=1, grain=6, planes=1|2|4) db = lvf.rfs(db_a, db_b, [(7535, 7894), (8579, 8947), (9602, 9769)]) db = lvf.rfs(db, db_c, [(29782, 29791)]) db = core.std.MaskedMerge(db, aa, db_m) grain = mdf.adptvgrnMod_mod(db, 0.2, size=1.25, sharp=60, luma_scaling=8) final = depth(grain, 10) return final, src