Beispiel #1
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
Beispiel #2
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)
    out = src



    ref = hvf.SMDegrain(out, thSAD=300)
    denoise = mvf.BM3D(out, [1.5, 1.25], radius1=1, ref=ref)
    out = denoise

    crop = core.std.Crop(out, left=12)
    crop = awf.bbmod(crop, left=2, thresh=20 << 8)
    resize = core.resize.Bicubic(crop, 1920)
    out = lvf.rfs(out, resize, [(78, 89)])


    y = get_y(out)
    lineart = gf.EdgeDetect(y, 'scharr').morpho.Dilate(2, 2).std.Inflate()

    fkrescale = fake_rescale(
        y, 882, 0, 1,
        deringer=lambda x: gf.MaskedDHA(x, rx=1.85, ry=1.85, darkstr=0.25, brightstr=1.0, maskpull=100, maskpush=200),
        antialiser=lambda c: lvf.sraa(c, 2, 13, downscaler=core.resize.Bicubic)
    )
    merged = core.std.MaskedMerge(y, fkrescale, lineart)
    out = vdf.merge_chroma(merged, out)


    dering = hvf.EdgeCleaner(out, 17, smode=1, hot=True)
    out = dering


    out = lvf.rfs(
        out, denoise,
        [(0, 11), (38, 77), (115, 133), (316, 395), (441, 460), (606, 779), (825, 844), (990, 1127)]
    )




    detail_mask = lvf.mask.detail_mask(out, brz_a=2250, brz_b=1000)
    deband = vdf.dumb3kdb(out, 15, threshold=17, grain=(24, 0))
    deband = core.std.MaskedMerge(deband, out, detail_mask)
    out = deband




    grain = adptvgrnMod(out, 0.3, static=True, grain_chroma=False, hi=[128, 240], seed=333)
    out = grain


    decz = vdf.decsiz(out, min_in=128 << 8, max_in=200 << 8)
    out = decz



    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 2])
Beispiel #3
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)
    out = src
    h = 720
    w = get_w(h)

    fixedges = awf.bbmod(out, 2, 2, 2, 2, 64 << 8, 999)
    out = fixedges

    clean = core.knlm.KNLMeansCL(out,
                                 h=0.55,
                                 a=2,
                                 d=3,
                                 device_type='gpu',
                                 device_id=0,
                                 channels='UV')
    clean = core.knlm.KNLMeansCL(clean,
                                 h=0.55,
                                 a=2,
                                 d=3,
                                 device_type='gpu',
                                 device_id=0,
                                 channels='Y')
    diff_den = core.std.MakeDiff(out, clean)
    out = depth(clean, 32)

    luma = get_y(out)
    line_mask = vdf.edge_detect(luma, 'FDOG', 0.05, (1, 1))

    descale = core.descale.Debilinear(luma, w, h)
    upscale = vdf.nnedi3_upscale(descale, correct_shift=False,
                                 pscrn=1).resize.Bicubic(src.width,
                                                         src.height,
                                                         src_left=.5,
                                                         src_top=.5)
    rescale = core.std.MaskedMerge(luma, upscale, line_mask)

    merged = vdf.merge_chroma(rescale, out)
    out = depth(merged, 16)

    moozzi = warping(out, 0.4, 4)
    sharp = hvf.LSFmod(moozzi,
                       strength=95,
                       Smode=3,
                       Lmode=1,
                       edgemode=1,
                       edgemaskHQ=True)
    out = sharp

    deband_mask = lvf.denoise.detail_mask(out, brz_a=2000, brz_b=1000)
    deband = dbs.f3kpf(out, 17, 30, 30)
    deband = core.std.MaskedMerge(deband, out, deband_mask)
    out = deband

    grain_org = core.std.MergeDiff(out, diff_den)
    out = grain_org

    return depth(out, 10)
Beispiel #4
0
def do_filter() -> vs.VideoNode:
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    out = src

    luma = get_y(out)
    rows = [
        core.std.CropAbs(luma, out.width, 1, top=out.height - 1),
        core.std.CropAbs(luma, out.width, 1, top=out.height - 2)
    ]
    diff = core.std.Expr(rows, 'x y - abs').std.PlaneStats()

    row_fix = vdf.merge_chroma(
        luma.fb.FillBorders(bottom=1, mode="fillmargins"),
        out.fb.FillBorders(bottom=2, mode="fillmargins"))

    fixrow = core.std.FrameEval(out,
                                partial(_select_row, clip=out,
                                        row_fix=row_fix),
                                prop_src=diff)
    out = fixrow

    fixedge_a = awf.bbmod(out, 1, 1, 1, 1, 20, blur=700, u=False, v=False)

    fixedge = out
    fixedge = lvf.rfs(fixedge, fixedge_a, [(EDSTART + 309, EDEND)])
    out = fixedge

    out = depth(out, 16)

    dehalo = gf.MaskedDHA(out, rx=1.4, ry=1.4, darkstr=0.02, brightstr=1)
    dehalo = lvf.rfs(out, dehalo, [(EDEND + 1, src.num_frames - 1)])
    out = dehalo

    resize = core.std.Crop(out, right=12, bottom=8).resize.Bicubic(1920, 1080)
    resize = lvf.rfs(out, resize, [(27005, 27076)])
    out = resize

    # Denoising only the chroma
    pre = hvf.SMDegrain(out, tr=2, thSADC=300, plane=3)
    planes = split(out)
    planes[1], planes[2] = [
        mvf.BM3D(planes[i], 1.25, radius2=2, pre=plane(pre, i))
        for i in range(1, 3)
    ]
    out = join(planes)

    preden = core.dfttest.DFTTest(out, sbsize=16, sosize=12, tbsize=1)
    detail_mask = lvf.mask.detail_mask(preden, brz_a=2500, brz_b=1500)

    deband = vdf.dumb3kdb(preden, 16, threshold=[17, 17], grain=[24, 0])
    deband = core.std.MergeDiff(deband, out.std.MakeDiff(preden))
    deband = core.std.MaskedMerge(deband, out, detail_mask)
    out = deband

    decz = vdf.decsiz(out, min_in=128 << 8, max_in=192 << 8)
    out = decz

    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 2])
Beispiel #5
0
def _fixplane(clip: vs.VideoNode,
              top: int,
              bottom: int,
              bbt: int,
              bbb: int,
              chroma: bool = False,
              blur: int = 20) -> vs.VideoNode:
    return core.std.StackVertical([
        bbmod(clip.std.Crop(bottom=clip.height - top),
              bottom=1 if not chroma else 0),
        bbmod(clip.std.Crop(top=top, bottom=bottom),
              top=bbt,
              bottom=bbb,
              blur=blur),
        bbmod(clip.std.Crop(top=clip.height - bottom),
              top=1 if not chroma else 0)
    ])
Beispiel #6
0
def rekt(clip: vs.VideoNode) -> vs.VideoNode:
    """Apply rekt consistently across multiple clips"""
    import rekt
    from awsmfunc import bbmod

    rkt = rekt.rektlvls(clip, [0, 1079], [17, 16],
                        [0, 1, 2, 3] + [1917, 1918, 1919],
                        [16, 4, -2, 2] + [-2, 5, 14])
    return bbmod(rkt, left=4, right=3, y=False)
