Beispiel #1
0
def regrain(clip: vs.VideoNode) -> vs.VideoNode:
    sgrain: vs.VideoNode = kgf.adaptive_grain(clip, 0.15, luma_scaling=10)
    dgrain: vs.VideoNode = kgf.adaptive_grain(clip,
                                              0.1,
                                              luma_scaling=25,
                                              static=False)
    grain = dgrain.std.MergeDiff(clip.std.MakeDiff(sgrain))
    return grain
Beispiel #2
0
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
Beispiel #3
0
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)
Beispiel #4
0
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)
Beispiel #5
0
def _dbgra(clip: vs.VideoNode) -> vs.VideoNode:
    clip = depth(clip, 16)
    clip = hvf.SMDegrain(clip, tr=1, thSAD=200)
    clip = vdf.deband.dumb3kdb(clip, threshold=45)
    clip = core.std.Expr(clip, ['x 64 -', 'x 32 +', 'x 32 +'])
    clip = kgf.adaptive_grain(clip, 0.4)
    return clip
Beispiel #6
0
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)
Beispiel #7
0
def general_filtering(clip: vs.VideoNode,
                      mode='low',
                      denoise=True,
                      deband=True,
                      grain=True):
    """
        Generic filterchain. You can set the overall strenght by changing the mode.

        Modes:
        - lower
        - low
        - medium
        - high
        - higher
    """

    # There's probably way nicer ways to do this
    modes = {
        'lower': (0.1, 2, 10, 16, 0.1),
        'low': (0.4, 3, 14, 24, 0.2),
        'medium': (0.6, 4, 16, 32, 0.3),
        'high': (1.0, 6, 18, 40, 0.8),
        'higher': (2.0, 10, 23, 64, 2.0)
    }
    try:
        h, sigma, range, y, grain_strength = modes[mode]
    except KeyError:
        raise ValueError("general_filtering: Unknown mode!")

    filtered = clip

    if denoise:
        filtered = lvf.quick_denoise(filtered, h=h, sigma=sigma)

    if deband:
        cb = cr = y - 8
        filtered = core.f3kdb.Deband(filtered,
                                     range=range,
                                     y=y,
                                     cb=cb,
                                     cr=cr,
                                     grainy=0,
                                     grainc=0,
                                     output_depth=16)

    if grain:
        filtered = kgf.adaptive_grain(filtered, strength=grain_strength)

    return filtered
Beispiel #8
0
def do_filter():
    """Vapoursynth filtering"""
    def _nneedi3_clamp(clip: vs.VideoNode, strength: int = 1)-> vs.VideoNode:
        bits = clip.format.bits_per_sample - 8
        thr = strength * (1 >> bits)

        luma = get_y(clip)

        def _strong(clip: vs.VideoNode)-> vs.VideoNode:
            args = dict(alpha=0.25, beta=0.5, gamma=40, nrad=2, mdis=20, vcheck=3)
            clip = core.eedi3m.EEDI3(clip, 1, True, **args).std.Transpose()
            clip = core.eedi3m.EEDI3(clip, 1, True, **args).std.Transpose()
            return core.resize.Spline36(clip, luma.width, luma.height, src_left=-.5, src_top=-.5)

        def _weak(clip: vs.VideoNode)-> vs.VideoNode:
            args = dict(nsize=3, nns=2, qual=2)
            clip = core.znedi3.nnedi3(clip, 1, True, **args).std.Transpose()
            clip = core.znedi3.nnedi3(clip, 1, True, **args).std.Transpose()
            return core.resize.Spline36(clip, luma.width, luma.height, src_left=-.5, src_top=-.5)

        clip_aa = core.std.Expr([_strong(luma), _weak(luma), luma],
                                'x z - y z - * 0 < y x y {0} + min y {0} - max ?'.format(thr))
        return vdf.merge_chroma(clip_aa, clip)

    src = JPBD.src_cut
    src = depth(src, 16)

    denoise = CoolDegrain(src, tr=2, thsad=48, blksize=8, overlap=4, plane=4)


    antialias = _nneedi3_clamp(denoise)


    predenoise = mClean(antialias, thSAD=200, chroma=False)
    detail_mask = lvf.denoise.detail_mask(predenoise, rad=2, radc=2, brz_a=3250, brz_b=1250)
    ret_mask = kgf.retinex_edgemask(predenoise).std.Binarize(9250).std.Median().std.Inflate()
    line_mask = core.std.Expr([detail_mask, ret_mask], 'x y max')


    deband = core.neo_f3kdb.Deband(antialias, 17, 42, 42, 42, 12, 0, sample_mode=4, keep_tv_range=True)
    deband = core.std.MaskedMerge(deband, antialias, line_mask)


    grain = kgf.adaptive_grain(deband, 0.25, luma_scaling=10)

    final = core.resize.Bicubic(grain, format=vs.YUV420P10, dither_type='error_diffusion')
    final = core.std.Limiter(final, 16, [235 << 2, 240 << 2])

    return depth(final, 10)
Beispiel #9
0
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

    radius = 2
    clip_in = depth(out, 32)
    y, u, v = split(clip_in)
    y_m = core.resize.Bicubic(y,
                              960,
                              540,
                              src_left=-.5,
                              filter_param_a=1 / 3,
                              filter_param_b=1 / 3)

    def demangle(clip):
        return core.resize.Bicubic(clip, 1920, 1080, src_left=.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)

    scaled = depth(join([y, u_r, v_r]), 16)
    out = scaled

    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)
Beispiel #10
0
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

    deband_mask = lvf.denoise.detail_mask(out, brz_a=2000, brz_b=1000)
    deband = dbs.f3kpf(out, 17, 30, 30)
    deband_b = dbs.f3kpf(out, 17, 48, 48)
    deband = lvf.rfs(deband, deband_b, [(0, 89)])
    deband = core.std.MaskedMerge(deband, out, deband_mask)
    out = deband

    grain = kgf.adaptive_grain(out, 0.2, luma_scaling=8)
    grain = lvf.rfs(out, grain, [(0, 89)])
    out = grain

    return depth(out, 10)
Beispiel #11
0
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 = vdf.merge_chroma(upscale, out)

    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)
    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

    return depth(out, 10)
