コード例 #1
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Main VapourSynth filterchain"""
    import EoEfunc as eoe
    import lvsfunc as lvf
    import vardefunc as vdf
    from ccd import ccd
    from finedehalo import fine_dehalo
    from vsutil import depth, get_y

    src, ep = JP_BD.clip_cut, JP_EP.clip_cut
    ep_ext = ep[0] * 16 + ep  # F**K THIS STUDIO HOLY SHIT
    src = lvf.rfs(src, ep_ext, [(811, 859)])
    src = depth(src, 16)

    # This noise can burn in hell.
    denoise_pre = get_y(src.dfttest.DFTTest(sigma=1.0))
    denoise_ret = core.retinex.MSRCP(denoise_pre, sigma=[50, 200, 350], upper_thr=0.005)
    denoise_mask = flt.detail_mask(denoise_ret, sigma=2.0, lines_brz=3000).rgvs.RemoveGrain(4)

    denoise_pre = core.dfttest.DFTTest(src, sigma=4.0)
    denoise_smd = eoe.dn.CMDegrain(src, tr=5, thSAD=275, freq_merge=True, prefilter=denoise_pre)
    denoise_masked = core.std.MaskedMerge(denoise_smd, src, denoise_mask)

    denoise_uv = ccd(denoise_masked, threshold=6)
    decs = vdf.noise.decsiz(denoise_uv, sigmaS=8, min_in=200 << 8, max_in=235 << 8)

    # F**K THIS SHOW'S LINEART HOLY SHIT
    baa = lvf.aa.based_aa(decs.std.Transpose(), str(shader_file), gamma=120)
    baa = lvf.aa.based_aa(baa.std.Transpose(), str(shader_file), gamma=120)
    sraa = lvf.sraa(decs, rfactor=1.4)
    clmp_aa = lvf.aa.clamp_aa(decs, baa, sraa, strength=1.65)

    # AAing introduces some haloing (zzzzzz)
    restr_edges = fine_dehalo(clmp_aa, decs)
    restr_dark = core.std.Expr([clmp_aa, restr_edges], "x y min")

    deband = core.average.Mean([
        flt.masked_f3kdb(restr_dark, rad=17, thr=[28, 20], grain=[12, 8]),
        flt.masked_f3kdb(restr_dark, rad=21, thr=[36, 32], grain=[24, 12]),
        flt.masked_placebo(restr_dark, rad=6.5, thr=2.5, itr=2, grain=4)
    ])

    grain = vdf.noise.Graigasm(
        thrs=[x << 8 for x in (32, 80, 128, 176)],
        strengths=[(0.25, 0.0), (0.20, 0.0), (0.15, 0.0), (0.0, 0.0)],
        sizes=(1.20, 1.15, 1.10, 1),
        sharps=(80, 70, 60, 50),
        grainers=[
            vdf.noise.AddGrain(seed=69420, constant=True),
            vdf.noise.AddGrain(seed=69420, constant=False),
            vdf.noise.AddGrain(seed=69420, constant=False)
        ]).graining(deband)

    return grain
コード例 #2
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Main VapourSynth filterchain"""
    import EoEfunc as eoe
    import havsfunc as haf
    import lvsfunc as lvf
    import vardefunc as vdf
    from vsutil import depth

    src = JP_BD.clip_cut
    yt = lvf.src(r"src/『魔法使いの夜』ティザーPV-NHIgc-seeSo.mkv", ref=src) \
        .std.AssumeFPS(fpsnum=24000, fpsden=1001)
    src = core.std.SetFrameProp(src, '_FieldBased', intval=0)
    se = core.tivtc.TDecimate(src)

    # Fix range compression and missing frame in TV release
    csp = core.resize.Bicubic(se,
                              range_in=0,
                              range=1,
                              dither_type="error_diffusion")
    csp = csp.std.SetFrameProp(prop="_ColorRange", intval=1)
    merge = csp[:400] + yt[400] + csp[400:]

    # "Delogoing" and "Edgefixing"
    sqmask = lvf.mask.BoundingBox(
        (1753, 27),
        (118, 50)).get_mask(merge).std.Inflate().std.Inflate().std.Maximum()
    sqmask = sqmask.std.Maximum().std.Maximum().std.Median().std.Convolution(
        [1] * 9).std.Convolution([1] * 9)

    mask_merge = core.std.MaskedMerge(merge, yt[:merge.num_frames], sqmask)

    sqmask_ef = lvf.mask.BoundingBox(
        (3, 3), (src.width - 3, src.height - 3)).get_mask(mask_merge)
    ef = core.std.MaskedMerge(yt, mask_merge, sqmask_ef)
    ef = depth(ef, 16)

    debl = lvf.deblock.vsdpir(ef, strength=35, cuda=use_cuda)
    csharp = eoe.misc.ContraSharpening(debl, ef, radius=2, rep=13)
    darken = haf.FastLineDarkenMOD(csharp, strength=24)

    deband = core.average.Mean([
        flt.masked_f3kdb(darken, rad=16, thr=[28, 20], grain=[16, 6]),
        flt.masked_placebo(darken, rad=14, thr=4.5, itr=2, grain=2)
    ])

    grain = vdf.noise.Graigasm(thrs=[x << 8 for x in (32, 80, 128, 176)],
                               strengths=[(0.15, 0.0), (0.10, 0.0),
                                          (0.05, 0.0), (0.0, 0.0)],
                               sizes=(1.15, 1.10, 1.05, 1),
                               sharps=(100, 90, 80, 50),
                               grainers=[
                                   vdf.noise.AddGrain(seed=69420,
                                                      constant=True),
                                   vdf.noise.AddGrain(seed=69420,
                                                      constant=False),
                                   vdf.noise.AddGrain(seed=69420,
                                                      constant=False)
                               ]).graining(deband)

    return grain