Beispiel #7
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    h = 720
    w = get_w(h)


    edgesfix = awf.bbmod(src, 1, 1, 1, 1, 48, 500)
    out = edgesfix


    clip = depth(out, 32)
    denoise = hybrid_denoise(clip, 0.45, 1.5)
    out = denoise



    luma = get_y(out)
    line_mask = line_mask_func(luma)

    descale = core.descale.Debilinear(luma, w, h)
    upscale = vdf.nnedi3_upscale(descale, pscrn=1)
    antialias = single_rate_antialiasing(upscale, 13, alpha=0.2, beta=0.5, gamma=600, mdis=15)


    scaled = core.resize.Bicubic(antialias, src.width, src.height)
    rescale = core.std.MaskedMerge(luma, scaled, depth(line_mask, 32))
    merged = vdf.merge_chroma(rescale, out)
    out = depth(merged, 16)



    preden = core.knlm.KNLMeansCL(get_y(out), h=0.75, a=2, d=3, device_type='gpu', device_id=0)
    detail_dark_mask = detail_dark_mask_func(preden, brz_a=8000, brz_b=6000)
    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.Convolution([1, 1, 1, 1, 1, 1, 1, 1, 1])

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


    deband_a = dbs.f3kpf(out, 16, 30, 42, thr=0.5, elast=2, thrc=0.2)
    deband_b = placebo.deband(out, 18, 5.5, 2, 4)
    deband = core.std.MaskedMerge(deband_a, deband_b, preden)
    deband = core.std.MaskedMerge(deband_a, out, detail_mask)
    deband = core.neo_f3kdb.Deband(deband, preset='depth', grainy=24, grainc=24)
    out = deband


    grain = adptvgrnMod(out, 0.4, 0.3, 1.25, luma_scaling=8, sharp=80, static=False, lo=19)
    out = grain


    return depth(out, 10)
Beispiel #8
0
def fix_edges(clip, rownum, rowval, colnum, colval, **kwargs):
    import rekt
    import awsmfunc as awsm

    bbmod_args = dict(top=3, bottom=3, left=3, right=3, thresh=None, blur=20)
    bbmod_args |= kwargs

    fix = rekt.rektlvls(clip, rownum, rowval, colnum, colval)
    return fix.std.MaskedMerge(
        awsm.bbmod(clip, **bbmod_args),
        core.std.Expr([
            fix,
            rekt.rektlvls(clip, rownum, rowval, colnum, colval, [16, 256])
        ], 'x y - abs 0 > 65535 0 ?'), 0, True)
Beispiel #9
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
Beispiel #10
0
    def prepare_hr(self, clip: vs.VideoNode,
                   dvd_clip: vs.VideoNode) -> vs.VideoNode:
        """
        Match with the DVD @640x480:
            bd.resize.Bicubic(720, 486, src_left=-0.75).std.Crop(top=3, bottom=3)
        """
        import havsfunc as haf
        import lvsfunc as lvf
        import muvsfunc as muf
        import rekt
        import vardefunc as vdf
        from awsmfunc import bbmod
        from vsutil import depth, join, plane
        from xvs import WarpFixChromaBlend

        rkt = rekt.rektlvls(clip, [0, 1079], [17, 16],
                            [0, 1, 2, 3] + [1917, 1918, 1919],
                            [16, 4, -2, 2] + [-2, 5, 14])
        ef = bbmod(rkt, left=4, right=3, y=False)

        clip = depth(ef, 32).std.AssumeFPS(fpsnum=24, fpsden=1)

        bd_descale = lvf.kernels.Bicubic().descale(plane(clip, 0), 1280, 720)
        bd_doubled = vdf.scale.nnedi3_upscale(bd_descale)
        bd_down = muf.SSIM_downsample(bd_doubled, dvd_clip.width * 2, 486 * 2)

        # Need to do some fuckery to make sure the chroma matches up perfectly
        bd_cshift = clip.resize.Bicubic(chromaloc_in=1,
                                        chromaloc=0,
                                        format=vs.YUV420P16)
        bd_cwarp = bd_cshift.warp.AWarpSharp2(thresh=88,
                                              blur=3,
                                              type=1,
                                              depth=6,
                                              planes=[1, 2])
        bd_chroma = bd_cwarp.resize.Bicubic(format=vs.YUV444P16,
                                            width=bd_down.width,
                                            height=bd_down.height)
        bd_i444 = core.std.ShufflePlanes([depth(bd_down, 16), bd_chroma])
        bd_shift = bd_i444.resize.Bicubic(src_left=-0.75).std.Crop(top=6,
                                                                   bottom=6)

        return bd_shift.resize.Bicubic(format=vs.RGB24, dither_type='error_diffusion') \
            .std.ShufflePlanes([1, 2, 0], vs.RGB)
Beispiel #11
0
def letterbox_edgefix(clip: vs.VideoNode,
                      crops: Optional[List[Range]] = None,
                      fades: Optional[List[Range]] = None) -> vs.VideoNode:
    assert clip.format is not None
    fixed = clip
    if fades:
        fy = _fixplane(clip.std.ShufflePlanes(planes=0, colorfamily=vs.GRAY),
                       top=132,
                       bottom=131,
                       bbt=2,
                       bbb=2)
        fu = _fixplane(clip.std.ShufflePlanes(planes=1, colorfamily=vs.GRAY),
                       top=66,
                       bottom=65,
                       bbt=1,
                       bbb=2,
                       chroma=True)
        fv = _fixplane(clip.std.ShufflePlanes(planes=2, colorfamily=vs.GRAY),
                       top=66,
                       bottom=66,
                       bbt=1,
                       bbb=2,
                       chroma=True)
        f = core.std.ShufflePlanes([fy, fu, fv],
                                   planes=[0, 0, 0],
                                   colorfamily=vs.YUV)
        fixed = replace_ranges(fixed, f, fades)
    if crops:
        black = [
            vsutil.scale_value(0,
                               8,
                               clip.format.bits_per_sample,
                               range_in=vsutil.Range.FULL,
                               range=vsutil.Range.LIMITED,
                               scale_offsets=True),
            scale_thresh(0.5, clip),
            scale_thresh(0.5, clip),
        ]
        crop = clip.std.Crop(top=132, bottom=132)
        bb = bbmod(crop, top=2, bottom=2, blur=500)
        f = bb.std.AddBorders(top=132, bottom=132, color=black)
        fixed = replace_ranges(fixed, f, crops)
    return fixed
Beispiel #12
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut

    full = core.resize.Bicubic(src,
                               format=vs.YUV444P8,
                               filter_param_a=0,
                               filter_param_b=1 / 2)
    crop = core.std.Crop(full, 10, 10, 5, 6)
    edgefix = awf.bbmod(crop, 1, 1, 1, 1, thresh=64)
    out = depth(edgefix, 16)

    antialias = lvf.sraa(get_y(out), 2, 13)
    antialias = lvf.rfs(out, vdf.merge_chroma(antialias, out),
                        [(1845, src.num_frames - 1)])
    out = antialias

    return core.resize.Bicubic(out,
                               1920,
                               1080,
                               format=vs.YUV420P10,
                               filter_param_a=0,
                               filter_param_b=1 / 2,
                               dither_type='error_diffusion')