Beispiel #12
0
def do_filter():
    """Vapoursynth filtering"""
    def _nneedi3_clamp(clip: vs.VideoNode, strength: int = 1) -> vs.VideoNode:
        bits = clip.format.bits_per_sample - 8
        thr = strength * (1 >> bits)

        luma = get_y(clip)

        def _strong(clip: vs.VideoNode) -> vs.VideoNode:
            args = dict(alpha=0.25,
                        beta=0.5,
                        gamma=40,
                        nrad=2,
                        mdis=20,
                        vcheck=3)
            clip = core.eedi3m.EEDI3(clip, 1, True, **args).std.Transpose()
            clip = core.eedi3m.EEDI3(clip, 1, True, **args).std.Transpose()
            return core.resize.Spline36(clip,
                                        luma.width,
                                        luma.height,
                                        src_left=-.5,
                                        src_top=-.5)

        def _weak(clip: vs.VideoNode) -> vs.VideoNode:
            args = dict(nsize=3, nns=2, qual=2)
            clip = core.znedi3.nnedi3(clip, 1, True, **args).std.Transpose()
            clip = core.znedi3.nnedi3(clip, 1, True, **args).std.Transpose()
            return core.resize.Spline36(clip,
                                        luma.width,
                                        luma.height,
                                        src_left=-.5,
                                        src_top=-.5)

        clip_aa = core.std.Expr(
            [_strong(luma), _weak(luma), luma],
            'x z - y z - * 0 < y x y {0} + min y {0} - max ?'.format(thr))
        return vdf.merge_chroma(clip_aa, clip)

    def _perform_endcard(path: str, ref: vs.VideoNode) -> vs.VideoNode:
        endcard = lvf.src(path).std.AssumeFPS(ref)
        endcard = core.std.CropRel(endcard, left=6, top=20, right=0, bottom=6)
        endcard = core.resize.Bicubic(endcard,
                                      ref.width,
                                      ref.height,
                                      vs.RGBS,
                                      dither_type='error_diffusion')

        endcard = iterate(
            endcard, partial(core.w2xc.Waifu2x, noise=3, scale=1, photo=True),
            2)

        endcard = core.resize.Bicubic(endcard,
                                      format=vs.YUV444PS,
                                      matrix_s='709',
                                      dither_type='error_diffusion')
        endcard = lvf.util.quick_resample(
            endcard,
            lambda c: core.neo_f3kdb.Deband(c, 15, 36, 36, 36, 24, 24, 4))

        return Tweak(endcard, sat=1.2, bright=-0.05, cont=1.2)

    src = JPBD.src_cut
    src = depth(src, 16)
    edstart = 31769

    denoise_a = CoolDegrain(src, tr=2, thsad=48, blksize=8, overlap=4, plane=4)
    denoise_b = CoolDegrain(src, tr=3, thsad=96, blksize=8, overlap=4, plane=4)
    denoise = lvf.rfs(denoise_a, denoise_b, [(edstart + 1870, edstart + 1900)])

    antialias_a = _nneedi3_clamp(denoise)
    downscaler = lambda c, w, h: core.fmtc.resample(
        c, w, h, kernel='gauss', invks=True, invkstaps=1, taps=1, a1=32)
    antialias_b = rekt_fast(
        denoise,
        lambda c: lvf.sraa(c, 1.45, rep=13, downscaler=downscaler),
        top=482)
    antialias = lvf.rfs(antialias_a, antialias_b, [(8185, 8280)])

    predenoise = mClean(antialias, thSAD=200, chroma=False)
    detail_mask = lvf.denoise.detail_mask(predenoise,
                                          rad=2,
                                          radc=2,
                                          brz_a=3250,
                                          brz_b=1250)
    ret_mask = kgf.retinex_edgemask(predenoise).std.Binarize(
        9250).std.Median().std.Inflate()
    line_mask = core.std.Expr([detail_mask, ret_mask], 'x y max')

    deband_a = core.neo_f3kdb.Deband(antialias,
                                     17,
                                     42,
                                     42,
                                     42,
                                     12,
                                     0,
                                     sample_mode=4,
                                     keep_tv_range=True)
    deband_a = core.std.MaskedMerge(deband_a, antialias, line_mask)
    deband_b = core.neo_f3kdb.Deband(deband_a,
                                     18,
                                     48,
                                     48,
                                     48,
                                     0,
                                     0,
                                     sample_mode=2,
                                     keep_tv_range=True)

    deband = lvf.rfs(deband_a, deband_b, [(edstart + 1870, edstart + 1900)])
    deband = lvf.rfs(deband, deband_b, [(13611, 13661), (20022, 20057)])

    grain = kgf.adaptive_grain(deband, 0.25, luma_scaling=10)

    endcard = _perform_endcard(
        '[BDMV][200610][Magia Record][Vol.3]/Scans/endcard6_front_descreen.png',
        src)
    endcard_length = 119
    final = core.std.Splice([grain, endcard * endcard_length], True)
    final = core.resize.Bicubic(final,
                                format=vs.YUV420P10,
                                dither_type='error_diffusion')
    final = core.std.Limiter(final, 16, [235 << 2, 240 << 2])

    return depth(final, 10), endcard_length
Beispiel #13
0
def finalize(clip: vs.VideoNode) -> vs.VideoNode:
    final = adaptive_grain(clip, 0.3)
    final = final.fmtc.bitdepth(bits=10, dmode=3)
    return final
Beispiel #14
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)

    h = 882
    w = get_w(h)
    kernel = 'lanczos'
    taps = 5
    opstart, opend = 1918, 4076
    edstart, edend = 31768, 33925

    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

    import G41Fun as gf
    from vsTAAmbk import TAAmbk
    dehalo = gf.MaskedDHA(out,
                          rx=2.8,
                          ry=2.8,
                          darkstr=0.4,
                          brightstr=1.4,
                          maskpull=48,
                          maskpush=140)
    aaa = TAAmbk(dehalo, 'Eedi3SangNom', cycle=4, mtype=0)
    aaa = lvf.rfs(out, aaa, [(16052, 16105)])
    out = aaa

    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 = lvf.rfs(antialias, vdf.merge_chroma(upscale, denoise),
                  [(edstart, edend)])

    deband_mask = lvf.denoise.detail_mask(out, brz_a=2000, brz_b=1000)

    deband = dbs.f3kpf(out, 17, 36, 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)
    creditless_mask = core.std.Expr([
        vdf.dcm(src, src[opstart:opend + 1],
                JPBD_NCOP.src_cut[:opend - opstart + 1], opstart, opend, 2,
                2).std.Deflate(),
        vdf.dcm(src, src[edstart:edend + 1],
                JPBD_NCED.src_cut[:edend - edstart + 1], edstart, edend, 2,
                2).std.Deflate()
    ], 'x y +')

    credit = out
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, src, rescale_mask,
                                                  0),
                     [(opstart + 425, opstart + 698),
                      (33972, src.num_frames - 1), (21962, 22009)])
    credit = lvf.rfs(credit,
                     core.std.MaskedMerge(credit, src, creditless_mask, 0),
                     [(opstart, opend), (edstart, edend)])
    credit = lvf.rfs(credit, src, [(5057, 5104), (12371, 12418)])
    out = credit

    return depth(out, 10)