コード例 #3
0
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
コード例 #4
0
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
コード例 #5
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Main VapourSynth filterchain"""
    import havsfunc as haf
    import lvsfunc as lvf
    import vardefunc as vdf
    from ccd import ccd
    from vsutil import depth

    src = JP_BD.clip_cut
    cloc = core.resize.Bicubic(src, chromaloc_in=2, chromaloc=0)
    src = depth(cloc, 16)

    halo_mask = lvf.mask.halo_mask(src, rad=1, brz=0.85, thmi=0.35, thma=0.95)
    halo_mask = halo_mask.std.Maximum().std.Inflate()

    bidehalo = lvf.dehalo.bidehalo(src,
                                   sigmaR=8 / 255,
                                   sigmaS=2.0,
                                   sigmaS_final=1.5)
    dehalo_den = core.dfttest.DFTTest(bidehalo, sigma=8.0)
    dehalo_clean = haf.EdgeCleaner(dehalo_den, strength=8, smode=1, hot=True)

    dehalo = core.std.MaskedMerge(src, dehalo_clean, halo_mask)

    # Certain cuts have a strong camera effect that amplifies haloing, and is likely intentional
    dehalo = lvf.rfs(dehalo, src, [(773, 786), (867, 886)])

    denoise = core.dfttest.DFTTest(dehalo, sigma=1.75)
    cdenoise = ccd(denoise, threshold=4, matrix='709')
    decs = vdf.noise.decsiz(cdenoise,
                            sigmaS=8.0,
                            min_in=208 << 8,
                            max_in=232 << 8)

    baa = lvf.aa.based_aa(decs, str(shader_file))
    sraa = lvf.sraa(decs, rfactor=1.45)
    clmp = lvf.aa.clamp_aa(decs, baa, sraa, strength=1.45)

    darken = haf.FastLineDarkenMOD(clmp, strength=12)

    # Debanding and graining
    deband = flt.masked_f3kdb(darken, rad=18, thr=[24, 20])

    grain = vdf.noise.Graigasm(thrs=[x << 8 for x in (32, 80, 128, 176)],
                               strengths=[(0.20, 0.0), (0.15, 0.0),
                                          (0.10, 0.0), (0.0, 0.0)],
                               sizes=(1.20, 1.15, 1.10, 1),
                               sharps=(70, 60, 50, 50),
                               grainers=[
                                   vdf.noise.AddGrain(seed=69420,
                                                      constant=True),
                                   vdf.noise.AddGrain(seed=69420,
                                                      constant=True),
                                   vdf.noise.AddGrain(seed=69420,
                                                      constant=True)
                               ]).graining(deband)

    return grain
コード例 #6
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Main filterchain"""
    import lvsfunc as lvf
    import muvsfunc as muf
    import vardefunc as vdf
    from adptvgrnMod import adptvgrnMod
    from ccd import ccd
    from vsutil import depth, get_w, get_y, iterate
    from xvs import WarpFixChromaBlend

    # Can't mean this one out this time because of credit changes
    src = JP_CR.clip_cut
    src = depth(src, 32)

    src_y = get_y(src)
    descale = lvf.kernels.Lanczos(taps=5).descale(src_y, get_w(945), 945)
    rescale = vdf.scale.nnedi3cl_double(descale, pscrn=1)
    rescale = muf.SSIM_downsample(rescale, src_y.width, src_y.height)
    scaled = vdf.misc.merge_chroma(rescale, src)
    scaled = depth(scaled, 16)

    # Having a hard time reliably catching the EDs. Oh well.
    upscale = lvf.kernels.Lanczos(taps=5).scale(descale, src_y.width,
                                                src_y.height)
    credit_mask = depth(
        lvf.scale.descale_detail_mask(src_y, upscale, threshold=0.08), 16)
    credit_mask = iterate(credit_mask, core.std.Minimum, 5)
    credit_mask = iterate(credit_mask, core.std.Maximum, 9)
    credit_mask = core.morpho.Close(credit_mask, 9)

    credits_merged = core.std.MaskedMerge(scaled, depth(src, 16), credit_mask)

    denoise_y = core.knlm.KNLMeansCL(credits_merged,
                                     d=1,
                                     a=3,
                                     s=4,
                                     h=0.55,
                                     channels='Y')
    denoise_uv = ccd(denoise_y, threshold=6, matrix='709')
    decs = vdf.noise.decsiz(denoise_uv,
                            sigmaS=8,
                            min_in=208 << 8,
                            max_in=232 << 8)

    darken = flt.line_darkening(decs, strength=0.175)

    deband = flt.masked_f3kdb(darken, thr=24, grain=[24, 12])
    grain: vs.VideoNode = adptvgrnMod(deband,
                                      seed=42069,
                                      strength=0.45,
                                      luma_scaling=10,
                                      size=1.25,
                                      sharp=100,
                                      static=True,
                                      grain_chroma=False)

    return grain
コード例 #7
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Main 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 vsutil import depth

    src = JP_BD.clip_cut
    src = depth(src, 16)

    # Native 855p OP.
    scaled, descale_mask = flt.rescaler(src, height=855)

    # Weak denoising for most of the clip to smoothen out the compression noise. Stronger over heavy grain scenes.
    denoise_y_wk = core.knlm.KNLMeansCL(scaled, d=2, a=3, h=0.3)
    denoise_y_str = eoe.dn.BM3D(scaled, sigma=[0.85, 0])
    denoise_y = lvf.rfs(denoise_y_wk, denoise_y_str, [(273, 676),
                                                      (1303, 1428)])
    denoise_uv = ccd(denoise_y, threshold=9, matrix='709')

    # Grain stabilising and blurring away super bright areas to save more filesize by limiting intra-frame differences.
    stab = haf.GSMC(denoise_uv, radius=1, thSAD=250, planes=[0])
    decs = vdf.noise.decsiz(stab, sigmaS=8, min_in=200 << 8, max_in=232 << 8)

    # Clamped AA to try and force ufo's meh lineart along and deal with some leftover lineart fuckery from rescaling.
    aa_weak = lvf.aa.nneedi3_clamp(decs, strength=4)
    aa_strong = lvf.sraa(decs, rfactor=1.6)
    aa_clamp = lvf.aa.clamp_aa(decs, aa_weak, aa_strong, strength=2)

    # AA has a tendency to slightly brighten lines, so we perform pretty weak line darkening here
    halo_mask = lvf.mask.halo_mask(aa_clamp)
    darken = flt.line_darkening(aa_clamp, strength=0.35)
    dehalo = core.std.MaskedMerge(
        darken, lvf.dehalo.bidehalo(darken, sigmaS_final=1.2, sigmaR=11 / 255),
        halo_mask)

    # But the dehaloing also destroys select scenes too much, so we undo that here.
    no_dehalo_aa = lvf.rfs(dehalo, decs, [(2967, 3031)])
    merged_credits = core.std.MaskedMerge(no_dehalo_aa, src, descale_mask)

    # Medium debanding. Smears the darker backgrounds a tiny bit, but the added grain should help hide that.
    deband = flt.masked_f3kdb(merged_credits,
                              rad=21,
                              thr=[28, 24],
                              grain=[32, 16])
    grain: vs.VideoNode = adptvgrnMod(deband,
                                      seed=42069,
                                      strength=0.25,
                                      luma_scaling=10,
                                      size=1.35,
                                      sharp=80,
                                      grain_chroma=False)

    return grain
コード例 #8
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Main filterchain"""
    import havsfunc as haf
    import lvsfunc as lvf
    import vardefunc as vdf
    from adptvgrnMod import adptvgrnMod
    from ccd import ccd
    from vsutil import depth

    src = JP_BD.clip_cut
    src = depth(src, 16)

    scaled, descale_mask = flt.rescaler(src, height=855)

    denoise_y = core.knlm.KNLMeansCL(scaled, d=2, a=3, h=0.15)
    denoise_uv = ccd(denoise_y, threshold=7, matrix='709')
    denoise_uv_str = ccd(denoise_y, threshold=15, matrix='709')
    denoise_uv = lvf.rfs(denoise_uv, denoise_uv_str, [(1999, 2041)])

    stab = haf.GSMC(denoise_uv, radius=1, thSAD=200, planes=[0])
    decs = vdf.noise.decsiz(stab, sigmaS=8, min_in=200 << 8, max_in=232 << 8)

    aa_weak = lvf.aa.nneedi3_clamp(decs, strength=4)
    aa_strong = lvf.sraa(decs, rfactor=1.6)
    aa_clamp = lvf.aa.clamp_aa(decs, aa_weak, aa_strong, strength=2)

    halo_mask = lvf.mask.halo_mask(aa_clamp)
    darken = flt.line_darkening(aa_clamp, strength=0.35)
    dehalo = core.std.MaskedMerge(
        darken, lvf.dehalo.bidehalo(darken, sigmaS_final=1.2, sigmaR=11 / 255),
        halo_mask)

    # ufo w h y y y y y this is why I hate working on your shows
    halo_mask_str = lvf.mask.halo_mask(aa_clamp, rad=1, brz=0.9, thlima=0.55)
    dehalo_str = core.std.MaskedMerge(
        darken,
        lvf.dehalo.bidehalo(darken,
                            sigmaS=4.0,
                            sigmaS_final=3.6,
                            sigmaR=22 / 255), halo_mask_str)
    dehalo = lvf.rfs(dehalo, dehalo_str, [(2042, 2077)])

    merged_credits = core.std.MaskedMerge(dehalo, src, descale_mask)

    deband = flt.masked_f3kdb(merged_credits,
                              rad=21,
                              thr=[28, 24],
                              grain=[32, 16])
    grain: vs.VideoNode = adptvgrnMod(deband,
                                      seed=42069,
                                      strength=0.25,
                                      luma_scaling=10,
                                      size=1.35,
                                      sharp=80,
                                      grain_chroma=False)

    return grain
コード例 #9
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Main filterchain"""
    import lvsfunc as lvf
    import rekt
    import vardefunc as vdf
    from muvsfunc import SSIM_downsample
    from vsutil import depth, get_y

    src = JP_BD.clip_cut
    rkt = rekt.rektlvls(src, [0, -1], [15, 15], [0, -1], [15, 15])
    cloc = depth(rkt, 32).resize.Bicubic(chromaloc_in=1, chromaloc=0)

    descale = lvf.kernels.Bilinear().descale(get_y(cloc), 1280, 720)
    supersample = vdf.scale.nnedi3_upscale(descale)
    downscaled = SSIM_downsample(supersample,
                                 src.width,
                                 src.height,
                                 smooth=((3**2 - 1) / 12)**0.5,
                                 sigmoid=True,
                                 filter_param_a=0,
                                 filter_param_b=0)
    scaled = vdf.misc.merge_chroma(downscaled, cloc)
    scaled = depth(scaled, 16)

    dft = core.dfttest.DFTTest(scaled,
                               sigma=0.6,
                               sbsize=8,
                               sosize=6,
                               tbsize=3,
                               tosize=1)
    decs = vdf.noise.decsiz(dft, sigmaS=4, min_in=200 << 8, max_in=232 << 8)

    baa = lvf.aa.based_aa(decs, str(shader_file))
    sraa = lvf.sraa(decs, rfactor=1.5)
    clmp = lvf.aa.clamp_aa(decs, baa, sraa, strength=1.5)

    deband = flt.masked_f3kdb(clmp, rad=16, thr=[20, 16])

    grain = vdf.noise.Graigasm(thrs=[x << 8 for x in (32, 80, 128, 176)],
                               strengths=[(0.25, 0.0), (0.20, 0.0),
                                          (0.15, 0.0), (0.0, 0.0)],
                               sizes=(1.20, 1.15, 1.10, 1),
                               sharps=(80, 70, 60, 50),
                               grainers=[
                                   vdf.noise.AddGrain(seed=69420,
                                                      constant=False),
                                   vdf.noise.AddGrain(seed=69420,
                                                      constant=False),
                                   vdf.noise.AddGrain(seed=69420,
                                                      constant=True)
                               ]).graining(deband)

    return grain