Beispiel #13
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)
    out = src
    if out.num_frames < 34046:
        while out.num_frames != 34046:
            out += out[-1]
    opstart, opend = 0, 2157
    h = 720
    w = get_w(h)


    fixedges = awf.bbmod(out, 2, 2, 2, 2, 64<<8, 999)
    out = fixedges


    decomb = hvf.Vinverse(out)
    decomb = lvf.rfs(out, decomb, [(2187, 2195)])
    ref = decomb
    out = decomb

    from adptvgrnMod import adptvgrnMod
    first_denoise = hybrid_denoise(out, 0.35, 1.5)
    regrain = adptvgrnMod(first_denoise, 0.275, 0.175, 1.25, 45)
    regrain = lvf.rfs(out, regrain, [(28691, 28818)])
    out = regrain


    clean = core.knlm.KNLMeansCL(out, h=0.55, a=2, d=3, device_type='gpu', device_id=0, channels='UV')
    clean = core.knlm.KNLMeansCL(clean, h=0.55, a=2, d=3, device_type='gpu', device_id=0, channels='Y')
    diff_den = core.std.MakeDiff(out, clean)
    out = depth(clean, 32)



    luma = get_y(out)
    line_mask = vdf.edge_detect(luma, 'FDOG', 0.05, (1, 1))

    descale = core.descale.Debilinear(luma, w, h)
    upscale = vdf.nnedi3_upscale(descale, correct_shift=False, pscrn=1).resize.Bicubic(src.width, src.height, src_left=.5, src_top=.5)
    rescale = core.std.MaskedMerge(luma, upscale, line_mask)

    merged = vdf.merge_chroma(rescale, out)
    out = depth(merged, 16)


    moozzi = warping(out, 0.4, 4)
    sharp = hvf.LSFmod(moozzi, strength=95, Smode=3, Lmode=1, edgemode=1, edgemaskHQ=True)
    out = sharp


    deband_mask = lvf.denoise.detail_mask(out, brz_a=2000, brz_b=1000)
    deband = dbs.f3kpf(out, 17, 30, 30)
    deband = core.std.MaskedMerge(deband, out, deband_mask)
    out = deband


    grain_org = core.std.MergeDiff(out, diff_den)
    out = grain_org


    credit_mask = vdf.diff_rescale_mask(ref, mthr=40, sw=5, sh=5)
    credit_mask = vdf.region_mask(credit_mask, 10, 10, 10, 10).std.Inflate().std.Inflate()
    antialias = lvf.sraa(ref, 2, 13, downscaler=core.resize.Bicubic)
    credit = lvf.rfs(out, core.std.MaskedMerge(out, antialias, credit_mask),
                     [(2188, 2305), (33926, src.num_frames-1)])
    credit = lvf.rfs(credit, core.std.MaskedMerge(out, ref, credit_mask), [(31684, 33925)])

    out = credit


    src_c, ncop = [clip.std.Median() for clip in [src, JPBD_NCOP.src_cut]]
    opening_mask = vdf.dcm(out, src_c[opstart:opend+1], ncop[:opend-opstart+1], opstart, opend, 3, 3)
    credit_mask = opening_mask.std.Convolution([1]*9)

    credit = lvf.rfs(out, core.std.MaskedMerge(out, src, credit_mask), [(opstart, opend)])
    out = credit


    return depth(out, 10)
Beispiel #14
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    h = 720
    w = get_w(h)

    edgesfix = awf.bbmod(src, 1, 1, 1, 1, 48, 500)
    out = edgesfix

    clip = depth(out, 32)
    denoise = hybrid_denoise(clip, 0.45, 1.5)
    out = denoise

    luma = get_y(out)
    line_mask = line_mask_func(luma)

    descale = core.descale.Debilinear(luma, w, h)
    upscale = vdf.nnedi3_upscale(descale, pscrn=1)
    antialias = single_rate_antialiasing(upscale,
                                         13,
                                         alpha=0.4,
                                         beta=0.3,
                                         gamma=400,
                                         mdis=15).resize.Bilinear(
                                             src.width, src.height)

    rescale = core.std.MaskedMerge(luma, antialias, depth(line_mask, 32))
    merged = vdf.merge_chroma(rescale, out)
    out = depth(merged, 16)

    preden = core.knlm.KNLMeansCL(get_y(out),
                                  h=0.75,
                                  a=2,
                                  d=3,
                                  device_type='gpu',
                                  device_id=0)
    detail_dark_mask = detail_dark_mask_func(preden, brz_a=8000, brz_b=6000)
    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.Convolution([1, 1, 1, 1, 1, 1, 1, 1, 1])

    detail_mask = core.std.Expr([preden, detail_mask_grow, detail_mask],
                                f'x {32<<8} < y z ?')
    custom_mask_a = lvf.src('rezeros2_07_25374-25642.png', detail_mask)
    custom_mask_a = core.std.Expr([custom_mask_a, detail_mask], 'x y +')

    deband_a = dbs.f3kpf(out, 17, 36, 42, thr=0.5, elast=2, thrc=0.2)
    deband_b = placebo.deband(out, 18, 5.5, 2, 0)
    deband_d = core.neo_f3kdb.Deband(out, 20, 30, 30, 30, 0, 0, 4)
    deband_e = placebo.deband(out, 18, 8, 2, 0)

    deband = core.std.MaskedMerge(deband_a, deband_b, preden)

    deband = lvf.rfs(deband, deband_d, [(1457, 1677), (8414, 8684),
                                        (8788, 8915), (9348, 10179),
                                        (11325, 11459), (12647, 12857),
                                        (13025, 13574), (13874, 13987),
                                        (20809, 21076), (23936, 25063),
                                        (25219, 25373), (26231, 26530),
                                        (26668, 26800), (26818, 27048),
                                        (27174, 27454), (27503, 27943),
                                        (28492, 28622), (29948, 30563),
                                        (30965, 31498), (31624, 32005),
                                        (32107, 32325), (32451, 35407),
                                        (37171, 37955)])
    deband = lvf.rfs(deband, deband_e, [(22116, 22173), (22454, 22459),
                                        (38028, 38035)])
    deband = core.std.MaskedMerge(deband, out, detail_mask)
    deband = lvf.rfs(deband,
                     core.std.MaskedMerge(deband_e, deband, custom_mask_a),
                     [(25374, 25642), (25708, 25889)])

    deband = core.neo_f3kdb.Deband(deband,
                                   preset='depth',
                                   grainy=24,
                                   grainc=24)
    out = deband

    ref, src, src_nced = [
        depth(x, 16) for x in [denoise, src, JPBD_NCED.src_cut[221:]]
    ]
    credit_mask = vdf.drm(ref, kernel='bilinear', mthr=65)
    credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, credit_mask, 0),
                     [(113, 3315), (37171, src.num_frames - 1)])
    credit = lvf.rfs(credit, ref, [(3316, 3435), (35408, 35485)])
    out = credit

    src_c, src_nced = [
        c.knlm.KNLMeansCL(a=7, h=35, d=0, device_type='gpu')
        for c in [src, src_nced]
    ]
    ending_mask = vdf.dcm(out, src_c[EDSTART:EDEND + 1],
                          src_nced[:EDEND - EDSTART + 1], EDSTART, EDEND, 4,
                          4).std.Inflate()
    credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, ending_mask),
                     [(EDSTART, EDEND)])
    out = credit

    grain = adptvgrnMod(out,
                        0.3,
                        0.15,
                        1.25,
                        luma_scaling=8,
                        sharp=80,
                        static=False,
                        lo=19)
    out = grain

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

    opstart, opend = 2712, 4869

    ref = hvf.SMDegrain(out, thSAD=300)
    denoise = mvf.BM3D(out, [1.5, 1.25], radius1=1, ref=ref)
    out = denoise

    crop = core.std.Crop(out, left=12)
    crop = awf.bbmod(crop, left=2, thresh=20 << 8)
    resize = core.resize.Bicubic(crop, 1920)
    out = lvf.rfs(out, resize, [(86, 201)])

    y = get_y(out)
    lineart = gf.EdgeDetect(y, 'scharr').morpho.Dilate(2, 2).std.Inflate()

    fkrescale = fake_rescale(y,
                             882,
                             0,
                             1,
                             deringer=lambda x: gf.MaskedDHA(x,
                                                             rx=1.85,
                                                             ry=1.85,
                                                             darkstr=0.25,
                                                             brightstr=1.0,
                                                             maskpull=100,
                                                             maskpush=200),
                             antialiser=lambda c: lvf.sraa(
                                 c, 2, 13, downscaler=core.resize.Bicubic))
    merged = core.std.MaskedMerge(y, fkrescale, lineart)
    out = vdf.merge_chroma(merged, out)

    dering = hvf.EdgeCleaner(out, 17, smode=1, hot=True)
    out = dering

    detail_mask = lvf.mask.detail_mask(out, brz_a=2250, brz_b=1000)
    deband = vdf.dumb3kdb(out, 15, threshold=17, grain=(24, 0))
    deband = core.std.MaskedMerge(deband, out, detail_mask)
    out = deband

    grain = adptvgrnMod(out,
                        0.3,
                        static=True,
                        grain_chroma=False,
                        hi=[128, 240],
                        seed=333)
    out = grain

    decz = vdf.decsiz(out, min_in=128 << 8, max_in=200 << 8)
    out = decz

    ref = depth(src, 16)
    src_c, src_ncop = [
        depth(x, 16).std.Convolution([1, 2, 1, 2, 4, 2, 1, 2, 1])
        for x in [src, JPBD_NCOP.src_cut]
    ]

    opening_mask = vdf.dcm(out, src_c[opstart:opend + 1],
                           src_ncop[:opend - opstart + 1], opstart, opend, 2,
                           2)
    opening_mask = iterate(opening_mask, core.std.Inflate, 4)

    credit = out
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, opening_mask),
                     [(opstart, opend)])
    credit = lvf.rfs(credit, ref, [(17985, 18128)])
    out = credit

    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 2])
