def main(self) -> vs.VideoNode: """Vapoursynth filtering""" src = JPBD.clip_cut src = depth(src, 16) src_cru = WEB_CRU.clip_cut src_aod = WEB_AOD.clip_cut # Dehardsubbing using .ass file masksub = Mask.hardsub_mask(src_aod.std.BlankClip(), SUB, FONTDIR) dehardsub = core.std.MaskedMerge(src_aod, src_cru, masksub) src_web = dehardsub # AoD is poorly rescaled src_y, src_cru_y, src_web_y = map(get_y, [src, src_cru, src_web]) thr = 10 src_web_y = core.std.Expr([src_web_y, src_cru_y], f'x y - abs {thr} < x y * sqrt y ?') src_web_y = depth(src_web_y, 16) ringrid = core.rgvs.Repair(src_web_y, src_web_y.std.Convolution([1] * 9), 11) ringrid = core.std.Expr([ringrid, src_web_y], 'x y min') # Remove ringing with AoD+CR ring_mask = Mask.ringing_mask(src_y) bdweb = core.std.MaskedMerge(src_y, ringrid, ring_mask) bdweb = lvf.rfs(bdweb, src_web_y, [(64, 1413), (32034, 33195), (33465, 33881), (34174, 34524)]) out = vdf.misc.merge_chroma(bdweb, src) # ranges_frames = [ # (64, 131), (215, 292), (339, 410), (444, 515), (566, 657), # (695, 786), (903, 971), (977, 1045), (1058, 1153), (1278, 1335), # (1355, 1413) # ] # cm = partial(vdf.mask.region_mask, clip=out.std.BlankClip(format=vs.GRAY16, color=65535)) # credit_mask = [ # cm() # ] # Restore BD changes dering_src = hvf.EdgeCleaner(src, 20, hot=True) diff_mask = Mask.diff_mask((src, src_cru), brz=4750.0) bdchanges = out bdchanges = lvf.rfs(bdchanges, dering_src, [(882, 902), (5596, 5701), (9909, 10064), (11804, 11864)]) bdchanges = lvf.rfs(bdchanges, core.std.MaskedMerge(out, dering_src, diff_mask), [(2534, 2682), (2840, 2887), (3188, 3271), (3818, 3859), (3986, 4087), (4499, 4618), (5009, 5088), (14736, 14801), (15744, 15872), (17106, 17135), (17913, 18143), (24247, 24438), (33196, 33329), (34021, 34173)]) # return bdchanges, diff_mask out = bdchanges ref = Denoise.ref_denoise(get_y(out), tr=1) denoise = Denoise.hybrid_denoise(depth(out, 32), knlm_h=0.15, sigma=1, knlm_args=dict(d=1, a=3, s=3), bm3d_args=dict(ref=depth(ref, 32))) denoise = depth(denoise, 16) out = denoise pre = get_y(out) # Remove haloing dehalo = gf.MaskedDHA(pre, rx=1.4, ry=1.4, darkstr=0.1, brightstr=1.0, maskpull=40, maskpush=255) bila = core.bilateral.Bilateral(dehalo, sigmaS=1, sigmaR=0.08) dehalorp = core.rgvs.Repair(dehalo, bila, 13) dehalo = core.std.MaskedMerge(dehalo, dehalorp, ring_mask.std.Maximum(), 0) dehalo = core.std.Expr([dehalo, pre], 'x y min') out = dehalo # Antialiasing sraaaaaaaaaa lineart = vdf.mask.ExPrewitt().get_mask(out, 4000, 7500).std.Convolution([1] * 25) aaa = AA().upscaled_sraaaaaaaaaa(out, height=1620) out = aaa unwarp = self.line_darkening(out, 0.075).warp.AWarpSharp2(depth=-1) out = unwarp motion = hvf.SMDegrain(out, tr=3, thSADC=600, RefineMotion=True) masked = core.std.MaskedMerge(out, motion, lineart) out = masked mergechroma = vdf.misc.merge_chroma(out, denoise) out = mergechroma db_mask = Mask.deband_mask(out, (4000, 4000, 4000), (2000, 2000, 2000)) deband_1 = vdf.deband.dumb3kdb(out, 17, [36, 48]) deband_2 = vdf.deband.dumb3kdb(out, 17, 30, sample_mode=4, use_neo=True) deband_d = vdf.deband.dumb3kdb(out, 17, 65) th_lo, th_hi = 22 << 8, 28 << 8 strength = f'{th_hi} x - {th_hi} {th_lo} - /' deband = core.std.Expr( [out.std.Convolution([1] * 9), deband_1, deband_2], [ f'x {th_lo} > x {th_hi} < and z ' + strength + ' * y 1 ' + strength + f' - * + x {th_lo} <= z y ? ?', 'x y * sqrt x z * sqrt * y * z * 0.25 pow' ]) deband = lvf.rfs(deband, deband_d, [(3920, 3985)]) deband = core.std.MaskedMerge(deband, out, db_mask) out = deband ref = get_y(out).std.PlaneStats() adgmask_a = ref.adg.Mask(25) adgmask_b = ref.adg.Mask(10) stgrain_a = core.grain.Add(out, 0.1, 0, seed=333, constant=True) stgrain_a = core.std.MaskedMerge(out, stgrain_a, adgmask_b.std.Invert()) stgrain_b = sizedgrn(out, 0.2, 0.1, 1.15, sharp=80, static=True, fade_edges=False, protect_neutral=False, seed=333) stgrain_b = core.std.MaskedMerge(out, stgrain_b, adgmask_b) stgrain_b = core.std.MaskedMerge(out, stgrain_b, adgmask_a.std.Invert()) stgrain = core.std.MergeDiff(stgrain_b, out.std.MakeDiff(stgrain_a)) dygrain = sizedgrn(out, 0.3, 0.1, 1.25, sharp=80, static=False, fade_edges=False, protect_neutral=False, seed=333) dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a) grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain)) out = grain if int(NUM) != 12: while out.num_frames < 34646: out += out[-1] return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 2])
def main(self) -> vs.VideoNode: """Vapoursynth filtering""" src = JPBD.clip_cut src = depth(src, 16) src_cru = WEB_CRU.clip_cut src_aod = WEB_AOD.clip_cut # Dehardsubbing using .ass file masksub = Mask.hardsub_mask(src_aod.std.BlankClip(), SUB, FONTDIR) dehardsub = core.std.MaskedMerge(src_aod, src_cru, masksub) src_web = dehardsub # AoD is poorly rescaled src_y, src_cru_y, src_web_y = map(get_y, [src, src_cru, src_web]) thr = 10 src_web_y = core.std.Expr([src_web_y, src_cru_y], f'x y - abs {thr} < x y * sqrt y ?') src_web_y = depth(src_web_y, 16) ringrid = core.rgvs.Repair(src_web_y, src_web_y.std.Convolution([1]*9), 11) ringrid = core.std.Expr([ringrid, src_web_y], 'x y min') # Remove ringing with AoD+CR ring_mask = Mask.ringing_mask(src_y) bdweb = core.std.MaskedMerge(src_y, ringrid, ring_mask) bdweb = lvf.rfs(bdweb, src_web_y, [(793, 1503), (1696, 2301), (32121, 34164), (34472, 34523)]) out = vdf.misc.merge_chroma(bdweb, src) # Restore BD changes dering_src = hvf.EdgeCleaner(src, 20, hot=True) diff_mask = Mask.diff_mask((src, src_cru), brz=4750.0) bdchanges = core.std.MaskedMerge(out, dering_src, diff_mask) bdchanges = lvf.rfs(out, bdchanges, [(9419, 9512), (17731, 17865)]) bdchanges = lvf.rfs(bdchanges, dering_src, [(14977, 15078), (15382, 15540), (23311, 23346)]) # return bdchanges, diff_mask out = bdchanges ref = Denoise.ref_denoise(get_y(out), tr=1) denoise = Denoise.hybrid_denoise( depth(out, 32), knlm_h=0.15, sigma=1, knlm_args=dict(d=1, a=3, s=3), bm3d_args=dict(ref=depth(ref, 32)) ) denoise = depth(denoise, 16) out = denoise pre = get_y(out) # Remove haloing dehalo = gf.MaskedDHA(pre, rx=1.4, ry=1.4, darkstr=0.1, brightstr=1.0, maskpull=40, maskpush=255) bila = core.bilateral.Bilateral(dehalo, sigmaS=1, sigmaR=0.08) dehalorp = core.rgvs.Repair(dehalo, bila, 13) dehalo = core.std.MaskedMerge(dehalo, dehalorp, ring_mask.std.Maximum(), 0) dehalo = core.std.Expr([dehalo, pre], 'x y min') out = dehalo # Antialiasing sraaaaaaaaaa lineart = vdf.mask.ExPrewitt().get_mask(out, 4000, 7500).std.Convolution([1] * 25) aaa = AA().upscaled_sraaaaaaaaaa(out, height=1620) out = aaa unwarp = self.line_darkening(out, 0.075).warp.AWarpSharp2(depth=-1) out = unwarp motion = hvf.SMDegrain(out, tr=3, thSADC=600, RefineMotion=True) masked = core.std.MaskedMerge(out, motion, lineart) out = masked mergechroma = vdf.misc.merge_chroma(out, denoise) out = mergechroma db_mask = Mask.deband_mask(out, (4000, 4000, 4000), (2000, 2000, 2000)) deband_1 = vdf.deband.dumb3kdb(out, 17, [36, 48]) deband_2 = vdf.deband.dumb3kdb(out, 17, 30, sample_mode=4, use_neo=True) deband_x = vdf.placebo.deband(out, 28, 4, iterations=3, grain=0) th_lo, th_hi = 22 << 8, 28 << 8 strength = f'{th_hi} x - {th_hi} {th_lo} - /' deband = core.std.Expr( [out.std.Convolution([1]*9), deband_1, deband_2], [f'x {th_lo} > x {th_hi} < and z ' + strength + ' * y 1 ' + strength + f' - * + x {th_lo} <= z y ? ?', 'x y * sqrt x z * sqrt * y * z * 0.25 pow']) deband = lvf.rfs(deband, deband_x, [(6688, 6714)]) deband = core.std.MaskedMerge(deband, out, db_mask) out = deband ref = get_y(out).std.PlaneStats() adgmask_a = ref.adg.Mask(25) adgmask_b = ref.adg.Mask(10) stgrain_a = core.grain.Add(out, 0.1, 0, seed=333, constant=True) stgrain_a = core.std.MaskedMerge(out, stgrain_a, adgmask_b.std.Invert()) stgrain_b = sizedgrn(out, 0.2, 0.1, 1.15, sharp=80, static=True, fade_edges=False, protect_neutral=False, seed=333) stgrain_b = core.std.MaskedMerge(out, stgrain_b, adgmask_b) stgrain_b = core.std.MaskedMerge(out, stgrain_b, adgmask_a.std.Invert()) stgrain = core.std.MergeDiff(stgrain_b, out.std.MakeDiff(stgrain_a)) dygrain = sizedgrn(out, 0.3, 0.1, 1.25, sharp=80, static=False, fade_edges=False, protect_neutral=False, seed=333) dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a) grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain)) out = grain if int(NUM) != 12: while out.num_frames < 34646: out += out[-1] return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 2])
def main(self) -> vs.VideoNode: """Vapoursynth filtering""" src = JPBD.clip_cut src = depth(src, 16) ring_mask = Mask.ringing_mask(get_y(src)) dering_src = hvf.EdgeCleaner(src, 20, hot=True) out = dering_src ref = Denoise.ref_denoise(get_y(out), tr=1) denoise = Denoise.hybrid_denoise(depth(out, 32), knlm_h=0.15, sigma=1, knlm_args=dict(d=1, a=3, s=3), bm3d_args=dict(ref=depth(ref, 32))) denoise = depth(denoise, 16) out = denoise pre = get_y(out) # Remove haloing dehalo = gf.MaskedDHA(pre, rx=1.4, ry=1.4, darkstr=0.1, brightstr=1.0, maskpull=40, maskpush=255) bila = core.bilateral.Bilateral(dehalo, sigmaS=1, sigmaR=0.08) dehalorp = core.rgvs.Repair(dehalo, bila, 13) dehalo = core.std.MaskedMerge(dehalo, dehalorp, ring_mask.std.Maximum(), 0) dehalo = core.std.Expr([dehalo, pre], 'x y min') out = dehalo # Antialiasing sraaaaaaaaaa lineart = vdf.mask.ExPrewitt().get_mask(out, 4000, 7500).std.Convolution([1] * 25) aaa = AA().upscaled_sraaaaaaaaaa(out, height=1620) out = aaa unwarp = self.line_darkening(out, 0.075).warp.AWarpSharp2(depth=-1) out = unwarp motion = hvf.SMDegrain(out, tr=3, thSADC=600, RefineMotion=True) masked = core.std.MaskedMerge(out, motion, lineart) out = masked mergechroma = vdf.misc.merge_chroma(out, denoise) out = mergechroma db_mask = Mask.deband_mask(out, (4000, 4000, 4000), (2000, 2000, 2000)) deband_1 = vdf.deband.dumb3kdb(out, 17, [36, 48]) deband_2 = vdf.deband.dumb3kdb(out, 17, 30, sample_mode=4, use_neo=True) deband_a = vdf.placebo.deband(out, 22, threshold=8, iterations=3, grain=0) th_lo, th_hi = 22 << 8, 28 << 8 strength = f'{th_hi} x - {th_hi} {th_lo} - /' deband = core.std.Expr( [out.std.Convolution([1] * 9), deband_1, deband_2], [ f'x {th_lo} > x {th_hi} < and z ' + strength + ' * y 1 ' + strength + f' - * + x {th_lo} <= z y ? ?', 'x y * sqrt x z * sqrt * y * z * 0.25 pow' ]) deband = lvf.rfs(deband, deband_a, [(OPSTART + 1382, OPSTART + 1433)]) deband = core.std.MaskedMerge(deband, out, db_mask) out = deband ref = get_y(out).std.PlaneStats() adgmask_a = ref.adg.Mask(25) adgmask_b = ref.adg.Mask(10) stgrain_a = core.grain.Add(out, 0.1, 0, seed=333, constant=True) stgrain_a = core.std.MaskedMerge(out, stgrain_a, adgmask_b.std.Invert()) stgrain_b = sizedgrn(out, 0.2, 0.1, 1.15, sharp=80, static=True, fade_edges=False, protect_neutral=False, seed=333) stgrain_b = core.std.MaskedMerge(out, stgrain_b, adgmask_b) stgrain_b = core.std.MaskedMerge(out, stgrain_b, adgmask_a.std.Invert()) stgrain = core.std.MergeDiff(stgrain_b, out.std.MakeDiff(stgrain_a)) dygrain = sizedgrn(out, 0.3, 0.1, 1.25, sharp=80, static=False, fade_edges=False, protect_neutral=False, seed=333) dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a) grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain)) out = grain if int(NUM) != 12: while out.num_frames < 2160: out += out[-1] return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 2])
def main(self) -> vs.VideoNode: """Vapoursynth filtering""" src = JPBD.clip_cut src = depth(src, 16) src_cru = WEB_CRU.clip_cut src_aod = WEB_AOD.clip_cut # Dehardsubbing using .ass file masksub = Mask.hardsub_mask(src_aod.std.BlankClip(), SUB, FONTDIR) dehardsub = core.std.MaskedMerge(src_aod, src_cru, masksub) src_web = dehardsub # AoD is poorly rescaled src_y, src_cru_y, src_web_y = map(get_y, [src, src_cru, src_web]) thr = 10 src_web_y = core.std.Expr([src_web_y, src_cru_y], f'x y - abs {thr} < x y * sqrt y ?') src_web_y = depth(src_web_y, 16) ringrid = core.rgvs.Repair(src_web_y, src_web_y.std.Convolution([1] * 9), 11) ringrid = core.std.Expr([ringrid, src_web_y], 'x y min') # Remove ringing with AoD+CR ring_mask = Mask.ringing_mask(src_y) bdweb = core.std.MaskedMerge(src_y, ringrid, ring_mask) out = vdf.misc.merge_chroma(bdweb, src) # Restore BD changes dering_src = hvf.EdgeCleaner(src, 20, hot=True) diff_mask = Mask.diff_mask((src, src_cru), brz=4750.0) bdchanges = core.std.MaskedMerge(out, dering_src, diff_mask) bdchanges = lvf.rfs(out, bdchanges, [(4455, 4607), (4876, 5078), (5199, 5246), (5958, 6035), (6894, 7076), (7275, 7406), (7653, 7784), (7863, 7970), (8142, 8348), (8784, 9065), (9276, 9800), (10613, 10720), (10739, 10780), (10949, 10969), (11105, 11230), (11924, 12289), (12865, 12891), (13139, 13213), (15520, 15733), (19160, 19243), (20351, 20422), (24824, 24979), (26357, 26527), (27920, 28000), (29576, 29659), (29780, 29881), (30128, 30271), (30644, 30763), (31776, 31811), (32522, 32641)]) # return bdchanges, diff_mask out = bdchanges ref = Denoise.ref_denoise(get_y(out), tr=1) denoise = Denoise.hybrid_denoise(depth(out, 32), knlm_h=0.15, sigma=1, knlm_args=dict(d=1, a=3, s=3), bm3d_args=dict(ref=depth(ref, 32))) denoise = depth(denoise, 16) out = denoise pre = get_y(out) # Remove haloing dehalo = gf.MaskedDHA(pre, rx=1.4, ry=1.4, darkstr=0.1, brightstr=1.0, maskpull=40, maskpush=255) bila = core.bilateral.Bilateral(dehalo, sigmaS=1, sigmaR=0.08) dehalorp = core.rgvs.Repair(dehalo, bila, 13) dehalo = core.std.MaskedMerge(dehalo, dehalorp, ring_mask.std.Maximum(), 0) dehalo = core.std.Expr([dehalo, pre], 'x y min') out = dehalo # Antialiasing sraaaaaaaaaa lineart = vdf.mask.ExPrewitt().get_mask(out, 4000, 7500).std.Convolution([1] * 25) aaa = AA().upscaled_sraaaaaaaaaa(out, height=1620) out = aaa unwarp = self.line_darkening(out, 0.075).warp.AWarpSharp2(depth=-1) out = unwarp motion = hvf.SMDegrain(out, tr=3, thSADC=600, RefineMotion=True) masked = core.std.MaskedMerge(out, motion, lineart) out = masked mergechroma = vdf.misc.merge_chroma(out, denoise) out = mergechroma ref = depth(src_cru, 16) cred_mask = Mask.credits_mask(src, JPBD_NCOP.clip_cut, JPBD_NCED.clip_cut, OPSTART, OPEND, EDSTART, EDEND) cred = out cred = lvf.rfs(cred, core.std.MaskedMerge(cred, ref, cred_mask, 0), [(OPSTART, OPEND), (EDSTART, EDEND)]) out = cred db_mask = Mask.deband_mask(out, (4000, 4000, 4000), (2000, 2000, 2000)) deband_1 = vdf.deband.dumb3kdb(out, 17, [36, 48]) deband_2 = vdf.deband.dumb3kdb(out, 17, 30, sample_mode=4, use_neo=True) deband_a = vdf.placebo.deband(out, 22, threshold=8, iterations=3, grain=0) import rekt deband_c = rekt.rekt_fast(out, lambda x: vdf.placebo.deband(x, 18, 6, 2, 0), bottom=600) deband_d = vdf.deband.dumb3kdb(out, 17, 65) th_lo, th_hi = 22 << 8, 28 << 8 strength = f'{th_hi} x - {th_hi} {th_lo} - /' deband = core.std.Expr( [out.std.Convolution([1] * 9), deband_1, deband_2], [ f'x {th_lo} > x {th_hi} < and z ' + strength + ' * y 1 ' + strength + f' - * + x {th_lo} <= z y ? ?', 'x y * sqrt x z * sqrt * y * z * 0.25 pow' ]) deband = lvf.rfs(deband, deband_a, [(OPSTART + 1382, OPSTART + 1433)]) deband = lvf.rfs(deband, deband_c, [(12362, 12391)]) deband = lvf.rfs(deband, deband_d, [(14789, 15025)]) deband = core.std.MaskedMerge(deband, out, db_mask) out = deband ref = get_y(out).std.PlaneStats() adgmask_a = ref.adg.Mask(25) adgmask_b = ref.adg.Mask(10) stgrain_a = core.grain.Add(out, 0.1, 0, seed=333, constant=True) stgrain_a = core.std.MaskedMerge(out, stgrain_a, adgmask_b.std.Invert()) stgrain_b = sizedgrn(out, 0.2, 0.1, 1.15, sharp=80, static=True, fade_edges=False, protect_neutral=False, seed=333) stgrain_b = core.std.MaskedMerge(out, stgrain_b, adgmask_b) stgrain_b = core.std.MaskedMerge(out, stgrain_b, adgmask_a.std.Invert()) stgrain = core.std.MergeDiff(stgrain_b, out.std.MakeDiff(stgrain_a)) dygrain = sizedgrn(out, 0.3, 0.1, 1.25, sharp=80, static=False, fade_edges=False, protect_neutral=False, seed=333) dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a) grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain)) out = grain if int(NUM) != 12: while out.num_frames < 34646: out += out[-1] return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 2])