コード例 #10
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Main filterchain"""
    import lvsfunc as lvf
    import rekt
    import vardefunc as vdf
    from awsmfunc import bbmod
    from ccd import ccd
    from muvsfunc import SSIM_downsample
    from vsutil import depth, get_y

    src = JP_BD.clip_cut
    rkt = rekt.rektlvls(src, [0, -1], [30, 17], [0], [17])
    bb_y = bbmod(rkt, top=2, left=2, right=2, bottom=2, u=False, v=False, blur=9999)
    bb_uv = bbmod(bb_y, left=2, right=2, y=False)
    bb = depth(bb_uv, 32)

    descale = lvf.kernels.Spline36().descale(get_y(bb), 1280, 720)
    up_chr = vdf.scale.to_444(bb, 1920, 1080, True).resize.Bicubic(1280, 720)
    descale_merge = vdf.misc.merge_chroma(descale, up_chr)
    denoise_down = lvf.deblock.vsdpir(descale_merge, strength=0.5, mode='deblock', matrix=1, i444=True, cuda=True)

    supersample = vdf.scale.nnedi3_upscale(get_y(denoise_down))
    downscaled = SSIM_downsample(supersample, bb.width, bb.height, smooth=((3 ** 2 - 1) / 12) ** 0.5,
                                 sigmoid=True, filter_param_a=0, filter_param_b=0)

    scaled = vdf.misc.merge_chroma(downscaled, bb)
    scaled = depth(scaled, 16)

    den_uv = ccd(scaled, matrix='709')
    decs = vdf.noise.decsiz(den_uv, sigmaS=8, min_in=200 << 8, max_in=232 << 8)

    nn_aa = lvf.aa.nnedi3(opencl=True, dh=False)(decs)
    sraa = lvf.sraa(decs, rfactor=1.75)
    clmp = lvf.aa.clamp_aa(decs, nn_aa, sraa)

    dehalo = lvf.dehalo.masked_dha(clmp, brightstr=0.65)

    deband = flt.masked_f3kdb(dehalo, rad=17, thr=[24, 16], grain=[24, 12])

    grain = vdf.noise.Graigasm(
        thrs=[x << 8 for x in (32, 80, 128, 176)],
        strengths=[(0.20, 0.0), (0.15, 0.0), (0.10, 0.0), (0.0, 0.0)],
        sizes=(1.20, 1.15, 1.10, 1),
        sharps=(100, 80, 60, 20),
        grainers=[
            vdf.noise.AddGrain(seed=69420, constant=False),
            vdf.noise.AddGrain(seed=69420, constant=False),
            vdf.noise.AddGrain(seed=69420, constant=True)
        ]).graining(deband)

    no_flt = lvf.rfs(grain, depth(bb, 16), no_filter)

    return no_flt
コード例 #11
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Regular VapourSynth filterchain"""
    import havsfunc as haf
    import lvsfunc as lvf
    import vardefunc as vdf
    from adptvgrnMod import adptvgrnMod
    from muvsfunc import SSIM_downsample
    from vsutil import depth, get_y, iterate

    src = pre_freeze()
    src = depth(src, 16)

    src_y = depth(get_y(src), 32)
    descale = lvf.kernels.Bicubic(b=0, c=3 / 4).descale(src_y, 1440, 810)
    double = vdf.scale.nnedi3cl_double(descale, pscrn=1)
    rescale = depth(SSIM_downsample(double, 1920, 1080), 16)
    scaled = vdf.misc.merge_chroma(rescale, src)

    denoise = core.knlm.KNLMeansCL(scaled, d=1, a=3, s=4, h=0.3, channels='Y')
    decs = vdf.noise.decsiz(denoise,
                            sigmaS=4,
                            min_in=208 << 8,
                            max_in=232 << 8)

    dehalo = haf.YAHR(decs, blur=2, depth=28)
    halo_mask = lvf.mask.halo_mask(decs, rad=3, brz=0.3, thma=0.42)
    dehalo_masked = core.std.MaskedMerge(decs, dehalo, halo_mask)

    aa = lvf.aa.nneedi3_clamp(dehalo_masked, strength=1.5)
    # Strong aliasing on the transformation scene (and probably elsewhere that I missed). Thanks, Silver Link!
    aa_strong = lvf.sraa(dehalo_masked, rfactor=1.35)
    aa_spliced = lvf.rfs(aa, aa_strong, [(7056, 7322)])

    upscale = lvf.kernels.Bicubic(b=0, c=3 / 4).scale(descale, 1920, 1080)
    credit_mask = lvf.scale.descale_detail_mask(src_y, upscale, threshold=0.08)
    credit_mask = iterate(credit_mask, core.std.Deflate, 3)
    credit_mask = iterate(credit_mask, core.std.Inflate, 3)
    credit_mask = iterate(credit_mask, core.std.Maximum, 2)
    merge_credits = core.std.MaskedMerge(aa_spliced, src,
                                         depth(credit_mask, 16))

    deband = flt.masked_f3kdb(merge_credits, rad=18, thr=32, grain=[24, 0])
    grain: vs.VideoNode = adptvgrnMod(deband,
                                      seed=42069,
                                      strength=0.15,
                                      luma_scaling=10,
                                      size=1.25,
                                      sharp=80,
                                      static=True,
                                      grain_chroma=False)

    return grain