Beispiel #16
0
from vapoursynth import core, YUV444P8, YUV420P8
from rekt import rektlvls
import havsfunc as haf
import awsmfunc as awf
import lvsfunc as lvf
import G41Fun

guilstein = core.d2v.Source("Guilstein/VTS_01_1.d2v")[:163645]
guilstein = guilstein.decross.DeCross().dedot.Dedot().resize.Bicubic(format=YUV444P8, matrix_s="170m")
topline = guilstein.vinverse.Vinverse().std.Crop(top=63, bottom=70, left=6, right=6).std.CropAbs(top=1, width=guilstein.width-12, height=2)
guilstein = core.std.MaskedMerge(guilstein.vinverse.Vinverse().std.Crop(top=66, left=6, right=6), guilstein.std.Crop(top=66, left=6, right=6).nnedi3.nnedi3(1), guilstein.std.Crop(top=66, left=6, right=6).comb.CombMask().morpho.Dilate())
guilstein = guilstein.std.Crop(bottom=70)
guilstein = core.std.StackVertical([topline, guilstein])

guilstein = rektlvls(guilstein, rownum=[0, 1], rowval=[50, 10], colnum=[0, 1, 2, 3, 4], colval=[14, 10, 9, -3, -2], prot_val=[16, 235])
guilstein = awf.bbmod(guilstein, right=4, thresh=7, blur=16)
guilstein = core.std.Expr([guilstein, awf.bbmod(guilstein, bottom=3, thresh=2, blur=16)], "x y > x y ?")
guilstein = core.std.Expr([guilstein, awf.bbmod(guilstein, left=8, thresh=1, blur=8)], "x y > x y ?")
guilstein = lvf.aa.upscaled_sraa(guilstein, rfactor=2.0)
guilstein = guilstein.dfttest.DFTTest(sigma=2.0)
guilstein = guilstein.f3kdb.Deband(range=30, grainy=2, grainc=2)
guilstein = G41Fun.MaskedDHA(guilstein, rx=1.6, ry=1.6, darkstr=0.0, brightstr=0.6, lowsens=120, highsens=10)
guilstein = haf.EdgeCleaner(guilstein, strength=10)

guilstein = guilstein.resize.Bicubic(format=YUV420P8, matrix_s="170m")
guilstein = guilstein.std.FreezeFrames(first=[110471], last=[110483], replacement=[110470])

guilstein.set_output()
Beispiel #17
0
from vapoursynth import core
import awsmfunc as awf
import havsfunc as haf

old_man_and_the_sea = core.lsmas.LWLibavSource("The.Old.Man.and.the.Sea.1958.1080p.AMZN.WEB-DL.DDP2.0.H.264-ISA.mkv")
old_man_and_the_sea = core.fb.FillBorders(old_man_and_the_sea, left=2)
old_man_and_the_sea = awf.fb(old_man_and_the_sea, right=1)
old_man_and_the_sea = awf.bbmod(old_man_and_the_sea, right=4, thresh=505, blur=15)
old_man_and_the_sea = awf.bbmod(old_man_and_the_sea, left=4, thresh=500, blur=3)
old_man_and_the_sea = haf.Deblock_QED(old_man_and_the_sea)