Beispiel #15
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)

    h = 882
    w = get_w(h)
    kernel = 'lanczos'
    taps = 5
    opstart, opend = 936, 3092
    edstart, edend = 31769, 33926

    clip_in = depth(src, 32)
    dedimm = gf.Tweak(clip_in, sat=1.65, cont=1.65)
    dedimm = vdf.fade_filter(clip_in, clip_in, dedimm, 26133, 26183)
    out = depth(dedimm, 16)

    denoise = CoolDegrain(out, 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 = lvf.rfs(antialias, vdf.merge_chroma(upscale, denoise),
                  [(edstart, edend)])

    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)
    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)
    creditless_mask = core.std.Expr([
        vdf.dcm(src, src[opstart:opend + 1],
                JPBD_NCOP.src_cut[:opend - opstart + 1], opstart, opend, 2,
                2).std.Deflate(),
        vdf.dcm(src, src[edstart:edend + 1],
                JPBD_NCED.src_cut[:edend - edstart + 1], edstart, edend, 2,
                2).std.Deflate()
    ], 'x y +')

    credit = out
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, src, rescale_mask,
                                                  0),
                     [(opstart + 425, opstart + 698),
                      (33973, src.num_frames - 1)])
    credit = lvf.rfs(credit,
                     core.std.MaskedMerge(credit, src, creditless_mask, 0),
                     [(opstart, opend), (edstart, edend)])
    credit = lvf.rfs(credit, src, [(16911, 16970), (24486, 24533)])
    out = credit

    return depth(out, 10)
Beispiel #16
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)
    out = src

    edstart, edend = 31888, src.num_frames-1


    shift = core.resize.Point(out, src_left=1).edgefixer.ContinuityFixer([2, 1, 1], 0, 0, 0)
    out = lvf.rfs(out, shift, [(235, 318)])



    ref = hvf.SMDegrain(out, tr=1, thSAD=300, plane=4)
    denoise = mvf.BM3D(out, [1.5, 1], 1, profile1='lc', ref=ref)
    out = denoise


    y = get_y(out)
    lineart = vdf.edge_detect(y, 'FDOG', scale_value(0.065, 32, 16), (1, 1)).std.Median().std.BoxBlur(0, 1, 1, 1, 1)

    rescale = fake_rescale(y, 837.5, 1/3, 1/3, coef_dering=0.1, coef_dark=1.25,
                           coef_warp=1.15, coef_sharp=0.75, coef_finalsharp=0.85)
    rescale = core.std.MaskedMerge(y, rescale, lineart)

    out = vdf.merge_chroma(rescale, out)





    preden = core.dfttest.DFTTest(get_y(out), ftype=0, sigma=0.5, sbsize=16, sosize=12, tbsize=1)
    detail_dark_mask = detail_dark_mask_func(preden, brz_a=6000, brz_b=5000)
    detail_light_mask = lvf.denoise.detail_mask(preden, brz_a=2500, brz_b=1200)
    detail_mask = core.std.Expr([detail_dark_mask, detail_light_mask], 'x y +').std.Median()
    detail_mask_grow = iterate(detail_mask, core.std.Maximum, 2)
    detail_mask_grow = iterate(detail_mask_grow, core.std.Inflate, 2).std.BoxBlur(0, 1, 1, 1, 1)

    detail_mask = core.std.Expr([preden, detail_mask_grow, detail_mask], f'x {40<<8} < y z ?')

    pf = vdf.merge_chroma(preden, out)
    deband = dumb3kdb(pf, 17, 40)
    deband_b = dumb3kdb(pf, 20, 80)

    deband = lvf.rfs(deband, deband_b, [(2194, 2216), (2283, 2306)])
    deband = core.std.MergeDiff(deband, out.std.MakeDiff(pf))
    deband = core.std.MaskedMerge(deband, out, detail_light_mask)
    out = deband


    grain = kgf.adaptive_grain(out, 0.35)
    out = grain



    ref = depth(src, 16)
    src_c, src_nced = [depth(x, 16) for x in [src, JPBD_NCED.src_cut[13:]]]

    ending_mask = vdf.dcm(out, src_c[edstart:edend+1], src_nced[:edend-edstart+1], edstart, edend, 2, 2).std.BoxBlur(0, 2, 2, 2, 2)

    credit = out
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, ending_mask), [(31900, src.num_frames-1)])
    out = credit



    return depth(out, 10).std.Limiter(16<<2, [235<<2, 240<<2], [0, 1, 2])
Beispiel #17
0
def do_filter():
    """Vapoursynth filtering"""
    def _nneedi3_clamp(clip: vs.VideoNode, strength: int = 1) -> vs.VideoNode:
        bits = clip.format.bits_per_sample - 8
        thr = strength * (1 >> bits)

        luma = get_y(clip)

        def _strong(clip: vs.VideoNode) -> vs.VideoNode:
            args = dict(alpha=0.25,
                        beta=0.5,
                        gamma=40,
                        nrad=2,
                        mdis=20,
                        vcheck=3)
            clip = core.eedi3m.EEDI3(clip, 1, True, **args).std.Transpose()
            clip = core.eedi3m.EEDI3(clip, 1, True, **args).std.Transpose()
            return core.resize.Spline36(clip,
                                        luma.width,
                                        luma.height,
                                        src_left=-.5,
                                        src_top=-.5)

        def _weak(clip: vs.VideoNode) -> vs.VideoNode:
            args = dict(nsize=3, nns=2, qual=2)
            clip = core.znedi3.nnedi3(clip, 1, True, **args).std.Transpose()
            clip = core.znedi3.nnedi3(clip, 1, True, **args).std.Transpose()
            return core.resize.Spline36(clip,
                                        luma.width,
                                        luma.height,
                                        src_left=-.5,
                                        src_top=-.5)

        clip_aa = core.std.Expr(
            [_strong(luma), _weak(luma), luma],
            'x z - y z - * 0 < y x y {0} + min y {0} - max ?'.format(thr))
        return vdf.merge_chroma(clip_aa, clip)

    def _perform_endcard(path: str, ref: vs.VideoNode) -> vs.VideoNode:
        endcard = lvf.src(path).std.AssumeFPS(ref)
        endcard = core.std.CropRel(endcard, left=4, top=12, right=0, bottom=21)
        endcard = core.resize.Bicubic(endcard,
                                      ref.width,
                                      ref.height,
                                      vs.RGBS,
                                      dither_type='error_diffusion')

        endcard = iterate(
            endcard, partial(core.w2xc.Waifu2x, noise=3, scale=1, photo=True),
            2)

        endcard = core.resize.Bicubic(endcard,
                                      format=vs.YUV444PS,
                                      matrix_s='709',
                                      dither_type='error_diffusion')
        endcard = lvf.util.quick_resample(
            endcard,
            lambda c: core.neo_f3kdb.Deband(c, 15, 36, 36, 36, 24, 24, 4))

        return Tweak(endcard, sat=1.2, bright=-0.05, cont=1.2)

    def to_gray(clip: vs.VideoNode, ref: vs.VideoNode) -> vs.VideoNode:
        clip = core.std.AssumeFPS(clip, ref)
        return core.resize.Point(clip,
                                 format=vs.GRAY16,
                                 matrix_s=mvf.GetMatrix(ref))

    src = JPBD.src_cut
    src = depth(src, 16)
    edstart = 30618

    denoise_a = CoolDegrain(src, tr=2, thsad=48, blksize=8, overlap=4, plane=4)
    denoise_b = CoolDegrain(src, tr=3, thsad=96, blksize=8, overlap=4, plane=4)
    denoise = lvf.rfs(denoise_a, denoise_b, [(edstart + 1870, edstart + 1900)])

    antialias_a = _nneedi3_clamp(denoise)
    antialias_b = TAAmbk(denoise, aatype='Eedi3', mtype=1)
    antialias = lvf.rfs(antialias_a, antialias_b, [(9478, 9501)])

    predenoise = mClean(antialias, thSAD=200, chroma=False)
    detail_mask = lvf.denoise.detail_mask(predenoise,
                                          rad=2,
                                          radc=2,
                                          brz_a=3250,
                                          brz_b=1250)
    ret_mask = kgf.retinex_edgemask(predenoise).std.Binarize(
        9250).std.Median().std.Inflate()
    line_mask = core.std.Expr([detail_mask, ret_mask], 'x y max')

    deband_a = core.neo_f3kdb.Deband(antialias,
                                     17,
                                     42,
                                     42,
                                     42,
                                     12,
                                     0,
                                     sample_mode=4,
                                     keep_tv_range=True)
    deband_a = core.std.MaskedMerge(deband_a, antialias, line_mask)
    deband_b = core.neo_f3kdb.Deband(deband_a,
                                     18,
                                     48,
                                     48,
                                     48,
                                     0,
                                     0,
                                     sample_mode=2,
                                     keep_tv_range=True)
    deband_c = core.neo_f3kdb.Deband(deband_a,
                                     20,
                                     64,
                                     64,
                                     64,
                                     24,
                                     0,
                                     sample_mode=2,
                                     keep_tv_range=True)

    deband = lvf.rfs(deband_a, deband_b, [(edstart + 1870, edstart + 1900)])
    deband = lvf.rfs(
        deband,
        core.std.MaskedMerge(
            deband_c, deband_a,
            to_gray(lvf.src('masks/magia_07_mask_01.png'), src)),
        [(6729, 6865)])

    grain = kgf.adaptive_grain(deband, 0.25, luma_scaling=10)

    borders = vdf.region_mask(grain, 240, 240, 0, 0)
    borders = lvf.rfs(grain, borders, [(25623, 25670)])

    endcard = _perform_endcard(
        '[BDMV][200610][Magia Record][Vol.3]/Scans/endcard7_front_descreen.png',
        src)
    endcard_length = 119
    final = core.std.Splice([borders, endcard * endcard_length], True)
    final = core.resize.Bicubic(final,
                                format=vs.YUV420P10,
                                dither_type='error_diffusion')
    final = core.std.Limiter(final, 16, [235 << 2, 240 << 2])

    return depth(final, 10), endcard_length