コード例 #12
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Main filterchain"""
    import havsfunc as haf
    import lvsfunc as lvf
    import vardefunc as vdf
    from adptvgrnMod import adptvgrnMod
    from ccd import ccd
    from vsutil import depth, insert_clip

    src = JP_BD.clip_cut
    src = depth(src, 16)

    scaled, descale_mask = flt.rescaler(src, height=855)

    denoise_y = core.knlm.KNLMeansCL(scaled, d=2, a=3, h=0.35)
    denoise_uv = ccd(denoise_y, threshold=7, matrix='709')
    stab = haf.GSMC(denoise_uv, radius=1, thSAD=200, planes=[0])
    decs = vdf.noise.decsiz(stab, sigmaS=8, min_in=200 << 8, max_in=232 << 8)

    aa_weak = lvf.aa.nneedi3_clamp(decs, strength=4)
    aa_strong = lvf.sraa(decs, rfactor=1.6)
    aa_clamp = lvf.aa.clamp_aa(decs, aa_weak, aa_strong, strength=2)
    aa_rfs = lvf.rfs(aa_clamp, aa_strong, [(434, 592)])

    halo_mask = lvf.mask.halo_mask(aa_rfs)
    darken = flt.line_darkening(aa_rfs, strength=0.35)
    dehalo = core.std.MaskedMerge(
        darken, lvf.dehalo.bidehalo(darken, sigmaS_final=1.2, sigmaR=11 / 255),
        halo_mask)

    merged_credits = core.std.MaskedMerge(dehalo, src, descale_mask)

    deband = flt.masked_f3kdb(merged_credits,
                              rad=21,
                              thr=[28, 24],
                              grain=[32, 16])
    grain: vs.VideoNode = adptvgrnMod(deband,
                                      seed=42069,
                                      strength=0.25,
                                      luma_scaling=10,
                                      size=1.35,
                                      sharp=80,
                                      grain_chroma=False)

    # Making sure there's no weird dynamic noise on the titlecard
    final = insert_clip(grain, grain[869] * (903 - 869), 869)

    return final
コード例 #13
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Main filterchain"""
    import lvsfunc as lvf
    import vardefunc as vdf
    from vsutil import depth, split, join
    from finedehalo import fine_dehalo

    src = JP_BD.clip_cut
    src = depth(src, 16)
    src = core.resize.Bicubic(src, chromaloc_in=1, chromaloc=0)

    debl = lvf.deblock.vsdpir(src, strength=1, i444=True)
    debl = depth(debl, 16)
    decs = vdf.noise.decsiz(debl, sigmaS=8, min_in=200 << 8, max_in=235 << 8)

    planes = split(decs)
    planes[2] = fine_dehalo(planes[2], rx=2, ry=2, brightstr=0.9, darkstr=0)
    cdehalo = join(planes)

    dehalo = lvf.dehalo.bidehalo(cdehalo, sigmaS=1.5, sigmaS_final=1)

    baa = lvf.aa.based_aa(dehalo, str(shader_file))
    sraa = lvf.sraa(dehalo, rfactor=1.65)
    clmp = lvf.aa.clamp_aa(dehalo, baa, sraa, strength=1.3)

    deband = flt.masked_f3kdb(clmp, thr=[32, 24])

    grain = vdf.noise.Graigasm(  # Mostly stolen from Varde tbh
        thrs=[x << 8 for x in (32, 80, 128, 176)],
        strengths=[(0.25, 0.0), (0.2, 0.0), (0.15, 0.0), (0.0, 0.0)],
        sizes=(1.15, 1.1, 1.05, 1),
        sharps=(65, 50, 40, 40),
        grainers=[
            vdf.noise.AddGrain(seed=69420, constant=True),
            vdf.noise.AddGrain(seed=69420, constant=False),
            vdf.noise.AddGrain(seed=69420, constant=False)
        ]).graining(deband)

    return grain
コード例 #14
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Main filterchain"""
    import lvsfunc as lvf
    import vardefunc as vdf
    from vsutil import depth

    src = JP_BD.clip_cut
    cloc = depth(src, 16).resize.Bicubic(chromaloc_in=1, chromaloc=0)

    dft = core.dfttest.DFTTest(cloc,
                               sigma=0.6,
                               sbsize=8,
                               sosize=6,
                               tbsize=3,
                               tosize=1)
    decs = vdf.noise.decsiz(dft, sigmaS=4, min_in=200 << 8, max_in=232 << 8)

    baa = lvf.aa.based_aa(decs, str(shader_file))
    sraa = lvf.sraa(decs, rfactor=1.5)
    clmp = lvf.aa.clamp_aa(decs, baa, sraa, strength=1.5)

    deband = flt.masked_f3kdb(clmp, rad=16, thr=[20, 16])

    grain = vdf.noise.Graigasm(thrs=[x << 8 for x in (32, 80, 128, 176)],
                               strengths=[(0.25, 0.0), (0.20, 0.0),
                                          (0.15, 0.0), (0.0, 0.0)],
                               sizes=(1.20, 1.15, 1.10, 1),
                               sharps=(80, 70, 60, 50),
                               grainers=[
                                   vdf.noise.AddGrain(seed=69420,
                                                      constant=False),
                                   vdf.noise.AddGrain(seed=69420,
                                                      constant=False),
                                   vdf.noise.AddGrain(seed=69420,
                                                      constant=True)
                               ]).graining(deband)

    return grain
コード例 #15
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Main filterchain"""
    import lvsfunc as lvf
    import rekt
    import vardefunc as vdf
    from awsmfunc import bbmod
    from ccd import ccd
    from vsutil import depth

    src = JP_BD.clip_cut
    rkt = rekt.rektlvls(src, [0, -1], [30, 17], [0], [17])
    bb_y = bbmod(rkt, top=2, left=2, right=2, bottom=2, blur=9999, u=False, v=False)
    bb_uv = bbmod(bb_y, left=2, right=2, y=False)
    bb = depth(bb_uv, 16)

    den = core.dfttest.DFTTest(bb, sigma=3.6, tbsize=5, tosize=3)
    den_uv = ccd(den, matrix='709')
    decs = vdf.noise.decsiz(den_uv, sigmaS=8, min_in=200 << 8, max_in=232 << 8)

    cwarp = core.warp.AWarpSharp2(decs, thresh=72, blur=3, type=1, depth=4, planes=[1, 2])

    deband = flt.masked_f3kdb(cwarp, rad=17, thr=[24, 16], grain=[24, 12])

    grain = vdf.noise.Graigasm(
        thrs=[x << 8 for x in (32, 80, 128, 176)],
        strengths=[(0.20, 0.0), (0.15, 0.0), (0.10, 0.0), (0.0, 0.0)],
        sizes=(1.20, 1.15, 1.10, 1),
        sharps=(100, 80, 60, 20),
        grainers=[
            vdf.noise.AddGrain(seed=69420, constant=True),
            vdf.noise.AddGrain(seed=69420, constant=True),
            vdf.noise.AddGrain(seed=69420, constant=True)
        ]).graining(deband)

    no_flt = lvf.rfs(grain, depth(bb, 16), no_filter)

    return no_flt