old_man_and_the_sea.set_output()
Beispiel #18
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Main VapourSynth filterchain"""
    import debandshit as dbs
    import havsfunc as haf
    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_w, get_y

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

    rkt_a = rekt.rektlvls(src, [0, 1, -2, -1], [12, -12, -10, 11],
                          [0, 1, -2, -1], [11, -12, -10, 11])
    rkt_b = rekt.rektlvls(src, [0, -1], [15, 15], [0, 1, 2, 3, -4, -2, -1],
                          [12, 3, -1, 1, 2, 4, 12])
    rkt_c = rekt.rektlvls(src, [-2, -1], [6, 11], [0, -2, -1], [15, 10, 15])
    bb_c = bbmod(rkt_c, bottom=2, blur=35, y=False)
    rkt = lvf.rfs(rkt_a, rkt_b, [(458, 522), (806, 919), (1148, 1179),
                                 (1321, 1442), (1989, 2129)])
    rkt = lvf.rfs(rkt, bb_c, [(2130, None)])

    ef = depth(rkt, 32)
    src_y = get_y(ef)

    pre_den = core.dfttest.DFTTest(src_y, sigma=3.0)
    l_mask = vdf.mask.FDOG().get_mask(
        pre_den, lthr=0.125,
        hthr=0.050).rgsf.RemoveGrain(4).rgsf.RemoveGrain(4)
    l_mask = l_mask.std.Minimum().std.Deflate().std.Median().std.Convolution(
        [1] * 9).std.Maximum()

    # Descaling.
    descaled = lvf.kernels.Catrom().descale(
        src_y, get_w(720, src_y.width / src_y.height), 720)
    descaled = core.resize.Bicubic(descaled, format=vs.YUV444P16)

    # Slight AA in an attempt to forcibly fix starved lineart.
    baa = lvf.aa.based_aa(descaled, shader_file)
    sraa = lvf.aa.upscaled_sraa(descaled, rfactor=1.45)
    clamp_aa = lvf.aa.clamp_aa(descaled, baa, sraa, strength=1.15)
    clamp_aa = depth(get_y(clamp_aa), 32)

    # Doing a mixed reupscale using nn3/fsrcnnx, grabbing the darkest parts of each
    rescaled_nn3 = vdf.scale.nnedi3cl_double(clamp_aa, use_znedi=True, pscrn=1)
    rescaled_fsrcnnx = vdf.scale.fsrcnnx_upscale(clamp_aa, rescaled_nn3.width,
                                                 rescaled_nn3.height,
                                                 shader_file)
    rescaled = core.std.Expr([rescaled_nn3, rescaled_fsrcnnx], "x y min")

    downscaled = SSIM_downsample(rescaled,
                                 src_y.width,
                                 src_y.height,
                                 smooth=((3**2 - 1) / 12)**0.5,
                                 sigmoid=True,
                                 filter_param_a=-1 / 2,
                                 filter_param_b=1 / 4)
    downscaled = core.std.MaskedMerge(src_y, downscaled, l_mask)

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

    # Chroma warping to forcibly wrap it a bit nicer around the lineart. Also fixing slight shift. 4:2:0 was a mistake.
    cwarp = scaled.warp.AWarpSharp2(thresh=72,
                                    blur=3,
                                    type=1,
                                    depth=6,
                                    planes=[1, 2])

    # The textures and detail are very smeary, so gotta be careful not to make it even worse
    stab = haf.GSMC(cwarp, radius=3, planes=[0], thSAD=75)
    den_uv = ccd(stab, threshold=5, matrix='709')
    decs = vdf.noise.decsiz(den_uv,
                            sigmaS=8.0,
                            min_in=200 << 8,
                            max_in=240 << 8)

    # Scenefiltered debanding. Not graining, since we kept most of the original grain anyway.
    deband_wk = dbs.debanders.dumb3kdb(decs,
                                       radius=16,
                                       threshold=[28, 0],
                                       grain=0)
    deband_wk = core.placebo.Deband(deband_wk,
                                    iterations=2,
                                    threshold=3.5,
                                    radius=12,
                                    grain=0,
                                    planes=2 | 4)

    # Strong denoising + debanding to hopefully deal with all the awful bands. Courtesy of :b:arde
    dft = core.dfttest.DFTTest(decs, sigma=4.0)
    ccd_uv = ccd(dft, threshold=10, matrix='709')
    f3k = dbs.debanders.dumb3kdb(ccd_uv, radius=8, threshold=[36, 24], grain=0)
    plac = flt.masked_placebo(f3k,
                              rad=18,
                              thr=5.5,
                              itr=2,
                              grain=3.0,
                              mask_args={
                                  'detail_brz': 100,
                                  'lines_brz': 450
                              })

    dft_diff = core.std.MakeDiff(decs, dft)
    plac_diff = core.std.MergeDiff(plac, dft_diff)

    deband = lvf.rfs(deband_wk, plac_diff, strong_debanding)

    return deband
Beispiel #19
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
Beispiel #20
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)
    out = src

    h = 720
    w = get_w(h)

    fixedges = awf.bbmod(out, 2, 2, 2, 2, 64 << 8, 999)
    out = fixedges

    decomb = hvf.Vinverse(out)
    decomb = lvf.rfs(out, decomb, [(828, 836)])
    out = decomb

    clean = core.knlm.KNLMeansCL(out,
                                 h=0.55,
                                 a=2,
                                 d=3,
                                 device_type='gpu',
                                 device_id=0,
                                 channels='UV')
    clean = core.knlm.KNLMeansCL(clean,
                                 h=0.55,
                                 a=2,
                                 d=3,
                                 device_type='gpu',
                                 device_id=0,
                                 channels='Y')
    diff_den = core.std.MakeDiff(out, clean)
    out = depth(clean, 32)

    luma = get_y(out)
    line_mask = vdf.edge_detect(luma, 'FDOG', 0.05, (1, 1))

    descale = core.descale.Debilinear(luma, w, h)
    upscale = vdf.nnedi3_upscale(descale, correct_shift=False,
                                 pscrn=1).resize.Bicubic(src.width,
                                                         src.height,
                                                         src_left=.5,
                                                         src_top=.5)
    rescale = core.std.MaskedMerge(luma, upscale, line_mask)

    merged = vdf.merge_chroma(rescale, out)
    out = depth(merged, 16)

    moozzi = warping(out, 0.4, 4)
    sharp = hvf.LSFmod(moozzi,
                       strength=95,
                       Smode=3,
                       Lmode=1,
                       edgemode=1,
                       edgemaskHQ=True)
    out = sharp

    deband_mask = lvf.denoise.detail_mask(out, brz_a=2000, brz_b=1000)
    deband = dbs.f3kpf(out, 17, 30, 30)
    deband = core.std.MaskedMerge(deband, out, deband_mask)
    out = deband

    grain_org = core.std.MergeDiff(out, diff_den)
    out = grain_org

    ref = decomb
    credit_mask = vdf.diff_rescale_mask(ref, mthr=40, sw=5, sh=5)
    credit_mask = vdf.region_mask(credit_mask, 10, 10, 10,
                                  10).std.Inflate().std.Inflate()
    credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, credit_mask),
                     [(0, 725), (31741, 33864)])
    antialias = lvf.sraa(ref, 2, 13, downscaler=core.resize.Bicubic)
    credit = lvf.rfs(credit, core.std.MaskedMerge(out, antialias, credit_mask),
                     [(833, 933), (1060, 1229), (1716, 1887), (2665, 2830),
                      (4813, 4947), (8179, 8272), (13757, 13810),
                      (20630, 20737), (20866, 20951), (21338, 21409),
                      (21480, 21520), (24719, 24786), (24829, 24869),
                      (28206, 28298), (28299, 28426), (33927, 34046)])
    out = credit

    return depth(out, 10)
Beispiel #21
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 awsmfunc import bbmod
    from ccd import ccd
    from vsutil import depth, get_y
    from xvs import WarpFixChromaBlend

    src = JP_NCED.clip_cut
    src_13 = JP_BD_13.clip_cut

    src = lvf.rfs(src, src_13, [(2073, None)])

    # Edgefixing
    rkt = rekt.rektlvls(src, [0, 1079], [17, 16],
                        [0, 1, 2, 3] + [1917, 1918, 1919],
                        [16, 4, -2, 2] + [-2, 5, 14])
    ef = bbmod(rkt, left=4, right=3, y=False)
    ef = depth(ef, 32)

    # Descaling + Rescaling
    src_y = get_y(ef)
    descaled = lvf.kernels.Bicubic().descale(src_y, 1280, 720)
    rescaled = vdf.scale.nnedi3_upscale(descaled)
    downscaled = lvf.kernels.Bicubic(-1 / 2, 1 / 4).scale(rescaled, 1920, 1080)

    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)

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

    unwarp = flt.line_darkening(scaled, 0.145).warp.AWarpSharp2(depth=2)
    sharp = haf.LSFmod(unwarp,
                       strength=65,
                       Smode=3,
                       Lmode=1,
                       edgemode=1,
                       edgemaskHQ=True)
    mask_sharp = core.std.MaskedMerge(scaled, sharp, depth(l_mask, 16))

    upscaled = lvf.kernels.Bicubic().scale(descaled, 1920, 1080)
    descale_mask = lvf.scale.descale_detail_mask(src_y, upscaled)
    details_merged = core.std.MaskedMerge(mask_sharp, depth(ef, 16),
                                          depth(descale_mask, 16))

    # Denoising
    denoise_y = core.knlm.KNLMeansCL(details_merged,
                                     d=1,
                                     a=3,
                                     s=4,
                                     h=0.15,
                                     channels='Y')
    denoise_uv = ccd(denoise_y, threshold=6, matrix='709')
    stab = haf.GSMC(denoise_uv, radius=2, adapt=1, planes=[0])
    decs = vdf.noise.decsiz(stab, sigmaS=8, min_in=208 << 8, max_in=232 << 8)

    # Fixing chroma
    cshift = core.resize.Bicubic(decs, chromaloc_in=1, chromaloc=0)
    cwarp = WarpFixChromaBlend(cshift, thresh=88, blur=3, depth=6)

    # Regular debanding + graining
    detail_mask = flt.detail_mask(cwarp, brz=(1800, 3500))
    deband = vdf.deband.dumb3kdb(cwarp, threshold=32, grain=16)
    deband_masked = core.std.MaskedMerge(deband, cwarp, detail_mask)
    grain: vs.VideoNode = adptvgrnMod(deband_masked,
                                      0.2,
                                      luma_scaling=10,
                                      size=1.35,
                                      static=True,
                                      grain_chroma=False)

    return grain
Beispiel #22
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut

    # Variables
    opstart, opend = 2111, 4268
    edstart, edend = 31650, 33809
    full_zone = [(18727, 18774), (31590, 31649), (33990, src.num_frames - 1)
                 ]  # eyecatch, episode name and next episode
    shabc_zone = [(edstart + 15, edstart + 1215),
                  (edstart + 1882, edstart + 2126)]
    h = 720
    w = get_w(h)

    # Bicubic sharp parts don't have bad edges
    edges_a = core.edgefixer.ContinuityFixer(src, *[[2, 1, 1]] * 4)
    edges_b = awf.bbmod(src, left=6, thresh=32, blur=200)
    edges = lvf.rfs(edges_a, edges_b, [(edstart + 1275, edstart + 1757)])
    edges = lvf.rfs(edges, src, [(opstart, opend)] + full_zone)
    out = depth(edges, 32)

    # Denoise
    ref = hvf.SMDegrain(depth(get_y(out), 16), thSAD=450)
    denoise = hybrid_denoise(out, 0.35, 1.4, dict(a=2, d=1),
                             dict(ref=depth(ref, 32)))
    out = denoise
    # denoise = out

    # Descale
    luma = get_y(out)
    lineart = vdf.edge_detect(luma, 'FDOG', 0.055,
                              (1, 1)).std.Median().std.BoxBlur(0, 1, 1, 1, 1)

    descale_a = core.descale.Despline36(luma, w,
                                        h).std.SetFrameProp('descaleKernel',
                                                            data='spline36')
    descale_b = core.descale.Debicubic(luma, w, h, 0, 1).std.SetFrameProp(
        'descaleKernel', data='sharp_bicubic')
    descale = lvf.rfs(descale_a, descale_b, shabc_zone)

    # Chroma reconstruction
    # y_m is the assumed mangled luma.
    # Descale 1080p -> Bad conversion in 422 720p -> Regular 1080p 420
    radius = 2
    y, u, v = descale, plane(out, 1), plane(out, 2)
    y_m = core.resize.Point(y, 640, 720,
                            src_left=-1).resize.Bicubic(960,
                                                        540,
                                                        filter_param_a=1 / 3,
                                                        filter_param_b=1 / 3)

    # 0.25 for 444 and 0.25 for right shifting
    y_m, u, v = [
        c.resize.Bicubic(w,
                         h,
                         src_left=0.25 + 0.25,
                         filter_param_a=0,
                         filter_param_b=.5) for c in [y_m, u, v]
    ]

    y_fixup = core.std.MakeDiff(y, y_m)
    yu, yv = Regress(y_m, u, v, radius=radius, eps=1e-7)

    u_fixup = ReconstructMulti(y_fixup, yu, radius=radius)
    u_r = core.std.MergeDiff(u, u_fixup)

    v_fixup = ReconstructMulti(y_fixup, yv, radius=radius)
    v_r = core.std.MergeDiff(v, v_fixup)

    # -0.5 * 720/1080 = -1/3
    # -1/3 for the right shift
    # https://forum.doom9.org/showthread.php?p=1802716#post1802716
    u_r, v_r = [
        c.resize.Bicubic(960,
                         540,
                         src_left=-1 / 3,
                         filter_param_a=-.5,
                         filter_param_b=.25) for c in [u_r, v_r]
    ]

    upscale = vdf.fsrcnnx_upscale(
        descale,
        height=h * 2,
        shader_file=r'shaders\FSRCNNX_x2_56-16-4-1.glsl',
        upscaler_smooth=eedi3_upscale,
        profile='zastin')

    antialias = sraa_eedi3(upscale,
                           3,
                           alpha=0.2,
                           beta=0.4,
                           gamma=40,
                           nrad=3,
                           mdis=20)

    downscale = muvf.SSIM_downsample(antialias,
                                     src.width,
                                     src.height,
                                     filter_param_a=0,
                                     filter_param_b=0)
    downscale = core.std.MaskedMerge(luma, downscale, lineart)

    merged_a = join([downscale, u_r, v_r])
    merged_b = vdf.merge_chroma(downscale, denoise)
    merged = lvf.rfs(merged_a, merged_b, shabc_zone)
    out = depth(merged, 16)

    warp = xvs.WarpFixChromaBlend(out, 80, 2, depth=8)
    out = warp

    dering = gf.MaskedDHA(out,
                          rx=1.25,
                          ry=1.25,
                          darkstr=0.05,
                          brightstr=1.0,
                          maskpull=48,
                          maskpush=140)
    out = dering

    qtgmc = hvf.QTGMC(out, Preset="Slower", InputType=1, ProgSADMask=2.0)
    qtgmc = vdf.fade_filter(out, out, qtgmc, edstart + 1522,
                            edstart + 1522 + 24)
    qtgmc = lvf.rfs(out, qtgmc, [(edstart + 1522 + 25, edstart + 1757)])
    out = qtgmc

    out = lvf.rfs(out, depth(denoise, 16), [(opstart, opend)])

    detail_dark_mask = detail_dark_mask_func(get_y(out),
                                             brz_a=8000,
                                             brz_b=6000)
    detail_light_mask = lvf.denoise.detail_mask(out, brz_a=2500, brz_b=1200)
    detail_mask = core.std.Expr([detail_dark_mask, detail_light_mask],
                                'x y +').std.Median()
    detail_mask_grow = iterate(detail_mask, core.std.Maximum, 2)
    detail_mask_grow = iterate(detail_mask_grow, core.std.Inflate,
                               2).std.BoxBlur(0, 1, 1, 1, 1)

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

    deband = dumb3kdb(out, 22, 30)
    deband = core.std.MaskedMerge(deband, out, detail_mask)
    out = deband

    ref = get_y(out).std.PlaneStats()
    adgmask_a = core.adg.Mask(ref, 30)
    adgmask_b = core.adg.Mask(ref, 12)

    stgrain = sizedgrn(out, 0.1, 0.05, 1.05, sharp=80)
    stgrain = core.std.MaskedMerge(out, stgrain, adgmask_b)
    stgrain = core.std.MaskedMerge(out, stgrain, adgmask_a.std.Invert())

    dygrain = sizedgrn(out, 0.2, 0.05, 1.15, sharp=80, static=False)
    dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a)
    grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain))
    out = grain

    ref = depth(edges, 16)
    credit = out
    rescale_mask = vdf.diff_rescale_mask(ref, h, b=0, c=1, mthr=40, sw=0, sh=0)
    rescale_mask = vdf.region_mask(rescale_mask, *[10] * 4)
    rescale_mask = hvf.mt_expand_multi(rescale_mask,
                                       mode='ellipse',
                                       sw=4,
                                       sh=4).std.BoxBlur(0, 1, 1, 1, 1)

    credit = lvf.rfs(credit, ref, full_zone)
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, rescale_mask),
                     [(edstart, edend)])
    out = credit

    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2])
Beispiel #23
0
from vapoursynth import core
import awsmfunc as awf

cheyenne_social_club = core.d2v.Source("The Cheyenne Social Club (1970)/VTS_01_1.d2v")
cheyenne_social_club = core.vivtc.VFM(cheyenne_social_club, 1)
cheyenne_social_club = core.std.SelectEvery(cheyenne_social_club, cycle=5, offsets=[0, 1, 2, 4])
cheyenne_social_club = core.std.Crop(cheyenne_social_club, top=64, bottom=60)
cheyenne_social_club = awf.fb(cheyenne_social_club, top=1)
cheyenne_social_club = awf.bbmod(cheyenne_social_club, top=5, right=4, thresh=15, blur=10)

cheyenne_social_club.set_output()
clip = depth(src, 16)

# 2 Filtering

# 2.1 Dirty lines & Borders
fix_borders = False
if fix_borders:
    fixed = awf.FixBrightnessProtect2(clip,
                                      row=[],
                                      adj_row=[],
                                      column=[],
                                      adj_column=[])
    fixed = awf.FillBorders(
        clip=clip, top=0, left=0, right=0, bottom=0
    )  # For 1080p only. If you're working on 720, please consider using CropResize!
    fixed = awf.bbmod(clip, top=0, bottom=0, left=0, right=0, thresh=0, blur=0)
else:
    fixed = clip

# 2.2 Resized
resize = False
if resize:
    resized = awf.CropResize(clip=fixed,
                             preset=720)  # Resize the cilp and fill borders
    resized = awf.zresize(fixed, preset=720)
else:
    resized = fixed

# 2.3 Deband & Deblock
deband = False
if deband:
Beispiel #25
0
def main() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Vapoursynth filtering"""
    # Don't worry, this script is barely readable anymore even for me
    import rekt
    from awsmfunc import bbmod
    from havsfunc import ContraSharpening
    from lvsfunc.aa import upscaled_sraa
    from lvsfunc.comparison import stack_compare
    from lvsfunc.mask import BoundingBox
    from lvsfunc.util import replace_ranges
    from vardefunc import dcm
    from vardefunc.deband import dumb3kdb
    from vardefunc.mask import FreyChen
    from vsutil import depth, get_y, insert_clip

    src = JP_BD.clip_cut
    b = core.std.BlankClip(src, length=1)

    if opstart is not False:
        src_NCOP = NCOP.clip_cut
        op_scomp = stack_compare(
            src[opstart:opstart + src_NCOP.num_frames - 1] + b,
            src_NCOP[:-op_offset] + b,
            make_diff=True)  # noqa
    if edstart is not False:
        src_NCED = NCED.clip_cut
        #ed_scomp = stack_compare(src[edstart:edstart+src_NCED.num_frames-1]+b, src_NCED[:-ed_offset]+b, make_diff=True)  # noqa

    # Masking credits
    op_mask = dcm(
        src, src[opstart:opstart+src_NCOP.num_frames], src_NCOP,
        start_frame=opstart, thr=25, prefilter=True) if opstart is not False \
        else get_y(core.std.BlankClip(src))
    ed_mask = dcm(
        src, src[edstart:edstart+src_NCED.num_frames], src_NCED,
        start_frame=edstart, thr=25, prefilter=True) 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()

    # Fixing an animation f**k-up
    for f in op_replace:
        src = insert_clip(src, src[f], f - 1)

    # 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)
    bb32 = depth(bb_uv, 32)

    # --- Very specific filtering that should probably be removed for future episodes entirely
    # Fading for some... well, fades.
    fade = flt.fader(bb32, start_frame=4437, end_frame=4452)
    fade = flt.fader(fade, start_frame=18660, end_frame=18697)

    # Different sport names
    rkt_aa_ranges: Union[Union[int, None, Tuple[Optional[int], Optional[int]]],
                         List[Union[int, None,
                                    Tuple[Optional[int],
                                          Optional[int]]]], None] = [  # noqa
                                              (8824, 8907), (9828, 9911),
                                              (10995, 11078), (11904, 12010)
                                          ]

    rkt_aa = rekt.rekt_fast(fade,
                            fun=lambda x: upscaled_sraa(x),
                            top=854,
                            left=422,
                            bottom=60,
                            right=422)
    rkt_aa = replace_ranges(fade, rkt_aa, rkt_aa_ranges)

    # QP GET!
    rkt_aa2_ranges: Union[Union[int, None, Tuple[Optional[int],
                                                 Optional[int]]],
                          List[Union[int, None,
                                     Tuple[Optional[int],
                                           Optional[int]]]], None] = [  # noqa
                                               (26333, 26333), (28291, 28344),
                                               (30271, 30364)
                                           ]
    rkt_aa2 = rekt.rekt_fast(rkt_aa,
                             fun=lambda x: upscaled_sraa(x),
                             top=714,
                             left=354,
                             bottom=224,
                             right=354)
    rkt_aa2 = replace_ranges(fade, rkt_aa, rkt_aa2_ranges)

    # Table stuff
    rkt_aa3_ranges: Union[Union[int, None, Tuple[Optional[int],
                                                 Optional[int]]],
                          List[Union[int, None,
                                     Tuple[Optional[int],
                                           Optional[int]]]], None] = [  # noqa
                                               (32797, 32952)
                                           ]
    rkt_aa3 = rekt.rekt_fast(rkt_aa2,
                             fun=lambda x: upscaled_sraa(x),
                             top=488,
                             left=312,
                             bottom=390,
                             right=850)
    rkt_aa3 = replace_ranges(fade, rkt_aa2, rkt_aa3_ranges)

    rkt_aa = rkt_aa3

    # Clipping error Nyatalante/Achilles
    fixed_frame = source(
        JP_BD.workdir.to_str() + r"/assets/01/FGCBD_01_8970_fixed.png", rkt_aa)
    fix_error = replace_ranges(rkt_aa, fixed_frame, [(8968, 8970)])

    sp_out32 = fix_error
    sp_out16 = depth(sp_out32, 16)

    # Rescaling
    l_mask = FreyChen().get_mask(get_y(sp_out16)).morpho.Close(size=6)
    l_mask = core.std.Binarize(l_mask, 24 << 8).std.Maximum().std.Maximum()
    scaled, credit_mask = flt.rescaler(sp_out32,
                                       height=720,
                                       shader_file=shader)
    scaled = core.std.MaskedMerge(sp_out16, scaled, l_mask)
    scaled = core.std.MaskedMerge(scaled, sp_out16, credit_mask)

    # Denoising
    denoise = flt.multi_denoise(scaled, l_mask)

    # Anti-aliasing
    aa_clamped = flt.clamp_aa(denoise, strength=3.0)
    aa_rfs = replace_ranges(denoise, aa_clamped, aa_ranges)

    # Fix edges because they get f****d during the denoising and AA stages
    box = BoundingBox((1, 1), (src.width - 2, src.height - 2))
    fix_edges = core.std.MaskedMerge(scaled, aa_rfs, box.get_mask(scaled))

    # Regular debanding, but then...
    deband = flt.multi_debander(fix_edges, sp_out16)

    # --- More very specific filtering that should almost definitely be removed for other episodes
    boxes = [
        BoundingBox((0, 880), (1920, 200)),
        BoundingBox((1367, 0), (552, 1080)),
        BoundingBox((1143, 0), (466, 83)),
        BoundingBox((1233, 84), (237, 84)),
    ]

    boxed_deband = flt.placebo_debander(fix_edges,
                                        iterations=2,
                                        threshold=8,
                                        radius=14,
                                        grain=4)
    boxed_mask = core.std.BlankClip(
        boxed_deband.std.ShufflePlanes(planes=0, colorfamily=vs.GRAY))
    for bx in boxes:  # Gonna be awfully slow but OH WELLLLLL
        boxed_mask = core.std.Expr(
            [boxed_mask, bx.get_mask(boxed_mask)], "x y max")

    boxed_deband_merged = core.std.MaskedMerge(deband, boxed_deband,
                                               boxed_mask)
    boxed_deband_merged = replace_ranges(deband, boxed_deband_merged,
                                         [(20554, 20625)])

    stronger_deband = dumb3kdb(fix_edges, radius=18, threshold=[48, 32])
    stronger_deband = replace_ranges(boxed_deband_merged, stronger_deband,
                                     [(22547, 22912), (28615, 28846),
                                      (33499, 33708), (37223, 37572),
                                      (37636, 37791), (38047, 38102),
                                      (38411, 38733)])

    deband_csharp = ContraSharpening(stronger_deband, scaled, 17)

    sp_out = deband_csharp

    # Back to regular graining
    grain = flt.grain(sp_out)

    return grain