Beispiel #18
0
def masked_f3kdb(clip: vs.VideoNode,
                 mask: Optional[vs.VideoNode] = None,
                 range: int = 15,
                 y: int = 40,
                 cb: Optional[int] = None,
                 cr: Optional[int] = None,
                 grainy: int = 0,
                 grainc: int = 0,
                 agrain: int = 0,
                 luma_scaling: int = 12,
                 sample_mode: int = 2,
                 keep_tv_range: bool = True,
                 output_depth: Optional[int] = None) -> vs.VideoNode:
    """Wrapper function for neo_f3kdb.

    Additional changes include sane defaults, the ability to merge with
    an external mask clip, and additionally add kagefunc's
    adaptive_grain to the final, debanded clip.

    grainy, grainc, and adaptive_grain are applied
    to the final, post-merged clip.

    Differing default behavior:
    - y defaults to 40 and cr/cb default to y//2.
    - output_depth defaults to the source bit depth.
    - grainy and grainc default to 0.
    - grain is always static.
    - keep_tv_range defaults to True (since typical sources are TV range).

    Args:
        Most f3kdb arguments: https://f3kdb.readthedocs.io/en/latest/index.html
        mask: Mask clip to use for merging with debanded clip.
        agrain: The strength arg for adaptive_grain.
        luma_scaling: The luma_scaling arg for adaptive_grain.
    """
    name = 'masked_f3kdb'

    if not isinstance(clip, vs.VideoNode):
        raise TypeError(name + ": 'clip' must be a clip")
    if mask is not None and not isinstance(mask, vs.VideoNode):
        raise TypeError(name + ": 'mask' must be a clip")

    src_bits = clip.format.bits_per_sample

    if cb is None:
        cb = y // 2
    if cr is None:
        cr = y // 2
    if output_depth is None:
        output_depth = src_bits
    if mask is not None and mask.format.bits_per_sample != src_bits:
        mask = fvf.Depth(mask, src_bits, dither_type='none')

    debanded = core.neo_f3kdb.Deband(clip,
                                     range=range,
                                     y=y,
                                     cb=cb,
                                     cr=cr,
                                     grainy=0,
                                     grainc=0,
                                     sample_mode=sample_mode,
                                     keep_tv_range=keep_tv_range,
                                     output_depth=src_bits)

    if mask is not None:
        debanded = core.std.MaskedMerge(debanded, clip, mask)
    if grainy > 0 or grainc > 0:
        debanded = core.neo_f3kdb.Deband(debanded,
                                         range=0,
                                         y=0,
                                         cb=0,
                                         cr=0,
                                         grainy=grainy,
                                         grainc=grainc,
                                         sample_mode=sample_mode,
                                         keep_tv_range=keep_tv_range,
                                         output_depth=src_bits)
    if agrain > 0:
        debanded = kgf.adaptive_grain(debanded,
                                      strength=agrain,
                                      luma_scaling=luma_scaling)

    return fvf.Depth(debanded, output_depth)