コード例 #16
0
def pre_filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """
    Regular filtering to get the output images to stitch.

    This is preferable over handling it unfiltered, since it'll be faster than encoding it
    and reduces the amount of jitter caused by the upscale after.
    """
    import lvsfunc as lvf
    import rekt
    import vardefunc as vdf
    from awsmfunc import bbmod
    from muvsfunc import SSIM_downsample
    from vsutil import depth, get_y, join, plane

    src = JP_BD.clip_cut

    # Fixing animation f**k-ups
    if freeze_ranges:
        src = core.std.FreezeFrames(
            src,
            [s[0] for s in freeze_ranges],
            [e[1] for e in freeze_ranges],
            [f[2] for f in freeze_ranges]
        )

    # Edgefixing
    ef = rekt.rektlvls(
        src, prot_val=[16, 235], min=16, max=235,
        rownum=[0, src.height-1], rowval=[16, 16],
        colnum=[0, src.width-1], colval=[16, 16],
    )

    bb_y = bbmod(ef, left=1, top=1, right=1, bottom=1, thresh=32, y=True, u=False, v=False)
    bb_uv = bbmod(bb_y, left=2, top=2, right=2, bottom=2, y=False, u=True, v=True)

    cshift = flt.shift_chroma(bb_uv, left=0.6)
    cshift = lvf.rfs(bb_uv, cshift, cshift_left_ranges)

    bb32 = depth(cshift, 32)
    bb32_y = get_y(bb32)

    # Descaling + DPIR while it's at a lower res (so I can actually run it because >memory issues xd)
    descale = lvf.kernels.Catrom().descale(bb32_y, 1280, 720)
    downscale = lvf.kernels.Catrom(format=vs.YUV444PS).scale(bb32, 1280, 720)
    descale_444 = join([descale, plane(downscale, 1), plane(downscale, 2)])
    denoise_y = lvf.deblock.vsdpir(descale_444, strength=2.75, mode='deblock', matrix=1, i444=True, cuda=True)

    supersample = vdf.scale.fsrcnnx_upscale(get_y(denoise_y), shader_file=shader_file, downscaler=None)
    downscaled = SSIM_downsample(supersample, src.width, src.height, smooth=((3 ** 2 - 1) / 12) ** 0.5,
                                 sigmoid=True, filter_param_a=0, filter_param_b=0)

    # Create credit mask
    upscale = lvf.kernels.Catrom().scale(descale, src.width, src.height)
    credit_mask = lvf.scale.descale_detail_mask(bb32_y, upscale, threshold=0.055) \
        .std.Deflate().std.Deflate().std.Minimum()

    # Merge early for additional accuracy with DPIR
    merged = core.std.MaskedMerge(downscaled, bb32_y, credit_mask)

    down_y = lvf.kernels.Catrom().scale(merged, src.width/2, src.height/2)
    down_i444 = join([down_y, plane(bb32, 1), plane(bb32, 2)])
    deblock_down = lvf.deblock.vsdpir(down_i444, strength=3, mode='denoise', matrix=1, i444=True, cuda=True)

    scaled = depth(join([merged, plane(deblock_down, 1), plane(deblock_down, 2)]), 16)

    # Final bit of "denoising"
    dft = core.dfttest.DFTTest(scaled, sigma=2.0, tbsize=5, tosize=3, planes=[0])
    decs = vdf.noise.decsiz(dft, sigmaS=4, min_in=208 << 8, max_in=232 << 8)

    # AA
    baa = lvf.aa.based_aa(decs, str(shader_file))
    sraa = lvf.sraa(decs, rfactor=1.65)
    clmp = lvf.aa.clamp_aa(decs, baa, sraa, strength=1.3)

    dehalo = lvf.dehalo.masked_dha(clmp, rx=1.4, ry=1.4, brightstr=0.4)
    cwarp = core.warp.AWarpSharp2(dehalo, thresh=72, blur=3, type=1, depth=4, planes=[1, 2])

    # Merge credits (if applicable)
    merged = core.std.MaskedMerge(cwarp, depth(bb32, 16), depth(credit_mask, 16))

    deband = core.average.Mean([
        flt.masked_f3kdb(merged, rad=16, thr=[20, 24], grain=[24, 12]),
        flt.masked_f3kdb(merged, rad=20, thr=[28, 24], grain=[24, 12]),
        flt.masked_placebo(merged, rad=6, thr=2.5, itr=2, grain=4)
    ])

    no_flt = lvf.rfs(deband, depth(bb32, 16), no_filter)

    return no_flt
コード例 #17
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Main filterchain"""
    import lvsfunc as lvf
    import rekt
    import vardefunc as vdf
    from awsmfunc import bbmod
    from muvsfunc import SSIM_downsample
    from vsutil import depth, get_y

    src = JP_BD.clip_cut
    rkt = rekt.rektlvls(src, [0, -1], [17, 17], [0, -1], [17, 21])
    bb_y = bbmod(rkt, top=2, left=2, right=1, u=False, v=False)
    bb_uv = bbmod(bb_y, left=2, right=2, y=False)
    bb = depth(bb_uv, 32)

    descale = lvf.kernels.Mitchell().descale(get_y(bb), 1280, 720)
    up_chr = vdf.scale.to_444(bb, 1920, 1080, True).resize.Bicubic(1280, 720)
    descale_merge = vdf.misc.merge_chroma(descale, up_chr)
    denoise_down = lvf.deblock.vsdpir(descale_merge, strength=5, mode='deblock', matrix=1, i444=True, cuda=True)

    supersample = vdf.scale.nnedi3_upscale(get_y(denoise_down))
    downscaled = SSIM_downsample(supersample, bb.width, bb.height, smooth=((3 ** 2 - 1) / 12) ** 0.5,
                                 sigmoid=True, filter_param_a=0, filter_param_b=0)

    den_chr_up = core.resize.Bicubic(denoise_down, bb.width, bb.height, bb.format.id)
    den_chr_up_shift = core.resize.Bicubic(denoise_down, bb.width, bb.height, bb.format.id, src_left=-0.5)
    den_chr_up = lvf.rfs(den_chr_up, den_chr_up_shift, shift_chr)

    scaled = vdf.misc.merge_chroma(downscaled, den_chr_up)
    scaled = depth(scaled, 16)

    decs = vdf.noise.decsiz(scaled, sigmaS=4, min_in=208 << 8, max_in=232 << 8)

    deband = core.average.Mean([
        flt.masked_f3kdb(decs, rad=17, thr=[20, 24], grain=[24, 12]),
        flt.masked_f3kdb(decs, rad=21, thr=[32, 24], grain=[24, 12]),
        flt.masked_placebo(decs, rad=6, thr=2.8, itr=2, grain=4)
    ])

    grain = vdf.noise.Graigasm(
        thrs=[x << 8 for x in (32, 80, 128, 176)],
        strengths=[(0.25, 0.0), (0.20, 0.0), (0.15, 0.0), (0.0, 0.0)],
        sizes=(1.25, 1.20, 1.15, 1),
        sharps=(80, 70, 60, 50),
        grainers=[
            vdf.noise.AddGrain(seed=69420, constant=False),
            vdf.noise.AddGrain(seed=69420, constant=False),
            vdf.noise.AddGrain(seed=69420, constant=True)
        ]).graining(deband)

    grain_str = vdf.noise.Graigasm(
        thrs=[x << 8 for x in (32, 80, 128, 176)],
        strengths=[(0.35, 0.0), (0.30, 0.0), (0.25, 0.0), (0.0, 0.0)],
        sizes=(1.25, 1.20, 1.15, 1),
        sharps=(80, 70, 60, 50),
        grainers=[
            vdf.noise.AddGrain(seed=69420, constant=False),
            vdf.noise.AddGrain(seed=69420, constant=False),
            vdf.noise.AddGrain(seed=69420, constant=True)
        ]).graining(deband)

    grain = lvf.rfs(grain, grain_str, str_grain)

    return grain
コード例 #18
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Main VapourSynth filterchain"""
    import EoEfunc as eoe
    import lvsfunc as lvf
    import vardefunc as vdf
    from ccd import ccd
    from finedehalo import fine_dehalo
    from vsutil import depth, get_y

    src = JP_BD.clip_cut
    src = depth(src, 16)

    # This noise can burn in hell.
    denoise_pre = get_y(src.dfttest.DFTTest(sigma=1.0))
    denoise_ret = core.retinex.MSRCP(denoise_pre, sigma=[50, 200, 350], upper_thr=0.005)
    denoise_mask = flt.detail_mask(denoise_ret, sigma=2.0, lines_brz=3000).rgvs.RemoveGrain(4)

    denoise_pre = core.dfttest.DFTTest(src, sigma=4.0)
    denoise_smd = eoe.dn.CMDegrain(src, tr=5, thSAD=275, freq_merge=True, prefilter=denoise_pre)
    denoise_masked = core.std.MaskedMerge(denoise_smd, src, denoise_mask)

    denoise_uv = ccd(denoise_masked, threshold=6)
    decs = vdf.noise.decsiz(denoise_uv, sigmaS=8, min_in=200 << 8, max_in=235 << 8)

    # F**K THIS SHOW'S LINEART HOLY SHIT
    baa = lvf.aa.based_aa(decs.std.Transpose(), str(shader_file), gamma=120)
    baa = lvf.aa.based_aa(baa.std.Transpose(), str(shader_file), gamma=120)
    sraa = lvf.sraa(decs, rfactor=1.4)
    clmp_aa = lvf.aa.clamp_aa(decs, baa, sraa, strength=1.65)

    # AAing introduces some haloing (zzzzzz)
    restr_edges = fine_dehalo(clmp_aa, decs)
    restr_dark = core.std.Expr([clmp_aa, restr_edges], "x y min")

    deband = core.average.Mean([
        flt.masked_f3kdb(restr_dark, rad=17, thr=[28, 20], grain=[12, 8]),
        flt.masked_f3kdb(restr_dark, rad=21, thr=[36, 32], grain=[24, 12]),
        flt.masked_placebo(restr_dark, rad=6.5, thr=2.5, itr=2, grain=4)
    ])

    grain = vdf.noise.Graigasm(
        thrs=[x << 8 for x in (32, 80, 128, 176)],
        strengths=[(0.25, 0.0), (0.20, 0.0), (0.15, 0.0), (0.0, 0.0)],
        sizes=(1.20, 1.15, 1.10, 1),
        sharps=(80, 70, 60, 50),
        grainers=[
            vdf.noise.AddGrain(seed=69420, constant=True),
            vdf.noise.AddGrain(seed=69420, constant=False),
            vdf.noise.AddGrain(seed=69420, constant=False)
        ]).graining(deband)

    # Masking credits at the end
    get_max = core.std.Expr([grain, decs], "x y max")

    sq_mask = [
        lvf.mask.BoundingBox((782, 603), (507, 389)),
        lvf.mask.BoundingBox((0, 957), (1920, 123)),
        lvf.mask.BoundingBox((1139, 835), (478, 142))
    ]

    sqmask = core.std.BlankClip(get_y(src))
    for sq in sq_mask:
        mask = sq.get_mask(src).std.BoxBlur(hpasses=20, vpasses=20)
        sqmask = core.std.Expr([mask, sqmask], "x y +")

    max_masked = core.std.MaskedMerge(get_max, grain, sqmask)
    max_ed = lvf.rfs(grain, max_masked, (5467, None))

    return max_ed