Beispiel #26
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 awsmfunc import bbmod
    from ccd import ccd
    from vsutil import depth, get_y
    from xvs import WarpFixChromaBlend

    src = JP_BD.clip_cut
    src_NCOP, src_NCED = JP_BD_NCOP.clip_cut, JP_BD_NCED.clip_cut
    src_NCOP = src_NCOP + src_NCOP[-1] * 11
    src_NCED = src_NCED + src_NCED[-1]
    src_03 = JP_BD_03.clip_cut
    # b = core.std.BlankClip(src, length=1)

    # Fixing an animation error in the NCOP
    sqmask_NCOP = lvf.mask.BoundingBox((419, 827), (1500, 68))
    masked_NCOP = core.std.MaskedMerge(src_NCOP, src_03,
                                       sqmask_NCOP.get_mask(src_NCOP))
    masked_NCOP = lvf.rfs(src_NCOP, masked_NCOP,
                          [(opstart + 2064, opstart + 2107)])

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

    # Masking credits
    op_mask = vdf.dcm(
        src, src[opstart:opstart+src_NCOP.num_frames-op_offset], masked_NCOP[:-op_offset],
        start_frame=opstart, thr=25, prefilter=True) if opstart is not False \
        else get_y(core.std.BlankClip(src))
    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 = core.std.Expr([op_mask, ed_mask], expr='x y +')
    credit_mask = depth(credit_mask, 16).std.Binarize()

    # Edgefixing
    ef = bbmod(src, left=1, right=1, top=1, bottom=1, u=False, v=False)
    ef = bbmod(ef, left=2, right=2, top=2, bottom=2, y=False)
    ef = depth(ef, 32)

    # Descaling + Rescaling
    src_y = get_y(ef)
    descaled = lvf.kernels.Lanczos(taps=5).descale(src_y, 1280, 720)
    rescaled = vdf.scale.nnedi3_upscale(descaled)
    downscaled = lvf.kernels.BicubicDidee().scale(rescaled, 1920, 1080)

    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)

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

    unwarp = flt.line_darkening(scaled, 0.145).warp.AWarpSharp2(depth=2)
    sharp = haf.LSFmod(unwarp,
                       strength=65,
                       Smode=3,
                       Lmode=1,
                       edgemode=1,
                       edgemaskHQ=True)
    mask_sharp = core.std.MaskedMerge(scaled, sharp, depth(l_mask, 16))

    upscaled = lvf.kernels.Bicubic().scale(descaled, 1920, 1080)
    descale_mask = lvf.scale.descale_detail_mask(src_y, upscaled)
    scale_restore_mask = core.std.Expr([credit_mask, descale_mask], "x y +")
    credits_merged = core.std.MaskedMerge(mask_sharp, depth(ef, 16),
                                          scale_restore_mask)

    # Denoising
    denoise_y = core.knlm.KNLMeansCL(credits_merged,
                                     d=1,
                                     a=3,
                                     s=4,
                                     h=0.15,
                                     channels='Y')
    denoise_uv = ccd(denoise_y, threshold=6, matrix='709')
    stab = haf.GSMC(denoise_uv, radius=2, planes=[0])
    decs = vdf.noise.decsiz(stab, sigmaS=8, min_in=208 << 8, max_in=232 << 8)

    # Fixing chroma
    cshift = core.resize.Bicubic(decs, chromaloc_in=1, chromaloc=0)
    cwarp = WarpFixChromaBlend(cshift, thresh=88, blur=3, depth=6)

    # Regular debanding + graining
    detail_mask = flt.detail_mask(cwarp, brz=(1800, 3500))
    deband = vdf.deband.dumb3kdb(cwarp, threshold=32, grain=16)
    deband_masked = core.std.MaskedMerge(deband, cwarp, detail_mask)
    grain: vs.VideoNode = adptvgrnMod(deband_masked,
                                      0.2,
                                      luma_scaling=10,
                                      size=1.35,
                                      static=True,
                                      grain_chroma=False)

    return grain