Beispiel #19
0
def do_filter():
    """Vapoursynth filtering"""
    def _nneedi3_clamp(clip: vs.VideoNode, strength: int = 1) -> vs.VideoNode:
        bits = clip.format.bits_per_sample - 8
        thr = strength * (1 >> bits)

        luma = get_y(clip)

        def _strong(clip: vs.VideoNode) -> vs.VideoNode:
            args = dict(alpha=0.25,
                        beta=0.5,
                        gamma=40,
                        nrad=2,
                        mdis=20,
                        vcheck=3)
            clip = core.eedi3m.EEDI3(clip, 1, True, **args).std.Transpose()
            clip = core.eedi3m.EEDI3(clip, 1, True, **args).std.Transpose()
            return core.resize.Spline36(clip,
                                        luma.width,
                                        luma.height,
                                        src_left=-.5,
                                        src_top=-.5)

        def _weak(clip: vs.VideoNode) -> vs.VideoNode:
            args = dict(nsize=3, nns=2, qual=2)
            clip = core.znedi3.nnedi3(clip, 1, True, **args).std.Transpose()
            clip = core.znedi3.nnedi3(clip, 1, True, **args).std.Transpose()
            return core.resize.Spline36(clip,
                                        luma.width,
                                        luma.height,
                                        src_left=-.5,
                                        src_top=-.5)

        clip_aa = core.std.Expr(
            [_strong(luma), _weak(luma), luma],
            'x z - y z - * 0 < y x y {0} + min y {0} - max ?'.format(thr))
        return vdf.merge_chroma(clip_aa, clip)

    def _perform_endcard(path: str, ref: vs.VideoNode) -> vs.VideoNode:
        endcard = lvf.src(path).std.AssumeFPS(ref)
        endcard = core.std.CropRel(endcard,
                                   left=14,
                                   top=12,
                                   right=18,
                                   bottom=23)
        endcard = core.resize.Bicubic(endcard,
                                      ref.width,
                                      ref.height,
                                      vs.RGBS,
                                      dither_type='error_diffusion')

        endcard = iterate(
            endcard, partial(core.w2xc.Waifu2x, noise=3, scale=1, photo=True),
            2)

        endcard = core.resize.Bicubic(endcard,
                                      format=vs.YUV444PS,
                                      matrix_s='709',
                                      dither_type='error_diffusion')

        return Tweak(endcard, sat=1.2, bright=-0.05, cont=1.2)

    src = JPBD.src_cut
    src = depth(src, 16)
    edstart = 32012

    denoise_a = CoolDegrain(src, tr=2, thsad=48, blksize=8, overlap=4, plane=4)
    denoise_b = CoolDegrain(src, tr=3, thsad=96, blksize=8, overlap=4, plane=4)
    denoise = lvf.rfs(denoise_a, denoise_b, [(edstart + 1870, edstart + 1900)])

    antialias_a = _nneedi3_clamp(denoise)
    antialias_b = lvf.sraa(denoise, 2, rep=13)
    antialias = lvf.rfs(antialias_a, antialias_b, [(14667, 14696)])

    predenoise = mClean(antialias, thSAD=200, chroma=False)
    detail_mask = lvf.denoise.detail_mask(predenoise,
                                          rad=2,
                                          radc=2,
                                          brz_a=3250,
                                          brz_b=1250)
    adapt_mask = core.adg.Mask(predenoise.std.PlaneStats(), 40)
    ret_mask = kgf.retinex_edgemask(predenoise).std.Binarize(
        9250).std.Median().std.Inflate()
    line_mask = core.std.Expr([detail_mask, ret_mask], 'x y max')

    deband_a = core.neo_f3kdb.Deband(antialias,
                                     17,
                                     42,
                                     42,
                                     42,
                                     12,
                                     0,
                                     sample_mode=4,
                                     keep_tv_range=True)
    deband_a = core.std.MaskedMerge(deband_a, antialias, line_mask)
    deband_b = core.neo_f3kdb.Deband(deband_a,
                                     18,
                                     48,
                                     48,
                                     48,
                                     0,
                                     0,
                                     sample_mode=2,
                                     keep_tv_range=True)
    deband_ca = dbs.f3kbilateral(deband_b, 8, 270, 270)
    deband_cb = dbs.f3kbilateral(deband_b, 12, 110, 110)
    deband_c = core.std.MaskedMerge(deband_ca, deband_cb, adapt_mask)

    deband = lvf.rfs(deband_a, deband_b, [(edstart + 1870, edstart + 1900),
                                          (13041, 13180), (13932, 13949),
                                          (14121, 14168), (14647, 14666)])
    deband = lvf.rfs(deband, deband_c, [(14667, 14669), (14673, 14674),
                                        (14676, 14677)])

    grain = kgf.adaptive_grain(deband, 0.25, luma_scaling=10)

    crop = core.std.Crop(grain, 0, 0, 132, 132)
    edgefixe = core.edgefixer.ContinuityFixer(crop, 0, [2, 1, 1], 0, [1, 1, 1])
    borders = core.std.AddBorders(edgefixe, 0, 0, 132, 132)
    borders = lvf.rfs(grain, borders, [(0, 2905)])

    endcard = _perform_endcard(
        '[BDMV][200304][Magia Record][Vol.1]/Scans/endcard3_front_descreen.png',
        src)
    endcard_length = 117
    final = core.std.Splice([borders, endcard * endcard_length], True)
    final = core.resize.Bicubic(final,
                                format=vs.YUV420P10,
                                dither_type='error_diffusion')
    final = core.std.Limiter(final, 16, [235 << 2, 240 << 2])

    return depth(final, 10), endcard_length
Beispiel #20
0
def do_filter():
    """Vapoursynth filtering"""
    def _fsrcnnx(clip: vs.VideoNode, width: int, height: int) -> vs.VideoNode:
        blank = core.std.BlankClip(clip, format=vs.GRAY16, color=128 << 8)
        clip = join([clip, blank, blank])
        clip = core.placebo.Shader(clip, 'FSRCNNX_x2_56-16-4-1.glsl',
                                   clip.width * 2, clip.height * 2)
        return core.resize.Spline36(get_y(clip), width, height)

    src = SRC_CUT

    fe = lvf.ef(src, [1, 1, 1])
    fe = depth(fe, 16)

    h = 864
    w = get_w(864)
    b, c = 0, 1 / 2
    luma = get_y(fe)
    descale = core.descale.Debicubic(depth(luma, 32), w, h, b, c)
    descale = depth(descale, 16)

    rescale_a = nnedi3_rpow2(descale,
                             2,
                             src.width,
                             src.height,
                             nns=4,
                             qual=2,
                             pscrn=2)
    rescale_b = _fsrcnnx(descale, src.width, src.height)
    rescale = core.std.Merge(rescale_a, rescale_b, 0.75)

    rescale_mask = vrf.drm(fe, 864, b=b, c=c, mthr=80, sw=4, sh=4)
    rescale = core.std.MaskedMerge(rescale, luma, rescale_mask)

    rescale = lvf.rfs(rescale, luma, [(OPSTART + 483, OPSTART + 721),
                                      (OPSTART + 822, OPSTART + 1083)])
    merge = core.std.ShufflePlanes([rescale, fe], [0, 1, 2], vs.YUV)

    antialias = join([lvf.sraa(plane) for plane in split(merge)])
    antialias = lvf.rfs(merge, antialias, [(2836, 2870)])

    denoise = core.knlm.KNLMeansCL(antialias,
                                   a=2,
                                   h=0.65,
                                   d=0,
                                   device_type='gpu',
                                   channels='UV')

    preden = CoolDegrain(denoise,
                         tr=2,
                         thsad=60,
                         blksize=8,
                         overlap=4,
                         plane=4)
    diff = core.std.MakeDiff(denoise, preden)
    deband_mask = lvf.denoise.detail_mask(preden, brz_a=3000, brz_b=1500)

    deband_a = dbs.f3kpf(preden, 17, 42, 42)
    deband_b = core.placebo.Deband(preden,
                                   radius=17,
                                   threshold=6,
                                   iterations=1,
                                   grain=0,
                                   planes=1 | 2 | 4)
    deband = lvf.rfs(deband_a, deband_b, [(2081, 2216), (2450, 2550),
                                          (3418, 3452), (3926, 3926)])

    deband = core.std.MaskedMerge(deband, preden, deband_mask)
    deband = core.std.MergeDiff(deband, diff)

    grain = kgf.adaptive_grain(deband, 0.25, luma_scaling=8)
    final = depth(grain, 10)

    return final