コード例 #19
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Main VapourSynth filterchain"""
    import havsfunc as haf
    import lvsfunc as lvf
    import vardefunc as vdf
    from ccd import ccd
    from muvsfunc import SSIM_downsample
    from vsutil import depth, get_y

    src = JP_BD.clip_cut
    src = depth(src, 32)

    src_y = get_y(src)
    l_mask = vdf.mask.FDOG().get_mask(src_y, lthr=0.065, hthr=0.065).std.Maximum().std.Minimum()
    l_mask = l_mask.std.Median().std.Convolution([1] * 9)

    # Rescaling
    descale = flt.auto_descale(src_y)
    desc_i = flt.descale_fields(src_y, kernel=lvf.kernels.BicubicSharp)
    descale = lvf.rfs(descale, desc_i, [(1555, 1685)])

    supersample = vdf.scale.nnedi3cl_double(descale, use_znedi=True, pscrn=1)
    downscaled = SSIM_downsample(supersample, src.width, src.height, smooth=((3 ** 2 - 1) / 12) ** 0.5,
                                 sigmoid=True, filter_param_a=0, filter_param_b=0)

    scaled_mask = core.std.MaskedMerge(src_y, downscaled, l_mask)
    scaled = depth(vdf.misc.merge_chroma(scaled_mask, src), 16)

    # Denoising
    l_mask_16 = depth(l_mask, 16).std.Minimum()
    dft = core.dfttest.DFTTest(scaled, sigma=1.25, tbsize=3, tosize=1)
    dft_masked = core.std.MaskedMerge(dft, scaled, l_mask_16)

    ccd_uv = ccd(dft, threshold=4, matrix='709')
    ccd_uv = core.std.MaskedMerge(ccd_uv, dft_masked, l_mask_16, planes=[1, 2])

    decs = vdf.noise.decsiz(ccd_uv, sigmaS=4, min_in=212 << 8, max_in=240 << 8)

    # AA and slight lineart enhancement
    baa = lvf.aa.based_aa(decs, shader_file)
    sraa = lvf.sraa(decs, rfactor=1.5, downscaler=lvf.kernels.Bicubic(b=-1/2, c=1/4).scale)
    clmp = lvf.aa.clamp_aa(decs, baa, sraa, strength=1.5)

    sraa_strong = flt.transpose_sraa(decs, rfactor=1.2, downscaler=lvf.kernels.Bicubic(b=-1/2, c=1/4).scale)
    clmp = lvf.rfs(clmp, sraa_strong, [])

    darken = haf.FastLineDarkenMOD(clmp, strength=36)

    # Debanding and graining
    deband = core.average.Mean([
        flt.masked_f3kdb(darken, rad=18, thr=[28, 24]),
        flt.masked_placebo(darken, rad=15, thr=4)
    ])

    grain = vdf.noise.Graigasm(
        thrs=[x << 8 for x in (32, 80, 128, 176)],
        strengths=[(0.15, 0.0), (0.10, 0.0), (0.10, 0.0), (0.0, 0.0)],
        sizes=(1.15, 1.10, 1.05, 1),
        sharps=(60, 50, 50, 50),
        grainers=[
            vdf.noise.AddGrain(seed=69420, constant=True),
            vdf.noise.AddGrain(seed=69420, constant=True),
            vdf.noise.AddGrain(seed=69420, constant=True)
        ]).graining(deband)

    return grain
コード例 #20
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Main filterchain"""
    import lvsfunc as lvf
    import muvsfunc as muf
    import vardefunc as vdf
    from adptvgrnMod import adptvgrnMod
    from vsutil import depth, get_w, get_y
    from xvs import WarpFixChromaBlend

    src_path = [
        r"websrc/CHRONOS RULER E05 [1080p][AAC][JapDub][GerEngSub][Web-DL].mkv",
        r"websrc/CHRONOS RULER E06 [1080p][AAC][JapDub][GerEngSub][Web-DL].mkv",
        r"websrc/CHRONOS RULER E07 [1080p][AAC][JapDub][GerEngSub][Web-DL].mkv",
        r"websrc/CHRONOS RULER E08 [1080p][AAC][JapDub][GerEngSub][Web-DL].mkv",
        r"websrc/CHRONOS RULER E09 [1080p][AAC][JapDub][GerEngSub][Web-DL].mkv",
        r"websrc/CHRONOS RULER E10 [1080p][AAC][JapDub][GerEngSub][Web-DL].mkv",
        r"websrc/CHRONOS RULER E11 [1080p][AAC][JapDub][GerEngSub][Web-DL].mkv",
        r"websrc/CHRONOS RULER E12 [1080p][AAC][JapDub][GerEngSub][Web-DL].mkv",
        r"websrc/CHRONOS RULER E13 [1080p][AAC][JapDub][GerEngSub][Web-DL].mkv"
    ]

    base = JP_CR.clip_cut
    src = [lvf.src(c, force_lsmas=True, cachedir='') for c in src_path]
    src_c = lvf.src(src_path[-3], force_lsmas=True, cachedir='')

    # Trimming clips to get just the OP
    src[0] = src[0][2182] * 11 + src[0][2182:2182 + base.num_frames - 11]
    src[1] = src[1][936:936 + base.num_frames]
    src[2] = src[2][1104:1104 + base.num_frames]
    src[3] = src[3][6378:6378 + base.num_frames]
    src[4] = src[4][5179:5179 + base.num_frames]
    src[5] = src[5][1200:1200 + base.num_frames]
    src[6] = src[6][1822:1822 + base.num_frames]
    src[7] = src[7][1558:1558 + base.num_frames]
    src[8] = src[8][1224:1224 + base.num_frames]

    mean = core.average.Mean(src)  # type:ignore[attr-defined]
    mean = mean[:-1] + src_c[1822:3980][-2:]
    mean = depth(mean, 32)

    mean_y = get_y(mean)
    descale = lvf.kernels.Lanczos(taps=5).descale(mean_y, get_w(945), 945)
    rescale = vdf.scale.nnedi3cl_double(descale, pscrn=1)
    rescale = muf.SSIM_downsample(rescale, mean_y.width, mean_y.height)
    scaled = vdf.misc.merge_chroma(rescale, mean)
    scaled = depth(scaled, 16)

    decs = vdf.noise.decsiz(scaled, sigmaS=8, min_in=208 << 8, max_in=232 << 8)

    deband_reg = flt.masked_f3kdb(decs, thr=24, grain=[24, 12])

    detail_mask = flt.detail_mask(decs, brz=(1200, 3000))
    den_ref = core.knlm.KNLMeansCL(decs, d=1, a=3, s=4, h=0.5, channels='Y')
    deband_str = flt.placebo_debander(den_ref, placebo_args={'threshold': 4})
    deband_str = core.std.MaskedMerge(deband_str, deband_reg, detail_mask)

    deband = lvf.rfs(deband_reg, deband_str, [(1162, 1193), (1210, 1216)])

    grain: vs.VideoNode = adptvgrnMod(deband,
                                      seed=42069,
                                      strength=0.3,
                                      luma_scaling=8,
                                      size=1.35,
                                      sharp=100,
                                      grain_chroma=False)

    return grain