Beispiel #27
0
from vapoursynth import core
import awsmfunc as awf

lady_of_fatima = core.ffms2.Source(
    "The.Miracle.of.Our.Lady.of.Fatima.1952.1080p.WEB-DL.DD+2.0.H.264-SbR.mkv")
lady_of_fatima = core.std.Crop(lady_of_fatima, left=2, right=2)
lady_of_fatima = core.fb.FillBorders(lady_of_fatima, right=1)
lady_of_fatima = awf.bbmod(lady_of_fatima, right=2, thresh=15, blur=20)

lady_of_fatima.set_output()
Beispiel #28
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    h = 720
    w = get_w(h)

    edgesfix = awf.bbmod(src, 1, 1, 1, 1, 48, 500)
    out = edgesfix

    clip = depth(out, 32)
    denoise = hybrid_denoise(clip, 0.45, 1.5)
    out = denoise

    luma = get_y(out)
    line_mask = line_mask_func(luma)

    descale = core.descale.Debilinear(luma, w, h)
    upscale = vdf.nnedi3_upscale(descale, pscrn=1)
    antialias = single_rate_antialiasing(upscale,
                                         13,
                                         alpha=0.2,
                                         beta=0.5,
                                         gamma=600,
                                         mdis=15)

    scaled = core.resize.Bicubic(antialias, src.width, src.height)
    rescale = core.std.MaskedMerge(luma, scaled, depth(line_mask, 32))
    merged = vdf.merge_chroma(rescale, out)
    out = depth(merged, 16)

    preden = core.knlm.KNLMeansCL(get_y(out),
                                  h=0.75,
                                  a=2,
                                  d=3,
                                  device_type='gpu',
                                  device_id=0)
    detail_dark_mask = detail_dark_mask_func(preden, brz_a=8000, brz_b=6000)
    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.Convolution([1, 1, 1, 1, 1, 1, 1, 1, 1])

    detail_mask = core.std.Expr([preden, detail_mask_grow, detail_mask],
                                f'x {32<<8} < y z ?')
    op_mask = mask_opening(out)
    op_mask = iterate(op_mask, core.std.Deflate, 2)

    deband_a = dbs.f3kpf(out, 17, 36, 42, thr=0.5, elast=2, thrc=0.2)
    deband_b = placebo.deband(out, 18, 5.5, 2, 0)
    deband_c = placebo.deband(out, 22, 10, 3, 0)
    deband = core.std.MaskedMerge(deband_a, deband_b, preden)
    deband = core.std.MaskedMerge(deband, out, detail_mask)

    deband = lvf.rfs(deband, core.std.MaskedMerge(deband_c, deband, op_mask),
                     [(OPSTART + 0, OPSTART + 38)])
    deband = lvf.rfs(deband, deband_b, [(OPSTART + 236, OPSTART + 284)])
    deband = lvf.rfs(deband, deband_c, [(OPSTART + 1934, OPSTART + 1944)])
    deband = core.neo_f3kdb.Deband(deband,
                                   preset='depth',
                                   grainy=24,
                                   grainc=24)
    out = deband

    ref, src, src_ncop = [
        depth(x, 16) for x in [denoise, src, JPBD_NCOP.src_cut]
    ]
    credit_mask = vdf.drm(ref, kernel='bilinear', mthr=65)
    credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, credit_mask, 0),
                     [(0, 3164)])
    credit = lvf.rfs(credit, ref, [(34693, 34764)])
    out = credit

    src_c, src_ncop = [
        c.knlm.KNLMeansCL(a=7, h=35, d=0, device_type='gpu')
        for c in [src, src_ncop]
    ]
    opening_mask = vdf.dcm(out, src_c[OPSTART:OPEND + 1],
                           src_ncop[:OPEND - OPSTART + 1], OPSTART, OPEND, 4,
                           4).std.Inflate()
    credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, opening_mask),
                     [(OPSTART, OPEND)])
    out = credit

    grain = adptvgrnMod(out,
                        0.3,
                        0.15,
                        1.25,
                        luma_scaling=8,
                        sharp=80,
                        static=False,
                        lo=19)
    out = grain

    return depth(out, 10)