Beispiel #21
0
import fvsfunc as fvf
import kagefunc as kgf
import lvsfunc
#from acsuite import eztrim

ep1 = core.ffms2.Source("Sukeban.Deka.S01.480p.AMZN.WEB-DL.DDP2.0.H.264-ARiN/Sukeban.Deka.S01E01.480p.AMZN.WEB-DL.DDP2.0.H.264-ARiN.mkv")

#eztrim(ep1, [(24,36876)], 'Sukeban.Deka.S01E01.480p.AMZN.WEB-DL.DDP2.0.H.264-ARiN.track_2.ac3')

ep1 = ep1[24:36876]
ep1 = havsfunc.Deblock_QED(ep1)
ep1 = awf.bbmod(ep1, left=3, thresh=5, blur=4)
ep1 = core.fb.FillBorders(ep1, right=2)
ep1 = rektlvls(ep1, colnum=[2,638], colval=[-20,-17])
ep1 = awf.bbmod(ep1, right=4, thresh=40, blur=40)
ep1 = core.resize.Bicubic(ep1, src_left=-1)

ep1 = rektlvls(ep1, colnum=[0,4,5], colval=[-40,-30,-10])
ep1 = rektlvls(ep1, colnum=[0,1,3,4,5], colval=[20,-10,20,30,10])
ep1 = awf.bbmod(ep1, right=6, thresh=10, blur=10)
ep1 = awf.bbmod(ep1, left=7, thresh=10, blur=90)

ep1 = lvsfunc.misc.fix_cr_tint(ep1)

ep1 = fvf.GradFun3(ep1, thr=0.35, radius=12, elast=8.0, mode=3, ampo=1, ampn=0, pat=32, dyn=False, staticnoise=False, thr_det=2 + round(max(1 - 0.35, 0) / 0.3), debug=False, thrc=1, radiusc=12, planes=list(range(ep1.format.num_planes)), ref=ep1, bits=ep1.format.bits_per_sample)
ep1 = kgf.adaptive_grain(ep1, strength=.25, static=True, luma_scaling=12, show_mask=False)

ep1 = havsfunc.FineDehalo(ep1)

ep1.set_output(0)
Beispiel #22
0
def do_filter():
    """Vapoursynth filtering"""
    def _sraa(clip: vs.VideoNode, nnargs: dict, eeargs: dict) -> vs.VideoNode:
        def _nnedi3(clip):
            return clip.nnedi3.nnedi3(0, False, **nnargs)

        def _eedi3(clip, sclip):
            return clip.eedi3m.EEDI3(0, False, **eeargs, sclip=sclip)

        clip = _eedi3(clip, _nnedi3(clip)).std.Transpose()
        clip = _eedi3(clip, _nnedi3(clip)).std.Transpose()
        return clip

    def _nnedi3(clip: vs.VideoNode, factor: float, args: dict) -> vs.VideoNode:
        upscale = clip.std.Transpose().nnedi3.nnedi3(0, True, **args) \
            .std.Transpose().nnedi3.nnedi3(0, True, **args)
        return core.resize.Spline36(upscale,
                                    clip.width * factor,
                                    clip.height * factor,
                                    src_top=.5,
                                    src_left=.5)

    def area_resize(clip: vs.VideoNode, width: int,
                    height: int) -> vs.VideoNode:
        blank = core.std.BlankClip(clip, format=vs.GRAY16, color=128 << 8)
        clip = join([clip, blank, blank])
        clip = core.area.AreaResize(clip, width, height)
        return get_y(clip)

    src = JPBD.src_cut
    src = depth(src, 16)

    flashback = [(31665, 31987), (68524, 68569)]

    denoise = CoolDegrain(src, tr=1, thsad=48, blksize=8, overlap=4, plane=4)
    denoise = lvf.rfs(denoise, src, flashback)

    dering = hvf.EdgeCleaner(denoise, 10, rmode=3, smode=1, hot=True)

    luma = get_y(dering)
    line_mask = TAAmbk(luma, mtype=2, showmask=1).std.Inflate()
    upscale = _nnedi3(luma, 2, dict(nsize=4, nns=4, qual=2, pscrn=2))
    sraa = _sraa(upscale, dict(nsize=0, nns=3, qual=1, pscrn=1),
                 dict(alpha=0.2, beta=0.5, gamma=40, nrad=3, mdis=20))
    sraa = core.rgvs.Repair(sraa, upscale, 13)
    antialias = area_resize(sraa, src.width, src.height)
    antialias = lvf.rfs(core.std.MaskedMerge(luma, antialias, line_mask),
                        antialias, [(22503, 22789)])
    antialias_merged = vdf.merge_chroma(antialias, denoise)

    deband_mask_a = lvf.denoise.detail_mask(antialias_merged,
                                            brz_a=3000,
                                            brz_b=1200)
    deband_mask_b = kgf.retinex_edgemask(antialias_merged)
    deband_mask = core.std.Expr([deband_mask_a, deband_mask_b], 'x y +')
    deband = dbs.f3kpf(antialias_merged, 18, 30, 30)
    deband = core.std.MaskedMerge(deband, antialias_merged, deband_mask)
    deband = hvf.ContraSharpening(deband, antialias_merged)
    deband = lvf.rfs(deband, antialias_merged, flashback)

    grain = core.neo_f3kdb.Deband(deband, preset='depth', grainy=24)
    grain_a = kgf.adaptive_grain(grain)
    grain_b = core.grain.Add(grain, 1, 0, constant=True)
    grain = lvf.rfs(grain_a, grain_b, flashback)

    mask_borders = core.std.BlankClip(grain,
                                      format=vs.GRAY16,
                                      color=(256 << 8) - 1)
    mask_borders = vdf.region_mask(mask_borders, 0, 0, 132, 132).std.Invert()
    final = lvf.rfs(grain, core.std.MaskedMerge(grain, src, mask_borders),
                    flashback + [(65388, 65413), (113621, 113763)])

    smooth = xvs.mvfrc(src[146178:src.num_frames], preset='slow')
    vfr = muvf.VFRSplice([final[:146178], smooth], 'sora_timecode.txt')

    return depth(vfr, 10)