コード例 #21
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Main filterchain"""
    import EoEfunc as eoe
    import havsfunc as haf
    import kagefunc as kgf
    import lvsfunc as lvf
    import vardefunc as vdf
    from adptvgrnMod import adptvgrnMod
    from ccd import ccd
    from vsdpir import DPIR
    from vsutil import depth

    src = pre_filter()
    src = depth(src, 16)

    # Fix slight green tint present throughout parts of the OP
    src_g = core.std.Expr(src, ["", "", "x 32768 = x x 96 + ?"])
    src_g = lvf.rfs(src, src_g, [(None, 873)])

    scaled, descale_mask = flt.rescaler(src_g,
                                        height=854,
                                        shader_file=shader_file)

    # Denoising this is rough. Lots of fine detail that's easy to destroy.
    detail_mask = flt.detail_mask(scaled,
                                  pf_sigma=1.5,
                                  rxsigma=[50, 150, 200, 300],
                                  rad=2,
                                  brz=[2250, 3500])
    denoise_y = eoe.dn.BM3D(scaled, sigma=[0.3, 0])
    denoise_y_str = flt.to_yuvps(
        DPIR(flt.to_rgbs(scaled),
             strength=40,
             task='deblock',
             device_type='cpu'))
    denoise_y = lvf.rfs(denoise_y, denoise_y_str, [(1384, 1398)])

    denoise_uv = ccd(denoise_y, threshold=7, matrix='709')
    denoise_uv_rep = core.std.MaskedMerge(denoise_uv, denoise_y, detail_mask)
    stab = haf.GSMC(denoise_uv_rep, radius=1, thSAD=200, planes=[0])
    stab = lvf.rfs(
        stab, scaled,
        [(1399, 1400),
         (1408, 1416)])  # Undo denoising because it eats lines on these scenes
    decs = vdf.noise.decsiz(stab, sigmaS=8, min_in=200 << 8, max_in=232 << 8)

    # F**k ufo lines
    eed = lvf.aa.nneedi3_clamp(decs, strength=1.6)
    sraa = lvf.sraa(decs, rfactor=1.5, aafun=flt.eedi3_singlerate_custom)
    clamp_aa = lvf.aa.clamp_aa(decs, eed, sraa, strength=1.6)

    # Certain frames have truly godawful aliasing. We attempt to fix those here
    tsraa = flt.transpose_sraa(decs,
                               rfactor=1.5,
                               aafun=flt.eedi3_singlerate_custom)
    tsraa_rep = core.rgvs.Repair(tsraa, clamp_aa, 13)
    aa_rfs = lvf.rfs(clamp_aa, tsraa_rep, strong_aa)

    # F**k ufo lines
    ec = haf.EdgeCleaner(aa_rfs, strength=4)

    # This fixes up all the super red scenes fairly well
    crecon = lvf.recon.chroma_reconstruct(ec)

    deband_a = flt.masked_f3kdb(crecon,
                                rad=18,
                                thr=24,
                                grain=[24, 16],
                                mask_args={'brz': (1250, 2250)})
    deband_b = flt.masked_f3kdb(crecon,
                                rad=24,
                                thr=40,
                                grain=[32, 24],
                                mask_args={'brz': (1000, 1750)})
    deband_c = flt.placebo_debander(crecon,
                                    grain=2,
                                    iterations=2,
                                    threshold=8,
                                    radius=16)
    deband = lvf.rfs(deband_a, deband_b, [])
    deband = kgf.crossfade(deband[:2246 + 48], deband_c[2246:], 47)
    deband = lvf.rfs(deband, crecon, [(1399, 1400)])

    sqmask = lvf.mask.BoundingBox((699, 50), (526, 870)).get_mask(deband)
    sqmask = core.bilateral.Gaussian(sqmask, sigma=4)
    blur = core.bilateral.Gaussian(deband,
                                   sigma=25).bilateral.Gaussian(sigma=25)
    blur_mask = core.std.MaskedMerge(blur, deband, sqmask)
    blurred = kgf.crossfade(deband[:2412 + 48], blur_mask[2411:], 48)

    blurred_del = core.std.DeleteFrames(blurred, [2293])

    grain_a = adptvgrnMod(blurred_del,
                          seed=42069,
                          strength=0.15,
                          static=True,
                          size=1.15,
                          sharp=80,
                          grain_chroma=False)
    grain_b = adptvgrnMod(blurred_del,
                          seed=42069,
                          strength=0.25,
                          static=True,
                          size=1.15,
                          sharp=100,
                          grain_chroma=False)
    grain_c = adptvgrnMod(blurred_del,
                          seed=42069,
                          strength=0.2,
                          static=False,
                          size=1.15,
                          sharp=100,
                          grain_chroma=False)
    grain = lvf.rfs(grain_a, grain_b, [(2390, None)])
    grain = lvf.rfs(grain, grain_c, [(885, 1149), (1324, 1345), (1489, 1506),
                                     (1603, 1810), (1981, 1996)])

    # Accidentally a frame during one of the previous processes. Easy to fix, though.
    oopsie = core.std.DeleteFrames(grain, [grain.num_frames - 1])
    out = enc.dither_down(oopsie)

    return out
コード例 #22
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Main VapourSynth filterchain"""
    import EoEfunc as eoe
    import lvsfunc as lvf
    import vardefunc as vdf
    from ccd import ccd
    from finedehalo import fine_dehalo
    from vsutil import depth, get_y, insert_clip

    src = JP_BD.clip_cut
    src_c = src
    src_ncop, src_nced = JP_NCOP.clip_cut, JP_NCED.clip_cut
    b = core.std.BlankClip(src, length=1)

    # OP/ED stack comps to check if they line up
    if opstart is not False:
        op_scomp = lvf.scomp(src[opstart:opstart+src_ncop.num_frames-1]+b, src_ncop[:-op_offset]+b) \
            .text.Text('src', 7).text.Text('op', 9)
    if edstart is not False:
        ed_scomp = lvf.scomp(src[edstart:edstart+src_nced.num_frames-1]+b, src_nced[:-ed_offset]+b) \
            .text.Text('src', 7).text.Text('ed', 9)

    # Splicing in NCs and diff'ing back the credits
    if opstart is not False:
        src = insert_clip(src, src_ncop[:-op_offset], opstart)
        src = lvf.rfs(src, src_c, [(opstart + 811, opstart + 859)])
    if edstart is not False:
        src = insert_clip(src, src_nced[:-ed_offset], edstart)

    den_src, den_ncs = map(partial(core.dfttest.DFTTest, sigma=10),
                           [src_c, src])
    den_src, den_ncs = depth(den_src, 32), depth(den_ncs, 32)
    diff = core.std.MakeDiff(den_src, den_ncs).dfttest.DFTTest(sigma=50.0)

    # For some reason there's noise from previous credits remaining? Removing that here
    diff_brz = vdf.misc.merge_chroma(diff.std.Binarize(0.03), diff)
    diff = core.std.Expr([diff, diff_brz], "x y min")

    src = depth(src, 16)

    # This noise can burn in hell.
    denoise_pre = get_y(src.dfttest.DFTTest(sigma=1.0))
    denoise_ret = core.retinex.MSRCP(denoise_pre,
                                     sigma=[50, 200, 350],
                                     upper_thr=0.005)
    denoise_mask = flt.detail_mask(denoise_ret, sigma=2.0,
                                   lines_brz=3000).rgvs.RemoveGrain(4)

    denoise_pre = core.dfttest.DFTTest(src, sigma=4.0)
    denoise_smd = eoe.dn.CMDegrain(src,
                                   tr=5,
                                   thSAD=275,
                                   freq_merge=True,
                                   prefilter=denoise_pre)
    denoise_masked = core.std.MaskedMerge(denoise_smd, src, denoise_mask)

    denoise_uv = ccd(denoise_masked, threshold=6)
    decs = vdf.noise.decsiz(denoise_uv,
                            sigmaS=8,
                            min_in=200 << 8,
                            max_in=235 << 8)

    # F**K THIS SHOW'S LINEART HOLY SHIT
    baa = lvf.aa.based_aa(decs.std.Transpose(), str(shader_file), gamma=120)
    baa = lvf.aa.based_aa(baa.std.Transpose(), str(shader_file), gamma=120)
    sraa = lvf.sraa(decs, rfactor=1.4)
    clmp_aa = lvf.aa.clamp_aa(decs, baa, sraa, strength=1.65)

    # AAing introduces some haloing (zzzzzz)
    restr_edges = fine_dehalo(clmp_aa, decs)
    restr_dark = core.std.Expr([clmp_aa, restr_edges], "x y min")

    # Masking credits at the end if there's no NCED
    get_max = core.std.Expr([restr_dark, decs], "x y max")

    if opstart is False:
        restr_dark = lvf.rfs(restr_dark, get_max, [(None, 3500)])
    if edstart is False:
        restr_dark = lvf.rfs(restr_dark, get_max, [(-5000, None)])

    deband = core.average.Mean([
        flt.masked_f3kdb(restr_dark, rad=17, thr=[28, 20], grain=[12, 8]),
        flt.masked_f3kdb(restr_dark, rad=21, thr=[36, 32], grain=[24, 12]),
        flt.masked_placebo(restr_dark, rad=6.5, thr=2.5, itr=2, grain=4)
    ])

    grain = vdf.noise.Graigasm(thrs=[x << 8 for x in (32, 80, 128, 176)],
                               strengths=[(0.25, 0.0), (0.20, 0.0),
                                          (0.15, 0.0), (0.0, 0.0)],
                               sizes=(1.20, 1.15, 1.10, 1),
                               sharps=(80, 70, 60, 50),
                               grainers=[
                                   vdf.noise.AddGrain(seed=69420,
                                                      constant=True),
                                   vdf.noise.AddGrain(seed=69420,
                                                      constant=False),
                                   vdf.noise.AddGrain(seed=69420,
                                                      constant=False)
                               ]).graining(deband)

    merge_creds = core.std.MergeDiff(depth(grain, 32), diff)

    return merge_creds