Beispiel #29
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src += src[-1] * 2
    h = 720
    w = get_w(h)

    edgesfix = awf.bbmod(src, 1, 1, 1, 1, 48, 500)
    out = edgesfix

    clip = depth(out, 32)
    denoise = hybrid_denoise(clip, 0.45, 1.5)
    out = denoise

    luma = get_y(out)
    line_mask = line_mask_func(luma)

    descale = core.descale.Debilinear(luma, w, h)
    upscale = vdf.nnedi3_upscale(descale, pscrn=1)
    antialias = single_rate_antialiasing(upscale,
                                         13,
                                         alpha=0.4,
                                         beta=0.3,
                                         gamma=400,
                                         mdis=15).resize.Bilinear(
                                             src.width, src.height)

    rescale = core.std.MaskedMerge(luma, antialias, depth(line_mask, 32))
    merged = vdf.merge_chroma(rescale, out)
    out = depth(merged, 16)

    preden = core.knlm.KNLMeansCL(get_y(out),
                                  h=0.75,
                                  a=2,
                                  d=3,
                                  device_type='gpu',
                                  device_id=0)
    detail_dark_mask = detail_dark_mask_func(preden, brz_a=8000, brz_b=6000)
    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.Convolution([1, 1, 1, 1, 1, 1, 1, 1, 1])

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

    deband_a = dbs.f3kpf(out, 17, 36, 42, thr=0.5, elast=2, thrc=0.2)
    deband_b = placebo.deband(out, 18, 5.5, 2, 0)

    deband = core.std.MaskedMerge(deband_a, deband_b, preden)
    deband = core.std.MaskedMerge(deband, out, detail_mask)

    deband = core.neo_f3kdb.Deband(deband,
                                   preset='depth',
                                   grainy=24,
                                   grainc=24)
    out = deband

    ref, src = [depth(x, 16) for x in [denoise, src]]
    credit_mask = vdf.drm(ref, kernel='bilinear', mthr=65)
    credit = out
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, credit_mask, 0),
                     [(0, 1380), (36437, 38719)])
    credit = lvf.rfs(credit, ref, [(20810, 20881),
                                   (38720, src.num_frames - 1)])
    out = credit

    grain = adptvgrnMod(out,
                        0.3,
                        0.15,
                        1.25,
                        luma_scaling=8,
                        sharp=80,
                        static=False,
                        lo=19)
    out = grain

    return depth(out, 10)
Beispiel #30
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