def denoise_and_rescale(clip): denoise = hybrid_denoise(clip, 0.5, 2) out = denoise luma = get_y(out) line_mask = vdf.edge_detect(luma, 'FDOG', 0.05, (1, 1)) descale = core.descale.Debicubic(luma, w, h, b, c) upscale = vdf.fsrcnnx_upscale(descale, None, descale.height * 2, '_shaders/FSRCNNX_x2_56-16-4-1.glsl', core.resize.Point) antialias = single_rate_antialiasing(upscale, 13, alpha=0.3, beta=0.45, gamma=320, mdis=18) scaled = muvf.SSIM_downsample(antialias, src.width, src.height, kernel='Bicubic') rescale = core.std.MaskedMerge(luma, scaled, line_mask) merged = vdf.merge_chroma(rescale, out) return depth(merged, 16)
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut src = depth(src, 32) h = 720 w = get_w(h) b, c = vdf.get_bicubic_params('robidoux') denoise = hybrid_denoise(src, 0.5, 2) out = denoise luma = get_y(out) line_mask = vdf.edge_detect(luma, 'FDOG', 0.05, (1, 1)) descale = core.descale.Debicubic(luma, w, h, b, c) upscale = vdf.fsrcnnx_upscale(descale, None, descale.height*2, '_shaders/FSRCNNX_x2_56-16-4-1.glsl', core.resize.Point) antialias = single_rate_antialiasing(upscale, 13, alpha=0.3, beta=0.45, gamma=320, mdis=18) scaled = muvf.SSIM_downsample(antialias, src.width, src.height, kernel='Bicubic') rescale = core.std.MaskedMerge(luma, scaled, line_mask) merged = vdf.merge_chroma(rescale, out) out = depth(merged, 16) # Slight sharp though CAS sharp = hvf.LSFmod(out, strength=75, Smode=3, Lmode=1, edgemode=1, edgemaskHQ=True) out = sharp dering = gf.HQDeringmod(out, thr=16, darkthr=0.1) out = dering warp = xvs.WarpFixChromaBlend(out, thresh=48, depth=8) out = warp preden = core.knlm.KNLMeansCL(out, d=0, a=3, h=0.6, device_type='GPU', channels='Y') deband_mask = lvf.denoise.detail_mask(preden, brz_a=2000, brz_b=800, rad=4) deband = dbs.f3kpf(out, 17, 42, 42) deband = core.std.MaskedMerge(deband, out, deband_mask) out = deband adg_mask = core.adg.Mask(out.std.PlaneStats(), 20).std.Expr(f'x x {128<<8} - 0.25 * +') grain = core.grain.Add(out, 0.2, constant=True) grain = core.std.MaskedMerge(out, grain, adg_mask, 0) out = grain return depth(out, 10)
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut src = depth(src, 16) out = src h = 720 w = get_w(h) fixedges = awf.bbmod(out, 2, 2, 2, 2, 64 << 8, 999) out = fixedges clean = core.knlm.KNLMeansCL(out, h=0.55, a=2, d=3, device_type='gpu', device_id=0, channels='UV') clean = core.knlm.KNLMeansCL(clean, h=0.55, a=2, d=3, device_type='gpu', device_id=0, channels='Y') diff_den = core.std.MakeDiff(out, clean) out = depth(clean, 32) luma = get_y(out) line_mask = vdf.edge_detect(luma, 'FDOG', 0.05, (1, 1)) descale = core.descale.Debilinear(luma, w, h) upscale = vdf.nnedi3_upscale(descale, correct_shift=False, pscrn=1).resize.Bicubic(src.width, src.height, src_left=.5, src_top=.5) rescale = core.std.MaskedMerge(luma, upscale, line_mask) merged = vdf.merge_chroma(rescale, out) out = depth(merged, 16) moozzi = warping(out, 0.4, 4) sharp = hvf.LSFmod(moozzi, strength=95, Smode=3, Lmode=1, edgemode=1, edgemaskHQ=True) out = sharp deband_mask = lvf.denoise.detail_mask(out, brz_a=2000, brz_b=1000) deband = dbs.f3kpf(out, 17, 30, 30) deband = core.std.MaskedMerge(deband, out, deband_mask) out = deband grain_org = core.std.MergeDiff(out, diff_den) out = grain_org return depth(out, 10)
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut ep10 = JPBD_10.src_cut h = 720 w = get_w(h) b, c = vdf.get_bicubic_params('robidoux') opstart, opend = 672, 3068 edstart, edend = 31888, src.num_frames - 1 opstart_ep10, opend_ep10 = 768, 3164 full_stuff = [(3853, 3984), (16130, 16279)] # Fix borders of the henshin start, end = 26596, 27387 white_clip = core.std.BlankClip(src, color=[235, 128, 128]) # Good length for the three henshins hibiki = TRANSFOS.src_cut[912:1716] hibiki = core.std.DeleteFrames(hibiki, [203, 204]) hibiki = core.std.DeleteFrames(hibiki, range(316, 320)) hibiki = core.std.DeleteFrames(hibiki, range(391, 394)) tsubasa = TRANSFOS.src_cut[2178:2738] tsubasa = core.std.DuplicateFrames(white_clip[:8] + tsubasa, range(10, 20)) tsubasa = core.std.DuplicateFrames(tsubasa, range(196, 203)) tsubasa = core.std.DuplicateFrames(tsubasa, [443, 443, 443]) yukine = TRANSFOS.src_cut[3240:3828] # The intro intro = 203 new_tranfos = hibiki[:intro] # Adjust croppings hibiki_crop_a = core.std.Crop(hibiki[intro:], src.width / 3, src.width / 3, 0, 0) dev = -150 hibiki_crop_b = core.std.Crop(hibiki[intro:], src.width / 3 + dev, src.width / 3 - dev, 0, 0) dev = -270 hibiki_crop_c = core.std.Crop(hibiki[intro:], src.width / 3 + dev, src.width / 3 - dev, 0, 0) hibiki_crop = lvf.rfs(hibiki_crop_a, hibiki_crop_b, [(391 - intro, 471 - intro)]) hibiki_crop = lvf.rfs(hibiki_crop, hibiki_crop_c, [(472 - intro, 552 - intro)]) tsubasa_crop_a = core.std.Crop(tsubasa, src.width / 3, src.width / 3, 0, 0) dev = -400 tsubasa_crop_b = core.std.Crop(tsubasa, src.width / 3 + dev, src.width / 3 - dev, 0, 0) tsubasa_crop = lvf.rfs(tsubasa_crop_a, tsubasa_crop_b, [(445 - intro, 460 - intro)]) tsubasa_crop = (tsubasa_crop[:461 - intro] + core.std.FrameEval( tsubasa_crop[461 - intro:478 - intro], partial(_prog_crop, clip=tsubasa[461 - intro:478 - intro], dev=dev)) + tsubasa_crop[478 - intro:]) yukine_crop = core.std.Crop(yukine, src.width / 3, src.width / 3, 0, 0) # Stack & merge new_tranfos += core.std.StackHorizontal( [tsubasa_crop, hibiki_crop, yukine_crop]) src = insert_clip(src, new_tranfos[:end - start], start) # Fix compositing error in the OP op_src, op_10 = src[opstart:opend + 1], ep10[opstart_ep10:opend_ep10 + 1] fix = lvf.rfs(op_src, op_10, [(0, 79), (1035, 1037)]) fix_src = insert_clip(src, fix, opstart) src = depth(fix_src, 32) denoise = hybrid_denoise(src, 0.5, 2) out = denoise luma = get_y(out) line_mask = vdf.edge_detect(luma, 'FDOG', 0.05, (1, 1)) descale = core.descale.Debicubic(luma, w, h, b, c) upscale = vdf.fsrcnnx_upscale(descale, None, descale.height * 2, '_shaders/FSRCNNX_x2_56-16-4-1.glsl', core.resize.Point) upscale_smooth = vdf.nnedi3_upscale(descale, pscrn=1) upscale = vdf.fade_filter(upscale, upscale, upscale_smooth, 18018, 18068) upscale = lvf.rfs(upscale, upscale_smooth, [(18068, 18134)]) antialias = single_rate_antialiasing(upscale, 13, alpha=0.3, beta=0.45, gamma=320, mdis=18) scaled = muvf.SSIM_downsample(antialias, src.width, src.height, kernel='Bicubic') rescale = core.std.MaskedMerge(luma, scaled, line_mask) merged = vdf.merge_chroma(rescale, out) out = depth(merged, 16) antialias = lvf.rfs( out, lvf.sraa(out, 1.65, 9, alpha=0.3, beta=0.45, gamma=240, nrad=3, mdis=25), [(opstart + 840, opstart + 881)]) antialias_a = lvf.sraa(out, 1.3, 3, alpha=0.3, beta=0.45, gamma=40, nrad=3, mdis=25) antialias_b = lvf.sraa(out, 1.85, 13, alpha=0.3, beta=0.6, gamma=400, nrad=2, mdis=15) antialias = vdf.fade_filter(antialias, antialias_a, antialias_b, 12718, 12861) antialias = lvf.rfs(antialias, antialias_b, [(24063, 24149)]) out = antialias # Slight sharp though CAS sharp = hvf.LSFmod(out, strength=75, Smode=3, Lmode=1, edgemode=1, edgemaskHQ=True) out = sharp dering = gf.HQDeringmod(out, thr=16, darkthr=0.1) out = dering warp = xvs.WarpFixChromaBlend(out, thresh=48, depth=8) out = warp preden = core.knlm.KNLMeansCL(out, d=0, a=3, h=0.6, device_type='GPU', channels='Y') deband_mask = lvf.denoise.detail_mask(preden, brz_a=2000, brz_b=800, rad=4) deband = dbs.f3kpf(out, 17, 42, 42) deband_b = placebo.deband(out, 22, 6, 2) deband = lvf.rfs(deband, deband_b, [(opstart + 1515, opstart + 1603)]) deband_c = placebo.deband(out, 10, 3, 1) deband = lvf.rfs(deband, deband_c, [(241, 300), (11076, 11183)]) deband = core.std.MaskedMerge(deband, out, deband_mask) out = deband adg_mask = core.adg.Mask(out.std.PlaneStats(), 20).std.Expr(f'x x {128<<8} - 0.25 * +') grain = core.grain.Add(out, 0.2, constant=True) grain = core.std.MaskedMerge(out, grain, adg_mask, 0) out = grain rescale_mask = vdf.drm(luma, b=b, c=c, sw=4, sh=4) ref, rescale_mask, src, src_ncop, src_nced = [ depth(x, 16) for x in [denoise, rescale_mask, src, JPBD_NCOP.src_cut, JPBD_NCED.src_cut] ] credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, rescale_mask), full_stuff) out = credit src_c, src_ncop, src_nced = [ c.knlm.KNLMeansCL(a=7, h=35, d=0, device_type='gpu') for c in [src, src_ncop, src_nced] ] opening_mask = vdf.dcm(out, src_c[opstart:opend + 1], src_ncop[:opend - opstart + 1], opstart, opend, 4, 4).std.Inflate() ending_mask = vdf.dcm(out, src_c[edstart:edend + 1], src_nced[:edend - edstart + 1], edstart, edend, 4, 4).std.Inflate() credit_mask = core.std.Expr([opening_mask, ending_mask], 'x y +') credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, credit_mask), [(opstart, opend), (edstart, edend)]) out = credit return depth(out, 10)
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut src = depth(src, 16) out = src opstart, opend = 59, 1630 edstart, edend = 30776, src.num_frames-1 h = 846 w = get_w(h) cubic_filters = ['catrom', 'mitchell', 'robidoux', 'robidoux sharp'] cubic_filters = [vdf.get_bicubic_params(cf) for cf in cubic_filters] degrain = hybrid_denoise(out, 0.35, 1.2, dict(a=2, d=1)) out = degrain y = get_y(out) y32 = depth(y, 32) lineart = vdf.edge_detect(y32, 'kirsch', 0.055, (1, 1)).std.Median().std.Inflate() descale_clips = [core.descale.Debicubic(y32, w, h, b, c) for b, c in cubic_filters] descale = core.std.Expr(descale_clips, 'x y z a min min min x y z max max min') conv = core.std.Convolution(descale, [1, 2, 1, 2, 0, 2, 1, 2, 1]) thr, coef = 0.013, 3 descale_fix = core.std.Expr([descale, conv], f'x y - abs {thr} < y x ?').std.PlaneStats() adapt_mask = core.adg.Mask(descale_fix, 12).std.Invert().std.Expr(f'x 0.5 - {coef} * 0.5 + 0 max 1 min') descale = core.std.MaskedMerge(descale, descale_fix, adapt_mask) upscale = vdf.fsrcnnx_upscale(descale, w*2, h*2, r'shaders\FSRCNNX_x2_56-16-4-1.glsl', upscaler_smooth=eedi3_upscale, profile='zastin', sharpener=partial(gf.DetailSharpen, sstr=1.25, power=4)) aa_strong = sraa_eedi3(upscale, 13, alpha=0.3, beta=0.5, gamma=40) aa = aa_strong down = muvf.SSIM_downsample(aa, src.width, src.height, filter_param_a=0, filter_param_b=0) upscale = depth( core.std.MaskedMerge(y32, down, lineart), 16 ) merged = vdf.merge_chroma(upscale, out) out = merged y = get_y(out) detail_light_mask = lvf.denoise.detail_mask(y, brz_a=2500, brz_b=1200) pf = iterate(out, core.std.Maximum, 2).std.Convolution([10] * 9, planes=0) diff = core.std.MakeDiff(out, pf) deband = core.f3kdb.Deband(pf, 17, 36, 36, 36, 12, 12, 2, keep_tv_range=True, output_depth=16) deband = core.std.MergeDiff(deband, diff) deband = core.std.MaskedMerge(deband, out, detail_light_mask) out = deband grain = adptvgrnMod(out, 0.25, 0.15, size=out.height/h, sharp=80, luma_scaling=10, static=True) out = grain # # Restore 1080p stuff ref = src rescale_mask = vdf.drm(ref, h, mthr=65, sw=4, sh=4) credit = out credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, rescale_mask, 0), [(opstart, opend), (1634, 1728), (edstart, edend)]) credit = lvf.rfs(credit, ref, [(15200, 15271)]) out = credit return depth(out, 10).std.Limiter(16<<2, [235<<2, 240<<2])
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut src += src[-1] # Variables opstart, opend = 2206, 4362 eptitle_s, eptitle_e = 4363, 4482 edstart, edend = 31528, 33685 preview_s, preview_e = 33686, src.num_frames - 1 h = 720 w = get_w(h) edges = core.edgefixer.ContinuityFixer(src, *[[2, 1, 1]] * 4) out = depth(edges, 32) ref = hvf.SMDegrain(depth(get_y(out), 16), thSAD=450) denoise = hybrid_denoise(out, 0.35, 1.75, dict(a=2, d=1), dict(ref=depth(ref, 32))) out = denoise y = get_y(out) lineart = vdf.edge_detect(y, 'FDOG', 0.055, (1, 1)).std.Median().std.Convolution([*[1] * 9]) descale = core.descale.Debilinear(y, w, h) upscale = vdf.fsrcnnx_upscale( descale, height=h * 2, shader_file=r'shaders\FSRCNNX_x2_56-16-4-1.glsl', upscaler_smooth=eedi3_upscale, profile='slow', strength=85) antialias = sraa_eedi3(upscale, 9) downscale = muvf.SSIM_downsample(antialias, src.width, src.height, filter_param_a=0, filter_param_b=0) downscale = core.std.MaskedMerge(y, downscale, lineart) merged = vdf.merge_chroma(downscale, out) merged = lvf.rfs(merged, out, [(opstart, opend), (eptitle_s, eptitle_e), (preview_s, preview_e)]) out = depth(merged, 16) detail_dark_mask = detail_dark_mask_func(get_y(out), brz_a=8000, brz_b=6000) detail_light_mask = lvf.denoise.detail_mask(out, brz_a=2500, brz_b=1200) detail_mask = core.std.Expr([detail_dark_mask, detail_light_mask], 'x y +').std.Median() detail_mask_grow = iterate(detail_mask, core.std.Maximum, 2) detail_mask_grow = iterate(detail_mask_grow, core.std.Inflate, 2).std.Convolution([*[1] * 9]) detail_mask = core.std.Expr([get_y(out), detail_mask_grow, detail_mask], f'x {32<<8} < y z ?') deband = dumb3kdbv2(out, 22, 24) deband = core.std.MaskedMerge(deband, out, detail_mask) out = deband ref = get_y(out).std.PlaneStats() adgmask_a = core.adg.Mask(ref, 30) adgmask_b = core.adg.Mask(ref, 12) stgrain = sizedgrn(out, 0.1, 0.05, 1.05, sharp=80) stgrain = core.std.MaskedMerge(out, stgrain, adgmask_b) stgrain = core.std.MaskedMerge(out, stgrain, adgmask_a.std.Invert()) dygrain = sizedgrn(out, 0.2, 0.05, 1.15, sharp=80, static=False) dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a) grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain)) out = grain ref = depth(src, 16) rescale_mask = vdf.drm(ref, 720, 'bilinear', mthr=30, sw=0, sh=0) rescale_mask = vdf.region_mask(rescale_mask, *[10] * 4) rescale_mask = hvf.mt_expand_multi(rescale_mask, mode='ellipse', sw=4, sh=4) rescale_mask = rescale_mask.std.Binarize(scale_value( 100, 8, 16)).std.Inflate().std.Convolution([*[1] * 9]) dehalo_ref = gf.MaskedDHA(ref, rx=1.65, ry=1.65, darkstr=0.15, brightstr=1.0, maskpull=48, maskpush=140) dehalo_mask_b = vdf.region_mask(rescale_mask, right=400) credit = out dehalo_range_b = [(18, 101), (16853, 16917)] credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, rescale_mask, 0), [(126, 160), (1722, 1761), (7749, 7795), (8189, 8232), (8445, 8504), (9020, 9067), (9727, 9768), (12430, 12520), (12876, 12971), (13608, 13646), (15833, 15879), (20526, 20586), (20783, 20823), (21193, 21239), (23812, 23854), (24018, 24059), (edstart, edend)] + dehalo_range_b) credit = lvf.rfs( credit, core.std.MaskedMerge(credit, dehalo_ref, dehalo_mask_b, 0), dehalo_range_b) out = credit return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2])
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut src = depth(src, 32) h = 720 w = get_w(h) # getnative script returns 0.2 0.5 as best combo but it introduces too much halos. # I think it's plain mitchell but robidoux is good too and very slightly sharp. b, c = vdf.get_bicubic_params('robidoux') opstart = 0 denoise = hybrid_denoise(src, 0.5, 2) out = denoise luma = get_y(out) line_mask = vdf.edge_detect(luma, 'FDOG', 0.05, (1, 1)) descale = core.descale.Debicubic(luma, w, h, b, c) upscale = vdf.fsrcnnx_upscale(descale, None, descale.height * 2, '_shaders/FSRCNNX_x2_56-16-4-1.glsl', core.resize.Point) antialias = single_rate_antialiasing(upscale, 13, alpha=0.3, beta=0.45, gamma=320, mdis=18) scaled = muvf.SSIM_downsample(antialias, src.width, src.height, kernel='Bicubic') rescale = core.std.MaskedMerge(luma, scaled, line_mask) merged = vdf.merge_chroma(rescale, out) out = depth(merged, 16) antialias = lvf.rfs( out, lvf.sraa(out, 1.65, 9, alpha=0.3, beta=0.45, gamma=240, nrad=3, mdis=25), [(opstart + 840, opstart + 881)]) out = antialias # Slight sharp though CAS sharp = hvf.LSFmod(out, strength=75, Smode=3, Lmode=1, edgemode=1, edgemaskHQ=True) out = sharp dering = gf.HQDeringmod(out, thr=16, darkthr=0.1, show=False) out = dering warp = xvs.WarpFixChromaBlend(out, thresh=48, depth=8) out = warp preden = core.knlm.KNLMeansCL(out, d=0, a=3, h=0.6, device_type='GPU', channels='Y') mask = lvf.denoise.detail_mask(preden, brz_a=2000, brz_b=800, rad=4) deband = dbs.f3kpf(out, 17, 42, 42) deband_b = placebo.deband(out, 22, 6, 2) deband = lvf.rfs(deband, deband_b, [(opstart + 1515, opstart + 1603)]) deband = core.std.MaskedMerge(deband, out, mask) out = deband adg_mask = core.adg.Mask(out.std.PlaneStats(), 20).std.Expr(f'x x {128<<8} - 0.25 * +') grain = core.grain.Add(out, 0.2, constant=True) grain = core.std.MaskedMerge(out, grain, adg_mask, 0) out = grain return depth(out, 10)
def do_filter(): """Vapoursynth filtering""" # Source and dithering src = JPBD.src_cut src = depth(src, 16) out = src # Variables h = 846 w = get_w(h) cubic_filters = ['catrom', 'mitchell', 'robidoux', 'robidoux sharp'] cubic_filters = [vdf.get_bicubic_params(cf) for cf in cubic_filters] # Remove the dynamic grain degrain = hybrid_denoise(out, 0.35, 1.2, dict(a=2, d=1)) out = degrain y = get_y(out) y32 = depth(y, 32) lineart = vdf.edge_detect(y32, 'kirsch', 0.055, (1, 1)).std.Median().std.Inflate() # Use multiple descaling kernel for a sharper result descale_clips = [ core.descale.Debicubic(y32, w, h, b, c) for b, c in cubic_filters ] descale = core.std.Expr(descale_clips, 'x y z a min min min x y z max max min') # Fix descaling artifacts (yes even for catrom there's still artifacts) conv = core.std.Convolution(descale, [1, 2, 1, 2, 0, 2, 1, 2, 1]) thr, coef = 0.013, 3.2 descale_fix = core.std.Expr([descale, conv], f'x y - abs {thr} < y x ?').std.PlaneStats() adapt_mask = core.adg.Mask( descale_fix, 12).std.Invert().std.Expr(f'x 0.80 - {coef} * 0.20 + 0 max 1 min') descale = core.std.MaskedMerge(descale, descale_fix, adapt_mask) # Double using eedi3+nnedi, fsrcnnx and a sharpener upscale = vdf.fsrcnnx_upscale(descale, w * 2, h * 2, r'shaders\FSRCNNX_x2_56-16-4-1.glsl', upscaler_smooth=eedi3_upscale, profile='zastin', sharpener=partial(gf.DetailSharpen, sstr=1.25, power=4)) # Antialiasing by eedi3 aa_strong = sraa_eedi3(upscale, 13, alpha=0.3, beta=0.5, gamma=40) aa = aa_strong # Rescale to 1080p with Bicubic b=0, c=0 AKA Hermite down = muvf.SSIM_downsample(aa, src.width, src.height, filter_param_a=0, filter_param_b=0) upscale = depth(core.std.MaskedMerge(y32, down, lineart), 16) merged = vdf.merge_chroma(upscale, out) out = merged # Deband with prefilter y = get_y(out) detail_light_mask = lvf.denoise.detail_mask(y, brz_a=2500, brz_b=1200) pf = iterate(out, core.std.Maximum, 2).std.Convolution([10] * 9, planes=0) diff = core.std.MakeDiff(out, pf) deband = core.f3kdb.Deband(pf, 17, 36, 36, 36, 12, 12, 2, keep_tv_range=True, output_depth=16) deband = core.std.MergeDiff(deband, diff) deband = core.std.MaskedMerge(deband, out, detail_light_mask) out = deband # Regraining grain = adptvgrnMod(out, 0.25, 0.15, size=out.height / h, sharp=80, luma_scaling=10, static=True) out = grain return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2])
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut src = depth(src, 16) out = src h = 720 w = get_w(h) fixedges = awf.bbmod(out, 2, 2, 2, 2, 64 << 8, 999) out = fixedges decomb = hvf.Vinverse(out) decomb = lvf.rfs(out, decomb, [(828, 836)]) out = decomb clean = core.knlm.KNLMeansCL(out, h=0.55, a=2, d=3, device_type='gpu', device_id=0, channels='UV') clean = core.knlm.KNLMeansCL(clean, h=0.55, a=2, d=3, device_type='gpu', device_id=0, channels='Y') diff_den = core.std.MakeDiff(out, clean) out = depth(clean, 32) luma = get_y(out) line_mask = vdf.edge_detect(luma, 'FDOG', 0.05, (1, 1)) descale = core.descale.Debilinear(luma, w, h) upscale = vdf.nnedi3_upscale(descale, correct_shift=False, pscrn=1).resize.Bicubic(src.width, src.height, src_left=.5, src_top=.5) rescale = core.std.MaskedMerge(luma, upscale, line_mask) merged = vdf.merge_chroma(rescale, out) out = depth(merged, 16) moozzi = warping(out, 0.4, 4) sharp = hvf.LSFmod(moozzi, strength=95, Smode=3, Lmode=1, edgemode=1, edgemaskHQ=True) out = sharp deband_mask = lvf.denoise.detail_mask(out, brz_a=2000, brz_b=1000) deband = dbs.f3kpf(out, 17, 30, 30) deband = core.std.MaskedMerge(deband, out, deband_mask) out = deband grain_org = core.std.MergeDiff(out, diff_den) out = grain_org ref = decomb credit_mask = vdf.diff_rescale_mask(ref, mthr=40, sw=5, sh=5) credit_mask = vdf.region_mask(credit_mask, 10, 10, 10, 10).std.Inflate().std.Inflate() credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, credit_mask), [(0, 725), (31741, 33864)]) antialias = lvf.sraa(ref, 2, 13, downscaler=core.resize.Bicubic) credit = lvf.rfs(credit, core.std.MaskedMerge(out, antialias, credit_mask), [(833, 933), (1060, 1229), (1716, 1887), (2665, 2830), (4813, 4947), (8179, 8272), (13757, 13810), (20630, 20737), (20866, 20951), (21338, 21409), (21480, 21520), (24719, 24786), (24829, 24869), (28206, 28298), (28299, 28426), (33927, 34046)]) out = credit return depth(out, 10)
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut # Variables opstart, opend = 2111, 4268 edstart, edend = 31650, 33809 full_zone = [(18727, 18774), (31590, 31649), (33990, src.num_frames - 1) ] # eyecatch, episode name and next episode shabc_zone = [(edstart + 15, edstart + 1215), (edstart + 1882, edstart + 2126)] h = 720 w = get_w(h) # Bicubic sharp parts don't have bad edges edges_a = core.edgefixer.ContinuityFixer(src, *[[2, 1, 1]] * 4) edges_b = awf.bbmod(src, left=6, thresh=32, blur=200) edges = lvf.rfs(edges_a, edges_b, [(edstart + 1275, edstart + 1757)]) edges = lvf.rfs(edges, src, [(opstart, opend)] + full_zone) out = depth(edges, 32) # Denoise ref = hvf.SMDegrain(depth(get_y(out), 16), thSAD=450) denoise = hybrid_denoise(out, 0.35, 1.4, dict(a=2, d=1), dict(ref=depth(ref, 32))) out = denoise # denoise = out # Descale luma = get_y(out) lineart = vdf.edge_detect(luma, 'FDOG', 0.055, (1, 1)).std.Median().std.BoxBlur(0, 1, 1, 1, 1) descale_a = core.descale.Despline36(luma, w, h).std.SetFrameProp('descaleKernel', data='spline36') descale_b = core.descale.Debicubic(luma, w, h, 0, 1).std.SetFrameProp( 'descaleKernel', data='sharp_bicubic') descale = lvf.rfs(descale_a, descale_b, shabc_zone) # Chroma reconstruction # y_m is the assumed mangled luma. # Descale 1080p -> Bad conversion in 422 720p -> Regular 1080p 420 radius = 2 y, u, v = descale, plane(out, 1), plane(out, 2) y_m = core.resize.Point(y, 640, 720, src_left=-1).resize.Bicubic(960, 540, filter_param_a=1 / 3, filter_param_b=1 / 3) # 0.25 for 444 and 0.25 for right shifting y_m, u, v = [ c.resize.Bicubic(w, h, src_left=0.25 + 0.25, filter_param_a=0, filter_param_b=.5) for c in [y_m, u, v] ] y_fixup = core.std.MakeDiff(y, y_m) yu, yv = Regress(y_m, u, v, radius=radius, eps=1e-7) u_fixup = ReconstructMulti(y_fixup, yu, radius=radius) u_r = core.std.MergeDiff(u, u_fixup) v_fixup = ReconstructMulti(y_fixup, yv, radius=radius) v_r = core.std.MergeDiff(v, v_fixup) # -0.5 * 720/1080 = -1/3 # -1/3 for the right shift # https://forum.doom9.org/showthread.php?p=1802716#post1802716 u_r, v_r = [ c.resize.Bicubic(960, 540, src_left=-1 / 3, filter_param_a=-.5, filter_param_b=.25) for c in [u_r, v_r] ] upscale = vdf.fsrcnnx_upscale( descale, height=h * 2, shader_file=r'shaders\FSRCNNX_x2_56-16-4-1.glsl', upscaler_smooth=eedi3_upscale, profile='zastin') antialias = sraa_eedi3(upscale, 3, alpha=0.2, beta=0.4, gamma=40, nrad=3, mdis=20) downscale = muvf.SSIM_downsample(antialias, src.width, src.height, filter_param_a=0, filter_param_b=0) downscale = core.std.MaskedMerge(luma, downscale, lineart) merged_a = join([downscale, u_r, v_r]) merged_b = vdf.merge_chroma(downscale, denoise) merged = lvf.rfs(merged_a, merged_b, shabc_zone) out = depth(merged, 16) warp = xvs.WarpFixChromaBlend(out, 80, 2, depth=8) out = warp dering = gf.MaskedDHA(out, rx=1.25, ry=1.25, darkstr=0.05, brightstr=1.0, maskpull=48, maskpush=140) out = dering qtgmc = hvf.QTGMC(out, Preset="Slower", InputType=1, ProgSADMask=2.0) qtgmc = vdf.fade_filter(out, out, qtgmc, edstart + 1522, edstart + 1522 + 24) qtgmc = lvf.rfs(out, qtgmc, [(edstart + 1522 + 25, edstart + 1757)]) out = qtgmc out = lvf.rfs(out, depth(denoise, 16), [(opstart, opend)]) detail_dark_mask = detail_dark_mask_func(get_y(out), brz_a=8000, brz_b=6000) detail_light_mask = lvf.denoise.detail_mask(out, brz_a=2500, brz_b=1200) detail_mask = core.std.Expr([detail_dark_mask, detail_light_mask], 'x y +').std.Median() detail_mask_grow = iterate(detail_mask, core.std.Maximum, 2) detail_mask_grow = iterate(detail_mask_grow, core.std.Inflate, 2).std.BoxBlur(0, 1, 1, 1, 1) detail_mask = core.std.Expr([get_y(out), detail_mask_grow, detail_mask], f'x {32<<8} < y z ?') deband = dumb3kdb(out, 22, 30) deband = core.std.MaskedMerge(deband, out, detail_mask) out = deband ref = get_y(out).std.PlaneStats() adgmask_a = core.adg.Mask(ref, 30) adgmask_b = core.adg.Mask(ref, 12) stgrain = sizedgrn(out, 0.1, 0.05, 1.05, sharp=80) stgrain = core.std.MaskedMerge(out, stgrain, adgmask_b) stgrain = core.std.MaskedMerge(out, stgrain, adgmask_a.std.Invert()) dygrain = sizedgrn(out, 0.2, 0.05, 1.15, sharp=80, static=False) dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a) grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain)) out = grain ref = depth(edges, 16) credit = out rescale_mask = vdf.diff_rescale_mask(ref, h, b=0, c=1, mthr=40, sw=0, sh=0) rescale_mask = vdf.region_mask(rescale_mask, *[10] * 4) rescale_mask = hvf.mt_expand_multi(rescale_mask, mode='ellipse', sw=4, sh=4).std.BoxBlur(0, 1, 1, 1, 1) credit = lvf.rfs(credit, ref, full_zone) credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, rescale_mask), [(edstart, edend)]) out = credit return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2])
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut src = depth(src, 32) h = 720 w = get_w(h) b, c = vdf.get_bicubic_params('robidoux') opstart, opend = 1392, 3788 edstart, edend = 31889, src.num_frames - 1 full_stuff = [(3801, 3908), (16203, 16358)] denoise = hybrid_denoise(src, 0.5, 2) out = denoise luma = get_y(out) line_mask = vdf.edge_detect(luma, 'FDOG', 0.05, (1, 1)) descale = core.descale.Debicubic(luma, w, h, b, c) upscale = vdf.fsrcnnx_upscale(descale, None, descale.height * 2, '_shaders/FSRCNNX_x2_56-16-4-1.glsl', core.resize.Point) upscale_smooth = vdf.nnedi3_upscale(descale, pscrn=1) upscale = lvf.rfs(upscale, upscale_smooth, [(18547, 18586)]) antialias = single_rate_antialiasing(upscale, 13, alpha=0.3, beta=0.45, gamma=320, mdis=18) scaled = muvf.SSIM_downsample(antialias, src.width, src.height, kernel='Bicubic') rescale = core.std.MaskedMerge(luma, scaled, line_mask) merged = vdf.merge_chroma(rescale, out) out = depth(merged, 16) antialias = lvf.rfs( out, lvf.sraa(out, 1.65, 9, alpha=0.3, beta=0.45, gamma=240, nrad=3, mdis=25), [(opstart + 840, opstart + 881)]) out = antialias # Slight sharp though CAS sharp = hvf.LSFmod(out, strength=75, Smode=3, Lmode=1, edgemode=1, edgemaskHQ=True) out = sharp dering = gf.HQDeringmod(out, thr=16, darkthr=0.1) out = dering warp = xvs.WarpFixChromaBlend(out, thresh=48, depth=8) out = warp preden = core.knlm.KNLMeansCL(out, d=0, a=3, h=0.6, device_type='GPU', channels='Y') deband_mask = lvf.denoise.detail_mask(preden, brz_a=2000, brz_b=800, rad=4) deband = dbs.f3kpf(out, 17, 42, 42) deband_b = placebo.deband(out, 22, 6, 2) deband = lvf.rfs(deband, deband_b, [(opstart + 1515, opstart + 1603)]) deband_c = placebo.deband(out, 17, 8, 3) import kagefunc deband_mask_c = kagefunc.retinex_edgemask(preden) deband_mask_c = iterate(deband_mask_c, core.std.Maximum, 3).std.Binarize(15000).std.Deflate() deband = lvf.rfs(deband, core.std.MaskedMerge(deband_c, deband, deband_mask_c), [(7409, 7600), (7960, 8055)]) deband = core.std.MaskedMerge(deband, out, deband_mask) out = deband adg_mask = core.adg.Mask(out.std.PlaneStats(), 20).std.Expr(f'x x {128<<8} - 0.25 * +') grain = core.grain.Add(out, 0.2, constant=True) grain = core.std.MaskedMerge(out, grain, adg_mask, 0) out = grain rescale_mask = vdf.drm(luma, b=b, c=c, sw=4, sh=4) ref, rescale_mask, src, src_ncop, src_nced = [ depth(x, 16) for x in [denoise, rescale_mask, src, JPBD_NCOP.src_cut, JPBD_NCED.src_cut] ] credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, rescale_mask), full_stuff) out = credit src_c, src_ncop, src_nced = [ c.knlm.KNLMeansCL(a=7, h=35, d=0, device_type='gpu') for c in [src, src_ncop, src_nced] ] opening_mask = vdf.dcm(out, src_c[opstart:opend + 1], src_ncop[:opend - opstart + 1], opstart, opend, 4, 4).std.Inflate() ending_mask = vdf.dcm(out, src_c[edstart:edend + 1], src_nced[:edend - edstart + 1], edstart, edend, 4, 4).std.Inflate() credit_mask = core.std.Expr([opening_mask, ending_mask], 'x y +') credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, credit_mask), [(opstart, opend), (edstart, edend)]) out = credit return depth(out, 10)
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut src = depth(src, 32) src += src[-1] h = 720 w = get_w(h) b, c = vdf.get_bicubic_params('robidoux') full_stuff = [(313, 1993), (15602, 15757), (19240, 19295)] denoise = hybrid_denoise(src, 0.5, 2) denoise_b = hybrid_denoise(src, 0.6, 7.5, bm3d_args=dict(profile1='high')) deband = lvf.rfs(denoise, denoise_b, [(4002, 4061)]) out = denoise luma = get_y(out) line_mask = vdf.edge_detect(luma, 'FDOG', 0.05, (1, 1)) descale = core.descale.Debicubic(luma, w, h, b, c) upscale = vdf.fsrcnnx_upscale(descale, None, descale.height * 2, '_shaders/FSRCNNX_x2_56-16-4-1.glsl', core.resize.Point) antialias = single_rate_antialiasing(upscale, 13, alpha=0.3, beta=0.45, gamma=320, mdis=18) scaled = muvf.SSIM_downsample(antialias, src.width, src.height, kernel='Bicubic') rescale = core.std.MaskedMerge(luma, scaled, line_mask) merged = vdf.merge_chroma(rescale, out) out = depth(merged, 16) antialias = lvf.rfs(out, _aa_extra(depth(denoise, 16)), [(2794, 2949)]) out = antialias # Slight sharp though CAS sharp = hvf.LSFmod(out, strength=75, Smode=3, Lmode=1, edgemode=1, edgemaskHQ=True) out = sharp dering = gf.HQDeringmod(out, thr=16, darkthr=0.1) out = dering warp = xvs.WarpFixChromaBlend(out, thresh=48, depth=8) out = warp preden = core.knlm.KNLMeansCL(out, d=0, a=3, h=0.6, device_type='GPU', channels='Y') deband_mask = lvf.denoise.detail_mask(preden, brz_a=2000, brz_b=800, rad=4) deband = dbs.f3kpf(out, 17, 42, 42) deband = core.std.MaskedMerge(deband, out, deband_mask) deband_b = rkt.rekt_fast( deband, lambda x: core.neo_f3kdb.Deband( x, 8, 96, 96, 96, sample_mode=1, keep_tv_range=True), 1112, 264, 184, 0) deband = lvf.rfs(deband, deband_b, [(4002, 4061)]) out = deband adg_mask = core.adg.Mask(out.std.PlaneStats(), 20).std.Expr(f'x x {128<<8} - 0.25 * +') grain = core.grain.Add(out, 0.2, constant=True) grain = core.std.MaskedMerge(out, grain, adg_mask, 0) grain_b = adptvgrnMod(grain, 0.6, size=1.85, static=False, luma_scaling=4, grain_chroma=False) grain = lvf.rfs(grain, grain_b, [(204, 2049)]) out = grain rescale_mask = vdf.drm(luma, b=b, c=c, sw=4, sh=4) ref, rescale_mask, src = [ depth(x, 16) for x in [denoise, rescale_mask, src] ] credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, rescale_mask), full_stuff) credit = lvf.rfs( credit, core.std.MaskedMerge(credit, ref, vdf.region_mask(rescale_mask, 1450, 0, 947, 0)), [(33860, 33925)]) credit = lvf.rfs(credit, src, [(0, 203), (2049, 2229), (31768, 33839)]) out = credit smooth = gf.JohnFPS(out[31888:33840], 60000, 1001) clips = [out[:31888], smooth, out[33840:]] vfr = muvf.VFRSplice(clips, 'symphogearg_01_timecode.txt') cfr = core.std.AssumeFPS(vfr, src) out = cfr return depth(out, 10)
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut src = depth(src, 16) out = src opstart, opend = 3106, 5263 h = 720 w = get_w(h) fixedges = awf.bbmod(out, 2, 2, 2, 2, 64 << 8, 999) out = fixedges decomb = hvf.Vinverse(out) decomb = lvf.rfs(out, decomb, [(10171, 10179)]) ref = decomb out = decomb clean = core.knlm.KNLMeansCL(out, h=0.55, a=2, d=3, device_type='gpu', device_id=0, channels='UV') clean = core.knlm.KNLMeansCL(clean, h=0.55, a=2, d=3, device_type='gpu', device_id=0, channels='Y') diff_den = core.std.MakeDiff(out, clean) out = depth(clean, 32) luma = get_y(out) line_mask = vdf.edge_detect(luma, 'FDOG', 0.05, (1, 1)) descale = core.descale.Debilinear(luma, w, h) upscale = vdf.nnedi3_upscale(descale, correct_shift=False, pscrn=1).resize.Bicubic(src.width, src.height, src_left=.5, src_top=.5) rescale = core.std.MaskedMerge(luma, upscale, line_mask) merged = vdf.merge_chroma(rescale, out) out = depth(merged, 16) moozzi = warping(out, 0.4, 4) sharp = hvf.LSFmod(moozzi, strength=95, Smode=3, Lmode=1, edgemode=1, edgemaskHQ=True) out = sharp deband_mask = lvf.denoise.detail_mask(out, brz_a=2000, brz_b=1000) deband = dbs.f3kpf(out, 17, 30, 30) deband = core.std.MaskedMerge(deband, out, deband_mask) out = deband grain_org = core.std.MergeDiff(out, diff_den) out = grain_org credit_mask = vdf.diff_rescale_mask(ref, mthr=40, sw=5, sh=5) credit_mask = vdf.region_mask(credit_mask, 10, 10, 10, 10).std.Inflate().std.Inflate() antialias = lvf.sraa(ref, 2, 13, downscaler=core.resize.Bicubic) credit = lvf.rfs(out, core.std.MaskedMerge(out, antialias, credit_mask), [(10178, 10248), (21423, 22764)]) out = credit src_c, ncop = [clip.std.Median() for clip in [src, JPBD_NCOP.src_cut]] opening_mask = vdf.dcm(out, src_c[opstart:opend + 1], ncop[:opend - opstart + 1], opstart, opend, 3, 3).std.Convolution([1] * 9) credit = lvf.rfs(out, core.std.MaskedMerge(out, src, opening_mask), [(opstart, opend)]) out = credit logo_mask = lvf.src('credit_mask_logo.png', out).std.Convolution([1] * 9) credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, logo_mask), [(20992, 23225)]) credit = lvf.rfs(credit, src, [(97766, src.num_frames - 1)]) out = credit return depth(out, 10)
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut src = depth(src, 32) h = 720 w = get_w(h) b, c = vdf.get_bicubic_params('robidoux') opstart, opend = 768, 3164 edstart, edend = 30571, 32728 full_stuff = [(3189, 3296), (13806, 13961)] denoise = hybrid_denoise(src, 0.5, 2) out = denoise luma = get_y(out) line_mask = vdf.edge_detect(luma, 'FDOG', 0.05, (1, 1)) descale = core.descale.Debicubic(luma, w, h, b, c) upscale = vdf.fsrcnnx_upscale(descale, None, descale.height * 2, '_shaders/FSRCNNX_x2_56-16-4-1.glsl', core.resize.Point) upscale_smooth = vdf.nnedi3_upscale(descale, pscrn=1) upscale = lvf.rfs(upscale, upscale_smooth, [(5534, 5598)]) antialias = single_rate_antialiasing(upscale, 13, alpha=0.3, beta=0.45, gamma=320, mdis=18) scaled = muvf.SSIM_downsample(antialias, src.width, src.height, kernel='Bicubic') rescale = core.std.MaskedMerge(luma, scaled, line_mask) merged = vdf.merge_chroma(rescale, out) out = depth(merged, 16) antialias = lvf.rfs( out, lvf.sraa(out, 1.65, 9, alpha=0.3, beta=0.45, gamma=240, nrad=3, mdis=25), [(opstart + 840, opstart + 881)]) out = antialias # Slight sharp though CAS sharp = hvf.LSFmod(out, strength=75, Smode=3, Lmode=1, edgemode=1, edgemaskHQ=True) out = sharp dering = gf.HQDeringmod(out, thr=16, darkthr=0.1) out = dering warp = xvs.WarpFixChromaBlend(out, thresh=48, depth=8) out = warp preden = core.knlm.KNLMeansCL(out, d=0, a=3, h=0.6, device_type='GPU', channels='Y') deband_mask = lvf.denoise.detail_mask(preden, brz_a=2000, brz_b=800, rad=4) deband = dbs.f3kpf(out, 17, 42, 42) deband_b = placebo.deband(out, 22, 6, 2) deband = lvf.rfs(deband, deband_b, [(opstart + 1515, opstart + 1603)]) deband = core.std.MaskedMerge(deband, out, deband_mask) out = deband adg_mask = core.adg.Mask(out.std.PlaneStats(), 20).std.Expr(f'x x {128<<8} - 0.25 * +') grain = core.grain.Add(out, 0.2, constant=True) grain = core.std.MaskedMerge(out, grain, adg_mask, 0) out = grain # Fix random productions errors # AAAAAAAAAAAAARGHHHHHHHHHHHHHHH WHYYYY THE STUDIO DID THIS ncop = JPBD_NCOP.src_cut ncop = lvf.rfs(ncop, depth(src, 8)[opstart:opend + 1], [(0, 79), (1035, 1037)]) rescale_mask = vdf.drm(luma, b=b, c=c, sw=4, sh=4) ref, rescale_mask, src, src_ncop, src_nced = [ depth(x, 16) for x in [denoise, rescale_mask, src, ncop, JPBD_NCED.src_cut] ] credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, rescale_mask), full_stuff) out = credit src_c, src_ncop, src_nced = [ c.knlm.KNLMeansCL(a=7, h=35, d=0, device_type='gpu') for c in [src, src_ncop, src_nced] ] opening_mask = vdf.dcm(out, src_c[opstart:opend + 1], src_ncop[:opend - opstart + 1], opstart, opend, 4, 4).std.Inflate() ending_mask = vdf.dcm(out, src_c[edstart:edend + 1], src_nced[:edend - edstart + 1], edstart, edend, 4, 4).std.Inflate() credit_mask = core.std.Expr([opening_mask, ending_mask], 'x y +') credit_mask = core.std.FreezeFrames(credit_mask, opstart + 1685, opstart + 1699, opstart + 1684) credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, credit_mask), [(opstart, opend), (edstart, edend)]) out = credit return depth(out, 10)
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut h = 720 w = get_w(h) fixedges = lvf.ef(src, [2, 1, 1]) out = depth(fixedges, 16) denoise = hybrid_denoise(out, 0.65, 3) denoise_b = hybrid_denoise(out, 0.3, 1) denoise_c = hvf.KNLMeansCL(out, 5, 3, 6, 2, device_type='gpu', device_id=0) denoise = lvf.rfs(denoise, denoise_b, [(75124, 82725)]) denoise = vdf.fade_filter(denoise, denoise, denoise_c, 82726, 82790) denoise = lvf.rfs(denoise, denoise_c, [(82791, src.num_frames - 1)]) diff = core.std.MakeDiff(out, denoise) out = denoise luma = get_y(out) line_mask = vdf.edge_detect(luma, 'FDOG', 7000, (1, 1)) line_mask = iterate(line_mask, core.std.Median, 4) # Not FSRCNNX this time )^: descale = depth(core.descale.Debilinear(depth(luma, 32), w, h), 16) upscale = lvf.sraa(descale, 2, 3, src.width, src.height, _ssim_downsample, alpha=0.2, beta=0.6, gamma=400, nrad=2, mdis=15) rescaled = core.std.MaskedMerge(luma, upscale, line_mask) out = vdf.merge_chroma(rescaled, out) # Slight sharp though CAS sharp = hvf.LSFmod(out, strength=75, Smode=3, Lmode=2, edgemode=1, edgemaskHQ=True) out = sharp deband_mask = lvf.denoise.detail_mask(out, brz_a=2000, brz_b=1200) deband = dbs.f3kpf(out, 16, 30, 30) deband = core.std.MaskedMerge(deband, out, deband_mask) out = deband avg = out.std.PlaneStats() adg_mask16 = core.adg.Mask(avg, 16) grain_hi = core.std.MergeDiff(out, diff) grain_hi = core.std.Merge(grain_hi, out, [0, 0.5]) # Half the grain on chroma planes grain_hi = core.std.MaskedMerge(out, grain_hi, core.adg.Mask(avg, 6)) grain_lo = core.neo_f3kdb.Deband(out, preset='depth', grainy=24, keep_tv_range=True) grain_lo = core.std.MaskedMerge(grain_lo, grain_hi, core.adg.Mask(avg, 14)) grain_b = core.std.MaskedMerge(out, out.grain.Add(0.1, constant=True), adg_mask16) grain = lvf.rfs(grain_hi, grain_lo, [(0, 16168), (24078, 41084), (63274, 75123)]) grain = lvf.rfs(grain, grain_b, [(75124, 82725)]) # Credits deband_c = placebo.deband(sharp, 17, 6, 3, 0) grain_c = core.std.MaskedMerge(deband_c, deband_c.grain.Add(6.5, constant=True), adg_mask16) grain = lvf.rfs(grain, grain_c, [(82791, src.num_frames - 1)]) grain = vdf.fade_filter(grain, grain, grain_c, 82726, 82790) out = grain return depth(out, 10)
def do_filter(): src = JPBD.src_cut fixedges = lvf.ef(src, [2, 1, 1]) fixedges = depth(fixedges, 16) out = fixedges h = 720 w = get_w(h) kernel = 'bilinear' denoise = CoolDegrain(out, tr=1, thsad=24, blksize=8, overlap=4, plane=4) out = denoise luma = get_y(out) line_mask = vdf.edge_detect(luma, 'FDOG', 0.05, (1, 1)) descale = kgf.get_descale_filter(kernel)(depth(luma, 32), w, h) rescale = vdf.fsrcnnx_upscale(depth(descale, 16), None, src.height, 'shaders/FSRCNNX_x2_56-16-4-1.glsl', partial(muvf.SSIM_downsample, kernel='Bicubic')) rescale = core.std.MaskedMerge(luma, rescale, line_mask) merged = vdf.merge_chroma(rescale, out) out = depth(merged, 16) # Slight sharp though CAS sharp = hvf.LSFmod(out, strength=95, Smode=3, Lmode=1, edgemode=1, edgemaskHQ=True) out = sharp dering = gf.HQDeringmod(out, thr=16, darkthr=0.1) out = dering warp = xvs.WarpFixChromaBlend(out, thresh=36, depth=6) out = warp deband_mask = lvf.denoise.detail_mask(out, brz_a=2500, brz_b=1500) deband = dbs.f3kpf(out, 17, 36, 36) deband = core.std.MaskedMerge(deband, out, deband_mask) out = deband grain = placebo.deband(out, iterations=0, grain=6, chroma=False) grain_mask = core.adg.Mask(out.std.PlaneStats(), 14).std.Expr(f'x x {128<<8} - 0.25 * +') grain = core.std.MaskedMerge(out, grain, grain_mask) out = grain rescale_mask = vdf.drm(luma, h, kernel, sw=4, sh=4) ref = fixedges credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, rescale_mask, 0), [(12805, src.num_frames-1)]) out = credit return depth(out, 10)
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut src = depth(src, 16) out = src if out.num_frames < 34046: while out.num_frames != 34046: out += out[-1] opstart, opend = 0, 2157 h = 720 w = get_w(h) fixedges = awf.bbmod(out, 2, 2, 2, 2, 64<<8, 999) out = fixedges decomb = hvf.Vinverse(out) decomb = lvf.rfs(out, decomb, [(2187, 2195)]) ref = decomb out = decomb from adptvgrnMod import adptvgrnMod first_denoise = hybrid_denoise(out, 0.35, 1.5) regrain = adptvgrnMod(first_denoise, 0.275, 0.175, 1.25, 45) regrain = lvf.rfs(out, regrain, [(28691, 28818)]) out = regrain clean = core.knlm.KNLMeansCL(out, h=0.55, a=2, d=3, device_type='gpu', device_id=0, channels='UV') clean = core.knlm.KNLMeansCL(clean, h=0.55, a=2, d=3, device_type='gpu', device_id=0, channels='Y') diff_den = core.std.MakeDiff(out, clean) out = depth(clean, 32) luma = get_y(out) line_mask = vdf.edge_detect(luma, 'FDOG', 0.05, (1, 1)) descale = core.descale.Debilinear(luma, w, h) upscale = vdf.nnedi3_upscale(descale, correct_shift=False, pscrn=1).resize.Bicubic(src.width, src.height, src_left=.5, src_top=.5) rescale = core.std.MaskedMerge(luma, upscale, line_mask) merged = vdf.merge_chroma(rescale, out) out = depth(merged, 16) moozzi = warping(out, 0.4, 4) sharp = hvf.LSFmod(moozzi, strength=95, Smode=3, Lmode=1, edgemode=1, edgemaskHQ=True) out = sharp deband_mask = lvf.denoise.detail_mask(out, brz_a=2000, brz_b=1000) deband = dbs.f3kpf(out, 17, 30, 30) deband = core.std.MaskedMerge(deband, out, deband_mask) out = deband grain_org = core.std.MergeDiff(out, diff_den) out = grain_org credit_mask = vdf.diff_rescale_mask(ref, mthr=40, sw=5, sh=5) credit_mask = vdf.region_mask(credit_mask, 10, 10, 10, 10).std.Inflate().std.Inflate() antialias = lvf.sraa(ref, 2, 13, downscaler=core.resize.Bicubic) credit = lvf.rfs(out, core.std.MaskedMerge(out, antialias, credit_mask), [(2188, 2305), (33926, src.num_frames-1)]) credit = lvf.rfs(credit, core.std.MaskedMerge(out, ref, credit_mask), [(31684, 33925)]) out = credit src_c, ncop = [clip.std.Median() for clip in [src, JPBD_NCOP.src_cut]] opening_mask = vdf.dcm(out, src_c[opstart:opend+1], ncop[:opend-opstart+1], opstart, opend, 3, 3) credit_mask = opening_mask.std.Convolution([1]*9) credit = lvf.rfs(out, core.std.MaskedMerge(out, src, credit_mask), [(opstart, opend)]) out = credit return depth(out, 10)
def do_filter(): """Vapoursynth filtering""" # Source and dithering src = JPBD.src_cut src = depth(src, 16) out = src # Variables opstart, opend = 17310, 19468 edstart, edend = 31889, src.num_frames - 1 h = 846 w = get_w(h) cubic_filters = ['catrom', 'mitchell', 'robidoux', 'robidoux sharp'] cubic_filters = [vdf.get_bicubic_params(cf) for cf in cubic_filters] # Remove the dynamic grain degrain = hybrid_denoise(out, 0.35, 1.2, dict(a=2, d=1)) out = degrain y = get_y(out) y32 = depth(y, 32) lineart = vdf.edge_detect(y32, 'kirsch', 0.055, (1, 1)).std.Median().std.Inflate() # Use multiple descaling kernel for a sharper result descale_clips = [ core.descale.Debicubic(y32, w, h, b, c) for b, c in cubic_filters ] descale = core.std.Expr(descale_clips, 'x y z a min min min x y z max max min') # Fix descaling artifacts (yes even for catrom there's still artifacts) conv = core.std.Convolution(descale, [1, 2, 1, 2, 0, 2, 1, 2, 1]) thr, coef = 0.013, 3.2 descale_fix = core.std.Expr([descale, conv], f'x y - abs {thr} < y x ?').std.PlaneStats() adapt_mask = core.adg.Mask( descale_fix, 12).std.Invert().std.Expr(f'x 0.80 - {coef} * 0.20 + 0 max 1 min') descale = core.std.MaskedMerge(descale, descale_fix, adapt_mask) # Double using eedi3+nnedi, fsrcnnx and a sharpener upscale = vdf.fsrcnnx_upscale(descale, w * 2, h * 2, r'shaders\FSRCNNX_x2_56-16-4-1.glsl', upscaler_smooth=eedi3_upscale, profile='zastin', sharpener=partial(gf.DetailSharpen, sstr=1.25, power=4)) # Antialiasing by eedi3 aa_strong = sraa_eedi3(upscale, 13, alpha=0.3, beta=0.5, gamma=40) aa = aa_strong # Rescale to 1080p with Bicubic b=0, c=0 AKA Hermite down = muvf.SSIM_downsample(aa, src.width, src.height, filter_param_a=0, filter_param_b=0) upscale = depth(core.std.MaskedMerge(y32, down, lineart), 16) merged = vdf.merge_chroma(upscale, out) out = merged # Very bad halo dehalo = rkt.rekt_fast(out, lambda x: gf.MaskedDHA(x, rx=4.5, ry=4.5, darkstr=0.05, brightstr=1.0, maskpull=48, maskpush=140), left=620, right=440, top=200, bottom=176) mask_halo = get_y(out.std.MakeDiff(dehalo, 0)).rgvs.RemoveGrain(2).std.Median() mask_halo = core.hist.Luma(mask_halo).std.Binarize( 33000).std.Maximum().std.Inflate() mask_halo = vdf.region_mask(mask_halo, left=630, right=440, top=200, bottom=176) blur_dehalo = core.std.BoxBlur(dehalo, hradius=1, vradius=1) dehalo = core.std.MaskedMerge(dehalo, blur_dehalo, mask_halo) out = lvf.rfs(out, dehalo, [(15936, 15973)]) # Deband with prefilter y = get_y(out) detail_light_mask = lvf.denoise.detail_mask(y, brz_a=2500, brz_b=1200) pf = iterate(out, core.std.Maximum, 2).std.Convolution([10] * 9, planes=0) diff = core.std.MakeDiff(out, pf) deband = core.f3kdb.Deband(pf, 17, 36, 36, 36, 12, 12, 2, keep_tv_range=True, output_depth=16) deband = core.std.MergeDiff(deband, diff) deband = core.std.MaskedMerge(deband, out, detail_light_mask) out = deband # Ending part ref = degrain pfed = ref.std.Median().std.Convolution([1] * 9, planes=0) diff_ed = core.std.MakeDiff(ref, pfed) deband_ed = core.f3kdb.Deband(pfed, 22, 30, 30, 30, 32, 32, 2, keep_tv_range=True, output_depth=16) deband_ed = core.std.MergeDiff(deband_ed, diff_ed) out = lvf.rfs(out, deband_ed, [(edstart, edend)]) # Regraining grain = adptvgrnMod(out, 0.25, 0.15, size=out.height / h, sharp=80, luma_scaling=10, static=True) out = grain # Restore 1080p stuff ref = src rescale_mask = vdf.drm(ref, h, mthr=65, sw=4, sh=4) credit = out credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, rescale_mask, 0), [(opstart, opend), (3917, 4024)]) out = credit return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2])
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut src += src[-1] ep10 = JPBD_10.src_cut h = 720 w = get_w(h) b, c = vdf.get_bicubic_params('robidoux') opstart, opend = 2973, 5370 edstart, edend = 31887, src.num_frames - 1 opstart_ep10, opend_ep10 = 768, 3164 full_stuff = [(5449, 5580), (16465, 16620)] # Fix compositing error in the OP op_src, op_10 = src[opstart:opend + 1], ep10[opstart_ep10:opend_ep10 + 1] fix = lvf.rfs(op_src, op_10, [(0, 79), (1035, 1037)]) fix_src = insert_clip(src, fix, opstart) src = depth(fix_src, 32) denoise = hybrid_denoise(src, 0.5, 2) out = denoise luma = get_y(out) line_mask = vdf.edge_detect(luma, 'FDOG', 0.05, (1, 1)) descale = core.descale.Debicubic(luma, w, h, b, c) upscale = vdf.fsrcnnx_upscale(descale, None, descale.height * 2, '_shaders/FSRCNNX_x2_56-16-4-1.glsl', core.resize.Point) antialias = single_rate_antialiasing(upscale, 13, alpha=0.3, beta=0.45, gamma=320, mdis=18) scaled = muvf.SSIM_downsample(antialias, src.width, src.height, kernel='Bicubic') rescale = core.std.MaskedMerge(luma, scaled, line_mask) merged = vdf.merge_chroma(rescale, out) out = depth(merged, 16) antialias = lvf.rfs( out, lvf.sraa(out, 1.65, 9, alpha=0.3, beta=0.45, gamma=240, nrad=3, mdis=25), [(opstart + 840, opstart + 881)]) out = antialias # Slight sharp though CAS sharp = hvf.LSFmod(out, strength=75, Smode=3, Lmode=1, edgemode=1, edgemaskHQ=True) out = sharp dering = gf.HQDeringmod(out, thr=16, darkthr=0.1) out = dering warp = xvs.WarpFixChromaBlend(out, thresh=48, depth=8) out = warp preden = core.knlm.KNLMeansCL(out, d=0, a=3, h=0.6, device_type='GPU', channels='Y') deband_mask = lvf.denoise.detail_mask(preden, brz_a=2000, brz_b=800, rad=4) deband = dbs.f3kpf(out, 17, 42, 42) deband_b = placebo.deband(out, 22, 6, 2) deband = lvf.rfs(deband, deband_b, [(opstart + 1515, opstart + 1603)]) deband_c = placebo.deband(deband, 17, 5, 1) deband_c = dbs.f3kbilateral(deband_c, 22, 64, 64) deband = lvf.rfs(deband, deband_c, [(15612, 15695)]) deband_mask2 = vdf.edge_detect( out.knlm.KNLMeansCL(d=2, a=2, h=0.4, device_type='GPU', channels='Y'), 'FDOG', 1100, (8, 1)) deband_mask2 = iterate(deband_mask2, core.std.Deflate, 4) deband_d = placebo.deband(out, 16, 12, 3) deband_d = core.std.MaskedMerge(deband_d, out, deband_mask2) deband = lvf.rfs(deband, deband_d, [(16339, 16542)]) deband = core.std.MaskedMerge(deband, out, deband_mask) out = deband adg_mask = core.adg.Mask(out.std.PlaneStats(), 20).std.Expr(f'x x {128<<8} - 0.25 * +') grain = core.grain.Add(out, 0.2, constant=True) grain = core.std.MaskedMerge(out, grain, adg_mask, 0) out = grain rescale_mask = vdf.drm(luma, b=b, c=c, sw=4, sh=4) ref, rescale_mask, src, src_ncop, src_nced = [ depth(x, 16) for x in [denoise, rescale_mask, src, JPBD_NCOP.src_cut, JPBD_NCED.src_cut] ] credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, rescale_mask), full_stuff) out = credit src_c, src_ncop, src_nced = [ c.knlm.KNLMeansCL(a=7, h=35, d=0, device_type='gpu') for c in [src, src_ncop, src_nced] ] opening_mask = vdf.dcm(out, src_c[opstart:opend + 1], src_ncop[:opend - opstart + 1], opstart, opend, 4, 4).std.Inflate() ending_mask = vdf.dcm(out, src_c[edstart:edend + 1], src_nced[:edend - edstart + 1], edstart, edend, 4, 4).std.Inflate() credit_mask = core.std.Expr([opening_mask, ending_mask], 'x y +') credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, credit_mask), [(opstart, opend), (edstart, edend)]) out = credit return depth(out, 10)
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut out = depth(src, 32) # Variables h = 900 w = get_w(h) ref = hvf.SMDegrain(depth(out, 16), thSAD=250) denoise = mvf.BM3D(out, [1, 0.75], radius2=1, ref=depth(ref, 32)) out = denoise y = get_y(out) lineart = vdf.edge_detect(y, 'FDOG', 0.085, (1, 2)).std.Median().std.Convolution([*[1]*9]) descale = core.descale.Despline36(y, w, h) upscale = eedi3_upscale(descale) antialias = sraa_eedi3(upscale, 9) downscale = muvf.SSIM_downsample(antialias, src.width, src.height, filter_param_a=-0.5, filter_param_b=0.25) downscale = core.std.MaskedMerge(y, downscale, lineart) merged = vdf.merge_chroma(downscale, out) out = depth(merged, 16) sharp = hvf.LSFmod(out, strength=40, Smode=3, Lmode=1, edgemode=1, edgemaskHQ=True) out = sharp detail_light_mask = lvf.denoise.detail_mask(out, brz_a=2500, brz_b=1200) deband = dumb3kdb(out, 17, 36) deband_b = dumb3kdb(out, 24, 64) deband = lvf.rfs(deband, deband_b, [(25600, 25691), (30867, 30938)]) deband = core.std.MaskedMerge(deband, out, detail_light_mask) out = deband ref = get_y(out).std.PlaneStats() adgmask_a = core.adg.Mask(ref, 30) adgmask_b = core.adg.Mask(ref, 12) stgrain = sizedgrn(out, 0.125, 0.075, 1.15, sharp=80) stgrain = core.std.MaskedMerge(out, stgrain, adgmask_b) stgrain = core.std.MaskedMerge(out, stgrain, adgmask_a.std.Invert()) dygrain = sizedgrn(out, 0.3, 0.15, 1.2, sharp=80, static=False) dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a) grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain)) out = grain ref = depth(src, 16) rescale_mask = vdf.drm(ref, h, 'spline36', mthr=50, sw=4, sh=4) credit = out credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, rescale_mask, 0), [(3032, 4101), (4290, 5284), (35677, 37282)]) credit = lvf.rfs(credit, ref, [(17688, 17783), (37695, src.num_frames-1)]) out = credit return depth(out, 10).std.Limiter(16<<2, [235<<2, 240<<2])
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut src = depth(src, 32) h = 720 w = get_w(h) b, c = vdf.get_bicubic_params('robidoux') full_stuff = [(0, 1310), (15484, 15639)] denoise = hybrid_denoise(src, 0.5, 2) out = denoise luma = get_y(out) line_mask = vdf.edge_detect(luma, 'FDOG', 0.05, (1, 1)) descale = core.descale.Debicubic(luma, w, h, b, c) upscale = vdf.fsrcnnx_upscale(descale, None, descale.height * 2, '_shaders/FSRCNNX_x2_56-16-4-1.glsl', core.resize.Point) upscale_smooth = vdf.nnedi3_upscale(descale, pscrn=1) upscale = lvf.rfs(upscale, upscale_smooth, [(5534, 5598)]) antialias = single_rate_antialiasing(upscale, 13, alpha=0.3, beta=0.45, gamma=320, mdis=18) scaled = muvf.SSIM_downsample(antialias, src.width, src.height, kernel='Bicubic') rescale = core.std.MaskedMerge(luma, scaled, line_mask) merged = vdf.merge_chroma(rescale, out) out = depth(merged, 16) # Slight sharp though CAS sharp = hvf.LSFmod(out, strength=75, Smode=3, Lmode=1, edgemode=1, edgemaskHQ=True) out = sharp dering = gf.HQDeringmod(out, thr=16, darkthr=0.1) out = dering warp = xvs.WarpFixChromaBlend(out, thresh=48, depth=8) out = warp preden = core.knlm.KNLMeansCL(out, d=0, a=3, h=0.6, device_type='GPU', channels='Y') deband_mask = lvf.denoise.detail_mask(preden, brz_a=2000, brz_b=800, rad=4) deband = dbs.f3kpf(out, 17, 42, 42) deband = core.std.MaskedMerge(deband, out, deband_mask) out = deband adg_mask = core.adg.Mask(out.std.PlaneStats(), 20).std.Expr(f'x x {128<<8} - 0.25 * +') grain = core.grain.Add(out, 0.2, constant=True) grain = core.std.MaskedMerge(out, grain, adg_mask, 0) out = grain rescale_mask = vdf.drm(luma, b=b, c=c, sw=4, sh=4) ref, rescale_mask, src = [ depth(x, 16) for x in [denoise, rescale_mask, src] ] credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, rescale_mask), full_stuff) credit = lvf.rfs(credit, src, [(31707, 33937)]) out = credit smooth = gf.JohnFPS(out[31707:33937 + 1], 60000, 1001) clips = [out[:31707], smooth, out[33937 + 1:]] vfr = muvf.VFRSplice(clips, 'symphogearg_13_timecode.txt') cfr = core.std.AssumeFPS(vfr, src) out = cfr return depth(out, 10)
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut # Variables h = 720 w = get_w(h) edges = core.edgefixer.ContinuityFixer(src, *[[2, 1, 1]] * 4) out = depth(edges, 32) ref = hvf.SMDegrain(depth(get_y(out), 16), thSAD=450) denoise = hybrid_denoise(out, 0.35, 1.75, dict(a=2, d=1), dict(ref=depth(ref, 32))) out = denoise y = get_y(out) lineart = vdf.edge_detect(y, 'FDOG', 0.055, (1, 1)).std.Median().std.Convolution([*[1] * 9]) descale = core.descale.Debilinear(y, w, h) upscale = vdf.fsrcnnx_upscale( descale, height=h * 2, shader_file=r'shaders\FSRCNNX_x2_56-16-4-1.glsl', upscaler_smooth=eedi3_upscale, profile='slow', strength=85) antialias = sraa_eedi3(upscale, 9) downscale = muvf.SSIM_downsample(antialias, src.width, src.height, filter_param_a=0, filter_param_b=0) downscale = core.std.MaskedMerge(y, downscale, lineart) merged = vdf.merge_chroma(downscale, out) out = depth(merged, 16) detail_dark_mask = detail_dark_mask_func(get_y(out), brz_a=8000, brz_b=6000) detail_light_mask = lvf.denoise.detail_mask(out, brz_a=2500, brz_b=1200) detail_mask = core.std.Expr([detail_dark_mask, detail_light_mask], 'x y +').std.Median() detail_mask_grow = iterate(detail_mask, core.std.Maximum, 2) detail_mask_grow = iterate(detail_mask_grow, core.std.Inflate, 2).std.Convolution([*[1] * 9]) detail_mask = core.std.Expr([get_y(out), detail_mask_grow, detail_mask], f'x {32<<8} < y z ?') deband = dumb3kdbv2(out, 22, 24) deband = core.std.MaskedMerge(deband, out, detail_mask) out = deband ref = get_y(out).std.PlaneStats() adgmask_a = core.adg.Mask(ref, 30) adgmask_b = core.adg.Mask(ref, 12) stgrain = sizedgrn(out, 0.1, 0.05, 1.05, sharp=80) stgrain = core.std.MaskedMerge(out, stgrain, adgmask_b) stgrain = core.std.MaskedMerge(out, stgrain, adgmask_a.std.Invert()) dygrain = sizedgrn(out, 0.2, 0.05, 1.15, sharp=80, static=False) dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a) grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain)) out = grain return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2])
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut # Variables opstart, opend = 2038, 4196 eptitle_s, eptitle_e = 4197, 4316 edstart, edend = 31530, 33687 preview_s, preview_e = 33688, src.num_frames - 1 h = 720 w = get_w(h) edges = core.edgefixer.ContinuityFixer(src, *[[2, 1, 1]] * 4) out = depth(edges, 32) ref = hvf.SMDegrain(depth(get_y(out), 16), thSAD=450) denoise = hybrid_denoise(out, 0.35, 1.75, dict(a=2, d=1), dict(ref=depth(ref, 32))) out = denoise y = get_y(out) lineart = vdf.edge_detect(y, 'FDOG', 0.055, (1, 1)).std.Median().std.Convolution([*[1] * 9]) descale = core.descale.Debilinear(y, w, h) upscale = vdf.fsrcnnx_upscale( descale, height=h * 2, shader_file=r'shaders\FSRCNNX_x2_56-16-4-1.glsl', upscaler_smooth=eedi3_upscale, profile='slow', strength=85) antialias = sraa_eedi3(upscale, 9) downscale = muvf.SSIM_downsample(antialias, src.width, src.height, filter_param_a=0, filter_param_b=0) downscale = core.std.MaskedMerge(y, downscale, lineart) merged = vdf.merge_chroma(downscale, out) merged = lvf.rfs(merged, out, [(opstart, opend), (eptitle_s, eptitle_e), (preview_s, preview_e)]) out = depth(merged, 16) detail_dark_mask = detail_dark_mask_func(get_y(out), brz_a=8000, brz_b=6000) detail_light_mask = lvf.denoise.detail_mask(out, brz_a=2500, brz_b=1200) detail_mask = core.std.Expr([detail_dark_mask, detail_light_mask], 'x y +').std.Median() detail_mask_grow = iterate(detail_mask, core.std.Maximum, 2) detail_mask_grow = iterate(detail_mask_grow, core.std.Inflate, 2).std.Convolution([*[1] * 9]) detail_mask = core.std.Expr([get_y(out), detail_mask_grow, detail_mask], f'x {32<<8} < y z ?') deband = dumb3kdbv2(out, 22, 24) deband = core.std.MaskedMerge(deband, out, detail_mask) deband_b = dumb3kdbv2(out, 24, 64) deband_b = core.std.MaskedMerge(deband_b, out, detail_light_mask) deband = lvf.rfs(deband, deband_b, [(opstart + 414, opstart + 496)]) out = deband ref = get_y(out).std.PlaneStats() adgmask_a = core.adg.Mask(ref, 30) adgmask_b = core.adg.Mask(ref, 12) stgrain = sizedgrn(out, 0.1, 0.05, 1.05, sharp=80) stgrain = core.std.MaskedMerge(out, stgrain, adgmask_b) stgrain = core.std.MaskedMerge(out, stgrain, adgmask_a.std.Invert()) dygrain = sizedgrn(out, 0.2, 0.05, 1.15, sharp=80, static=False) dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a) grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain)) out = grain ref = depth(src, 16) rescale_mask = vdf.drm(ref, 720, 'bilinear', mthr=30, sw=0, sh=0) rescale_mask = vdf.region_mask(rescale_mask, *[10] * 4) rescale_mask = hvf.mt_expand_multi(rescale_mask, mode='ellipse', sw=4, sh=4) rescale_mask = rescale_mask.std.Binarize(scale_value( 100, 8, 16)).std.Inflate().std.Convolution([*[1] * 9]) credit = out credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, rescale_mask, 0), [(8993, 9066), (20104, 20223), (edstart, edend)]) out = credit return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2])
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut # src += src[-1] src = depth(src, 16) out = src opstart, opend = 480, 2637 edstart, edend = 32249, 34405 # Remove the noise ref = hvf.SMDegrain(out, tr=1, thSAD=300, plane=4) denoise = mvf.BM3D(out, sigma=[2, 1], radius1=1, ref=ref) out = denoise # Limited antialiasing y = get_y(out) lineart = core.std.Sobel(y).std.Binarize(75<<8).std.Maximum().std.Inflate() aa = lvf.sraa(y, 2, 13, downscaler=partial(core.resize.Bicubic, filter_param_a=-0.5, filter_param_b=0.25)) sharp = hvf.LSFmod(aa, strength=70, Smode=3, edgemode=0, source=y) y = core.std.MaskedMerge(y, sharp, lineart) out = vdf.merge_chroma(y, out) # Deband masks planes = split(out) preden = core.dfttest.DFTTest(out, sigma=14.0, sigma2=10.0, sbsize=1, sosize=0).rgvs.RemoveGrain(3) grad_mask, yrangebig = morpho_mask(preden) rgb = core.resize.Bicubic(preden, 960, 540, format=vs.RGB48).std.SetFrameProp('_Matrix', delete=True) chroma_masks = [core.std.Prewitt(p).std.Binarize(5500).rgvs.RemoveGrain(11) for p in split(rgb) + split(preden)[1:]] chroma_mask = core.std.Expr(chroma_masks, 'x y + z + a + b +').std.Maximum() chroma_mask = core.std.Merge(chroma_mask, chroma_mask.std.Minimum()).std.BoxBlur(0, 1, 1, 1, 1) fdogmask = vdf.edge_detect(preden.std.Median(), 'FDOG', 8250, (4, 1)).std.BoxBlur(0, 2, 1, 2, 1) detail_mask = lvf.denoise.detail_mask(planes[0].std.BoxBlur(0, 1, 1, 1, 1), brz_a=3300, brz_b=2000) # Debanding stages debands = [None] * 3 deband_y_strong = dbs.f3kbilateral(planes[0], 16, 65) deband_y_normal = dumb3kdb(planes[0], 16, 36) deband_y_light = core.std.MaskedMerge(dumb3kdb(planes[0], 14, 32), planes[0], detail_mask) debands[1] = dbs.f3kbilateral(planes[1], 12, 50) debands[2] = dbs.f3kbilateral(planes[2], 12, 50) debands[0] = core.std.MaskedMerge(deband_y_strong, deband_y_normal, grad_mask) debands[0] = core.std.MaskedMerge(debands[0], deband_y_light, yrangebig) debands[1], debands[2] = [core.std.MaskedMerge(debands[i], planes[i], chroma_mask) for i in range(1, 3)] deband = join(debands) deband = lvf.rfs(deband, core.std.MaskedMerge(dbs.f3kbilateral(out, 20, 97), out, fdogmask), [(opstart+2019, opstart+2036), (opstart+1504, opstart+1574)]) out = deband # Regraining ref = get_y(out).std.PlaneStats() adgmask_a = core.adg.Mask(ref, 25) adgmask_b = core.adg.Mask(ref, 10) stgrain_a = core.grain.Add(out, 0.1, 0, seed=333) stgrain_a = core.std.MaskedMerge(out, stgrain_a, adgmask_b.std.Invert()) stgrain_b = sizedgrn(out, 0.2, 0.1, 1.15, sharp=80, 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, seed=333) dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a) grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain)) out = grain # Credits OP and ED ref = src src_ncop, src_nced = [depth(c, 16) for c in [JPBD_NCOP.src_cut, JPBD_NCED.src_cut]] src_c, src_ncop, src_nced = [c.std.BoxBlur(0, 2, 1, 2, 1) for c in [src, src_ncop, src_nced]] opening_mask = vdf.dcm(out, src_c[opstart:opend+1], src_ncop[:opend-opstart+1], opstart, opend, 2, 2) ending_mask = vdf.dcm(out, src_c[edstart:edend+1], src_nced[:edend-edstart+1], edstart, edend, 2, 2) credit_mask = core.std.Expr([opening_mask, ending_mask], 'x y +').std.Inflate() credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, credit_mask), [(opstart, opend), (edstart, edend)]) out = credit # Fix letterboxes ending crop = core.std.Crop(out, 0, 0, 132, 132).edgefixer.ContinuityFixer(0, 1, 0, 0) crop = core.std.AddBorders(crop, 0, 0, 132, 132) out = lvf.rfs(out, crop, [(edstart, edend)]) return depth(out, 10).std.Limiter(16<<2, [235<<2, 240<<2], [0, 1, 2])
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut # Variables opstart, opend = 6161, 8319 eptitle_s, eptitle_e = 8320, 8439 edstart, edend = 31170, 33326 preview_s, preview_e = 33687, src.num_frames - 1 h = 720 w = get_w(h) edges = core.edgefixer.ContinuityFixer(src, *[[2, 1, 1]] * 4) out = depth(edges, 32) ref = hvf.SMDegrain(depth(get_y(out), 16), thSAD=450) denoise = hybrid_denoise(out, 0.35, 1.75, dict(a=2, d=1), dict(ref=depth(ref, 32))) out = denoise y = get_y(out) lineart = vdf.edge_detect(y, 'FDOG', 0.055, (1, 1)).std.Median().std.Convolution([*[1] * 9]) descale = core.descale.Debilinear(y, w, h) upscale = vdf.fsrcnnx_upscale( descale, height=h * 2, shader_file=r'shaders\FSRCNNX_x2_56-16-4-1.glsl', upscaler_smooth=eedi3_upscale, profile='slow', strength=85) antialias = sraa_eedi3(upscale, 9) downscale = muvf.SSIM_downsample(antialias, src.width, src.height, filter_param_a=0, filter_param_b=0) downscale = core.std.MaskedMerge(y, downscale, lineart) merged = vdf.merge_chroma(downscale, out) merged = lvf.rfs(merged, out, [(opstart, opend), (eptitle_s, eptitle_e), (preview_s, preview_e)]) out = depth(merged, 16) detail_dark_mask = detail_dark_mask_func(get_y(out), brz_a=8000, brz_b=6000) detail_light_mask = lvf.denoise.detail_mask(out, brz_a=2500, brz_b=1200) detail_mask = core.std.Expr([detail_dark_mask, detail_light_mask], 'x y +').std.Median() detail_mask_grow = iterate(detail_mask, core.std.Maximum, 2) detail_mask_grow = iterate(detail_mask_grow, core.std.Inflate, 2).std.Convolution([*[1] * 9]) detail_mask = core.std.Expr([get_y(out), detail_mask_grow, detail_mask], f'x {32<<8} < y z ?') deband = dumb3kdbv2(out, 22, 24) deband = core.std.MaskedMerge(deband, out, detail_mask) out = deband ref = get_y(out).std.PlaneStats() adgmask_a = core.adg.Mask(ref, 30) adgmask_b = core.adg.Mask(ref, 12) stgrain = sizedgrn(out, 0.1, 0.05, 1.05, sharp=80) stgrain = core.std.MaskedMerge(out, stgrain, adgmask_b) stgrain = core.std.MaskedMerge(out, stgrain, adgmask_a.std.Invert()) dygrain = sizedgrn(out, 0.2, 0.05, 1.15, sharp=80, static=False) dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a) grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain)) out = grain ref = depth(src, 16) rescale_mask = vdf.drm(ref, 720, 'bilinear', mthr=30, sw=0, sh=0) rescale_mask = vdf.region_mask(rescale_mask, *[10] * 4) rescale_mask = hvf.mt_expand_multi(rescale_mask, mode='ellipse', sw=4, sh=4) rescale_mask = rescale_mask.std.Binarize(scale_value( 100, 8, 16)).std.Inflate().std.Convolution([*[1] * 9]) dehalo_ref = gf.MaskedDHA(ref, rx=1.65, ry=1.65, darkstr=0.15, brightstr=1.0, maskpull=48, maskpush=140) dehalo_mask_a = vdf.region_mask(rescale_mask, top=650) dehalo_mask_b = vdf.region_mask(rescale_mask, right=400) credit = out dehalo_range_a = [(25, 205), (518, 612), (2090, 2172), (14449, 14537)] dehalo_range_b = [(3893, 3981)] credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, rescale_mask, 0), [(2197, 2252), (4072, 4129), (4409, 4527), (5390, 5484), (8473, 8603), (8610, 8669), (9826, 9909), (10666, 10713), (12088, 12507), (14943, 15052), (17988, 18136), (18897, 18976), (edstart, edend)] + dehalo_range_a + dehalo_range_b) credit = lvf.rfs( credit, core.std.MaskedMerge(credit, dehalo_ref, dehalo_mask_a, 0), dehalo_range_a) credit = lvf.rfs( credit, core.std.MaskedMerge(credit, dehalo_ref, dehalo_mask_b, 0), dehalo_range_b) out = credit return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2])
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut src = depth(src, 16) out = src dbzone = (14775, 14846) opstart, opend = 1200, 3356 edstart, edend = 31888, src.num_frames - 1 h = 846 w = get_w(h) cubic_filters = ['catrom', 'mitchell', 'robidoux', 'robidoux sharp'] cubic_filters = [vdf.get_bicubic_params(cf) for cf in cubic_filters] degrain = hybrid_denoise(out, 0.35, 1.2, dict(a=2, d=1)) degrain_b = hybrid_denoise(out, 0.55, 3, dict(a=2, d=1)) degrain = lvf.rfs(degrain, degrain_b, [dbzone]) out = degrain y = get_y(out) y32 = depth(y, 32) lineart = vdf.edge_detect(y32, 'kirsch', 0.055, (1, 1)).std.Median().std.Inflate() descale_clips = [ core.descale.Debicubic(y32, w, h, b, c) for b, c in cubic_filters ] descale = core.std.Expr(descale_clips, 'x y z a min min min x y z max max min') conv = core.std.Convolution(descale, [1, 2, 1, 2, 0, 2, 1, 2, 1]) thr, coef = 0.013, 3 descale_fix = core.std.Expr([descale, conv], f'x y - abs {thr} < y x ?').std.PlaneStats() adapt_mask = core.adg.Mask( descale_fix, 12).std.Invert().std.Expr(f'x 0.5 - {coef} * 0.5 + 0 max 1 min') descale = core.std.MaskedMerge(descale, descale_fix, adapt_mask) upscale = vdf.fsrcnnx_upscale(descale, w * 2, h * 2, r'shaders\FSRCNNX_x2_56-16-4-1.glsl', upscaler_smooth=eedi3_upscale, profile='zastin', sharpener=partial(gf.DetailSharpen, sstr=1.25, power=4)) aa_strong = sraa_eedi3(upscale, 13, alpha=0.3, beta=0.5, gamma=40) aa = aa_strong down = muvf.SSIM_downsample(aa, src.width, src.height, filter_param_a=0, filter_param_b=0) upscale = depth(core.std.MaskedMerge(y32, down, lineart), 16) merged = vdf.merge_chroma(upscale, out) out = merged # Very bad halo dehalo_a = gf.MaskedDHA(out, rx=2.75, ry=2.75, darkstr=0.25, brightstr=1.0, maskpull=48, maskpush=140) dehalo_a = core.std.MaskedMerge(out, dehalo_a, lvf.src('lapis_05_halomask_1.png', out)) dehalo_b = gf.MaskedDHA(out, rx=2.25, ry=2.25, darkstr=0.25, brightstr=1.0, maskpull=48, maskpush=140) dehalo = lvf.rfs(out, dehalo_a, [(11677, 11765)]) dehalo = lvf.rfs(dehalo, dehalo_b, [(20509, 20690), (21242, 21276), (25834, 25856), (26614, 26648), (26682, 26761), (27685, 27719), (27861, 27895), (27955, 28025)]) out = dehalo y = get_y(out) detail_light_mask = lvf.denoise.detail_mask(y, brz_a=2500, brz_b=1200) pf = iterate(out, core.std.Maximum, 2).std.Convolution([10] * 9, planes=0) diff = core.std.MakeDiff(out, pf) deband = core.f3kdb.Deband(pf, 17, 36, 36, 36, 12, 12, 2, keep_tv_range=True, output_depth=16) deband_b = core.f3kdb.Deband(pf, 17, 48, 48, 48, 12, 12, 2, keep_tv_range=True, output_depth=16) deband = lvf.rfs(deband, deband_b, [dbzone]) deband = core.std.MergeDiff(deband, diff) deband = core.std.MaskedMerge(deband, out, detail_light_mask) out = deband ref = degrain pfed = ref.std.Median().std.Convolution([1] * 9, planes=0) diff_ed = core.std.MakeDiff(ref, pfed) deband_ed = core.f3kdb.Deband(pfed, 22, 30, 30, 30, 32, 32, 2, keep_tv_range=True, output_depth=16) deband_ed = core.std.MergeDiff(deband_ed, diff_ed) out = lvf.rfs(out, deband_ed, [(edstart, edend)]) grain = adptvgrnMod(out, 0.25, 0.15, size=out.height / h, sharp=80, luma_scaling=10, static=True) out = grain # # Restore 1080p stuff ref = src rescale_mask = vdf.drm(ref, h, mthr=65, sw=4, sh=4) credit = out credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, rescale_mask, 0), [(opstart, opend), (3369, 3451)]) credit = lvf.rfs(credit, ref, [(18989, 19108)]) out = credit return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2])
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut src = depth(src, 16) out = src h = 900 w = get_w(h) # Remove the grain ref = hvf.SMDegrain(out, tr=1, thSAD=300, plane=4) degrain = mvf.BM3D(out, sigma=[1.5, 1], radius1=1, ref=ref) degrain = insert_clip(degrain, smhdegrain(out[5539:5670], 2, 280), 5539) degrain = insert_clip(degrain, smhdegrain(out[5933:5992], 2, 200), 5933) degrain = insert_clip(degrain, smhdegrain(out[6115:6180], 2, 200), 6115) degrain = insert_clip(degrain, smhdegrain(out[6180:6281], 2, 200), 6180) degrain = insert_clip(degrain, smhdegrain(out[39303:39482], 2, 280), 39303) degrain = insert_clip(degrain, smhdegrain(out[40391:40837], 2, 200), 40391) degrain = insert_clip(degrain, smhdegrain(out[40908:41087], 2, 280), 40908) degrain = insert_clip(degrain, smhdegrain(out[41671:41791], 2, 280), 41671) degrain = insert_clip(degrain, smhdegrain(out[41791:41977], 2, 280), 41791) degrain = insert_clip(degrain, smhdegrain(out[41977:42073], 2, 280), 41977) degrain = insert_clip(degrain, smhdegrain(out[43083:44462], 2, 350), 43083) degrain = lvf.rfs(degrain, out, [(51749, 52387)]) out = depth(degrain, 32) luma = get_y(out) line_mask = vdf.edge_detect(luma, 'kirsch', 0.075, (1, 1)).std.Median().std.Inflate() descale = core.descale.Debilinear(luma, w, h) upscale = eedi3_upscale(descale) antialias = single_rate_antialiasing(upscale, 13, alpha=0.2, beta=0.6, gamma=300, mdis=15).resize.Bicubic( src.width, src.height) rescale = core.std.MaskedMerge(luma, antialias, line_mask) merged = vdf.merge_chroma(rescale, out) out = depth(merged, 16) y = get_y(out) detail_light_mask = lvf.denoise.detail_mask(y.std.Median(), brz_a=2500, brz_b=1200) pf = out.std.Convolution([1] * 9).std.Merge(out, 0.45) diffdb = core.std.MakeDiff(out, pf) deband = dumb3kdb(pf, 16, 30) deband_b = dbs.f3kbilateral(pf, 20, 100) deband = lvf.rfs(deband, deband_b, [(43083, 44461)]) deband = core.std.MergeDiff(deband, diffdb) deband = core.std.MaskedMerge(deband, out, detail_light_mask) deband = lvf.rfs(deband, out, [(51749, 52387)]) out = deband sharp = hvf.LSFmod(out, strength=65, Smode=3, Lmode=1, edgemode=1, edgemaskHQ=True) out = sharp ref = get_y(out).std.PlaneStats() adgmask_a = core.adg.Mask(ref, 30) adgmask_b = core.adg.Mask(ref, 12) stgrain = sizedgrn(out, 0.1, 0.05, 1.00) stgrain = core.std.MaskedMerge(out, stgrain, adgmask_b) stgrain = core.std.MaskedMerge(out, stgrain, adgmask_a.std.Invert()) dygrain = sizedgrn(out, 0.2, 0.05, 1.05, sharp=60, static=False) dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a) grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain)) out = grain ref = src rescale_mask = vdf.drm(ref, h, mthr=65, sw=4, sh=4) credit = out credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, rescale_mask, 0), [(0, 2956), (43104, 45749)]) credit = lvf.rfs(credit, ref, [(45824, 50401), (52388, src.num_frames - 1)]) out = credit return depth(out, 10)
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut src = depth(src, 16) out = src edstart, edend = 31888, src.num_frames-1 shift = core.resize.Point(out, src_left=1).edgefixer.ContinuityFixer([2, 1, 1], 0, 0, 0) out = lvf.rfs(out, shift, [(235, 318)]) ref = hvf.SMDegrain(out, tr=1, thSAD=300, plane=4) denoise = mvf.BM3D(out, [1.5, 1], 1, profile1='lc', ref=ref) out = denoise y = get_y(out) lineart = vdf.edge_detect(y, 'FDOG', scale_value(0.065, 32, 16), (1, 1)).std.Median().std.BoxBlur(0, 1, 1, 1, 1) rescale = fake_rescale(y, 837.5, 1/3, 1/3, coef_dering=0.1, coef_dark=1.25, coef_warp=1.15, coef_sharp=0.75, coef_finalsharp=0.85) rescale = core.std.MaskedMerge(y, rescale, lineart) out = vdf.merge_chroma(rescale, out) preden = core.dfttest.DFTTest(get_y(out), ftype=0, sigma=0.5, sbsize=16, sosize=12, tbsize=1) detail_dark_mask = detail_dark_mask_func(preden, brz_a=6000, brz_b=5000) detail_light_mask = lvf.denoise.detail_mask(preden, brz_a=2500, brz_b=1200) detail_mask = core.std.Expr([detail_dark_mask, detail_light_mask], 'x y +').std.Median() detail_mask_grow = iterate(detail_mask, core.std.Maximum, 2) detail_mask_grow = iterate(detail_mask_grow, core.std.Inflate, 2).std.BoxBlur(0, 1, 1, 1, 1) detail_mask = core.std.Expr([preden, detail_mask_grow, detail_mask], f'x {40<<8} < y z ?') pf = vdf.merge_chroma(preden, out) deband = dumb3kdb(pf, 17, 40) deband_b = dumb3kdb(pf, 20, 80) deband = lvf.rfs(deband, deband_b, [(2194, 2216), (2283, 2306)]) deband = core.std.MergeDiff(deband, out.std.MakeDiff(pf)) deband = core.std.MaskedMerge(deband, out, detail_light_mask) out = deband grain = kgf.adaptive_grain(out, 0.35) out = grain ref = depth(src, 16) src_c, src_nced = [depth(x, 16) for x in [src, JPBD_NCED.src_cut[13:]]] ending_mask = vdf.dcm(out, src_c[edstart:edend+1], src_nced[:edend-edstart+1], edstart, edend, 2, 2).std.BoxBlur(0, 2, 2, 2, 2) credit = out credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, ending_mask), [(31900, src.num_frames-1)]) out = credit return depth(out, 10).std.Limiter(16<<2, [235<<2, 240<<2], [0, 1, 2])
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut src += src[-1] # Variables opstart, opend = 8296, 10452 eptitle_s, eptitle_e = 10453, 10572 edstart, edend = 31528, 33685 preview_s, preview_e = 33686, src.num_frames - 1 h = 720 w = get_w(h) edges = core.edgefixer.ContinuityFixer(src, *[[2, 1, 1]] * 4) out = depth(edges, 32) ref = hvf.SMDegrain(depth(get_y(out), 16), thSAD=450) denoise = hybrid_denoise(out, 0.35, 1.75, dict(a=2, d=1), dict(ref=depth(ref, 32))) out = denoise y = get_y(out) lineart = vdf.edge_detect(y, 'FDOG', 0.055, (1, 1)).std.Median().std.Convolution([*[1] * 9]) descale = core.descale.Debilinear(y, w, h) upscale = vdf.fsrcnnx_upscale( descale, height=h * 2, shader_file=r'shaders\FSRCNNX_x2_56-16-4-1.glsl', upscaler_smooth=eedi3_upscale, profile='slow', strength=85) antialias = sraa_eedi3(upscale, 9) downscale = muvf.SSIM_downsample(antialias, src.width, src.height, filter_param_a=0, filter_param_b=0) downscale = core.std.MaskedMerge(y, downscale, lineart) merged = vdf.merge_chroma(downscale, out) merged = lvf.rfs(merged, out, [(opstart, opend), (eptitle_s, eptitle_e), (preview_s, preview_e)]) out = depth(merged, 16) detail_dark_mask = detail_dark_mask_func(get_y(out), brz_a=8000, brz_b=6000) detail_light_mask = lvf.denoise.detail_mask(out, brz_a=2500, brz_b=1200) detail_mask = core.std.Expr([detail_dark_mask, detail_light_mask], 'x y +').std.Median() detail_mask_grow = iterate(detail_mask, core.std.Maximum, 2) detail_mask_grow = iterate(detail_mask_grow, core.std.Inflate, 2).std.Convolution([*[1] * 9]) detail_mask = core.std.Expr([get_y(out), detail_mask_grow, detail_mask], f'x {32<<8} < y z ?') deband = dumb3kdbv2(out, 22, 24) deband = core.std.MaskedMerge(deband, out, detail_mask) deband_b = dumb3kdbv2(out, 24, 64) deband_b = core.std.MaskedMerge(deband_b, out, detail_light_mask) deband = lvf.rfs(deband, deband_b, [(opstart + 414, opstart + 496)]) out = deband ref = get_y(out).std.PlaneStats() adgmask_a = core.adg.Mask(ref, 30) adgmask_b = core.adg.Mask(ref, 12) stgrain = sizedgrn(out, 0.1, 0.05, 1.05, sharp=80) stgrain = core.std.MaskedMerge(out, stgrain, adgmask_b) stgrain = core.std.MaskedMerge(out, stgrain, adgmask_a.std.Invert()) dygrain = sizedgrn(out, 0.2, 0.05, 1.15, sharp=80, static=False) dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a) grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain)) out = grain ref = depth(src, 16) rescale_mask = vdf.drm(ref, 720, 'bilinear', mthr=30, sw=0, sh=0) rescale_mask = vdf.region_mask(rescale_mask, *[10] * 4) rescale_mask = hvf.mt_expand_multi(rescale_mask, mode='ellipse', sw=4, sh=4) rescale_mask = rescale_mask.std.Binarize(scale_value( 100, 8, 16)).std.Inflate().std.Convolution([*[1] * 9]) dehalo_ref = gf.MaskedDHA(ref, rx=1.65, ry=1.65, darkstr=0.15, brightstr=1.0, maskpull=48, maskpush=140) dehalo_mask_a = vdf.region_mask(rescale_mask, top=650, right=200) credit = out dehalo_range_a = [(18, 130), (1291, 1355), (14691, 14846), (15126, 15189)] credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, rescale_mask, 0), [(131, 220), (400, 505), (817, 899), (1766, 1809), (1925, 2041), (4033, 4116), (4342, 4453), (4964, 5031), (6422, 6515), (7848, 7978), (10606, 10728), (11619, 11701), (15339, 15457), (edstart, edend)] + dehalo_range_a) credit = lvf.rfs( credit, core.std.MaskedMerge(credit, dehalo_ref, dehalo_mask_a, 0), dehalo_range_a) out = credit return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2])
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut ep10 = JPBD_10.src_cut h = 720 w = get_w(h) b, c = vdf.get_bicubic_params('robidoux') opstart, opend = 744, 3140 opstart_ep10, opend_ep10 = 768, 3164 full_stuff = [(3145, 3269), (18289, 18444), (29158, 33410)] border = rkt.rekt_fast(src, lambda x: core.fb.FillBorders(x, 0, 0, 0, 2), right=1212) fixstudioshit = lvf.rfs(src, border, [31759]) border = rkt.rekt_fast(src, lambda x: core.fb.FillBorders(x, 0, 0, 0, 6), right=1212) fixstudioshit = lvf.rfs(fixstudioshit, border, [31760]) border = rkt.rekt_fast(src, lambda x: core.fb.FillBorders(x, 0, 0, 0, 6), right=1274) fixstudioshit = lvf.rfs(fixstudioshit, border, [(31761, 31762)]) border = rkt.rekt_fast(src, lambda x: core.fb.FillBorders(x, 0, 0, 0, 6), right=1300) fixstudioshit = lvf.rfs(fixstudioshit, border, [31763]) border = rkt.rekt_fast(src, lambda x: core.fb.FillBorders(x, 0, 0, 0, 6), right=1322) fixstudioshit = lvf.rfs(fixstudioshit, border, [31764]) border = rkt.rekt_fast(src, lambda x: core.fb.FillBorders(x, 0, 0, 0, 6), right=1342) fixstudioshit = lvf.rfs(fixstudioshit, border, [31765]) border = rkt.rekt_fast(src, lambda x: core.fb.FillBorders(x, 0, 0, 0, 6), right=1356) fixstudioshit = lvf.rfs(fixstudioshit, border, [31766]) border = rkt.rekt_fast(src, lambda x: core.fb.FillBorders(x, 0, 0, 0, 6), right=1368) fixstudioshit = lvf.rfs(fixstudioshit, border, [31767]) border = rkt.rekt_fast(src, lambda x: core.fb.FillBorders(x, 0, 0, 0, 6), right=1376) fixstudioshit = lvf.rfs(fixstudioshit, border, [31768]) border = rkt.rekt_fast(src, lambda x: core.fb.FillBorders(x, 0, 0, 0, 6), right=1382) fixstudioshit = lvf.rfs(fixstudioshit, border, [(31769, 31793)]) src = fixstudioshit # Fix compositing error in the OP op_src, op_10 = src[opstart:opend + 1], ep10[opstart_ep10:opend_ep10 + 1] fix = lvf.rfs(op_src, op_10, [(0, 79), (1035, 1037)]) fix_src = insert_clip(src, fix, opstart) src = depth(fix_src, 32) denoise = hybrid_denoise(src, 0.5, 2) out = denoise luma = get_y(out) line_mask = vdf.edge_detect(luma, 'FDOG', 0.05, (1, 1)) descale = core.descale.Debicubic(luma, w, h, b, c) upscale = vdf.fsrcnnx_upscale(descale, None, descale.height * 2, '_shaders/FSRCNNX_x2_56-16-4-1.glsl', core.resize.Point) antialias = single_rate_antialiasing(upscale, 13, alpha=0.3, beta=0.45, gamma=320, mdis=18) scaled = muvf.SSIM_downsample(antialias, src.width, src.height, kernel='Bicubic') rescale = core.std.MaskedMerge(luma, scaled, line_mask) merged = vdf.merge_chroma(rescale, out) out = depth(merged, 16) antialias = lvf.rfs( out, lvf.sraa(out, 1.65, 9, alpha=0.3, beta=0.45, gamma=240, nrad=3, mdis=25), [(opstart + 840, opstart + 881)]) out = antialias # Slight sharp though CAS sharp = hvf.LSFmod(out, strength=75, Smode=3, Lmode=1, edgemode=1, edgemaskHQ=True) out = sharp dering = gf.HQDeringmod(out, thr=16, darkthr=0.1) out = dering warp = xvs.WarpFixChromaBlend(out, thresh=48, depth=8) out = warp preden = core.knlm.KNLMeansCL(out, d=0, a=3, h=0.6, device_type='GPU', channels='Y') deband_mask = lvf.denoise.detail_mask(preden, brz_a=2000, brz_b=800, rad=4) deband = dbs.f3kpf(out, 17, 42, 42) deband_b = placebo.deband(out, 22, 6, 2) deband = lvf.rfs(deband, deband_b, [(opstart + 1515, opstart + 1603)]) deband_c = placebo.deband(out, 17, 6, 3) deband = lvf.rfs(deband, deband_c, [(12529, 12615)]) deband_d = placebo.deband(out, 10, 3, 1) deband = lvf.rfs(deband, deband_d, [(21077, 21304), (22141, 22278), (22861, 22944), (29354, 29425), (33555, 33614)]) deband = core.std.MaskedMerge(deband, out, deband_mask) out = deband adg_mask = core.adg.Mask(out.std.PlaneStats(), 20).std.Expr(f'x x {128<<8} - 0.25 * +') grain = core.grain.Add(out, 0.2, constant=True) grain = core.std.MaskedMerge(out, grain, adg_mask, 0) out = grain rescale_mask = vdf.drm(luma, b=b, c=c, sw=4, sh=4) ref, rescale_mask, src, src_ncop = [ depth(x, 16) for x in [denoise, rescale_mask, src, JPBD_NCOP.src_cut] ] credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, rescale_mask), full_stuff) out = credit src_c, src_ncop = [ c.knlm.KNLMeansCL(a=7, h=35, d=0, device_type='gpu') for c in [src, src_ncop] ] opening_mask = vdf.dcm(out, src_c[opstart:opend + 1], src_ncop[:opend - opstart + 1], opstart, opend, 4, 4).std.Inflate() credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, opening_mask), [(opstart, opend)]) out = credit return depth(out, 10)