コード例 #23
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Regular VapourSynth filterchain"""
    import EoEfunc.denoise as eoe
    import havsfunc as haf
    import lvsfunc as lvf
    import vardefunc as vdf
    from adptvgrnMod import adptvgrnMod
    from ccd import ccd
    from muvsfunc import SSIM_downsample
    from vsutil import depth, get_y, iterate
    from xvs import WarpFixChromaBlend

    src = JP_clip.clip_cut.std.AssumeFPS(fpsnum=24000, fpsden=1001)
    src = depth(src, 16)

    # TO-DO: Figure out how they post-sharpened it. Probably some form of unsharpening?
    src_y = depth(get_y(src), 32)
    descale = lvf.kernels.Bicubic(b=0, c=3 / 4).descale(src_y, 1440, 810)
    double = vdf.scale.nnedi3cl_double(descale, pscrn=1)
    rescale = depth(SSIM_downsample(double, 1920, 1080), 16)
    scaled = vdf.misc.merge_chroma(rescale, src)

    denoise_ref = core.dfttest.DFTTest(scaled, sigma=1.8)
    denoise = lvf.denoise.bm3d(scaled, sigma=[0.75, 0.65], ref=denoise_ref)
    cdenoise = ccd(denoise, threshold=3, matrix='709')
    decs = vdf.noise.decsiz(cdenoise,
                            sigmaS=4,
                            min_in=208 << 8,
                            max_in=232 << 8)

    # Dehalo fuckery. F**k the sharpening, dude
    dehalo = haf.YAHR(decs, blur=2, depth=32)
    dehalo_2 = lvf.dehalo.masked_dha(dehalo, ry=2.5, rx=2.5)
    halo_mask = lvf.mask.halo_mask(decs, rad=3, brz=0.3, thma=0.42)
    dehalo_masked = core.std.MaskedMerge(decs, dehalo_2, halo_mask)
    dehalo_min = core.std.Expr([dehalo_masked, decs], "x y min")

    # Brightening the lines to undo the unsharpening's line darkening
    bright = haf.FastLineDarkenMOD(dehalo_min, strength=-24)

    # AA
    baa = lvf.aa.based_aa(bright, str(shader_file))
    sraa = lvf.sraa(bright, rfactor=1.45)
    clmp = lvf.aa.clamp_aa(bright, baa, sraa, strength=1.45)

    line_mask = core.std.Prewitt(clmp)
    cwarp = WarpFixChromaBlend(clmp, thresh=96, depth=6)
    cwarp = core.std.MaskedMerge(cwarp, clmp, line_mask)

    upscale = lvf.kernels.Bicubic(b=0, c=3 / 4).scale(descale, 1920, 1080)
    credit_mask = lvf.scale.descale_detail_mask(src_y, upscale, threshold=0.08)
    credit_mask = iterate(credit_mask, core.std.Deflate, 3)
    credit_mask = iterate(credit_mask, core.std.Inflate, 3)
    credit_mask = iterate(credit_mask, core.std.Maximum, 2)
    merge_credits = core.std.MaskedMerge(cwarp, src, depth(credit_mask, 16))

    deband = flt.masked_f3kdb(merge_credits, rad=15, thr=20, grain=[12, 0])
    grain: vs.VideoNode = adptvgrnMod(deband,
                                      seed=42069,
                                      strength=0.15,
                                      luma_scaling=10,
                                      size=1.25,
                                      sharp=70,
                                      static=True,
                                      grain_chroma=False)

    return grain