def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]: """Regular VapourSynth filterchain""" import EoEfunc as eoe import havsfunc as haf import lvsfunc as lvf import vardefunc as vdf from adptvgrnMod import adptvgrnMod from ccd import ccd from muvsfunc import SSIM_downsample from vsutil import depth, get_y, iterate src = pre_freeze().std.AssumeFPS(fpsnum=24000, fpsden=1001) src = depth(src, 16) # TO-DO: Figure out how they post-sharpened it. Probably some form of unsharpening? src_y = depth(get_y(src), 32) descale = lvf.kernels.Bicubic(b=0, c=3 / 4).descale(src_y, 1440, 810) double = vdf.scale.nnedi3cl_double(descale, pscrn=1) rescale = depth(SSIM_downsample(double, 1920, 1080), 16) scaled = vdf.misc.merge_chroma(rescale, src) denoise = core.knlm.KNLMeansCL(scaled, d=1, a=3, s=4, h=0.4, channels='Y') stab = haf.GSMC(denoise, radius=2, planes=[0]) cdenoise = ccd(stab, threshold=5, matrix='709') decs = vdf.noise.decsiz(cdenoise, sigmaS=4, min_in=208 << 8, max_in=232 << 8) dehalo = haf.YAHR(decs, blur=2, depth=32) halo_mask = lvf.mask.halo_mask(decs, rad=3, brz=0.3, thma=0.42) dehalo_masked = core.std.MaskedMerge(decs, dehalo, halo_mask) dehalo_min = core.std.Expr([dehalo_masked, decs], "x y min") aa = lvf.aa.nneedi3_clamp(dehalo_min, strength=1.5) # Some scenes have super strong aliasing that I really don't wanna scenefilter until BDs. Thanks, Silver Link! aa_strong = lvf.sraa(dehalo_min, rfactor=1.35) aa_spliced = lvf.rfs(aa, aa_strong, []) upscale = lvf.kernels.Bicubic(b=0, c=3 / 4).scale(descale, 1920, 1080) credit_mask = lvf.scale.descale_detail_mask(src_y, upscale, threshold=0.08) credit_mask = iterate(credit_mask, core.std.Deflate, 3) credit_mask = iterate(credit_mask, core.std.Inflate, 3) credit_mask = iterate(credit_mask, core.std.Maximum, 2) merge_credits = core.std.MaskedMerge(aa_spliced, src, depth(credit_mask, 16)) deband = flt.masked_f3kdb(merge_credits, rad=18, thr=32, grain=[24, 0]) grain: vs.VideoNode = adptvgrnMod(deband, seed=42069, strength=0.15, luma_scaling=10, size=1.25, sharp=80, static=True, grain_chroma=False) return grain
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]: """Main filterchain""" import lvsfunc as lvf import rekt import vardefunc as vdf from muvsfunc import SSIM_downsample from vsutil import depth, get_y src = JP_BD.clip_cut rkt = rekt.rektlvls(src, [0, -1], [15, 15], [0, -1], [15, 15]) cloc = depth(rkt, 32).resize.Bicubic(chromaloc_in=1, chromaloc=0) descale = lvf.kernels.Bilinear().descale(get_y(cloc), 1280, 720) supersample = vdf.scale.nnedi3_upscale(descale) downscaled = SSIM_downsample(supersample, src.width, src.height, smooth=((3**2 - 1) / 12)**0.5, sigmoid=True, filter_param_a=0, filter_param_b=0) scaled = vdf.misc.merge_chroma(downscaled, cloc) scaled = depth(scaled, 16) dft = core.dfttest.DFTTest(scaled, sigma=0.6, sbsize=8, sosize=6, tbsize=3, tosize=1) decs = vdf.noise.decsiz(dft, sigmaS=4, min_in=200 << 8, max_in=232 << 8) baa = lvf.aa.based_aa(decs, str(shader_file)) sraa = lvf.sraa(decs, rfactor=1.5) clmp = lvf.aa.clamp_aa(decs, baa, sraa, strength=1.5) deband = flt.masked_f3kdb(clmp, rad=16, thr=[20, 16]) grain = vdf.noise.Graigasm(thrs=[x << 8 for x in (32, 80, 128, 176)], strengths=[(0.25, 0.0), (0.20, 0.0), (0.15, 0.0), (0.0, 0.0)], sizes=(1.20, 1.15, 1.10, 1), sharps=(80, 70, 60, 50), grainers=[ vdf.noise.AddGrain(seed=69420, constant=False), vdf.noise.AddGrain(seed=69420, constant=False), vdf.noise.AddGrain(seed=69420, constant=True) ]).graining(deband) return grain
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]: """Main filterchain""" import lvsfunc as lvf import rekt import vardefunc as vdf from awsmfunc import bbmod from ccd import ccd from muvsfunc import SSIM_downsample from vsutil import depth, get_y src = JP_BD.clip_cut rkt = rekt.rektlvls(src, [0, -1], [30, 17], [0], [17]) bb_y = bbmod(rkt, top=2, left=2, right=2, bottom=2, u=False, v=False, blur=9999) bb_uv = bbmod(bb_y, left=2, right=2, y=False) bb = depth(bb_uv, 32) descale = lvf.kernels.Spline36().descale(get_y(bb), 1280, 720) up_chr = vdf.scale.to_444(bb, 1920, 1080, True).resize.Bicubic(1280, 720) descale_merge = vdf.misc.merge_chroma(descale, up_chr) denoise_down = lvf.deblock.vsdpir(descale_merge, strength=0.5, mode='deblock', matrix=1, i444=True, cuda=True) supersample = vdf.scale.nnedi3_upscale(get_y(denoise_down)) downscaled = SSIM_downsample(supersample, bb.width, bb.height, smooth=((3 ** 2 - 1) / 12) ** 0.5, sigmoid=True, filter_param_a=0, filter_param_b=0) scaled = vdf.misc.merge_chroma(downscaled, bb) scaled = depth(scaled, 16) den_uv = ccd(scaled, matrix='709') decs = vdf.noise.decsiz(den_uv, sigmaS=8, min_in=200 << 8, max_in=232 << 8) nn_aa = lvf.aa.nnedi3(opencl=True, dh=False)(decs) sraa = lvf.sraa(decs, rfactor=1.75) clmp = lvf.aa.clamp_aa(decs, nn_aa, sraa) dehalo = lvf.dehalo.masked_dha(clmp, brightstr=0.65) deband = flt.masked_f3kdb(dehalo, rad=17, thr=[24, 16], grain=[24, 12]) grain = vdf.noise.Graigasm( thrs=[x << 8 for x in (32, 80, 128, 176)], strengths=[(0.20, 0.0), (0.15, 0.0), (0.10, 0.0), (0.0, 0.0)], sizes=(1.20, 1.15, 1.10, 1), sharps=(100, 80, 60, 20), grainers=[ vdf.noise.AddGrain(seed=69420, constant=False), vdf.noise.AddGrain(seed=69420, constant=False), vdf.noise.AddGrain(seed=69420, constant=True) ]).graining(deband) no_flt = lvf.rfs(grain, depth(bb, 16), no_filter) return no_flt
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]: """Regular VapourSynth filterchain""" import havsfunc as haf import lvsfunc as lvf import vardefunc as vdf from adptvgrnMod import adptvgrnMod from muvsfunc import SSIM_downsample from vsutil import depth, get_y, iterate src = pre_freeze() src = depth(src, 16) src_y = depth(get_y(src), 32) descale = lvf.kernels.Bicubic(b=0, c=3 / 4).descale(src_y, 1440, 810) double = vdf.scale.nnedi3cl_double(descale, pscrn=1) rescale = depth(SSIM_downsample(double, 1920, 1080), 16) scaled = vdf.misc.merge_chroma(rescale, src) denoise = core.knlm.KNLMeansCL(scaled, d=1, a=3, s=4, h=0.3, channels='Y') decs = vdf.noise.decsiz(denoise, sigmaS=4, min_in=208 << 8, max_in=232 << 8) dehalo = haf.YAHR(decs, blur=2, depth=28) halo_mask = lvf.mask.halo_mask(decs, rad=3, brz=0.3, thma=0.42) dehalo_masked = core.std.MaskedMerge(decs, dehalo, halo_mask) aa = lvf.aa.nneedi3_clamp(dehalo_masked, strength=1.5) # Strong aliasing on the transformation scene (and probably elsewhere that I missed). Thanks, Silver Link! aa_strong = lvf.sraa(dehalo_masked, rfactor=1.35) aa_spliced = lvf.rfs(aa, aa_strong, [(7056, 7322)]) upscale = lvf.kernels.Bicubic(b=0, c=3 / 4).scale(descale, 1920, 1080) credit_mask = lvf.scale.descale_detail_mask(src_y, upscale, threshold=0.08) credit_mask = iterate(credit_mask, core.std.Deflate, 3) credit_mask = iterate(credit_mask, core.std.Inflate, 3) credit_mask = iterate(credit_mask, core.std.Maximum, 2) merge_credits = core.std.MaskedMerge(aa_spliced, src, depth(credit_mask, 16)) deband = flt.masked_f3kdb(merge_credits, rad=18, thr=32, grain=[24, 0]) grain: vs.VideoNode = adptvgrnMod(deband, seed=42069, strength=0.15, luma_scaling=10, size=1.25, sharp=80, static=True, grain_chroma=False) return grain
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]: """Main VapourSynth filterchain""" import havsfunc as haf import lvsfunc as lvf import vardefunc as vdf from ccd import ccd from muvsfunc import SSIM_downsample from vsutil import depth, get_y src = JP_BD.clip_cut src = depth(src, 32) src_y = get_y(src) l_mask = vdf.mask.FDOG().get_mask(src_y, lthr=0.065, hthr=0.065).std.Maximum().std.Minimum() l_mask = l_mask.std.Median().std.Convolution([1] * 9) # Rescaling descale = flt.auto_descale(src_y) desc_i = flt.descale_fields(src_y, kernel=lvf.kernels.BicubicSharp) descale = lvf.rfs(descale, desc_i, [(1555, 1685)]) supersample = vdf.scale.nnedi3cl_double(descale, use_znedi=True, pscrn=1) downscaled = SSIM_downsample(supersample, src.width, src.height, smooth=((3 ** 2 - 1) / 12) ** 0.5, sigmoid=True, filter_param_a=0, filter_param_b=0) scaled_mask = core.std.MaskedMerge(src_y, downscaled, l_mask) scaled = depth(vdf.misc.merge_chroma(scaled_mask, src), 16) # Denoising l_mask_16 = depth(l_mask, 16).std.Minimum() dft = core.dfttest.DFTTest(scaled, sigma=1.25, tbsize=3, tosize=1) dft_masked = core.std.MaskedMerge(dft, scaled, l_mask_16) ccd_uv = ccd(dft, threshold=4, matrix='709') ccd_uv = core.std.MaskedMerge(ccd_uv, dft_masked, l_mask_16, planes=[1, 2]) decs = vdf.noise.decsiz(ccd_uv, sigmaS=4, min_in=212 << 8, max_in=240 << 8) # AA and slight lineart enhancement baa = lvf.aa.based_aa(decs, shader_file) sraa = lvf.sraa(decs, rfactor=1.5, downscaler=lvf.kernels.Bicubic(b=-1/2, c=1/4).scale) clmp = lvf.aa.clamp_aa(decs, baa, sraa, strength=1.5) sraa_strong = flt.transpose_sraa(decs, rfactor=1.2, downscaler=lvf.kernels.Bicubic(b=-1/2, c=1/4).scale) clmp = lvf.rfs(clmp, sraa_strong, []) darken = haf.FastLineDarkenMOD(clmp, strength=36) # Debanding and graining deband = core.average.Mean([ flt.masked_f3kdb(darken, rad=18, thr=[28, 24]), flt.masked_placebo(darken, rad=15, thr=4) ]) grain = vdf.noise.Graigasm( thrs=[x << 8 for x in (32, 80, 128, 176)], strengths=[(0.15, 0.0), (0.10, 0.0), (0.10, 0.0), (0.0, 0.0)], sizes=(1.15, 1.10, 1.05, 1), sharps=(60, 50, 50, 50), grainers=[ vdf.noise.AddGrain(seed=69420, constant=True), vdf.noise.AddGrain(seed=69420, constant=True), vdf.noise.AddGrain(seed=69420, constant=True) ]).graining(deband) return grain
def pre_filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]: """ Regular filtering to get the output images to stitch. This is preferable over handling it unfiltered, since it'll be faster than encoding it and reduces the amount of jitter caused by the upscale after. """ import lvsfunc as lvf import rekt import vardefunc as vdf from awsmfunc import bbmod from muvsfunc import SSIM_downsample from vsutil import depth, get_y, join, plane src = JP_BD.clip_cut # Fixing animation f**k-ups if freeze_ranges: src = core.std.FreezeFrames( src, [s[0] for s in freeze_ranges], [e[1] for e in freeze_ranges], [f[2] for f in freeze_ranges] ) # Edgefixing ef = rekt.rektlvls( src, prot_val=[16, 235], min=16, max=235, rownum=[0, src.height-1], rowval=[16, 16], colnum=[0, src.width-1], colval=[16, 16], ) bb_y = bbmod(ef, left=1, top=1, right=1, bottom=1, thresh=32, y=True, u=False, v=False) bb_uv = bbmod(bb_y, left=2, top=2, right=2, bottom=2, y=False, u=True, v=True) cshift = flt.shift_chroma(bb_uv, left=0.6) cshift = lvf.rfs(bb_uv, cshift, cshift_left_ranges) bb32 = depth(cshift, 32) bb32_y = get_y(bb32) # Descaling + DPIR while it's at a lower res (so I can actually run it because >memory issues xd) descale = lvf.kernels.Catrom().descale(bb32_y, 1280, 720) downscale = lvf.kernels.Catrom(format=vs.YUV444PS).scale(bb32, 1280, 720) descale_444 = join([descale, plane(downscale, 1), plane(downscale, 2)]) denoise_y = lvf.deblock.vsdpir(descale_444, strength=2.75, mode='deblock', matrix=1, i444=True, cuda=True) supersample = vdf.scale.fsrcnnx_upscale(get_y(denoise_y), shader_file=shader_file, downscaler=None) downscaled = SSIM_downsample(supersample, src.width, src.height, smooth=((3 ** 2 - 1) / 12) ** 0.5, sigmoid=True, filter_param_a=0, filter_param_b=0) # Create credit mask upscale = lvf.kernels.Catrom().scale(descale, src.width, src.height) credit_mask = lvf.scale.descale_detail_mask(bb32_y, upscale, threshold=0.055) \ .std.Deflate().std.Deflate().std.Minimum() # Merge early for additional accuracy with DPIR merged = core.std.MaskedMerge(downscaled, bb32_y, credit_mask) down_y = lvf.kernels.Catrom().scale(merged, src.width/2, src.height/2) down_i444 = join([down_y, plane(bb32, 1), plane(bb32, 2)]) deblock_down = lvf.deblock.vsdpir(down_i444, strength=3, mode='denoise', matrix=1, i444=True, cuda=True) scaled = depth(join([merged, plane(deblock_down, 1), plane(deblock_down, 2)]), 16) # Final bit of "denoising" dft = core.dfttest.DFTTest(scaled, sigma=2.0, tbsize=5, tosize=3, planes=[0]) decs = vdf.noise.decsiz(dft, sigmaS=4, min_in=208 << 8, max_in=232 << 8) # AA baa = lvf.aa.based_aa(decs, str(shader_file)) sraa = lvf.sraa(decs, rfactor=1.65) clmp = lvf.aa.clamp_aa(decs, baa, sraa, strength=1.3) dehalo = lvf.dehalo.masked_dha(clmp, rx=1.4, ry=1.4, brightstr=0.4) cwarp = core.warp.AWarpSharp2(dehalo, thresh=72, blur=3, type=1, depth=4, planes=[1, 2]) # Merge credits (if applicable) merged = core.std.MaskedMerge(cwarp, depth(bb32, 16), depth(credit_mask, 16)) deband = core.average.Mean([ flt.masked_f3kdb(merged, rad=16, thr=[20, 24], grain=[24, 12]), flt.masked_f3kdb(merged, rad=20, thr=[28, 24], grain=[24, 12]), flt.masked_placebo(merged, rad=6, thr=2.5, itr=2, grain=4) ]) no_flt = lvf.rfs(deband, depth(bb32, 16), no_filter) return no_flt
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]: """Main filterchain""" import lvsfunc as lvf import rekt import vardefunc as vdf from awsmfunc import bbmod from muvsfunc import SSIM_downsample from vsutil import depth, get_y src = JP_BD.clip_cut rkt = rekt.rektlvls(src, [0, -1], [17, 17], [0, -1], [17, 21]) bb_y = bbmod(rkt, top=2, left=2, right=1, u=False, v=False) bb_uv = bbmod(bb_y, left=2, right=2, y=False) bb = depth(bb_uv, 32) descale = lvf.kernels.Mitchell().descale(get_y(bb), 1280, 720) up_chr = vdf.scale.to_444(bb, 1920, 1080, True).resize.Bicubic(1280, 720) descale_merge = vdf.misc.merge_chroma(descale, up_chr) denoise_down = lvf.deblock.vsdpir(descale_merge, strength=5, mode='deblock', matrix=1, i444=True, cuda=True) supersample = vdf.scale.nnedi3_upscale(get_y(denoise_down)) downscaled = SSIM_downsample(supersample, bb.width, bb.height, smooth=((3 ** 2 - 1) / 12) ** 0.5, sigmoid=True, filter_param_a=0, filter_param_b=0) den_chr_up = core.resize.Bicubic(denoise_down, bb.width, bb.height, bb.format.id) den_chr_up_shift = core.resize.Bicubic(denoise_down, bb.width, bb.height, bb.format.id, src_left=-0.5) den_chr_up = lvf.rfs(den_chr_up, den_chr_up_shift, shift_chr) scaled = vdf.misc.merge_chroma(downscaled, den_chr_up) scaled = depth(scaled, 16) decs = vdf.noise.decsiz(scaled, sigmaS=4, min_in=208 << 8, max_in=232 << 8) deband = core.average.Mean([ flt.masked_f3kdb(decs, rad=17, thr=[20, 24], grain=[24, 12]), flt.masked_f3kdb(decs, rad=21, thr=[32, 24], grain=[24, 12]), flt.masked_placebo(decs, rad=6, thr=2.8, itr=2, grain=4) ]) grain = vdf.noise.Graigasm( thrs=[x << 8 for x in (32, 80, 128, 176)], strengths=[(0.25, 0.0), (0.20, 0.0), (0.15, 0.0), (0.0, 0.0)], sizes=(1.25, 1.20, 1.15, 1), sharps=(80, 70, 60, 50), grainers=[ vdf.noise.AddGrain(seed=69420, constant=False), vdf.noise.AddGrain(seed=69420, constant=False), vdf.noise.AddGrain(seed=69420, constant=True) ]).graining(deband) grain_str = vdf.noise.Graigasm( thrs=[x << 8 for x in (32, 80, 128, 176)], strengths=[(0.35, 0.0), (0.30, 0.0), (0.25, 0.0), (0.0, 0.0)], sizes=(1.25, 1.20, 1.15, 1), sharps=(80, 70, 60, 50), grainers=[ vdf.noise.AddGrain(seed=69420, constant=False), vdf.noise.AddGrain(seed=69420, constant=False), vdf.noise.AddGrain(seed=69420, constant=True) ]).graining(deband) grain = lvf.rfs(grain, grain_str, str_grain) return grain
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]: """Main VapourSynth filterchain""" import debandshit as dbs import havsfunc as haf import lvsfunc as lvf import rekt import vardefunc as vdf from awsmfunc import bbmod from ccd import ccd from muvsfunc import SSIM_downsample from vsutil import depth, get_w, get_y src = JP_BD.clip_cut src = depth(src, 16) rkt_a = rekt.rektlvls(src, [0, 1, -2, -1], [12, -12, -10, 11], [0, 1, -2, -1], [11, -12, -10, 11]) rkt_b = rekt.rektlvls(src, [0, -1], [15, 15], [0, 1, 2, 3, -4, -2, -1], [12, 3, -1, 1, 2, 4, 12]) rkt_c = rekt.rektlvls(src, [-2, -1], [6, 11], [0, -2, -1], [15, 10, 15]) bb_c = bbmod(rkt_c, bottom=2, blur=35, y=False) rkt = lvf.rfs(rkt_a, rkt_b, [(458, 522), (806, 919), (1148, 1179), (1321, 1442), (1989, 2129)]) rkt = lvf.rfs(rkt, bb_c, [(2130, None)]) ef = depth(rkt, 32) src_y = get_y(ef) pre_den = core.dfttest.DFTTest(src_y, sigma=3.0) l_mask = vdf.mask.FDOG().get_mask( pre_den, lthr=0.125, hthr=0.050).rgsf.RemoveGrain(4).rgsf.RemoveGrain(4) l_mask = l_mask.std.Minimum().std.Deflate().std.Median().std.Convolution( [1] * 9).std.Maximum() # Descaling. descaled = lvf.kernels.Catrom().descale( src_y, get_w(720, src_y.width / src_y.height), 720) descaled = core.resize.Bicubic(descaled, format=vs.YUV444P16) # Slight AA in an attempt to forcibly fix starved lineart. baa = lvf.aa.based_aa(descaled, shader_file) sraa = lvf.aa.upscaled_sraa(descaled, rfactor=1.45) clamp_aa = lvf.aa.clamp_aa(descaled, baa, sraa, strength=1.15) clamp_aa = depth(get_y(clamp_aa), 32) # Doing a mixed reupscale using nn3/fsrcnnx, grabbing the darkest parts of each rescaled_nn3 = vdf.scale.nnedi3cl_double(clamp_aa, use_znedi=True, pscrn=1) rescaled_fsrcnnx = vdf.scale.fsrcnnx_upscale(clamp_aa, rescaled_nn3.width, rescaled_nn3.height, shader_file) rescaled = core.std.Expr([rescaled_nn3, rescaled_fsrcnnx], "x y min") downscaled = SSIM_downsample(rescaled, src_y.width, src_y.height, smooth=((3**2 - 1) / 12)**0.5, sigmoid=True, filter_param_a=-1 / 2, filter_param_b=1 / 4) downscaled = core.std.MaskedMerge(src_y, downscaled, l_mask) scaled = depth(vdf.misc.merge_chroma(downscaled, ef), 16) # Chroma warping to forcibly wrap it a bit nicer around the lineart. Also fixing slight shift. 4:2:0 was a mistake. cwarp = scaled.warp.AWarpSharp2(thresh=72, blur=3, type=1, depth=6, planes=[1, 2]) # The textures and detail are very smeary, so gotta be careful not to make it even worse stab = haf.GSMC(cwarp, radius=3, planes=[0], thSAD=75) den_uv = ccd(stab, threshold=5, matrix='709') decs = vdf.noise.decsiz(den_uv, sigmaS=8.0, min_in=200 << 8, max_in=240 << 8) # Scenefiltered debanding. Not graining, since we kept most of the original grain anyway. deband_wk = dbs.debanders.dumb3kdb(decs, radius=16, threshold=[28, 0], grain=0) deband_wk = core.placebo.Deband(deband_wk, iterations=2, threshold=3.5, radius=12, grain=0, planes=2 | 4) # Strong denoising + debanding to hopefully deal with all the awful bands. Courtesy of :b:arde dft = core.dfttest.DFTTest(decs, sigma=4.0) ccd_uv = ccd(dft, threshold=10, matrix='709') f3k = dbs.debanders.dumb3kdb(ccd_uv, radius=8, threshold=[36, 24], grain=0) plac = flt.masked_placebo(f3k, rad=18, thr=5.5, itr=2, grain=3.0, mask_args={ 'detail_brz': 100, 'lines_brz': 450 }) dft_diff = core.std.MakeDiff(decs, dft) plac_diff = core.std.MergeDiff(plac, dft_diff) deband = lvf.rfs(deband_wk, plac_diff, strong_debanding) return deband
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]: """Regular VapourSynth filterchain""" import EoEfunc.denoise as eoe import havsfunc as haf import lvsfunc as lvf import vardefunc as vdf from adptvgrnMod import adptvgrnMod from ccd import ccd from muvsfunc import SSIM_downsample from vsutil import depth, get_y, iterate from xvs import WarpFixChromaBlend src = JP_clip.clip_cut.std.AssumeFPS(fpsnum=24000, fpsden=1001) src = depth(src, 16) # TO-DO: Figure out how they post-sharpened it. Probably some form of unsharpening? src_y = depth(get_y(src), 32) descale = lvf.kernels.Bicubic(b=0, c=3 / 4).descale(src_y, 1440, 810) double = vdf.scale.nnedi3cl_double(descale, pscrn=1) rescale = depth(SSIM_downsample(double, 1920, 1080), 16) scaled = vdf.misc.merge_chroma(rescale, src) denoise_ref = core.dfttest.DFTTest(scaled, sigma=1.8) denoise = lvf.denoise.bm3d(scaled, sigma=[0.75, 0.65], ref=denoise_ref) cdenoise = ccd(denoise, threshold=3, matrix='709') decs = vdf.noise.decsiz(cdenoise, sigmaS=4, min_in=208 << 8, max_in=232 << 8) # Dehalo fuckery. F**k the sharpening, dude dehalo = haf.YAHR(decs, blur=2, depth=32) dehalo_2 = lvf.dehalo.masked_dha(dehalo, ry=2.5, rx=2.5) halo_mask = lvf.mask.halo_mask(decs, rad=3, brz=0.3, thma=0.42) dehalo_masked = core.std.MaskedMerge(decs, dehalo_2, halo_mask) dehalo_min = core.std.Expr([dehalo_masked, decs], "x y min") # Brightening the lines to undo the unsharpening's line darkening bright = haf.FastLineDarkenMOD(dehalo_min, strength=-24) # AA baa = lvf.aa.based_aa(bright, str(shader_file)) sraa = lvf.sraa(bright, rfactor=1.45) clmp = lvf.aa.clamp_aa(bright, baa, sraa, strength=1.45) line_mask = core.std.Prewitt(clmp) cwarp = WarpFixChromaBlend(clmp, thresh=96, depth=6) cwarp = core.std.MaskedMerge(cwarp, clmp, line_mask) upscale = lvf.kernels.Bicubic(b=0, c=3 / 4).scale(descale, 1920, 1080) credit_mask = lvf.scale.descale_detail_mask(src_y, upscale, threshold=0.08) credit_mask = iterate(credit_mask, core.std.Deflate, 3) credit_mask = iterate(credit_mask, core.std.Inflate, 3) credit_mask = iterate(credit_mask, core.std.Maximum, 2) merge_credits = core.std.MaskedMerge(cwarp, src, depth(credit_mask, 16)) deband = flt.masked_f3kdb(merge_credits, rad=15, thr=20, grain=[12, 0]) grain: vs.VideoNode = adptvgrnMod(deband, seed=42069, strength=0.15, luma_scaling=10, size=1.25, sharp=70, static=True, grain_chroma=False) return grain