Esempio n. 1
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Regular VapourSynth filterchain"""
    import lvsfunc as lvf
    import vardefunc as vdf
    from vsutil import depth, get_y

    src, *_ = trim()
    src_CR = JP_CR.clip_cut
    src_NCOP, src_NCED = YT_NCOP.clip, YT_NCED.clip
    b = core.std.BlankClip(src, length=1)

    # OP/ED stack comps to check that it lines up
    op_scomp = lvf.scomp(src[opstart:opstart + src_NCOP.num_frames - 1] + b,
                         src_NCOP[:-op_offset] + b)  # noqa
    ed_scomp = lvf.scomp(src[edstart:edstart + src_NCED.num_frames - 1] + b,
                         src_NCED[:-ed_offset] + b)  # noqa

    # Blurring clips
    blur_src = core.bilateral.Gaussian(src, sigma=2.5)
    blur_NCOP = core.bilateral.Gaussian(src_NCOP, sigma=2.5)
    blur_NCED = core.bilateral.Gaussian(src_NCED, sigma=2.5)

    # Masking credits
    op_mask = vdf.dcm(
        blur_src, blur_src[opstart:opstart+src_NCOP.num_frames-op_offset], blur_NCOP[:-op_offset],
        start_frame=opstart, thr=28, prefilter=False) if opstart is not False \
        else get_y(core.std.BlankClip(src))
    ed_mask = vdf.dcm(
        blur_src, blur_src[edstart:edstart+src_NCED.num_frames-ed_offset], blur_NCED[:-ed_offset],
        start_frame=edstart, thr=25, prefilter=False) if edstart is not False \
        else get_y(core.std.BlankClip(src))
    credit_mask = core.std.Expr([op_mask, ed_mask], expr='x y +')
    credit_mask = depth(credit_mask, 16).std.Binarize()

    src = depth(src, 16)
    line_mask = vdf.mask.FDOG().get_mask(get_y(src))
    src_merge = core.std.MaskedMerge(src, depth(src_CR, 16), line_mask)

    src_y = get_y(src_merge)
    denoise_y = flt.bm3d_ref(src_y,
                             bm3d_sigma=1,
                             dec_sigma=8,
                             dec_min=192 << 8)
    denoise_y = core.std.MaskedMerge(denoise_y, src_y, line_mask)
    merged = vdf.misc.merge_chroma(denoise_y, src)

    dehalo = flt.bidehalo(merged, sigma=1, mask_args={'brz': 0.25})

    cmerged = core.std.MaskedMerge(dehalo, src, credit_mask)

    deband = flt.masked_f3kdb(cmerged,
                              thr=20,
                              grain=12,
                              mask_args={'brz': (1500, 3500)})
    grain = flt.default_grain(deband)

    return grain  # type: ignore
Esempio n. 2
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
Esempio n. 3
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Regular VapourSynth filterchain"""
    import lvsfunc as lvf
    import vardefunc as vdf
    from vsutil import depth, get_y

    src, *_ = trim()
    src_CR = JP_CR.clip_cut
    src_NCOP, src_NCED = YT_NCOP.clip, YT_NCED.clip
    b = core.std.BlankClip(src, length=1)

    # OP/ED stack comps to check that it lines up
    op_scomp = lvf.scomp(src[opstart:opstart + src_NCOP.num_frames - 1] + b,
                         src_NCOP[:-op_offset] + b)  # noqa
    ed_scomp = lvf.scomp(src[edstart:edstart + src_NCED.num_frames - 1] + b,
                         src_NCED[:-ed_offset] + b)  # noqa

    # Blurring clips
    blur_src = core.bilateral.Gaussian(src, sigma=2.5)
    blur_NCOP = core.bilateral.Gaussian(src_NCOP, sigma=2.5)
    blur_NCED = core.bilateral.Gaussian(src_NCED, sigma=2.5)

    # Masking credits
    op_mask = vdf.dcm(
        blur_src, blur_src[opstart:opstart+src_NCOP.num_frames-op_offset], blur_NCOP[:-op_offset],
        start_frame=opstart, thr=28, prefilter=False) if opstart is not False \
        else get_y(core.std.BlankClip(src))
    ed_mask = vdf.dcm(
        blur_src, blur_src[edstart:edstart+src_NCED.num_frames-ed_offset], blur_NCED[:-ed_offset],
        start_frame=edstart, thr=25, prefilter=False) if edstart is not False \
        else get_y(core.std.BlankClip(src))
    credit_mask = core.std.Expr([op_mask, ed_mask], expr='x y +')
    credit_mask = depth(credit_mask, 16).std.Binarize()

    # This time, AoD has better lines but worse gradients (over-debanded + super grained),
    # but only on certain dark and texture-heavy (but low-motion) scenes, but ugh effort
    src = depth(src, 16)
    line_mask = vdf.mask.FDOG().get_mask(get_y(src))
    src_merge = core.std.MaskedMerge(depth(src_CR, 16), src, line_mask)
    src_merge = lvf.rfs(src, src_merge, [(2637, 2722), (10933, 10978),
                                         (11388, 11479), (13058, 13406),
                                         (13539, 14029), (14052, 14300),
                                         (14422, 14560)])

    src_merge = depth(src_merge, 16)

    src_y = get_y(src_merge)
    denoise_y = flt.bm3d_ref(src_y,
                             bm3d_sigma=1,
                             dec_sigma=8,
                             dec_min=192 << 8)
    denoise_y = core.std.MaskedMerge(denoise_y, src_y, line_mask)
    merged = vdf.misc.merge_chroma(denoise_y, src)

    dehalo = flt.bidehalo(merged, sigma=1, mask_args={'brz': 0.25})

    cmerged = core.std.MaskedMerge(dehalo, src, credit_mask)

    deband = flt.masked_f3kdb(cmerged,
                              thr=20,
                              grain=12,
                              mask_args={'brz': (1500, 3500)})
    grain = flt.default_grain(deband)

    return grain  # type: ignore