Beispiel #23
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 32)
    src += src[-1]

    src = core.std.FreezeFrames(src, 3130, 3153, 3129)
    black = src.std.BlankClip().grain.Add(0.2)
    src = vdf.fade_filter(src, src, black, 3130, 3154)
    src = depth(src, 16)

    h = 882
    w = get_w(h)
    kernel = 'lanczos'
    taps = 5
    opstart, opend = 264, 2421
    edstart, edend = 31767, 33924


    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 = lvf.rfs(antialias, vdf.merge_chroma(upscale, denoise), [(edstart, edend)])



    deband_mask = lvf.denoise.detail_mask(out, brz_a=2000, brz_b=1000)

    deband = dbs.f3kpf(out, 17, 36, 36)
    deband_b = dbs.f3kpf(out, 17, 56, 56)
    deband = lvf.rfs(deband, out, [(3149, 3153)])
    deband = lvf.rfs(deband, deband_b, [(30213, 30422)])

    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)
    creditless_mask = core.std.Expr([
        vdf.dcm(src, src[opstart:opend+1], JPBD_NCOP.src_cut[:opend-opstart+1],
                opstart, opend, 2, 2).std.Deflate(),
        vdf.dcm(src, src[edstart:edend+1], JPBD_NCED.src_cut[:edend-edstart+1],
                edstart, edend, 2, 2).std.Deflate()], 'x y +')

    credit = out
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, src, rescale_mask, 0),
                     [(opstart+425, opstart+698), (33971, src.num_frames-1)])
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, src, creditless_mask, 0),
                     [(opstart, opend), (edstart, edend)])
    credit = lvf.rfs(credit, src, [(7670, 7717), (20824, 20871), (26581, 26628)])
    out = credit


    return depth(out, 10)
Beispiel #24
0
def do_filter():
    """Vapoursynth filtering"""
    def _nneedi3_clamp(clip: vs.VideoNode, strength: int = 1) -> vs.VideoNode:
        bits = clip.format.bits_per_sample - 8
        thr = strength * (1 >> bits)

        luma = get_y(clip)

        def _strong(clip: vs.VideoNode) -> vs.VideoNode:
            args = dict(alpha=0.25,
                        beta=0.5,
                        gamma=40,
                        nrad=2,
                        mdis=20,
                        vcheck=3)
            clip = core.eedi3m.EEDI3(clip, 1, True, **args).std.Transpose()
            clip = core.eedi3m.EEDI3(clip, 1, True, **args).std.Transpose()
            return core.resize.Spline36(clip,
                                        luma.width,
                                        luma.height,
                                        src_left=-.5,
                                        src_top=-.5)

        def _weak(clip: vs.VideoNode) -> vs.VideoNode:
            args = dict(nsize=3, nns=2, qual=2)
            clip = core.znedi3.nnedi3(clip, 1, True, **args).std.Transpose()
            clip = core.znedi3.nnedi3(clip, 1, True, **args).std.Transpose()
            return core.resize.Spline36(clip,
                                        luma.width,
                                        luma.height,
                                        src_left=-.5,
                                        src_top=-.5)

        clip_aa = core.std.Expr(
            [_strong(luma), _weak(luma), luma],
            'x z - y z - * 0 < y x y {0} + min y {0} - max ?'.format(thr))
        return vdf.merge_chroma(clip_aa, clip)

    def _perform_endcard(path: str, ref: vs.VideoNode) -> vs.VideoNode:
        endcard = lvf.src(path).std.AssumeFPS(ref)
        endcard = core.std.CropRel(endcard,
                                   left=10,
                                   top=17,
                                   right=17,
                                   bottom=23)
        endcard = core.resize.Bicubic(endcard,
                                      ref.width,
                                      ref.height,
                                      vs.RGBS,
                                      dither_type='error_diffusion')

        endcard = iterate(
            endcard, partial(core.w2xc.Waifu2x, noise=3, scale=1, photo=True),
            2)

        endcard = core.resize.Bicubic(endcard,
                                      format=vs.YUV444PS,
                                      matrix_s='709',
                                      dither_type='error_diffusion')

        return Tweak(endcard, sat=1.2, bright=-0.05, cont=1.2)

    src = JPBD.src_cut
    src = depth(src, 16)

    denoise = CoolDegrain(src, tr=2, thsad=48, blksize=8, overlap=4, plane=4)

    antialias_a = _nneedi3_clamp(denoise)

    antialias_b = lvf.sraa(denoise, rep=6)
    antialias = lvf.rfs(antialias_a, antialias_b, [(29453, 29476),
                                                   (29510, 29532),
                                                   (29640, 29663),
                                                   (29775, 29798),
                                                   (29866, 29889),
                                                   (30011, 30034)])

    predenoise = mClean(antialias, thSAD=200, chroma=False)
    detail_mask = lvf.denoise.detail_mask(predenoise,
                                          rad=2,
                                          radc=2,
                                          brz_a=3250,
                                          brz_b=1250)
    ret_mask = kgf.retinex_edgemask(predenoise).std.Binarize(
        9250).std.Median().std.Inflate()
    line_mask = core.std.Expr([detail_mask, ret_mask], 'x y max')

    deband = core.neo_f3kdb.Deband(antialias,
                                   17,
                                   42,
                                   42,
                                   42,
                                   12,
                                   0,
                                   sample_mode=4,
                                   keep_tv_range=True)
    deband = core.std.MaskedMerge(deband, antialias, line_mask)

    grain_a = kgf.adaptive_grain(deband, 0.25, luma_scaling=10)
    grain_b = adptvgrnMod(deband,
                          2,
                          size=2,
                          luma_scaling=2,
                          static=False,
                          grain_chroma=False)
    grain = lvf.rfs(grain_a, grain_b, [(5149, 5598), (8691, 10137)])

    borders_mask = vdf.region_mask(
        src.std.BlankClip(format=vs.GRAY16, color=(256 << 8) - 1), 240 + 2,
        240 + 2, 0, 0)
    borders = core.std.MaskedMerge(src, grain, borders_mask)
    borders = lvf.rfs(grain, borders, [(5149, 5598)])

    endcard = _perform_endcard(
        '[BDMV][200304][Magia Record][Vol.1]/Scans/endcard1_front_descreen.png',
        src)
    endcard_length = 119
    final = core.std.Splice([borders, endcard * endcard_length], True)
    final = core.resize.Bicubic(final,
                                format=vs.YUV420P10,
                                dither_type='error_diffusion')
    final = core.std.Limiter(final, 16, [235 << 2, 240 << 2])

    return depth(final, 10), endcard_length
Beispiel #25
0
 def test_adaptive_grain(self):
     grained = kgf.adaptive_grain(self.BLACK_SAMPLE_CLIP)
     self.assert_same_metadata(grained, self.BLACK_SAMPLE_CLIP)
     grained.get_frame(0)
