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 + src[-1] * 3 dehalo = gf.MaskedDHA(out, rx=1.35, ry=1.35, darkstr=0.25, brightstr=1.0, maskpull=46, maskpush=148) out = dehalo antialias = lvf.sraa(out, 1.5, 9, downscaler=core.resize.Bicubic) out = antialias sharp = hvf.LSFmod(out, strength=75, 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, 24, 24) deband = core.std.MaskedMerge(deband, out, deband_mask) out = deband return depth(out, 10)
def scradit_mask(src_luma: vs.VideoNode, rescaled_luma: vs.VideoNode, absthresh: float = 0.060, iters: int = 4) -> vs.VideoNode: """ Basic detail and credit masking function borrowed from Scrad. Changed it to be used in a more generic manner, but the core stuff and logic comes from him. Or wherever he got it. Geared towards catching very light detail in a different native resolution than the rest of the video. Returns a 32 bit (GrayS) mask. :param src_luma: Luma plane of the source. If it has more planes, the luma plane will be extracted. :param rescaled_luma: Luma plane of the rescaled video. If it has more planes, the luma plane will be extracted. :param absthresh: The threshold for binarizing the mask with. :param iters: How often to iterate Maximum and Inflate calls. """ luma = depth(get_y(src_luma), 32) rescaled = depth(get_y(rescaled_luma), 32) mask = core.std.Expr([luma, rescaled], f"x y - abs {absthresh} < 0 1 ?") mask = iterate(mask, core.std.Maximum, iters) return iterate(mask, core.std.Inflate, iters)
def descale(clip: vs.VideoNode, kernel: Kernel = Bicubic(b=0, c=1 / 2), mask: bool = False) -> vs.VideoNode: def _fsrlineart(clip: vs.VideoNode, width: int, height: int) -> vs.VideoNode: clip = clip.resize.Point(1280, 720) assert clip.format is not None nn = depth(_nnedi3_double(depth(clip, 16)), clip.format.bits_per_sample) fsr = fsrcnnx_upscale(clip, width, height, upscaled_smooth=nn, shader_file=FSRCNNX) mask = retinex_edgemask(depth(fsr.std.ShufflePlanes(0, vs.GRAY), 16)) mask = mask.std.Binarize(scale_thresh(0.65, mask)).std.Maximum() mask = depth(mask, clip.format.bits_per_sample, range_in=CRange.FULL, range=CRange.FULL) return core.std.MaskedMerge( nn.resize.Bicubic(width, height, filter_param_a=0, filter_param_b=1 / 2), fsr, mask) return depth(ldescale(clip, height=720, kernel=kernel, upscaler=_fsrlineart), 16) if mask \ else depth(ldescale(clip, height=720, kernel=kernel, upscaler=_fsrlineart, mask=None), 16)
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut src = depth(src, 16) src = core.std.FreezeFrames(src, 45219, 45219, 45219 - 1) adg_mask = core.adg.Mask(src.std.PlaneStats(), 20) denoise_a = CoolDegrain(src, tr=1, thsad=48, blksize=8, overlap=4, plane=4) denoise_b = CoolDegrain(src, tr=1, thsad=24, blksize=8, overlap=4, plane=4) denoise = core.std.MaskedMerge(denoise_a, denoise_b, adg_mask) denoise = vdf.merge_chroma(denoise, denoise_a) out = denoise deband_mask = lvf.denoise.detail_mask(out.std.Median(), brz_a=3000, brz_b=1500) deband = dbs.f3kpf(out, 20, 24, 30) deband = core.std.MaskedMerge(deband, out, deband_mask) out = deband grain = kgf.adaptive_grain(out, 0.1, luma_scaling=16) out = grain return depth(out, 10)
def get_mask(self, clip: vs.VideoNode, ref: vs.VideoNode) -> vs.VideoNode: """ Get the bounded mask. :param clip: Source :param ref: Reference clip :return: Bounded mask """ if ref.format is None or clip.format is None: raise ValueError("get_mask: 'Variable-format clips not supported'") if self.bound: bm = self.bound.get_mask(ref) bm = bm if not self.blur else bm.std.BoxBlur(hradius=5, vradius=5, hpasses=5, vpasses=5) if len(self.refframes) == 0: hm = depth(self._mask(clip, ref), clip.format.bits_per_sample, range=CRange.FULL, range_in=CRange.FULL) else: hm = core.std.BlankClip(ref, format=ref.format.replace(color_family=vs.GRAY, subsampling_h=0, subsampling_w=0).id) for range, rf in zip(self.ranges, self.refframes): if rf is None: rf = ref.num_frames - 1 elif rf < 0: rf = ref.num_frames - 1 + rf mask = depth(self._mask(clip[rf], ref[rf]), clip.format.bits_per_sample, range=CRange.FULL, range_in=CRange.FULL) hm = replace_ranges(hm, core.std.Expr([hm, mask*len(hm)], expr="x y max"), range) return hm if self.bound is None else core.std.MaskedMerge(core.std.BlankClip(hm), hm, bm)
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut src = depth(src, 32) denoise = mvf.BM3D(src, 1.1, radius1=1, depth=16) out = denoise antialias = lvf.sraa(out, 2, 13, downscaler=core.resize.Bicubic, gamma=500, nrad=2, mdis=16) out = antialias deband_mask = lvf.denoise.detail_mask(out, brz_a=2250, brz_b=1600).std.Median() deband = dbs.f3kbilateral(out, 17, 36, 36) deband = core.std.MaskedMerge(deband, out, deband_mask) out = deband grain = core.grain.Add(out, 0.3, constant=True) out = grain return depth(out, 10)
def do_filter(): """Vapoursynth filtering""" def _nneedi3_clamp(clip: vs.VideoNode, strength: int = 1): bits = clip.format.bits_per_sample - 8 thr = strength * (1 >> bits) luma = get_y(clip) strong = TAAmbk(luma, aatype='Eedi3', alpha=0.4, beta=0.4) weak = TAAmbk(luma, aatype='Nnedi3') expr = 'x z - y z - * 0 < y x y {0} + min y {0} - max ?'.format(thr) clip_aa = core.std.Expr([strong, weak, luma], expr) return core.std.ShufflePlanes([clip_aa, clip], [0, 1, 2], vs.YUV) src = SRC_CUT interpolate = core.resize.Bicubic(src, src_left=3) f_1 = 1006 src = src[:EDSTART + f_1] + interpolate[EDSTART + f_1] + src[EDSTART + f_1:-1] src = depth(src, 16) blur = core.bilateral.Gaussian(src, [0.45, 0]) den = CoolDegrain(blur, tr=1, thsad=60, blksize=8, overlap=4, plane=4) dering = core.std.MaskedMerge(den, hvf.YAHR(den, 2, 32), muvf.AnimeMask(den, 0.2), 0) aa_a = core.std.MaskedMerge(dering, _nneedi3_clamp(dering), TAAmbk(dering, mtype=2, showmask=1)) aa_b = TAAmbk(src, aatype='Nnedi3', mtype=1, nns=4, qual=2, nsize=6) aa = lvf.rfs(aa_a, aa_b, [(OPSTART, OPEND), (EDSTART, EDEND)]) preden = core.knlm.KNLMeansCL(aa, a=2, h=2, d=0, device_type='gpu', channels='Y') diff = core.std.MakeDiff(aa, preden, 0) db_m = lvf.denoise.detail_mask(aa.std.Median(), brz_a=3000, brz_b=1500) db_a = dbs.f3kpf(aa, 17) db_b = core.placebo.Deband(preden, radius=17, threshold=5.5, iterations=1, grain=4, planes=1 | 2 | 4) db_b = core.std.MergeDiff(db_b, diff, 0) db = lvf.rfs(db_a, db_b, [(9729, 9845), (13652, 14048)]) db = core.std.MaskedMerge(db, aa, db_m) grain = mdf.adptvgrnMod_mod(db, 0.2, size=1.25, sharp=60, luma_scaling=8) final = depth(grain, 10) return final, src
def do_filter(): """Vapoursynth filtering""" src = SRC_CUT src = depth(src, 16) denoise = core.knlm.KNLMeansCL(src, a=2, h=0.8, d=3, device_type='gpu', channels='UV') denoise_mask = core.adg.Mask(src.std.PlaneStats(), 2).std.Invert() denoise = core.std.MaskedMerge(denoise, mvf.BM3D(denoise, 2), denoise_mask) antialias = lvf.sraa(denoise, 1.75, 6, sharp_downscale=True) antialias_mask = core.std.Prewitt(get_y(denoise)).std.Maximum() antialias = core.std.MaskedMerge(denoise, antialias, antialias_mask) preden = core.knlm.KNLMeansCL(antialias, a=2, h=1.5, d=0, device_type='gpu', channels='Y') deband_mask = lvf.denoise.detail_mask(preden, brz_a=2500, brz_b=1000) deband = dbs.f3kpf(preden, 17, 36, 36) diff = core.std.MakeDiff(antialias, preden) deband = core.std.MergeDiff(deband, diff) deband = core.std.MaskedMerge(deband, antialias, deband_mask) final = depth(deband, 10) return final
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 quick_resample( clip: vs.VideoNode, function: Callable[[vs.VideoNode], vs.VideoNode]) -> vs.VideoNode: """ A function to quickly resample to 32/16/8 bit and back to the original depth in a one-liner. Useful for filters that only work in 16 bit or lower when you're working in float. :param clip: Input clip :param function: Filter to run after resampling (accepts and returns clip) :return: Filtered clip in original depth """ check_variable(clip, "quick_resample") assert clip.format try: # Excepts all generic because >plugin/script writers being consistent >_> dither = depth(clip, 32) filtered = function(dither) except: # noqa: E722 try: dither = depth(clip, 16) filtered = function(dither) except: # noqa: E722 dither = depth(clip, 8) filtered = function(dither) return depth(filtered, clip.format.bits_per_sample)
def un_ugly_background(clip: vs.VideoNode) -> vs.VideoNode: descale = core.descale.Debicubic(depth(clip, 32), 1505, 847, 1 / 3, 1 / 3) def _fsrcnnx(clip: vs.VideoNode) -> vs.VideoNode: clip = core.placebo.Shader(clip.resize.Point(format=vs.YUV444P16), 'Shaders/FSRCNNX_x2_56-16-4-1.glsl', clip.width * 2, clip.height * 2, filter='box') return get_y(clip) double = _fsrcnnx(depth(descale, 16)) rescale = core.fmtc.resample(double, clip.width, clip.height, kernel='gauss', invks=True, invkstaps=2, taps=1, a1=32) blur = core.std.Convolution(rescale, [1, 1, 1, 1, 1, 1, 1, 1, 1]) sharp = core.std.Expr([rescale, blur], 'x y - {} * x +'.format(1)) mask = core.std.Sobel(luma).std.Binarize(40000).std.Maximum() return core.std.MaskedMerge(sharp, rescale, mask)
def do_filter(): """Vapoursynth filtering""" def _perform_filtering_ending(clip: vs.VideoNode, adapt_mask: vs.VideoNode) -> vs.VideoNode: luma = get_y(clip) denoise_a = mvf.BM3D(luma, 2.25, 1) denoise_b = mvf.BM3D(luma, 1.25, 1) denoise = core.std.MaskedMerge(denoise_a, denoise_b, adapt_mask) grain = core.grain.Add(denoise, 0.3, constant=True) return core.std.MaskedMerge(denoise, grain, adapt_mask) src = JPBD.src_cut src = depth(src, 16) avg = core.std.PlaneStats(src) adapt_mask = core.adg.Mask(get_y(avg), 28) denoise_chroma = core.knlm.KNLMeansCL(src, a=2, h=0.55, d=3, device_type='gpu', channels='UV') denoise_luma = _perform_filtering_ending(src, adapt_mask) final = vdf.merge_chroma(denoise_luma, denoise_chroma) return depth(final, 10)
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut src = depth(src, 16) denoise = CoolDegrain(src, tr=1, thsad=24, blksize=8, overlap=4, plane=4) out = denoise luma = get_y(out) antialias = vdf.nnedi3_upscale(luma, correct_shift=False, pscrn=4) \ .resize.Bicubic(src.width, src.height, src_left=.5, src_top=.5, filter_param_a=0, filter_param_b=1/2) out = vdf.merge_chroma(antialias, out) deband_mask = lvf.denoise.detail_mask(out, brz_a=2000, brz_b=1000) deband = dbs.f3kpf(out, 17, 24, 24) deband = core.std.MaskedMerge(deband, out, deband_mask) out = deband grain = kgf.adaptive_grain(out, 0.2, luma_scaling=14) out = grain return depth(out, 10)
def do_filter(): """Vapoursynth filtering""" src = SRC_CLIP src = depth(src, 16) denoise = core.knlm.KNLMeansCL(src, a=2, h=0.8, d=3, device_type='gpu', channels='UV') denoise_mask = core.adg.Mask(src.std.PlaneStats(), 6).std.Invert() denoise = core.std.MaskedMerge(denoise, mvf.BM3D(denoise, 1.25), denoise_mask) downscaler = lambda c, w, h: core.fmtc.resample( c, w, h, kernel='gauss', invks=True, invkstaps=1, taps=1, a1=32) antialias = lvf.sraa(denoise, 1.75, 6, downscaler=downscaler) antialias_mask = core.std.Prewitt(get_y(denoise)).std.Maximum() antialias = core.std.MaskedMerge(denoise, antialias, antialias_mask) preden = core.knlm.KNLMeansCL(antialias, a=2, h=1.5, d=0, device_type='gpu', channels='Y') deband_mask = lvf.denoise.detail_mask(preden, brz_a=2500, brz_b=1000) deband = dbs.f3kpf(preden, 17, 36, 36) diff = core.std.MakeDiff(antialias, preden) deband = core.std.MergeDiff(deband, diff) deband = core.std.MaskedMerge(deband, antialias, deband_mask) final = depth(deband, 10) return final
def _open(self, path: str) -> vs.VideoNode: if path in self.nodes: return self.nodes[path] self.nodes[path] = depth(core.lsmas.LWLibavSource(path), 16) if path.lower().endswith(".m2ts") \ else depth(core.d2v.Source(path), 16) if path.lower().endswith(".d2v") \ else depth(core.ffms2.Source(path), 16) return self.nodes[path]
def ED(ed_in: vs.VideoNode) -> vs.VideoNode: src = ed_in # Rescale using a modified version of Zastin's dogahomo() rescale = rvs.questionable_rescale(vsutil.depth(src, 16), 810, b=1/3, c=1/3, mask_thresh=0.05) # Detail- and linemasking for denoising det_mask = lvf.mask.detail_mask(rescale, brz_a=0.25, brz_b=0.15) denoise_ya = core.knlm.KNLMeansCL(rescale, d=2, a=3, s=3, h=1.2, channels="Y") denoise_ca = core.knlm.KNLMeansCL(rescale, d=2, a=2, s=3, h=1.0, channels="UV") denoise_a = core.std.ShufflePlanes([denoise_ya,denoise_ca,denoise_ca], [0,1,2], colorfamily=vs.YUV) denoise_b = mvf.BM3D(rescale, sigma=[1.9], ref=denoise_a, profile1="fast", radius1=3) # BM3D left some gunk in chroma, most noticeably around hard contrast edges denoise = core.std.ShufflePlanes([denoise_b,denoise_a,denoise_a], [0,1,2], colorfamily=vs.YUV) denoise = core.std.MaskedMerge(denoise, rescale, det_mask) # Thanks for handling the effort of AA for me, Light aa = lvf.aa.nneedi3_clamp(denoise, strength=1.25, mthr=0.25) # Dehaloing it dehalom = rvs.dehalo_mask(aa, iter_out=3) dehalo_a = haf.DeHalo_alpha(aa, darkstr=0.9, brightstr=1.1) dehalo_a = vsutil.depth(dehalo_a, 16) dehalo = core.std.MaskedMerge(aa, dehalo_a, dehalom) # Generate a new detail mask and deband it, putting back fine detail the way it was det_mask = lvf.mask.detail_mask(dehalo, rad=2, radc=1, brz_a=0.05, brz_b=0.09) y,u,v = vsutil.split(dehalo) deband_a = vsutil.join([pdb(y, threshold=3.0, grain=6.5), pdb(u, threshold=3.0, grain=2.0), pdb(v, threshold=3.0, grain=2.0)]) deband = core.std.MaskedMerge(deband_a, dehalo, det_mask) # Finish up and output grain = kgf.adaptive_grain(deband, strength=0.65, luma_scaling=5) out = vsutil.depth(grain, 10) return out
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut src = depth(src, 16) out = src ref = hvf.SMDegrain(out, thSAD=300) denoise = mvf.BM3D(out, [1.5, 1.25], radius1=1, ref=ref) out = denoise crop = core.std.Crop(out, left=12) crop = awf.bbmod(crop, left=2, thresh=20 << 8) resize = core.resize.Bicubic(crop, 1920) out = lvf.rfs(out, resize, [(78, 89)]) y = get_y(out) lineart = gf.EdgeDetect(y, 'scharr').morpho.Dilate(2, 2).std.Inflate() fkrescale = fake_rescale( y, 882, 0, 1, deringer=lambda x: gf.MaskedDHA(x, rx=1.85, ry=1.85, darkstr=0.25, brightstr=1.0, maskpull=100, maskpush=200), antialiser=lambda c: lvf.sraa(c, 2, 13, downscaler=core.resize.Bicubic) ) merged = core.std.MaskedMerge(y, fkrescale, lineart) out = vdf.merge_chroma(merged, out) dering = hvf.EdgeCleaner(out, 17, smode=1, hot=True) out = dering out = lvf.rfs( out, denoise, [(0, 11), (38, 77), (115, 133), (316, 395), (441, 460), (606, 779), (825, 844), (990, 1127)] ) detail_mask = lvf.mask.detail_mask(out, brz_a=2250, brz_b=1000) deband = vdf.dumb3kdb(out, 15, threshold=17, grain=(24, 0)) deband = core.std.MaskedMerge(deband, out, detail_mask) out = deband grain = adptvgrnMod(out, 0.3, static=True, grain_chroma=False, hi=[128, 240], seed=333) out = grain decz = vdf.decsiz(out, min_in=128 << 8, max_in=200 << 8) out = decz return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 2])
def rescaler(clip: vs.VideoNode, height: int) -> Tuple[vs.VideoNode, vs.VideoNode]: """ Basic rescaling and mask generating function using nnedi3. """ from lvsfunc.kernels import Bicubic from lvsfunc.scale import descale_detail_mask from vardefunc.mask import FDOG from vardefunc.scale import nnedi3_upscale from vsutil import Range, get_w, join, plane bits, clip = _get_bits(clip, expected_depth=32) clip_y = get_y(clip) descale = Bicubic().descale(clip_y, get_w(height, clip.width / clip.height), height) rescale = Bicubic().scale(nnedi3_upscale(descale, pscrn=1), clip.width, clip.height) l_mask = FDOG().get_mask(clip_y, lthr=0.065, hthr=0.065).std.Maximum().std.Minimum() l_mask = l_mask.std.Median().std.Convolution([1] * 9) # stolen from varde xd masked_rescale = core.std.MaskedMerge(clip_y, rescale, l_mask) scaled = join([masked_rescale, plane(clip, 1), plane(clip, 2)]) upscale = Bicubic().scale(descale, 1920, 1080) detail_mask = descale_detail_mask(clip_y, upscale, threshold=0.055) scaled_down = scaled if bits == 32 else depth(scaled, bits) mask_down = detail_mask if bits == 32 else depth( detail_mask, 16, range_in=Range.FULL, range=Range.LIMITED) return scaled_down, mask_down
def _hell_deband(clip: vs.VideoNode): clip = depth(clip, 32) preden = vrf.knlmcl(clip, 2, 2, bits=32) diff = core.std.MakeDiff(clip, preden) deband = core.placebo.Deband(preden, radius=20, threshold=28, iterations=3, grain=8, planes=1|2|4) merge = core.std.MergeDiff(deband, diff) return depth(merge, 16)
def lfdeband(clip: vs.VideoNode) -> vs.VideoNode: """A simple debander ported from AviSynth by Zastin from debandshit Args: clip (vs.VideoNode): Source clip Returns: vs.VideoNode: Debanded clip. """ if clip.format is None: raise ValueError("lfdeband: 'Variable-format clips not supported'") bits = get_depth(clip) wss, hss = 1 << clip.format.subsampling_w, 1 << clip.format.subsampling_h w, h = clip.width, clip.height dw, dh = round(w / 2), round(h / 2) clip = depth(clip, 16) dsc = core.resize.Spline64(clip, dw - dw % wss, dh - dh % hss) d3kdb = dumb3kdb(dsc, radius=30, threshold=80, grain=0) ddif = core.std.MakeDiff(d3kdb, dsc) dif = core.resize.Spline64(ddif, w, h) out = core.std.MergeDiff(clip, dif) return depth(out, bits)
def main(self: Filtering) -> vs.VideoNode: # noqa """Vapoursynth filtering""" src = WEB.clip_cut src = src.std.AssumeFPS(src) src = depth(src, 16) out = src denoise = hvf.SMDegrain(out, tr=1, thSAD=100, thSADC=100) out = denoise dering = hvf.EdgeCleaner(out, 15, smode=1, hot=True) dering = gf.MaskedDHA(dering, darkstr=0.05, brightstr=0.75) out = dering aaa = vdf.scale.nnedi3_upscale(get_y(out), pscrn=1, correct_shift=False) aaa = aaa.resize.Bicubic(1920, 1080, src_left=0.5, src_top=0.5, filter_param_a=-0.5, filter_param_b=0.25) out = vdf.misc.merge_chroma(aaa, out) cwarp = xvs.WarpFixChromaBlend(out, 64, depth=4) out = cwarp detail_mask = lvf.mask.detail_mask(out, brz_a=2250, brz_b=1200) deband = vdf.deband.dumb3kdb(out, 16, threshold=33, grain=[24, 0]) deband = core.std.MaskedMerge(deband, out, detail_mask) out = deband return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 2])[:100]
def rescaler(clip: vs.VideoNode, height: int) -> vs.VideoNode: """ Basic rescaling function using nnedi3. """ from lvsfunc.kernels import Bicubic, BicubicSharp from vardefunc.mask import FDOG from vardefunc.scale import nnedi3_upscale from vsutil import Range, depth, get_w, get_y clip = depth(clip, 32) clip_y = get_y(clip) descale = BicubicSharp().descale(clip_y, get_w(height, clip.width / clip.height), height) rescale = Bicubic(b=-1 / 2, c=1 / 4).scale(nnedi3_upscale(descale, pscrn=1), clip.width, clip.height) l_mask = FDOG().get_mask(clip_y, lthr=0.065, hthr=0.065).std.Maximum().std.Minimum() l_mask = l_mask.std.Median().std.Convolution([1] * 9) # stolen from varde xd masked_rescale = core.std.MaskedMerge(clip_y, rescale, l_mask) scaled = join([masked_rescale, plane(clip, 1), plane(clip, 2)]) return depth(scaled, 16)
def do_filter() -> vs.VideoNode: """Vapoursynth filtering""" src = JPBD.src_cut out = src luma = get_y(out) rows = [ core.std.CropAbs(luma, out.width, 1, top=out.height - 1), core.std.CropAbs(luma, out.width, 1, top=out.height - 2) ] diff = core.std.Expr(rows, 'x y - abs').std.PlaneStats() row_fix = vdf.merge_chroma( luma.fb.FillBorders(bottom=1, mode="fillmargins"), out.fb.FillBorders(bottom=2, mode="fillmargins")) fixrow = core.std.FrameEval(out, partial(_select_row, clip=out, row_fix=row_fix), prop_src=diff) out = fixrow fixedge_a = awf.bbmod(out, 1, 1, 1, 1, 20, blur=700, u=False, v=False) fixedge = out fixedge = lvf.rfs(fixedge, fixedge_a, [(EDSTART + 309, EDEND)]) out = fixedge out = depth(out, 16) dehalo = gf.MaskedDHA(out, rx=1.4, ry=1.4, darkstr=0.02, brightstr=1) dehalo = lvf.rfs(out, dehalo, [(EDEND + 1, src.num_frames - 1)]) out = dehalo resize = core.std.Crop(out, right=12, bottom=8).resize.Bicubic(1920, 1080) resize = lvf.rfs(out, resize, [(27005, 27076)]) out = resize # Denoising only the chroma pre = hvf.SMDegrain(out, tr=2, thSADC=300, plane=3) planes = split(out) planes[1], planes[2] = [ mvf.BM3D(planes[i], 1.25, radius2=2, pre=plane(pre, i)) for i in range(1, 3) ] out = join(planes) preden = core.dfttest.DFTTest(out, sbsize=16, sosize=12, tbsize=1) detail_mask = lvf.mask.detail_mask(preden, brz_a=2500, brz_b=1500) deband = vdf.dumb3kdb(preden, 16, threshold=[17, 17], grain=[24, 0]) deband = core.std.MergeDiff(deband, out.std.MakeDiff(preden)) deband = core.std.MaskedMerge(deband, out, detail_mask) out = deband decz = vdf.decsiz(out, min_in=128 << 8, max_in=192 << 8) out = decz 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 = depth(src, 16) h = 882 w = get_w(h) kernel = 'lanczos' taps = 5 denoise = CoolDegrain(src, tr=1, thsad=24, blksize=8, overlap=4, plane=4) out = denoise luma = get_y(out) descale = kgf.get_descale_filter(kernel, taps=taps)(depth(luma, 32), w, h) upscale = vdf.fsrcnnx_upscale( depth(descale, 16), src.width, src.height, '_assets/shaders/FSRCNNX_x2_56-16-4-1.glsl', partial(core.resize.Bicubic, filter_param_a=0, filter_param_b=0)) out = upscale unwarp = line_darkening(out, 0.275).warp.AWarpSharp2(depth=-2.5) sharp = hvf.LSFmod(unwarp, strength=90, Smode=3, Lmode=1, edgemode=1, edgemaskHQ=True) stabilize = stabilization(out, sharp, 2, 1, 8, 16) out = vdf.merge_chroma(stabilize, denoise) antialias = lvf.sraa(out, 1.4, rep=7, downscaler=core.resize.Bicubic) out = antialias deband_mask = lvf.denoise.detail_mask(out, brz_a=2000, brz_b=1000) deband = dbs.f3kpf(out, 17, 42, 36) deband = core.std.MaskedMerge(deband, out, deband_mask) deband = core.neo_f3kdb.Deband(deband, preset='depth', grainy=24, grainc=18, keep_tv_range=True) out = deband grain = kgf.adaptive_grain(out, 0.2, luma_scaling=14) out = grain rescale_mask = vdf.drm(src, h, kernel, taps, mthr=40, sw=4, sh=4) credit = out credit = lvf.rfs(credit, core.std.MaskedMerge(credit, src, rescale_mask, 0), [(0, 647), (29954, 34046)]) credit = lvf.rfs(credit, src, [(0, 1)]) out = credit return depth(out, 10)
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]: """Main filterchain""" import havsfunc as haf import lvsfunc as lvf import rekt import vardefunc as vdf from adptvgrnMod import adptvgrnMod from ccd import ccd from vsutil import depth, get_w, get_y src: vs.VideoNode = pre_corrections() # type:ignore[assignment] src_NCED = JP_BD_NCED.clip_cut # Masking credits ed_mask = vdf.dcm( src, src[edstart:edstart+src_NCED.num_frames-ed_offset], src_NCED[:-ed_offset], start_frame=edstart, thr=25, prefilter=False) if edstart is not False \ else get_y(core.std.BlankClip(src)) credit_mask = depth(ed_mask, 16).std.Binarize() rkt = rekt.rektlvls(src, [0, 1079], [7, 7], [0, 1919], [7, 7], prot_val=None) rkt = depth(rkt, 16) denoise_uv = ccd(rkt, threshold=7, matrix='709') stab = haf.GSMC(denoise_uv, radius=1, thSAD=200, planes=[0]) decs = vdf.noise.decsiz(stab, sigmaS=8, min_in=208 << 8, max_in=232 << 8) l_mask = vdf.mask.FDOG().get_mask(get_y(decs), lthr=0.065, hthr=0.065).std.Maximum().std.Minimum() l_mask = l_mask.std.Median().std.Convolution([1] * 9) aa_weak = lvf.aa.taa(decs, lvf.aa.nnedi3(opencl=True)) aa_strong = lvf.aa.upscaled_sraa(decs, downscaler=lvf.kernels.Bicubic(b=-1 / 2, c=1 / 4).scale) aa_clamp = lvf.aa.clamp_aa(decs, aa_weak, aa_strong, strength=1.5) aa_masked = core.std.MaskedMerge(decs, aa_clamp, l_mask) dehalo = haf.FineDehalo(aa_masked, rx=1.6, ry=1.6, darkstr=0, brightstr=1.25) darken = flt.line_darkening(dehalo, 0.275).warp.AWarpSharp2(depth=2) merged_credits = core.std.MaskedMerge(darken, decs, credit_mask) deband = flt.masked_f3kdb(merged_credits, rad=18, thr=32, grain=[32, 12]) grain: vs.VideoNode = adptvgrnMod(deband, seed=42069, strength=0.35, luma_scaling=8, size=1.05, sharp=80, grain_chroma=False) return grain
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut src = depth(src, 16) out = src opstart, opend = 480, 2637 edstart, edend = 29707, 31863 dehalo = gf.MaskedDHA(out, rx=1.35, ry=1.35, darkstr=0.25, brightstr=1.0, maskpull=46, maskpush=148) out = dehalo antialias = lvf.sraa(out, 1.5, 9, downscaler=core.resize.Bicubic) antialias_b = lvf.sraa(antialias, 1.05, 3, downscaler=core.resize.Bicubic) antialias_b = TAAmbk(antialias_b, aatype='Eedi3SangNom', cycle=4, thin=2, sharp=100, mtype=0, down8=False) antialias = lvf.rfs(antialias, antialias_b, [(19956, 20029)]) out = antialias sharp = hvf.LSFmod(out, strength=75, 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, 24, 24) deband = core.std.MaskedMerge(deband, out, deband_mask) out = deband src_c, ncop, nced = [ clip.std.Median() for clip in [src, JPBD_NCOP.src_cut, JPBD_NCED.src_cut] ] opening_mask = vdf.dcm(out, src_c[opstart:opend + 1], ncop[:opend - opstart + 1], opstart, opend, 3, 3) ending_mask = vdf.dcm(out, src_c[edstart:edend + 1], nced[:edend - edstart + 1], edstart, edend, 3, 3) credit_mask = core.std.Expr([opening_mask, ending_mask], 'x y +').std.Convolution([1] * 9) credit = lvf.rfs(out, core.std.MaskedMerge(out, src, credit_mask), [(opstart, opend), (edstart, edend)]) out = credit return depth(out, 10)
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut out = depth(src, 16) denoise = hvf.SMDegrain(out, thSAD=150, thSADC=75) out = denoise y = get_y(out) lineart = core.std.Sobel(y).std.Binarize( 75 << 8).std.Maximum().std.Inflate() antialias = lvf.sraa(y, 1.5, 9, downscaler=core.resize.Spline36, gamma=200, mdis=18) sharp = hvf.LSFmod(antialias, strength=95, Smode=3, Lmode=1, edgemode=1, edgemaskHQ=True) minmax = core.std.Expr([y, sharp, antialias], 'x y z min max y z max min') merge = core.std.MaskedMerge(y, minmax, lineart) out = vdf.merge_chroma(merge, out) y = get_y(out) detail_dark_mask = detail_dark_mask_func(y, brz_a=10000, brz_b=9000) detail_light_mask = lvf.denoise.detail_mask(y, 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, 1, 1, 1, 1, 1, 1, 1, 1]) detail_mask = core.std.Expr([y, detail_mask_grow, detail_mask], f'x {28<<8} < y z ?') deband = dbs.f3kpf(out, 17, 24, 24) deband = core.std.MaskedMerge(deband, out, detail_mask) out = deband grain = adptvgrnMod(out, 0.2, 0.1, 1.25, luma_scaling=14, sharp=80, static=False, lo=19, hi=[192, 240]) out = grain 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 = depth(src, 32) out = src full_range = core.resize.Bicubic(out, range_in=0, range=1, dither_type='error_diffusion') out = full_range radius = 3 y, u, v = split(out) y_m = core.resize.Point(y, 960, 1080, src_left=-1) y_m = core.resize.Bicubic(y_m, 960, 540) def demangle(clip): return vdf.nnedi3_upscale(clip, pscrn=0, correct_shift=False).resize.Spline16(src_left=0.5+0.25, src_top=.5) y_m, u, v = map(demangle, (y_m, u, v)) y_fixup = core.std.MakeDiff(y, y_m) yu, yv = Regress(y_m, u, v, radius=radius) 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) out = join([y, u_r, v_r]) out = depth(out, 16) dehalo = gf.MaskedDHA(out, rx=1.25, ry=1.25, darkstr=0.10, brightstr=1.0, maskpull=46, maskpush=148) out = dehalo upscale = atf.eedi3Scale(out, 2160, pscrn=0) out = upscale dehalo = gf.MaskedDHA(out, rx=1.15, ry=1.15, darkstr=0.10, brightstr=1.0, maskpull=46, maskpush=148) out = dehalo deband_mask = lvf.denoise.detail_mask(out, brz_a=2000, brz_b=1000) deband = dbs.f3kpf(out, 28, 48, 48) deband = core.std.MaskedMerge(deband, out, deband_mask) out = deband grain = core.grain.Add(out, 1) out = grain return out.std.AssumeFPS(fpsnum=1, fpsden=1)
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