Beispiel #26
0
def do_filter():
    """Vapoursynth filtering"""
    def _nneedi3_clamp(clip: vs.VideoNode, strength: int = 1)-> vs.VideoNode:
        bits = clip.format.bits_per_sample - 8
        thr = strength * (1 >> bits)

        luma = get_y(clip)

        def _strong(clip: vs.VideoNode)-> vs.VideoNode:
            args = dict(alpha=0.25, beta=0.5, gamma=40, nrad=2, mdis=20, vcheck=3)
            clip = core.eedi3m.EEDI3(clip, 1, True, **args).std.Transpose()
            clip = core.eedi3m.EEDI3(clip, 1, True, **args).std.Transpose()
            return core.resize.Spline36(clip, luma.width, luma.height, src_left=-.5, src_top=-.5)

        def _weak(clip: vs.VideoNode)-> vs.VideoNode:
            args = dict(nsize=3, nns=2, qual=2)
            clip = core.znedi3.nnedi3(clip, 1, True, **args).std.Transpose()
            clip = core.znedi3.nnedi3(clip, 1, True, **args).std.Transpose()
            return core.resize.Spline36(clip, luma.width, luma.height, src_left=-.5, src_top=-.5)

        clip_aa = core.std.Expr([_strong(luma), _weak(luma), luma],
                                'x z - y z - * 0 < y x y {0} + min y {0} - max ?'.format(thr))
        return vdf.merge_chroma(clip_aa, clip)


    def _perform_endcard(path: str, ref: vs.VideoNode)-> vs.VideoNode:
        endcard = lvf.src(path).std.AssumeFPS(ref)
        endcard = core.std.CropRel(endcard, left=7, top=0, right=11, bottom=22)
        endcard = core.resize.Bicubic(endcard, ref.width, ref.height, vs.RGBS, dither_type='error_diffusion')

        endcard = core.w2xc.Waifu2x(endcard, noise=3, scale=1, photo=True)

        endcard = core.resize.Bicubic(endcard, format=vs.YUV444PS, matrix_s='709', dither_type='error_diffusion')
        endcard = lvf.util.quick_resample(endcard, lambda c: core.neo_f3kdb.Deband(c, 15, 36, 36, 36, 24, 24, 4))

        return Tweak(endcard, sat=1.4, cont=1.2)


    def _perform_motion_mask(clip: vs.VideoNode, brz: int)-> vs.VideoNode:
        clip = depth(clip, 8)
        sup = core.hqdn3d.Hqdn3d(clip).neo_fft3d.FFT3D().mv.Super(sharp=1)
        fv1 = core.mv.Analyse(sup, isb=False, delta=1, truemotion=False, dct=2)
        fv2 = core.mv.Analyse(sup, isb=True, delta=1, truemotion=True, dct=2)

        momask1 = core.mv.Mask(clip, fv1, ml=2, kind=1)
        momask2 = core.mv.Mask(clip, fv2, ml=3, kind=1)
        momask = core.std.Merge(momask1, momask2).rgvs.RemoveGrain(3).std.Binarize(brz)
        momask = momask.std.Minimum().std.Minimum()

        return depth(get_y(momask), 16)


    src = JPBD.src_cut
    src = depth(src, 16)

    denoise_a = CoolDegrain(src, tr=2, thsad=48, blksize=8, overlap=4, plane=4)
    denoise = denoise_a


    antialias = _nneedi3_clamp(denoise)
    antialias_a = TAAmbk(antialias, aatype='Eedi3', cycle=3)
    antialias_b = lvf.sraa(denoise, 2, 13)

    motion_mask = _perform_motion_mask(denoise[16914:17001], 140).std.FreezeFrames([0, 18, 57], [2, 38, 86], [2, 38, 57])
    motion_mask = insert_clip(src.std.BlankClip(format=vs.GRAY16), motion_mask, 16914)


    antialias = lvf.rfs(antialias, core.std.MaskedMerge(antialias_a, antialias, motion_mask), [(16914, 17000)])
    antialias = lvf.rfs(antialias, antialias_b, [(18084, 18179)])


    predenoise = mClean(antialias, thSAD=200, chroma=False)
    detail_mask = lvf.denoise.detail_mask(predenoise, rad=2, radc=2, brz_a=3250, brz_b=1250)
    ret_mask = kgf.retinex_edgemask(predenoise).std.Binarize(9250).std.Median().std.Inflate()
    line_mask = core.std.Expr([detail_mask, ret_mask], 'x y max')


    deband_a = core.neo_f3kdb.Deband(antialias, 17, 42, 42, 42, 12, 0, sample_mode=4, keep_tv_range=True)
    deband_a = core.std.MaskedMerge(deband_a, antialias, line_mask)
    deband = deband_a


    grain = kgf.adaptive_grain(deband, 0.25, luma_scaling=10)


    ending = lvf.rfs(grain, src, [(32079, 33098)])


    endcard = _perform_endcard(r'[BDMV][200902][Magia Record][Vol.5]\Scans\endcard13_front_descreen.png', src)
    endcard_length = 119
    final = core.std.Splice([ending, endcard * endcard_length], True)
    final = core.resize.Bicubic(final, format=vs.YUV420P10, dither_type='error_diffusion')
    final = core.std.Limiter(final, 16, [235 << 2, 240 << 2])

    return depth(final, 10), endcard_length
def adptvgrnMod(clip_in: vs.VideoNode,
                strength=0.25,
                cstrength=None,
                size=1,
                sharp=50,
                static=False,
                luma_scaling=12,
                grain_chroma=True,
                grainer=None,
                fade_edges=True,
                tv_range=True,
                lo=None,
                hi=None,
                protect_neutral=True,
                seed=-1,
                show_mask=False) -> vs.VideoNode:
    """
    Original header:
    Generates grain based on frame and pixel brightness. Details can be found here:
    https://kageru.moe/blog/article/adaptivegrain
    Strength is the strength of the grain generated by AddGrain, static=True for static grain, luma_scaling
    manipulates the grain alpha curve. Higher values will generate less grain (especially in brighter scenes),
    while lower values will generate more grain, even in brighter scenes.
    ====================================================================================================================
    This mod simply adds the size and sharpness features from havsfunc's GrainFactory3.
    Additionally, the option to process only luma is added. Requires YUV input.
    New:
    - Option to add your own graining function (i.e. grainer=lambda x: core.f3kdb.Deband(x, y=0, cr=0, cb=0, grainy=64,
      dynamic_grain=True, keep_tv_range=True, output_depth=16)
    - Fixed grain_chroma and added cstrength. Mod 2 sources with size=1 now work, too.
    - Option to fade amount of grain added on edge values where grain raises/lowers average plane value.
      - Additional protect_neutral parameter to keep neutral chroma in blacks neutral.
    - Added seed option.
    - Change defaults: static=False, fade_edges=True
    - Added custom hi and lo params.
    """

    dpth = get_depth(clip_in)

    try:
        from kagefunc import adaptive_grain
        mask = adaptive_grain(clip_in,
                              luma_scaling=luma_scaling,
                              show_mask=True)
    except ModuleNotFoundError:
        mask = core.adg.Mask(clip_in.std.PlaneStats(), luma_scaling)

    if get_depth(mask) != dpth:
        mask = depth(mask, dpth)
    if show_mask:
        return mask

    grained = sizedgrn(clip_in,
                       strength=strength,
                       cstrength=cstrength,
                       size=size,
                       sharp=sharp,
                       static=static,
                       grain_chroma=grain_chroma,
                       grainer=grainer,
                       fade_edges=fade_edges,
                       tv_range=tv_range,
                       lo=lo,
                       hi=hi,
                       protect_neutral=protect_neutral,
                       seed=seed)

    return core.std.MaskedMerge(clip_in, grained, mask)