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

    h = 720
    w = get_w(h)
    b, c = vdf.get_bicubic_params('robidoux')




    denoise = hybrid_denoise(src, 0.5, 2)
    out = denoise


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


    descale = core.descale.Debicubic(luma, w, h, b, c)
    upscale = vdf.fsrcnnx_upscale(descale, None, descale.height*2, '_shaders/FSRCNNX_x2_56-16-4-1.glsl', core.resize.Point)

    antialias = single_rate_antialiasing(upscale, 13, alpha=0.3, beta=0.45, gamma=320, mdis=18)

    scaled = muvf.SSIM_downsample(antialias, src.width, src.height, kernel='Bicubic')
    rescale = core.std.MaskedMerge(luma, scaled, line_mask)
    merged = vdf.merge_chroma(rescale, out)
    out = depth(merged, 16)



    # Slight sharp though CAS
    sharp = hvf.LSFmod(out, strength=75, Smode=3, Lmode=1, edgemode=1, edgemaskHQ=True)
    out = sharp


    dering = gf.HQDeringmod(out, thr=16, darkthr=0.1)
    out = dering



    warp = xvs.WarpFixChromaBlend(out, thresh=48, depth=8)
    out = warp


    preden = core.knlm.KNLMeansCL(out, d=0, a=3, h=0.6, device_type='GPU', channels='Y')
    deband_mask = lvf.denoise.detail_mask(preden, brz_a=2000, brz_b=800, rad=4)
    deband = dbs.f3kpf(out, 17, 42, 42)
    deband = core.std.MaskedMerge(deband, out, deband_mask)
    out = deband


    adg_mask = core.adg.Mask(out.std.PlaneStats(), 20).std.Expr(f'x x {128<<8} - 0.25 * +')
    grain = core.grain.Add(out, 0.2, constant=True)
    grain = core.std.MaskedMerge(out, grain, adg_mask, 0)
    out = grain


    return depth(out, 10)
예제 #3
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)
    out = src + src[-1] * 3

    dehalo = gf.MaskedDHA(out,
                          rx=1.35,
                          ry=1.35,
                          darkstr=0.25,
                          brightstr=1.0,
                          maskpull=46,
                          maskpush=148)
    out = dehalo

    antialias = lvf.sraa(out, 1.5, 9, downscaler=core.resize.Bicubic)
    out = antialias

    sharp = hvf.LSFmod(out,
                       strength=75,
                       Smode=3,
                       Lmode=1,
                       edgemode=1,
                       edgemaskHQ=True)
    out = sharp

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

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

    opstart, opend = 480, 2637
    edstart, edend = 29707, 31863

    dehalo = gf.MaskedDHA(out,
                          rx=1.35,
                          ry=1.35,
                          darkstr=0.25,
                          brightstr=1.0,
                          maskpull=46,
                          maskpush=148)
    out = dehalo

    antialias = lvf.sraa(out, 1.5, 9, downscaler=core.resize.Bicubic)
    antialias_b = lvf.sraa(antialias, 1.05, 3, downscaler=core.resize.Bicubic)
    antialias_b = TAAmbk(antialias_b,
                         aatype='Eedi3SangNom',
                         cycle=4,
                         thin=2,
                         sharp=100,
                         mtype=0,
                         down8=False)
    antialias = lvf.rfs(antialias, antialias_b, [(19956, 20029)])
    out = antialias

    sharp = hvf.LSFmod(out,
                       strength=75,
                       Smode=3,
                       Lmode=1,
                       edgemode=1,
                       edgemaskHQ=True)
    out = sharp

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

    src_c, ncop, nced = [
        clip.std.Median()
        for clip in [src, JPBD_NCOP.src_cut, JPBD_NCED.src_cut]
    ]
    opening_mask = vdf.dcm(out, src_c[opstart:opend + 1],
                           ncop[:opend - opstart + 1], opstart, opend, 3, 3)
    ending_mask = vdf.dcm(out, src_c[edstart:edend + 1],
                          nced[:edend - edstart + 1], edstart, edend, 3, 3)
    credit_mask = core.std.Expr([opening_mask, ending_mask],
                                'x y +').std.Convolution([1] * 9)

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

    return depth(out, 10)
예제 #5
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)
예제 #6
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    out = depth(src, 16)

    denoise = hvf.SMDegrain(out, thSAD=150, thSADC=75)
    out = denoise

    y = get_y(out)
    lineart = core.std.Sobel(y).std.Binarize(
        75 << 8).std.Maximum().std.Inflate()

    antialias = lvf.sraa(y,
                         1.5,
                         9,
                         downscaler=core.resize.Spline36,
                         gamma=200,
                         mdis=18)

    sharp = hvf.LSFmod(antialias,
                       strength=95,
                       Smode=3,
                       Lmode=1,
                       edgemode=1,
                       edgemaskHQ=True)

    minmax = core.std.Expr([y, sharp, antialias], 'x y z min max y z max min')
    merge = core.std.MaskedMerge(y, minmax, lineart)
    out = vdf.merge_chroma(merge, out)

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

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

    deband = dbs.f3kpf(out, 17, 24, 24)
    deband = core.std.MaskedMerge(deband, out, detail_mask)
    out = deband

    grain = adptvgrnMod(out,
                        0.2,
                        0.1,
                        1.25,
                        luma_scaling=14,
                        sharp=80,
                        static=False,
                        lo=19,
                        hi=[192, 240])
    out = grain

    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 2])
예제 #7
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)
    out = src + src[-1]

    opstart, opend = 2638, 4794
    edstart, edend = 31767, 33924

    dehalo = gf.MaskedDHA(out,
                          rx=1.35,
                          ry=1.35,
                          darkstr=0.25,
                          brightstr=1.0,
                          maskpull=46,
                          maskpush=148)
    out = dehalo

    antialias = lvf.sraa(out, 1.5, 9, downscaler=core.resize.Bicubic)
    out = antialias

    sharp = hvf.LSFmod(out,
                       strength=75,
                       Smode=3,
                       Lmode=1,
                       edgemode=1,
                       edgemaskHQ=True)
    out = sharp

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

    src_c, ncop, nced = [
        clip.std.Median()
        for clip in [src, JPBD_NCOP.src_cut, JPBD_NCED.src_cut]
    ]
    opening_mask = vdf.dcm(out, src_c[opstart:opend + 1],
                           ncop[:opend - opstart + 1], opstart, opend, 3, 3)
    ending_mask = vdf.dcm(out, src_c[edstart:edend + 1],
                          nced[:edend - edstart + 1], edstart, edend, 3, 3)
    credit_mask = core.std.Expr([opening_mask, ending_mask],
                                'x y +').std.Convolution([1] * 9)

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

    return depth(out, 10)
예제 #8
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)
예제 #9
0
def filtering() -> Union[vs.VideoNode, Tuple[vs.VideoNode, vs.VideoNode]]:
    """Vapoursynth filtering"""
    src_cru = WEB_CRU.clip_cut
    src_aod = WEB_AOD.clip_cut

    _, masksub = core.sub.TextFile(src_aod, SUB, fontdir='fonts', blend=False)
    masksub = core.std.Binarize(masksub, 1)
    masksub = hvf.mt_expand_multi(masksub, 'ellipse', sw=6, sh=4)
    masksub = hvf.mt_inflate_multi(masksub, radius=4).std.Convolution([1] * 9)

    dehardsub = core.std.MaskedMerge(src_aod, src_cru, masksub)
    dehardsub = depth(dehardsub, 16)
    out = dehardsub

    lineart = ScharrG41().get_mask(
        get_y(out), 4000,
        multi=1.2).rgvs.RemoveGrain(3).std.Maximum().std.Minimum()

    luma = get_y(out)
    ssing = vdf.scale.fsrcnnx_upscale(
        luma,
        height=1620,
        shader_file='shaders/FSRCNNX_x2_16-0-4-1.glsl',
        downscaler=lambda c, w, h: core.resize.Bicubic(
            c, w, h, filter_param_a=-0.5, filter_param_b=0.25),
        profile='fast',
    )
    sraing = sraa_eedi3(ssing, 13, gamma=100, nrad=2, mdis=15)
    down = core.resize.Bicubic(sraing,
                               out.width,
                               out.height,
                               filter_param_a=-0.5,
                               filter_param_b=0.25)
    masked = core.std.MaskedMerge(luma, down, lineart)
    merged = vdf.misc.merge_chroma(masked, out)
    out = merged

    contra = hvf.LSFmod(out,
                        strength=80,
                        Smode=3,
                        edgemode=0,
                        source=dehardsub)
    out = contra

    # I gave up on this
    ending = lvf.rfs(out, dehardsub, [(31782, out.num_frames - 1)])
    out = ending

    dehalo = gf.MaskedDHA(out, rx=1.4, ry=1.4, darkstr=0, brightstr=0.8)
    out = dehalo

    dbgra_cru = _dbgra(src_cru)
    deband = core.std.MaskedMerge(out, dbgra_cru, depth(masksub, 16))
    out = deband

    ref = src_cru
    rsc_m = vdf.mask.diff_rescale_mask(ref, 837, thr=80)
    rsc_m = depth(rsc_m, 16)

    ref = dehardsub
    credit = out

    # Beginning credits
    creds = [
        Credit([(0, 117)], vdf.mask.region_mask(rsc_m[94], 700, 600, 300,
                                                300)),
        Credit([(125, 233)],
               core.std.Expr([
                   vdf.mask.region_mask(rsc_m, 100, 1300, 120, 600),
                   vdf.mask.region_mask(rsc_m, 100, 1700, 80, 600)
               ], 'x y max')[137]),
        Credit([(288, 399)], vdf.mask.region_mask(rsc_m[303], 0, 1200, 0,
                                                  500)),
        Credit([(288, 399)], vdf.mask.region_mask(rsc_m[303], 0, 1200, 0,
                                                  500)),
        Credit([(526, 631)], vdf.mask.region_mask(rsc_m[543], 1200, 0, 0,
                                                  500)),
        Credit([(644, 749)], vdf.mask.region_mask(rsc_m[672], 0, 1000, 0, 0)),
        Credit([(758, 851)], vdf.mask.region_mask(rsc_m[771], 1300, 0, 0,
                                                  400)),
        Credit([(859, 966)], vdf.mask.region_mask(rsc_m[935], 1325, 0, 0, 0)),
        Credit([(996, 1083)], vdf.mask.region_mask(rsc_m[1007], 1325, 0, 0,
                                                   0)),
        Credit([(1091, 1198)], vdf.mask.region_mask(rsc_m[1117], 1325, 0, 0,
                                                    0)),
        Credit([(1216, 1315)],
               vdf.mask.region_mask(rsc_m[1253], 800, 800, 400, 400)),
        Credit([(1333, 1439)],
               core.std.Expr([
                   vdf.mask.region_mask(rsc_m, 1265, 0, 850, 0),
                   vdf.mask.region_mask(rsc_m, 1400, 0, 800, 0),
                   vdf.mask.region_mask(rsc_m, 1000, 0, 950, 0)
               ], 'x y max z max')[1365]),
    ]
    for cred in creds:
        credit = lvf.rfs(credit, core.std.MaskedMerge(out, ref, cred.mask),
                         cred.range_frames)

    # Ep Title
    creds = [
        Credit([(1653, 1772)],
               vdf.mask.region_mask(rsc_m[1705], 100, 600, 40, 940)),
    ]
    for cred in creds:
        credit = lvf.rfs(credit, core.std.MaskedMerge(out, ref, cred.mask),
                         cred.range_frames)

    out = credit

    # return dehardsub, rsc_m
    # return dehardsub, masksub

    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 2])
예제 #10
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src += src[-1]
    ep10 = JPBD_10.src_cut

    h = 720
    w = get_w(h)
    b, c = vdf.get_bicubic_params('robidoux')
    opstart, opend = 2973, 5370
    edstart, edend = 31887, src.num_frames - 1
    opstart_ep10, opend_ep10 = 768, 3164
    full_stuff = [(5449, 5580), (16465, 16620)]

    # Fix compositing error in the OP
    op_src, op_10 = src[opstart:opend + 1], ep10[opstart_ep10:opend_ep10 + 1]
    fix = lvf.rfs(op_src, op_10, [(0, 79), (1035, 1037)])
    fix_src = insert_clip(src, fix, opstart)
    src = depth(fix_src, 32)

    denoise = hybrid_denoise(src, 0.5, 2)
    out = denoise

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

    descale = core.descale.Debicubic(luma, w, h, b, c)
    upscale = vdf.fsrcnnx_upscale(descale, None, descale.height * 2,
                                  '_shaders/FSRCNNX_x2_56-16-4-1.glsl',
                                  core.resize.Point)

    antialias = single_rate_antialiasing(upscale,
                                         13,
                                         alpha=0.3,
                                         beta=0.45,
                                         gamma=320,
                                         mdis=18)

    scaled = muvf.SSIM_downsample(antialias,
                                  src.width,
                                  src.height,
                                  kernel='Bicubic')
    rescale = core.std.MaskedMerge(luma, scaled, line_mask)
    merged = vdf.merge_chroma(rescale, out)
    out = depth(merged, 16)

    antialias = lvf.rfs(
        out,
        lvf.sraa(out,
                 1.65,
                 9,
                 alpha=0.3,
                 beta=0.45,
                 gamma=240,
                 nrad=3,
                 mdis=25), [(opstart + 840, opstart + 881)])
    out = antialias

    # Slight sharp though CAS
    sharp = hvf.LSFmod(out,
                       strength=75,
                       Smode=3,
                       Lmode=1,
                       edgemode=1,
                       edgemaskHQ=True)
    out = sharp

    dering = gf.HQDeringmod(out, thr=16, darkthr=0.1)
    out = dering

    warp = xvs.WarpFixChromaBlend(out, thresh=48, depth=8)
    out = warp

    preden = core.knlm.KNLMeansCL(out,
                                  d=0,
                                  a=3,
                                  h=0.6,
                                  device_type='GPU',
                                  channels='Y')
    deband_mask = lvf.denoise.detail_mask(preden, brz_a=2000, brz_b=800, rad=4)

    deband = dbs.f3kpf(out, 17, 42, 42)
    deband_b = placebo.deband(out, 22, 6, 2)
    deband = lvf.rfs(deband, deband_b, [(opstart + 1515, opstart + 1603)])

    deband_c = placebo.deband(deband, 17, 5, 1)
    deband_c = dbs.f3kbilateral(deband_c, 22, 64, 64)
    deband = lvf.rfs(deband, deband_c, [(15612, 15695)])

    deband_mask2 = vdf.edge_detect(
        out.knlm.KNLMeansCL(d=2, a=2, h=0.4, device_type='GPU', channels='Y'),
        'FDOG', 1100, (8, 1))
    deband_mask2 = iterate(deband_mask2, core.std.Deflate, 4)
    deband_d = placebo.deband(out, 16, 12, 3)
    deband_d = core.std.MaskedMerge(deband_d, out, deband_mask2)
    deband = lvf.rfs(deband, deband_d, [(16339, 16542)])

    deband = core.std.MaskedMerge(deband, out, deband_mask)

    out = deband

    adg_mask = core.adg.Mask(out.std.PlaneStats(),
                             20).std.Expr(f'x x {128<<8} - 0.25 * +')
    grain = core.grain.Add(out, 0.2, constant=True)
    grain = core.std.MaskedMerge(out, grain, adg_mask, 0)
    out = grain

    rescale_mask = vdf.drm(luma, b=b, c=c, sw=4, sh=4)
    ref, rescale_mask, src, src_ncop, src_nced = [
        depth(x, 16) for x in
        [denoise, rescale_mask, src, JPBD_NCOP.src_cut, JPBD_NCED.src_cut]
    ]

    credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, rescale_mask),
                     full_stuff)
    out = credit

    src_c, src_ncop, src_nced = [
        c.knlm.KNLMeansCL(a=7, h=35, d=0, device_type='gpu')
        for c in [src, src_ncop, src_nced]
    ]

    opening_mask = vdf.dcm(out, src_c[opstart:opend + 1],
                           src_ncop[:opend - opstart + 1], opstart, opend, 4,
                           4).std.Inflate()
    ending_mask = vdf.dcm(out, src_c[edstart:edend + 1],
                          src_nced[:edend - edstart + 1], edstart, edend, 4,
                          4).std.Inflate()
    credit_mask = core.std.Expr([opening_mask, ending_mask], 'x y +')

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

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

    # Remove the noise
    ref = hvf.SMDegrain(out, tr=1, thSAD=300, plane=4)
    denoise = mvf.BM3D(out, sigma=[2, 1], radius1=1, ref=ref)
    out = denoise

    # Limited antialiasing
    y = get_y(out)
    lineart = core.std.Sobel(y).std.Binarize(
        75 << 8).std.Maximum().std.Inflate()
    aa = lvf.sraa(y,
                  2,
                  13,
                  downscaler=partial(core.resize.Bicubic,
                                     filter_param_a=-0.5,
                                     filter_param_b=0.25))
    sharp = hvf.LSFmod(aa, strength=70, Smode=3, edgemode=0, source=y)

    y = core.std.MaskedMerge(y, sharp, lineart)
    out = vdf.merge_chroma(y, out)

    # Deband masks
    planes = split(out)

    preden = core.dfttest.DFTTest(out,
                                  sigma=14.0,
                                  sigma2=10.0,
                                  sbsize=1,
                                  sosize=0,
                                  planes=[0, 1, 2]).rgvs.RemoveGrain(3)
    grad_mask, yrangebig = morpho_mask(preden)

    rgb = core.resize.Bicubic(preden, 960, 540,
                              format=vs.RGB48).std.SetFrameProp('_Matrix',
                                                                delete=True)
    chroma_masks = [
        core.std.Prewitt(p).std.Binarize(5500).rgvs.RemoveGrain(11)
        for p in split(rgb) + split(preden)[1:]
    ]
    chroma_mask = core.std.Expr(chroma_masks,
                                'x y + z + a + b +').std.Maximum()
    chroma_mask = core.std.Merge(chroma_mask,
                                 chroma_mask.std.Minimum()).std.BoxBlur(
                                     0, 1, 1, 1, 1)

    detail_mask = lvf.denoise.detail_mask(planes[0].std.BoxBlur(0, 1, 1, 1, 1),
                                          brz_a=3300,
                                          brz_b=2000)

    # Debanding stages
    debands = [None] * 3
    deband_y_strong = dbs.f3kbilateral(planes[0], 16, 65)
    deband_y_normal = dumb3kdb(planes[0], 16, 41)
    deband_y_light = core.std.MaskedMerge(dumb3kdb(planes[0], 14, 32),
                                          planes[0], detail_mask)
    debands[1] = dbs.f3kbilateral(planes[1], 12, 50)
    debands[2] = dbs.f3kbilateral(planes[2], 12, 50)

    debands[0] = core.std.MaskedMerge(deband_y_strong, deband_y_normal,
                                      grad_mask)
    debands[0] = core.std.MaskedMerge(debands[0], deband_y_light, yrangebig)
    debands[1], debands[2] = [
        core.std.MaskedMerge(debands[i], planes[i], chroma_mask)
        for i in range(1, 3)
    ]
    deband = join(debands)
    out = deband

    # Regraining
    ref = get_y(out).std.PlaneStats()
    adgmask_a = core.adg.Mask(ref, 25)
    adgmask_b = core.adg.Mask(ref, 10)

    stgrain_a = core.grain.Add(out, 0.1, 0, seed=333)
    stgrain_a = core.std.MaskedMerge(out, stgrain_a, adgmask_b.std.Invert())

    stgrain_b = sizedgrn(out, 0.2, 0.1, 1.15, sharp=80, seed=333)
    stgrain_b = core.std.MaskedMerge(out, stgrain_b, adgmask_b)
    stgrain_b = core.std.MaskedMerge(out, stgrain_b, adgmask_a.std.Invert())
    stgrain = core.std.MergeDiff(stgrain_b, out.std.MakeDiff(stgrain_a))

    dygrain = sizedgrn(out, 0.3, 0.1, 1.25, sharp=80, static=False, seed=333)
    dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a)
    grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain))
    out = grain

    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 2])
예제 #12
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 32)

    h = 720
    w = get_w(h)
    # getnative script returns 0.2 0.5 as best combo but it introduces too much halos.
    # I think it's plain mitchell but robidoux is good too and very slightly sharp.
    b, c = vdf.get_bicubic_params('robidoux')
    opstart = 0

    denoise = hybrid_denoise(src, 0.5, 2)
    out = denoise

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

    descale = core.descale.Debicubic(luma, w, h, b, c)
    upscale = vdf.fsrcnnx_upscale(descale, None, descale.height * 2,
                                  '_shaders/FSRCNNX_x2_56-16-4-1.glsl',
                                  core.resize.Point)

    antialias = single_rate_antialiasing(upscale,
                                         13,
                                         alpha=0.3,
                                         beta=0.45,
                                         gamma=320,
                                         mdis=18)
    scaled = muvf.SSIM_downsample(antialias,
                                  src.width,
                                  src.height,
                                  kernel='Bicubic')

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

    antialias = lvf.rfs(
        out,
        lvf.sraa(out,
                 1.65,
                 9,
                 alpha=0.3,
                 beta=0.45,
                 gamma=240,
                 nrad=3,
                 mdis=25), [(opstart + 840, opstart + 881)])
    out = antialias

    # Slight sharp though CAS
    sharp = hvf.LSFmod(out,
                       strength=75,
                       Smode=3,
                       Lmode=1,
                       edgemode=1,
                       edgemaskHQ=True)
    out = sharp

    dering = gf.HQDeringmod(out, thr=16, darkthr=0.1, show=False)
    out = dering

    warp = xvs.WarpFixChromaBlend(out, thresh=48, depth=8)
    out = warp

    preden = core.knlm.KNLMeansCL(out,
                                  d=0,
                                  a=3,
                                  h=0.6,
                                  device_type='GPU',
                                  channels='Y')
    mask = lvf.denoise.detail_mask(preden, brz_a=2000, brz_b=800, rad=4)
    deband = dbs.f3kpf(out, 17, 42, 42)
    deband_b = placebo.deband(out, 22, 6, 2)
    deband = lvf.rfs(deband, deband_b, [(opstart + 1515, opstart + 1603)])
    deband = core.std.MaskedMerge(deband, out, mask)
    out = deband

    adg_mask = core.adg.Mask(out.std.PlaneStats(),
                             20).std.Expr(f'x x {128<<8} - 0.25 * +')
    grain = core.grain.Add(out, 0.2, constant=True)
    grain = core.std.MaskedMerge(out, grain, adg_mask, 0)
    out = grain

    return depth(out, 10)
예제 #13
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 32)

    h = 720
    w = get_w(h)
    b, c = vdf.get_bicubic_params('robidoux')
    full_stuff = [(0, 1310), (15484, 15639)]

    denoise = hybrid_denoise(src, 0.5, 2)
    out = denoise

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

    descale = core.descale.Debicubic(luma, w, h, b, c)
    upscale = vdf.fsrcnnx_upscale(descale, None, descale.height * 2,
                                  '_shaders/FSRCNNX_x2_56-16-4-1.glsl',
                                  core.resize.Point)
    upscale_smooth = vdf.nnedi3_upscale(descale, pscrn=1)
    upscale = lvf.rfs(upscale, upscale_smooth, [(5534, 5598)])

    antialias = single_rate_antialiasing(upscale,
                                         13,
                                         alpha=0.3,
                                         beta=0.45,
                                         gamma=320,
                                         mdis=18)

    scaled = muvf.SSIM_downsample(antialias,
                                  src.width,
                                  src.height,
                                  kernel='Bicubic')
    rescale = core.std.MaskedMerge(luma, scaled, line_mask)
    merged = vdf.merge_chroma(rescale, out)
    out = depth(merged, 16)

    # Slight sharp though CAS
    sharp = hvf.LSFmod(out,
                       strength=75,
                       Smode=3,
                       Lmode=1,
                       edgemode=1,
                       edgemaskHQ=True)
    out = sharp

    dering = gf.HQDeringmod(out, thr=16, darkthr=0.1)
    out = dering

    warp = xvs.WarpFixChromaBlend(out, thresh=48, depth=8)
    out = warp

    preden = core.knlm.KNLMeansCL(out,
                                  d=0,
                                  a=3,
                                  h=0.6,
                                  device_type='GPU',
                                  channels='Y')
    deband_mask = lvf.denoise.detail_mask(preden, brz_a=2000, brz_b=800, rad=4)

    deband = dbs.f3kpf(out, 17, 42, 42)

    deband = core.std.MaskedMerge(deband, out, deband_mask)

    out = deband

    adg_mask = core.adg.Mask(out.std.PlaneStats(),
                             20).std.Expr(f'x x {128<<8} - 0.25 * +')
    grain = core.grain.Add(out, 0.2, constant=True)
    grain = core.std.MaskedMerge(out, grain, adg_mask, 0)
    out = grain

    rescale_mask = vdf.drm(luma, b=b, c=c, sw=4, sh=4)
    ref, rescale_mask, src = [
        depth(x, 16) for x in [denoise, rescale_mask, src]
    ]
    credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, rescale_mask),
                     full_stuff)
    credit = lvf.rfs(credit, src, [(31707, 33937)])
    out = credit

    smooth = gf.JohnFPS(out[31707:33937 + 1], 60000, 1001)
    clips = [out[:31707], smooth, out[33937 + 1:]]
    vfr = muvf.VFRSplice(clips, 'symphogearg_13_timecode.txt')
    cfr = core.std.AssumeFPS(vfr, src)
    out = cfr

    return depth(out, 10)
예제 #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)
예제 #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)
예제 #16
0
def do_filter():
    src = JPBD.src_cut

    fixedges = lvf.ef(src, [2, 1, 1])
    fixedges = depth(fixedges, 16)
    out = fixedges


    h = 720
    w = get_w(h)
    kernel = 'bilinear'


    denoise = CoolDegrain(out, tr=1, thsad=24, blksize=8, overlap=4, plane=4)
    out = denoise


    luma = get_y(out)

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

    descale = kgf.get_descale_filter(kernel)(depth(luma, 32), w, h)
    rescale = vdf.fsrcnnx_upscale(depth(descale, 16), None, src.height, 'shaders/FSRCNNX_x2_56-16-4-1.glsl',
                                  partial(muvf.SSIM_downsample, kernel='Bicubic'))
    rescale = core.std.MaskedMerge(luma, rescale, line_mask)


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


    # Slight sharp though CAS
    sharp = hvf.LSFmod(out, strength=95, Smode=3, Lmode=1, edgemode=1, edgemaskHQ=True)
    out = sharp

    dering = gf.HQDeringmod(out, thr=16, darkthr=0.1)
    out = dering

    warp = xvs.WarpFixChromaBlend(out, thresh=36, depth=6)
    out = warp



    deband_mask = lvf.denoise.detail_mask(out, brz_a=2500, brz_b=1500)
    deband = dbs.f3kpf(out, 17, 36, 36)
    deband = core.std.MaskedMerge(deband, out, deband_mask)
    out = deband


    grain = placebo.deband(out, iterations=0, grain=6, chroma=False)
    grain_mask = core.adg.Mask(out.std.PlaneStats(), 14).std.Expr(f'x x {128<<8} - 0.25 * +')
    grain = core.std.MaskedMerge(out, grain, grain_mask)
    out = grain

    rescale_mask = vdf.drm(luma, h, kernel, sw=4, sh=4)
    ref = fixedges
    credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, rescale_mask, 0), [(12805, src.num_frames-1)])
    out = credit


    return depth(out, 10)
예제 #17
0
def do_filter():
    """Vapoursynth filtering"""
    src = WEB.src_cut
    src = src.std.AssumeFPS(src)

    src = depth(src, 16)
    out = src

    denoise = hvf.SMDegrain(out, tr=3, thSAD=150, thSADC=150)
    out = denoise

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

    y = get_y(out)
    taps = 5
    w, h = 1600, 900
    descale = core.descale.Delanczos(depth(y, 32), w, h, taps)

    upscale = vdf.nnedi3_upscale(descale, pscrn=1, correct_shift=False)
    rescale = core.resize.Bicubic(upscale,
                                  1920,
                                  1080,
                                  src_left=.5,
                                  src_top=.5,
                                  filter_param_a=-.5,
                                  filter_param_b=.25)
    out = depth(rescale, 16)

    sharp = hvf.LSFmod(out,
                       strength=90,
                       Smode=3,
                       edgemode=0,
                       source=get_y(denoise))
    out = sharp

    merge = vdf.merge_chroma(out, denoise)
    out = merge

    detail_mask = lvf.mask.detail_mask(out, brz_a=2250, brz_b=1200)
    pref = out.std.Convolution([1, 2, 1, 2, 4, 2, 1, 2,
                                1]).std.Convolution([1] * 9)
    deband1 = vdf.dumb3kdb(pref, 17, 45, grain=16, seed=333)
    deband2 = vdf.dumb3kdb(pref,
                           15,
                           49,
                           grain=16,
                           sample_mode=4,
                           use_neo=True,
                           blur_first=False,
                           seed=333)

    th_lo, th_hi = 20 << 8, 26 << 8
    strength = '{1} x - {1} {0} - /'.format(th_lo, th_hi)
    deband = core.std.Expr([pref, deband1, deband2], [
        f'x {th_lo} > x {th_hi} < and z ' + strength + ' * y 1 ' + strength +
        f' - * + x {th_lo} <= z y ? ?', 'y'
    ])

    deband = core.std.MergeDiff(deband, out.std.MakeDiff(pref))
    deband = core.std.MaskedMerge(deband, out, detail_mask)
    out = deband

    grain = adptvgrnMod(out,
                        0.3,
                        0.15,
                        size=1.2,
                        luma_scaling=16,
                        hi=[128, 240],
                        protect_neutral=False,
                        seed=333)
    out = grain

    ref = denoise
    rescale_mask = vdf.drm(src, h, 'spline36', mthr=80).std.Maximum()
    credit = out
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, rescale_mask),
                     [(2374, 4530), (4544, 4648), (4701, 4762), (30070, 30210),
                      (31266, 33422)])
    credit = lvf.rfs(credit, ref, [(33423, src.num_frames - 1)])
    out = credit

    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 2])
예제 #18
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    # src += src[-1]
    src = depth(src, 16)
    out = src

    opstart, opend = 480, 2637
    edstart, edend = 32249, 34405



    # Remove the noise
    ref = hvf.SMDegrain(out, tr=1, thSAD=300, plane=4)
    denoise = mvf.BM3D(out, sigma=[2, 1], radius1=1, ref=ref)
    out = denoise




    # Limited antialiasing
    y = get_y(out)
    lineart = core.std.Sobel(y).std.Binarize(75<<8).std.Maximum().std.Inflate()
    aa = lvf.sraa(y, 2, 13, downscaler=partial(core.resize.Bicubic, filter_param_a=-0.5, filter_param_b=0.25))
    sharp = hvf.LSFmod(aa, strength=70, Smode=3, edgemode=0, source=y)


    y = core.std.MaskedMerge(y, sharp, lineart)
    out = vdf.merge_chroma(y, out)






    # Deband masks
    planes = split(out)

    preden = core.dfttest.DFTTest(out, sigma=14.0, sigma2=10.0, sbsize=1, sosize=0).rgvs.RemoveGrain(3)
    grad_mask, yrangebig = morpho_mask(preden)


    rgb = core.resize.Bicubic(preden, 960, 540, format=vs.RGB48).std.SetFrameProp('_Matrix', delete=True)
    chroma_masks = [core.std.Prewitt(p).std.Binarize(5500).rgvs.RemoveGrain(11) for p in split(rgb) + split(preden)[1:]]
    chroma_mask = core.std.Expr(chroma_masks, 'x y + z + a + b +').std.Maximum()
    chroma_mask = core.std.Merge(chroma_mask, chroma_mask.std.Minimum()).std.BoxBlur(0, 1, 1, 1, 1)

    fdogmask = vdf.edge_detect(preden.std.Median(), 'FDOG', 8250, (4, 1)).std.BoxBlur(0, 2, 1, 2, 1)
    detail_mask = lvf.denoise.detail_mask(planes[0].std.BoxBlur(0, 1, 1, 1, 1), brz_a=3300, brz_b=2000)


    # Debanding stages
    debands = [None] * 3
    deband_y_strong = dbs.f3kbilateral(planes[0], 16, 65)
    deband_y_normal = dumb3kdb(planes[0], 16, 36)
    deband_y_light = core.std.MaskedMerge(dumb3kdb(planes[0], 14, 32), planes[0], detail_mask)
    debands[1] = dbs.f3kbilateral(planes[1], 12, 50)
    debands[2] = dbs.f3kbilateral(planes[2], 12, 50)


    debands[0] = core.std.MaskedMerge(deband_y_strong, deband_y_normal, grad_mask)
    debands[0] = core.std.MaskedMerge(debands[0], deband_y_light, yrangebig)
    debands[1], debands[2] = [core.std.MaskedMerge(debands[i], planes[i], chroma_mask) for i in range(1, 3)]
    deband = join(debands)
    deband = lvf.rfs(deband, core.std.MaskedMerge(dbs.f3kbilateral(out, 20, 97), out, fdogmask), [(opstart+2019, opstart+2036), (opstart+1504, opstart+1574)])
    out = deband


    # Regraining
    ref = get_y(out).std.PlaneStats()
    adgmask_a = core.adg.Mask(ref, 25)
    adgmask_b = core.adg.Mask(ref, 10)

    stgrain_a = core.grain.Add(out, 0.1, 0, seed=333)
    stgrain_a = core.std.MaskedMerge(out, stgrain_a, adgmask_b.std.Invert())

    stgrain_b = sizedgrn(out, 0.2, 0.1, 1.15, sharp=80, seed=333)
    stgrain_b = core.std.MaskedMerge(out, stgrain_b, adgmask_b)
    stgrain_b = core.std.MaskedMerge(out, stgrain_b, adgmask_a.std.Invert())
    stgrain = core.std.MergeDiff(stgrain_b, out.std.MakeDiff(stgrain_a))

    dygrain = sizedgrn(out, 0.3, 0.1, 1.25, sharp=80, static=False, seed=333)
    dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a)
    grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain))
    out = grain



    # Credits OP and ED
    ref = src
    src_ncop, src_nced = [depth(c, 16) for c in [JPBD_NCOP.src_cut, JPBD_NCED.src_cut]]
    src_c, src_ncop, src_nced = [c.std.BoxBlur(0, 2, 1, 2, 1) for c in [src, src_ncop, src_nced]]

    opening_mask = vdf.dcm(out, src_c[opstart:opend+1], src_ncop[:opend-opstart+1], opstart, opend, 2, 2)
    ending_mask = vdf.dcm(out, src_c[edstart:edend+1], src_nced[:edend-edstart+1], edstart, edend, 2, 2)
    credit_mask = core.std.Expr([opening_mask, ending_mask], 'x y +').std.Inflate()

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





    # Fix letterboxes ending
    crop = core.std.Crop(out, 0, 0, 132, 132).edgefixer.ContinuityFixer(0, 1, 0, 0)
    crop = core.std.AddBorders(crop, 0, 0, 132, 132)
    out = lvf.rfs(out, crop, [(edstart, edend)])




    return depth(out, 10).std.Limiter(16<<2, [235<<2, 240<<2], [0, 1, 2])
예제 #19
0
def filtering() -> Union[vs.VideoNode, Tuple[vs.VideoNode, vs.VideoNode]]:
    """Vapoursynth filtering"""
    src_cru = WEB_CRU.clip_cut
    src_aod = WEB_AOD.clip_cut

    _, masksub = core.sub.TextFile(src_aod, SUB, fontdir='fonts', blend=False)
    masksub = core.std.Binarize(masksub, 1)
    masksub = hvf.mt_expand_multi(masksub, 'ellipse', sw=6, sh=4)
    masksub = hvf.mt_inflate_multi(masksub, radius=4).std.Convolution([1] * 9)

    dehardsub = core.std.MaskedMerge(src_aod, src_cru, masksub)
    dehardsub = depth(dehardsub, 16)
    out = dehardsub


    lineart = ScharrG41().get_mask(get_y(out), 4000, multi=1.2).rgvs.RemoveGrain(3).std.Maximum().std.Minimum()


    luma = get_y(out)
    ssing = vdf.scale.fsrcnnx_upscale(
        luma, height=1620, shader_file='shaders/FSRCNNX_x2_16-0-4-1.glsl',
        downscaler=lambda c, w, h: core.resize.Bicubic(c, w, h, filter_param_a=-0.5, filter_param_b=0.25),
        profile='fast',
    )
    sraing = sraa_eedi3(ssing, 13, gamma=100, nrad=2, mdis=15)
    down = core.resize.Bicubic(sraing, out.width, out.height, filter_param_a=-0.5, filter_param_b=0.25)
    masked = core.std.MaskedMerge(luma, down, lineart)
    merged = vdf.misc.merge_chroma(masked, out)
    out = merged


    contra = hvf.LSFmod(out, strength=80, Smode=3, edgemode=0, source=dehardsub)
    out = contra


    # I gave up on this
    ending = lvf.rfs(out, dehardsub, [(1368, 3524), (31072, out.num_frames - 1)])
    out = ending



    dehalo = gf.MaskedDHA(out, rx=1.4, ry=1.4, darkstr=0, brightstr=0.8)
    out = dehalo




    dbgra_cru = _dbgra(src_cru)
    deband = core.std.MaskedMerge(out, dbgra_cru, depth(masksub, 16))
    out = deband




    ref = src_cru
    rsc_m = vdf.mask.diff_rescale_mask(ref, 837, thr=80)
    rsc_m = depth(rsc_m, 16)

    ref = dehardsub
    credit = out


    # Ep Title
    creds = [
        Credit([(3691, 3810)], vdf.mask.region_mask(rsc_m[3696], 1450, 0, 800, 0)),
    ]
    for cred in creds:
        credit = lvf.rfs(credit, core.std.MaskedMerge(out, ref, cred.mask), cred.range_frames)

    out = credit



    # return dehardsub, vdf.mask.region_mask(rsc_m, 1450, 0, 800, 0)
    # return dehardsub, out


    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 2])
예제 #20
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)
예제 #21
0
def PostProcessing(clip, dispWidth, dispHeight, deblock, deband, nnedi3,
                   supersampling, ssf, sharpen, sstr, gpu_scaling, smooth):

    mWidth = clip.width
    mHeight = clip.height

    scaling = False
    if mWidth > dispWidth or mHeight > dispWidth:
        scaling = "DOWN"
    elif mWidth < dispWidth and mHeight < dispWidth:
        scaling = "UP"

    ratio = (mWidth / mHeight)
    newHeight = round((dispWidth / ratio) / 8) * 8
    if newHeight > dispHeight:
        newHeight = dispHeight
        newWidth = round((newHeight * ratio) / 8) * 8
    else:
        newWidth = dispWidth

    if deblock:
        if (mWidth % 8 == 0) and (mHeight % 8 == 0):
            clip = core.deblock.Deblock(clip)

    if scaling == "UP":
        if nnedi3:
            if supersampling:
                clip = core.nnedi3.nnedi3_rpow2(clip, 2)
            if sharpen == "finesharp":
                clip = fs.sharpen(clip, sstr=sstr)
            elif sharpen == "lsfmod":
                ssf = 1.0
                clip = haf.LSFmod(clip,
                                  defaults="slow",
                                  ss_x=ssf,
                                  ss_y=ssf,
                                  strength=sstr,
                                  noring=True)
            if supersampling:
                clip = haf.Resize(clip,
                                  mWidth,
                                  mHeight,
                                  kernel='spline64',
                                  noring=True)
            if not supersampling:
                clip = core.nnedi3.nnedi3_rpow2(clip, 2)
        else:
            if sharpen == "finesharp":
                if supersampling:
                    clip = FinesharpSs(clip, ssf=ssf, sstr=sstr)
                else:
                    clip = fs.sharpen(clip, sstr=sstr)
            elif sharpen == "lsfmod":
                if not supersampling:
                    ssf = 1.0
                clip = haf.LSFmod(clip,
                                  defaults="slow",
                                  ss_x=ssf,
                                  ss_y=ssf,
                                  strength=sstr,
                                  noring=True)
        if not gpu_scaling:
            clip = haf.Resize(clip,
                              newWidth,
                              newHeight,
                              kernel='spline64',
                              noring=True)
        if deband:
            clip = core.f3kdb.Deband(clip, grainy=0, grainc=0, output_depth=8)

    elif scaling == "DOWN":
        if sharpen == "finesharp":
            clip = fs.sharpen(clip, sstr=sstr)
        elif sharpen == "lsfmod":
            ssf = 1.0
            clip = haf.LSFmod(clip,
                              defaults="slow",
                              ss_x=ssf,
                              ss_y=ssf,
                              strength=sstr)
        if not gpu_scaling:
            clip = haf.Resize(clip,
                              newWidth,
                              newHeight,
                              kernel='spline64',
                              noring=True)
        if deband:
            clip = core.f3kdb.Deband(clip, grainy=0, grainc=0, output_depth=8)

    else:
        if sharpen == "finesharp":
            if supersampling:
                clip = FinesharpSs(clip, ssf=ssf, sstr=sstr)
            else:
                clip = fs.sharpen(clip, sstr=sstr)
        elif sharpen == "lsfmod":
            if not supersampling:
                ssf = 1.0
            clip = haf.LSFmod(clip,
                              defaults="slow",
                              ss_x=ssf,
                              ss_y=ssf,
                              strength=sstr)
        if deband:
            clip = core.f3kdb.Deband(clip, grainy=0, grainc=0, output_depth=8)

    if smooth:
        clip = Interpolation(clip)

    return clip
예제 #22
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)
    out = src

    h = 900
    w = get_w(h)

    # Remove the grain
    ref = hvf.SMDegrain(out, tr=1, thSAD=300, plane=4)
    degrain = mvf.BM3D(out, sigma=[1.5, 1], radius1=1, ref=ref)
    degrain = insert_clip(degrain, smhdegrain(out[5539:5670], 2, 280), 5539)
    degrain = insert_clip(degrain, smhdegrain(out[5933:5992], 2, 200), 5933)
    degrain = insert_clip(degrain, smhdegrain(out[6115:6180], 2, 200), 6115)
    degrain = insert_clip(degrain, smhdegrain(out[6180:6281], 2, 200), 6180)
    degrain = insert_clip(degrain, smhdegrain(out[39303:39482], 2, 280), 39303)
    degrain = insert_clip(degrain, smhdegrain(out[40391:40837], 2, 200), 40391)
    degrain = insert_clip(degrain, smhdegrain(out[40908:41087], 2, 280), 40908)
    degrain = insert_clip(degrain, smhdegrain(out[41671:41791], 2, 280), 41671)
    degrain = insert_clip(degrain, smhdegrain(out[41791:41977], 2, 280), 41791)
    degrain = insert_clip(degrain, smhdegrain(out[41977:42073], 2, 280), 41977)

    degrain = insert_clip(degrain, smhdegrain(out[43083:44462], 2, 350), 43083)
    degrain = lvf.rfs(degrain, out, [(51749, 52387)])
    out = depth(degrain, 32)

    luma = get_y(out)
    line_mask = vdf.edge_detect(luma, 'kirsch', 0.075,
                                (1, 1)).std.Median().std.Inflate()

    descale = core.descale.Debilinear(luma, w, h)
    upscale = eedi3_upscale(descale)
    antialias = single_rate_antialiasing(upscale,
                                         13,
                                         alpha=0.2,
                                         beta=0.6,
                                         gamma=300,
                                         mdis=15).resize.Bicubic(
                                             src.width, src.height)

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

    y = get_y(out)
    detail_light_mask = lvf.denoise.detail_mask(y.std.Median(),
                                                brz_a=2500,
                                                brz_b=1200)

    pf = out.std.Convolution([1] * 9).std.Merge(out, 0.45)

    diffdb = core.std.MakeDiff(out, pf)

    deband = dumb3kdb(pf, 16, 30)
    deband_b = dbs.f3kbilateral(pf, 20, 100)
    deband = lvf.rfs(deband, deband_b, [(43083, 44461)])

    deband = core.std.MergeDiff(deband, diffdb)
    deband = core.std.MaskedMerge(deband, out, detail_light_mask)

    deband = lvf.rfs(deband, out, [(51749, 52387)])
    out = deband

    sharp = hvf.LSFmod(out,
                       strength=65,
                       Smode=3,
                       Lmode=1,
                       edgemode=1,
                       edgemaskHQ=True)
    out = sharp

    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.00)
    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.05, sharp=60, static=False)
    dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a)
    grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain))
    out = grain

    ref = src
    rescale_mask = vdf.drm(ref, h, mthr=65, sw=4, sh=4)
    credit = out
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, rescale_mask,
                                                  0), [(0, 2956),
                                                       (43104, 45749)])
    credit = lvf.rfs(credit, ref, [(45824, 50401),
                                   (52388, src.num_frames - 1)])
    out = credit

    return depth(out, 10)
예제 #23
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
예제 #24
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    out = depth(src, 32)

    # Variables
    h = 900
    w = get_w(h)


    ref = hvf.SMDegrain(depth(out, 16), thSAD=250)
    denoise = mvf.BM3D(out, [1, 0.75], radius2=1, ref=depth(ref, 32))
    out = denoise



    y = get_y(out)
    lineart = vdf.edge_detect(y, 'FDOG', 0.085, (1, 2)).std.Median().std.Convolution([*[1]*9])


    descale = core.descale.Despline36(y, w, h)
    upscale = eedi3_upscale(descale)
    antialias = sraa_eedi3(upscale, 9)

    downscale = muvf.SSIM_downsample(antialias, src.width, src.height, filter_param_a=-0.5, filter_param_b=0.25)
    downscale = core.std.MaskedMerge(y, downscale, lineart)

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




    sharp = hvf.LSFmod(out, strength=40, Smode=3, Lmode=1, edgemode=1, edgemaskHQ=True)
    out = sharp




    detail_light_mask = lvf.denoise.detail_mask(out, brz_a=2500, brz_b=1200)

    deband = dumb3kdb(out, 17, 36)
    deband_b = dumb3kdb(out, 24, 64)
    deband = lvf.rfs(deband, deband_b, [(25600, 25691), (30867, 30938)])
    deband = core.std.MaskedMerge(deband, out, detail_light_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.125, 0.075, 1.15, sharp=80)
    stgrain = core.std.MaskedMerge(out, stgrain, adgmask_b)
    stgrain = core.std.MaskedMerge(out, stgrain, adgmask_a.std.Invert())

    dygrain = sizedgrn(out, 0.3, 0.15, 1.2, 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(src, 16)
    rescale_mask = vdf.drm(ref, h, 'spline36', mthr=50, sw=4, sh=4)
    credit = out
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, rescale_mask, 0),
                     [(3032, 4101), (4290, 5284), (35677, 37282)])
    credit = lvf.rfs(credit, ref, [(17688, 17783), (37695, src.num_frames-1)])
    out = credit


    return depth(out, 10).std.Limiter(16<<2, [235<<2, 240<<2])
예제 #25
0
def TAAmbk(clip,
           aatype=1,
           aatypeu=None,
           aatypev=None,
           preaa=0,
           strength=0.0,
           cycle=0,
           mtype=None,
           mclip=None,
           mthr=None,
           mlthresh=None,
           mpand=(0, 0),
           txtmask=0,
           txtfade=0,
           thin=0,
           dark=0.0,
           sharp=0,
           aarepair=0,
           postaa=None,
           src=None,
           stabilize=0,
           down8=True,
           showmask=0,
           opencl=False,
           opencl_device=-1,
           **kwargs):
    core = vs.get_core()

    aatypeu = aatype if aatypeu is None else aatypeu
    aatypev = aatype if aatypev is None else aatypev
    if mtype is None:
        mtype = 0 if preaa == 0 and True not in (aatype, aatypeu,
                                                 aatypev) else 1
    if postaa is None:
        postaa = True if abs(sharp) > 70 or (0.4 < abs(sharp) < 1) else False
    if src is None:
        src = clip
    else:
        if clip.format.id != src.format.id:
            raise ValueError(MODULE_NAME +
                             ': clip format and src format mismatch.')
        elif clip.width != src.width or clip.height != src.height:
            raise ValueError(MODULE_NAME +
                             ': clip resolution and src resolution mismatch.')

    preaa_clip = clip if preaa == 0 else daa(clip, preaa, opencl,
                                             opencl_device)
    edge_enhanced_clip = (
        thin != 0 and core.warp.AWarpSharp2(preaa_clip, depth=int(thin))
        or preaa_clip)
    edge_enhanced_clip = (dark != 0
                          and haf.Toon(edge_enhanced_clip, str=float(dark))
                          or edge_enhanced_clip)

    aa_kernel = {
        0:
        lambda clip, *args, **kwargs: type('', (), {'out': lambda: clip}),
        1:
        AAEedi2,
        2:
        AAEedi3,
        3:
        AANnedi3,
        4:
        AANnedi3UpscaleSangNom,
        5:
        AASpline64NRSangNom,
        6:
        AASpline64SangNom,
        -1:
        AAEedi2SangNom,
        -2:
        AAEedi3SangNom,
        -3:
        AANnedi3SangNom,
        'Eedi2':
        AAEedi2,
        'Eedi3':
        AAEedi3,
        'Nnedi3':
        AANnedi3,
        'Nnedi3UpscaleSangNom':
        AANnedi3UpscaleSangNom,
        'Spline64NrSangNom':
        AASpline64NRSangNom,
        'Spline64SangNom':
        AASpline64SangNom,
        'Eedi2SangNom':
        AAEedi2SangNom,
        'Eedi3SangNom':
        AAEedi3SangNom,
        'Nnedi3SangNom':
        AANnedi3SangNom,
        'PointSangNom':
        AAPointSangNom,
        'Unknown':
        lambda clip, *args, **kwargs: type(
            '', (), {
                'out':
                lambda: exec(
                    'raise ValueError(MODULE_NAME + ": unknown aatype, aatypeu or aatypev")'
                )
            }),
        'Custom':
        kwargs.get(
            'aakernel', lambda clip, *args, **kwargs: type(
                '', (), {
                    'out':
                    lambda: exec(
                        'raise RuntimeError(MODULE_NAME + ": custom aatype: aakernel must be set.")'
                    )
                })),
    }

    if clip.format.color_family is vs.YUV:
        yuv = [
            core.std.ShufflePlanes(edge_enhanced_clip, i, vs.GRAY)
            for i in range(clip.format.num_planes)
        ]
        aatypes = [aatype, aatypeu, aatypev]
        aa_classes = [
            aa_kernel.get(aatype, aa_kernel['Unknown']) for aatype in aatypes
        ]
        aa_clips = [
            aa_cycle(plane,
                     aa_class,
                     cycle,
                     strength if yuv.index(plane) == 0 else 0,
                     down8,
                     opencl=opencl,
                     opencl_device=opencl_device,
                     **kwargs) for plane, aa_class in zip(yuv, aa_classes)
        ]
        aaed_clip = core.std.ShufflePlanes(aa_clips, [0, 0, 0], vs.YUV)
    elif clip.format.color_family is vs.GRAY:
        gray = edge_enhanced_clip
        aa_class = aa_kernel.get(aatype, aa_kernel['Unknown'])
        aaed_clip = aa_cycle(gray, aa_class, cycle, strength, down8, **kwargs)
    else:
        raise ValueError(MODULE_NAME + ': Unsupported color family.')

    abs_sharp = abs(sharp)
    if sharp >= 1:
        sharped_clip = haf.LSFmod(aaed_clip,
                                  strength=int(abs_sharp),
                                  defaults='old',
                                  source=src)
    elif sharp > 0:
        per = int(40 * abs_sharp)
        matrix = [-1, -2, -1, -2, 52 - per, -2, -1, -2, -1]
        sharped_clip = core.std.Convolution(aaed_clip, matrix)
    elif sharp == 0:
        sharped_clip = aaed_clip
    elif sharp > -1:
        sharped_clip = haf.LSFmod(aaed_clip,
                                  strength=round(abs_sharp * 100),
                                  defaults='fast',
                                  source=src)
    elif sharp == -1:
        blured = core.rgvs.RemoveGrain(
            aaed_clip, mode=20 if aaed_clip.width > 1100 else 11)
        diff = core.std.MakeDiff(aaed_clip, blured)
        diff = core.rgvs.Repair(diff,
                                core.std.MakeDiff(src, aaed_clip),
                                mode=13)
        sharped_clip = core.std.MergeDiff(aaed_clip, diff)
    else:
        sharped_clip = aaed_clip

    postaa_clip = sharped_clip if postaa is False else soothe(
        sharped_clip, src, 24)
    repaired_clip = (
        (aarepair > 0 and core.rgvs.Repair(src, postaa_clip, aarepair))
        or (aarepair < 0 and core.rgvs.Repair(postaa_clip, src, -aarepair))
        or postaa_clip)
    stabilized_clip = repaired_clip if stabilize == 0 else temporal_stabilize(
        repaired_clip, src, stabilize)

    if mclip is not None:
        try:
            masked_clip = core.std.MaskedMerge(src,
                                               stabilized_clip,
                                               mclip,
                                               first_plane=True)
            masker = type('', (), {
                '__call__': lambda *args, **kwargs: mclip
            })()
        except vs.Error:
            raise RuntimeError(
                MODULE_NAME +
                ': Something wrong with your mclip. Maybe format, resolution or bit_depth mismatch.'
            )
    else:
        # Use lambda for lazy evaluation
        mask_kernel = {
            0:
            lambda: lambda a, b, *args, **kwargs: b,
            1:
            lambda: mask_lthresh(clip,
                                 mthr,
                                 mlthresh,
                                 mask_sobel,
                                 mpand,
                                 opencl=opencl,
                                 opencl_device=opencl_device,
                                 **kwargs),
            2:
            lambda: mask_lthresh(clip, mthr, mlthresh, mask_robert, mpand, **
                                 kwargs),
            3:
            lambda: mask_lthresh(clip, mthr, mlthresh, mask_prewitt, mpand, **
                                 kwargs),
            4:
            lambda: mask_lthresh(clip, mthr, mlthresh, mask_tedge, mpand, **
                                 kwargs),
            5:
            lambda: mask_lthresh(clip,
                                 mthr,
                                 mlthresh,
                                 mask_canny_continuous,
                                 mpand,
                                 opencl=opencl,
                                 opencl_device=opencl_device,
                                 **kwargs),
            6:
            lambda: mask_lthresh(clip, mthr, mlthresh, mask_msharpen, mpand, **
                                 kwargs),
            'Sobel':
            lambda: mask_lthresh(clip,
                                 mthr,
                                 mlthresh,
                                 mask_sobel,
                                 mpand,
                                 opencl=opencl,
                                 opencl_device=opencl_device,
                                 **kwargs),
            'Canny':
            lambda: mask_lthresh(clip,
                                 mthr,
                                 mlthresh,
                                 mask_canny_binarized,
                                 mpand,
                                 opencl=opencl,
                                 opencl_device=opencl_device,
                                 **kwargs),
            'Prewitt':
            lambda: mask_lthresh(clip, mthr, mlthresh, mask_prewitt, mpand, **
                                 kwargs),
            'Robert':
            lambda: mask_lthresh(clip, mthr, mlthresh, mask_robert, mpand, **
                                 kwargs),
            'TEdge':
            lambda: mask_lthresh(clip, mthr, mlthresh, mask_tedge, mpand, **
                                 kwargs),
            'Canny_Old':
            lambda: mask_lthresh(clip,
                                 mthr,
                                 mlthresh,
                                 mask_canny_continuous,
                                 mpand,
                                 opencl=opencl,
                                 opencl_device=opencl_device,
                                 **kwargs),
            'MSharpen':
            lambda: mask_lthresh(clip, mthr, mlthresh, mask_msharpen, mpand, **
                                 kwargs),
            'Unknown':
            lambda: exec('raise ValueError(MODULE_NAME + ": unknown mtype")')
        }
        mtype = 5 if mtype is None else mtype
        mthr = (24, ) if mthr is None else mthr
        masker = mask_kernel.get(mtype, mask_kernel['Unknown'])()
        masked_clip = masker(src, stabilized_clip)

    if txtmask > 0 and clip.format.color_family is not vs.GRAY:
        text_mask = mask_fadetxt(clip, lthr=txtmask, fade_num=txtfade)
        txt_protected_clip = core.std.MaskedMerge(masked_clip,
                                                  src,
                                                  text_mask,
                                                  first_plane=True)
    else:
        text_mask = src
        txt_protected_clip = masked_clip

    final_output = (
        (showmask == -1 and text_mask)
        or (showmask == 1 and masker(None, src, show=True))
        or (showmask == 2 and core.std.StackVertical([
            core.std.ShufflePlanes(
                [masker(None, src, show=True),
                 core.std.BlankClip(src)], [0, 1, 2], vs.YUV), src
        ])) or (showmask == 3 and core.std.Interleave([
            core.std.ShufflePlanes(
                [masker(None, src, show=True),
                 core.std.BlankClip(src)], [0, 1, 2], vs.YUV), src
        ])) or txt_protected_clip)
    return final_output
예제 #26
0
def SMDegrain(input,
              tr=2,
              thSAD=300,
              thSADC=None,
              RefineMotion=False,
              contrasharp=None,
              CClip=None,
              interlaced=False,
              tff=None,
              plane=4,
              Globals=0,
              pel=None,
              subpixel=2,
              prefilter=-1,
              mfilter=None,
              blksize=None,
              overlap=None,
              search=4,
              truemotion=None,
              MVglobal=None,
              dct=0,
              limit=255,
              limitc=None,
              thSCD1=400,
              thSCD2=130,
              chroma=True,
              hpad=None,
              vpad=None,
              Str=1.0,
              Amp=0.0625,
              opencl=False,
              device=None):
    if not isinstance(input, vs.VideoNode):
        raise vs.Error('SMDegrain: This is not a clip')

    if input.format.color_family == vs.GRAY:
        plane = 0
        chroma = False

    peak = (1 << input.format.bits_per_sample) - 1

    # Defaults & Conditionals
    thSAD2 = thSAD // 2
    if thSADC is None:
        thSADC = thSAD2

    GlobalR = (Globals == 1)
    GlobalO = (Globals >= 3)
    if1 = CClip is not None

    if contrasharp is None:
        contrasharp = not GlobalO and if1

    w = input.width
    h = input.height
    preclip = isinstance(prefilter, vs.VideoNode)
    ifC = isinstance(contrasharp, bool)
    if0 = contrasharp if ifC else contrasharp > 0
    if4 = w > 1024 or h > 576

    if pel is None:
        pel = 1 if if4 else 2
    if pel < 2:
        subpixel = min(subpixel, 2)
    pelclip = pel > 1 and subpixel >= 3

    if blksize is None:
        blksize = 16 if if4 else 8
    blk2 = blksize // 2
    if overlap is None:
        overlap = blk2
    ovl2 = overlap // 2
    if truemotion is None:
        truemotion = not if4
    if MVglobal is None:
        MVglobal = truemotion

    planes = [0, 1, 2] if chroma else [0]
    plane0 = (plane != 0)

    if hpad is None:
        hpad = blksize
    if vpad is None:
        vpad = blksize
    limit = havsfunc.scale(limit, peak)
    if limitc is None:
        limitc = limit
    else:
        limitc = havsfunc.scale(limitc, peak)

    # Error Report
    if not (ifC or isinstance(contrasharp, int)):
        raise vs.Error(
            "SMDegrain: 'contrasharp' only accepts bool and integer inputs")
    if if1 and (not isinstance(CClip, vs.VideoNode)
                or CClip.format.id != input.format.id):
        raise vs.Error("SMDegrain: 'CClip' must be the same format as input")
    if interlaced and h & 3:
        raise vs.Error(
            'SMDegrain: Interlaced source requires mod 4 height sizes')
    if interlaced and not isinstance(tff, bool):
        raise vs.Error(
            "SMDegrain: 'tff' must be set if source is interlaced. Setting tff to true means top field first and false means bottom field first"
        )
    if not (isinstance(prefilter, int) or preclip):
        raise vs.Error(
            "SMDegrain: 'prefilter' only accepts integer and clip inputs")
    if preclip and prefilter.format.id != input.format.id:
        raise vs.Error(
            "SMDegrain: 'prefilter' must be the same format as input")
    if mfilter is not None and (not isinstance(mfilter, vs.VideoNode)
                                or mfilter.format.id != input.format.id):
        raise vs.Error("SMDegrain: 'mfilter' must be the same format as input")
    if RefineMotion and blksize < 8:
        raise vs.Error(
            'SMDegrain: For RefineMotion you need a blksize of at least 8')
    if not chroma and plane != 0:
        raise vs.Error(
            'SMDegrain: Denoising chroma with luma only vectors is bugged in mvtools and thus unsupported'
        )

    # RefineMotion Variables
    if RefineMotion:
        halfblksize = blk2  # MRecalculate works with half block size
        halfoverlap = overlap if overlap <= 2 else ovl2 + ovl2 % 2  # Halve the overlap to suit the halved block size
        halfthSAD = thSAD2  # MRecalculate uses a more strict thSAD, which defaults to 150 (half of function's default of 300)

    # Input preparation for Interlacing
    if not interlaced:
        inputP = input
    else:
        inputP = input.std.SeparateFields(tff=tff)

    # Prefilter & Motion Filter
    if mfilter is None:
        mfilter = inputP

    if not GlobalR:
        if preclip:
            pref = prefilter
        elif prefilter <= -1:
            pref = inputP
        elif prefilter == 3:
            expr = 'x {i} < {peak} x {j} > 0 {peak} x {i} - {peak} {j} {i} - / * - ? ?'.format(
                i=havsfunc.scale(16, peak),
                j=havsfunc.scale(75, peak),
                peak=peak)
            pref = core.std.MaskedMerge(inputP.dfttest.DFTTest(
                tbsize=1,
                slocation=[0.0, 4.0, 0.2, 9.0, 1.0, 15.0],
                planes=planes),
                                        inputP,
                                        mvf.GetPlane(inputP,
                                                     0).std.Expr(expr=[expr]),
                                        planes=planes)
        elif prefilter >= 4:
            if chroma:
                pref = KNLMeansCL(inputP, d=1, a=1, h=7)
            else:
                pref = inputP.knlm.KNLMeansCL(d=1, a=1, h=7)
        else:
            pref = havsfunc.MinBlur(inputP, r=prefilter, planes=planes)
    else:
        pref = inputP

    # Default Auto-Prefilter - Luma expansion TV->PC (up to 16% more values for motion estimation)
    if not GlobalR:
        pref = havsfunc.DitherLumaRebuild(pref, s0=Str, c=Amp, chroma=chroma)

    # Subpixel 3
    if pelclip:
        nnediMode = 'znedi3' if opencl else 'znedi'
        cshift = 0.25 if pel == 2 else 0.375
        pclip = nnedi3_resample.nnedi3_resample(pref,
                                                w * pel,
                                                h * pel,
                                                src_left=cshift,
                                                src_top=cshift,
                                                nns=4,
                                                mode=nnediMode,
                                                device=device)
        if not GlobalR:
            pclip2 = nnedi3_resample.nnedi3_resample(inputP,
                                                     w * pel,
                                                     h * pel,
                                                     src_left=cshift,
                                                     src_top=cshift,
                                                     nns=4,
                                                     mode=nnediMode,
                                                     device=device)

    # Motion vectors search
    global bv6, bv4, bv3, bv2, bv1, fv1, fv2, fv3, fv4, fv6
    super_args = dict(hpad=hpad, vpad=vpad, pel=pel)
    analyse_args = dict(blksize=blksize,
                        search=search,
                        chroma=chroma,
                        truemotion=truemotion,
                        global_=MVglobal,
                        overlap=overlap,
                        dct=dct)
    if RefineMotion:
        recalculate_args = dict(thsad=halfthSAD,
                                blksize=halfblksize,
                                search=search,
                                chroma=chroma,
                                truemotion=truemotion,
                                overlap=halfoverlap,
                                dct=dct)

    if pelclip:
        super_search = pref.mv.Super(chroma=chroma,
                                     rfilter=4,
                                     pelclip=pclip,
                                     **super_args)
    else:
        super_search = pref.mv.Super(chroma=chroma,
                                     sharp=subpixel,
                                     rfilter=4,
                                     **super_args)

    if not GlobalR:
        if pelclip:
            super_render = inputP.mv.Super(levels=1,
                                           chroma=plane0,
                                           pelclip=pclip2,
                                           **super_args)
            if RefineMotion:
                Recalculate = pref.mv.Super(levels=1,
                                            chroma=chroma,
                                            pelclip=pclip,
                                            **super_args)
        else:
            super_render = inputP.mv.Super(levels=1,
                                           chroma=plane0,
                                           sharp=subpixel,
                                           **super_args)
            if RefineMotion:
                Recalculate = pref.mv.Super(levels=1,
                                            chroma=chroma,
                                            sharp=subpixel,
                                            **super_args)

        if interlaced:
            if tr > 2:
                bv6 = super_search.mv.Analyse(isb=True,
                                              delta=6,
                                              **analyse_args)
                fv6 = super_search.mv.Analyse(isb=False,
                                              delta=6,
                                              **analyse_args)
                if RefineMotion:
                    bv6 = core.mv.Recalculate(Recalculate, bv6,
                                              **recalculate_args)
                    fv6 = core.mv.Recalculate(Recalculate, fv6,
                                              **recalculate_args)
            if tr > 1:
                bv4 = super_search.mv.Analyse(isb=True,
                                              delta=4,
                                              **analyse_args)
                fv4 = super_search.mv.Analyse(isb=False,
                                              delta=4,
                                              **analyse_args)
                if RefineMotion:
                    bv4 = core.mv.Recalculate(Recalculate, bv4,
                                              **recalculate_args)
                    fv4 = core.mv.Recalculate(Recalculate, fv4,
                                              **recalculate_args)
        else:
            if tr > 2:
                bv3 = super_search.mv.Analyse(isb=True,
                                              delta=3,
                                              **analyse_args)
                fv3 = super_search.mv.Analyse(isb=False,
                                              delta=3,
                                              **analyse_args)
                if RefineMotion:
                    bv3 = core.mv.Recalculate(Recalculate, bv3,
                                              **recalculate_args)
                    fv3 = core.mv.Recalculate(Recalculate, fv3,
                                              **recalculate_args)
            bv1 = super_search.mv.Analyse(isb=True, delta=1, **analyse_args)
            fv1 = super_search.mv.Analyse(isb=False, delta=1, **analyse_args)
            if RefineMotion:
                bv1 = core.mv.Recalculate(Recalculate, bv1, **recalculate_args)
                fv1 = core.mv.Recalculate(Recalculate, fv1, **recalculate_args)
        if interlaced or tr > 1:
            bv2 = super_search.mv.Analyse(isb=True, delta=2, **analyse_args)
            fv2 = super_search.mv.Analyse(isb=False, delta=2, **analyse_args)
            if RefineMotion:
                bv2 = core.mv.Recalculate(Recalculate, bv2, **recalculate_args)
                fv2 = core.mv.Recalculate(Recalculate, fv2, **recalculate_args)
    else:
        super_render = super_search

    # Finally, MDegrain
    degrain_args = dict(thsad=thSAD,
                        thsadc=thSADC,
                        plane=plane,
                        limit=limit,
                        limitc=limitc,
                        thscd1=thSCD1,
                        thscd2=thSCD2)
    if not GlobalO:
        if interlaced:
            if tr >= 3:
                output = core.mv.Degrain3(mfilter, super_render, bv2, fv2, bv4,
                                          fv4, bv6, fv6, **degrain_args)
            elif tr == 2:
                output = core.mv.Degrain2(mfilter, super_render, bv2, fv2, bv4,
                                          fv4, **degrain_args)
            else:
                output = core.mv.Degrain1(mfilter, super_render, bv2, fv2,
                                          **degrain_args)
        else:
            if tr >= 3:
                output = core.mv.Degrain3(mfilter, super_render, bv1, fv1, bv2,
                                          fv2, bv3, fv3, **degrain_args)
            elif tr == 2:
                output = core.mv.Degrain2(mfilter, super_render, bv1, fv1, bv2,
                                          fv2, **degrain_args)
            else:
                output = core.mv.Degrain1(mfilter, super_render, bv1, fv1,
                                          **degrain_args)

    # Contrasharp (only sharpens luma)
    if not GlobalO and if0:
        if if1:
            if interlaced:
                CClip = CClip.std.SeparateFields(tff=tff)
        else:
            CClip = inputP

    # Output
    if not GlobalO:
        if if0:
            if interlaced:
                if ifC:
                    return havsfunc.Weave(ContraSharpening(output,
                                                           CClip,
                                                           planes=planes),
                                          tff=tff)
                else:
                    return havsfunc.Weave(LSFmod(output,
                                                 strength=contrasharp,
                                                 source=CClip,
                                                 Lmode=0,
                                                 soothe=False,
                                                 defaults='slow'),
                                          tff=tff)
            elif ifC:
                return havsfunc.ContraSharpening(output, CClip, planes=planes)
            else:
                return havsfunc.LSFmod(output,
                                       strength=contrasharp,
                                       source=CClip,
                                       Lmode=0,
                                       soothe=False,
                                       defaults='slow')
        elif interlaced:
            return havsfunc.Weave(output, tff=tff)
        else:
            return output
    else:
        return input
예제 #27
0
def TAAmbk(clip,
           aatype=1,
           aatypeu=None,
           aatypev=None,
           preaa=0,
           strength=0.0,
           cycle=0,
           mtype=None,
           mclip=None,
           mthr=None,
           mthr2=None,
           mlthresh=None,
           mpand=(1, 0),
           txtmask=0,
           txtfade=0,
           thin=0,
           dark=0.0,
           sharp=0,
           aarepair=0,
           postaa=None,
           src=None,
           stabilize=0,
           down8=True,
           showmask=0,
           opencl=False,
           opencl_device=0,
           **args):
    core = vs.get_core()
    aatypeu = aatype if aatypeu is None else aatypeu
    aatypev = aatype if aatypev is None else aatypev

    if mtype is None:
        mtype = 0 if preaa == 0 and True not in (aatype, aatypeu,
                                                 aatypev) else 1

    if postaa is None:
        postaa = True if abs(sharp) > 70 or (0.4 < abs(sharp) < 1) else False

    if src is None:
        src = clip
    else:
        if clip.format.id != src.format.id:
            raise ValueError(MODULE_NAME +
                             ': clip format and src format mismatch.')
        elif clip.width != src.width or clip.height != src.height:
            raise ValueError(MODULE_NAME +
                             ': clip resolution and src resolution mismatch.')

    preaa_clip = clip if preaa == 0 else daa(clip, preaa)

    if thin == 0 and dark == 0:
        edge_enhanced_clip = preaa_clip
    elif thin != 0 and dark != 0:
        edge_enhanced_clip = haf.Toon(core.warp.AWarpSharp2(preaa_clip,
                                                            depth=int(thin)),
                                      str=float(dark))
    elif thin == 0:
        edge_enhanced_clip = haf.Toon(preaa_clip, str=float(dark))
    else:
        edge_enhanced_clip = core.warp.AWarpSharp2(preaa_clip, depth=int(thin))

    aa_kernel = {
        1: AAEedi2,
        2: AAEedi3,
        3: AANnedi3,
        4: AANnedi3UpscaleSangNom,
        5: AASpline64NRSangNom,
        6: AASpline64SangNom,
        -1: AAEedi2SangNom,
        -2: AAEedi3SangNom,
        -3: AANnedi3SangNom,
        'Eedi2': AAEedi2,
        'Eedi3': AAEedi3,
        'Nnedi3': AANnedi3,
        'Nnedi3UpscaleSangNom': AANnedi3UpscaleSangNom,
        'Spline64NrSangNom': AASpline64NRSangNom,
        'Spline64SangNom': AASpline64SangNom,
        'Eedi2SangNom': AAEedi2SangNom,
        'Eedi3SangNom': AAEedi3SangNom,
        'Nnedi3SangNom': AANnedi3SangNom,
        'PointSangNom': AAPointSangNom
    }

    aaed_clip = None
    if clip.format.color_family is vs.YUV:
        y = core.std.ShufflePlanes(edge_enhanced_clip, 0, vs.GRAY)
        u = core.std.ShufflePlanes(edge_enhanced_clip, 1, vs.GRAY)
        v = core.std.ShufflePlanes(edge_enhanced_clip, 2, vs.GRAY)
        if aatype != 0:
            try:
                y = aa_kernel[aatype](y,
                                      strength,
                                      down8,
                                      opencl=opencl,
                                      opencl_device=opencl_device,
                                      **args).out()
                cycle_y = cycle
                while cycle_y > 0:
                    y = aa_kernel[aatype](y,
                                          strength,
                                          down8,
                                          opencl=opencl,
                                          opencl_device=opencl_device,
                                          **args).out()
                    cycle_y -= 1
                y = mvf.Depth(
                    y, clip.format.bits_per_sample) if down8 is True else y
            except KeyError:
                raise ValueError(MODULE_NAME + ': unknown aatype.')
        if aatypeu != 0:
            try:
                u = aa_kernel[aatypeu](
                    u,
                    0,
                    down8,
                    opencl=opencl,
                    opencl_device=opencl_device,
                    **args).out()  # Won't do predown for u plane
                cycle_u = cycle
                while cycle_u > 0:
                    u = aa_kernel[aatypeu](u,
                                           0,
                                           down8,
                                           opencl=opencl,
                                           opencl_device=opencl_device,
                                           **args).out()
                    cycle_u -= 1
                u = mvf.Depth(
                    u, clip.format.bits_per_sample) if down8 is True else u
            except KeyError:
                raise ValueError(MODULE_NAME + ': unknown aatypeu.')
        if aatypev != 0:
            try:
                v = aa_kernel[aatypev](
                    v,
                    0,
                    down8,
                    opencl=opencl,
                    opencl_device=opencl_device,
                    **args).out()  # Won't do predown for v plane
                cycle_v = cycle
                while cycle_v > 0:
                    v = aa_kernel[aatypev](v,
                                           0,
                                           down8,
                                           opencl=opencl,
                                           opencl_device=opencl_device,
                                           **args).out()
                    cycle_v -= 1
                v = mvf.Depth(
                    v, clip.format.bits_per_sample) if down8 is True else v
            except KeyError:
                raise ValueError(MODULE_NAME + ': unknown aatypev.')
        aaed_clip = core.std.ShufflePlanes([y, u, v], [0, 0, 0], vs.YUV)
    elif clip.format.color_family is vs.GRAY:
        y = edge_enhanced_clip
        if aatype != 0:
            try:
                y = aa_kernel[aatype](y, strength, down8, **args).out()
                cycle_y = cycle
                while cycle_y > 0:
                    y = aa_kernel[aatype](y, strength, down8, **args).out()
                    cycle_y -= 1
                aaed_clip = mvf.Depth(
                    y, clip.format.bits_per_sample) if down8 is True else y
            except KeyError:
                raise ValueError(MODULE_NAME + ': unknown aatype.')
    else:
        raise ValueError(MODULE_NAME + ': Unsupported color family.')

    abs_sharp = abs(sharp)
    if sharp >= 1:
        sharped_clip = haf.LSFmod(aaed_clip,
                                  strength=int(abs_sharp),
                                  defaults='old',
                                  source=src)
    elif sharp > 0:
        per = int(40 * abs_sharp)
        matrix = [-1, -2, -1, -2, 52 - per, -2, -1, -2, -1]
        sharped_clip = core.std.Convolution(aaed_clip, matrix)
    elif sharp == 0:
        sharped_clip = aaed_clip
    elif sharp > -1:
        sharped_clip = haf.LSFmod(aaed_clip,
                                  strength=round(abs_sharp * 100),
                                  defaults='fast',
                                  source=src)
    elif sharp == -1:
        blured = core.rgvs.RemoveGrain(
            aaed_clip, mode=20 if aaed_clip.width > 1100 else 11)
        diff = core.std.MakeDiff(aaed_clip, blured)
        diff = core.rgvs.Repair(diff,
                                core.std.MakeDiff(src, aaed_clip),
                                mode=13)
        sharped_clip = core.std.MergeDiff(aaed_clip, diff)
    else:
        sharped_clip = aaed_clip

    postaa_clip = sharped_clip if postaa is False else soothe(
        sharped_clip, src, 24)
    repaired_clip = postaa_clip if aarepair == 0 else core.rgvs.Repair(
        src, postaa_clip, aarepair)
    stabilized_clip = repaired_clip if stabilize == 0 else temporal_stabilize(
        repaired_clip, src, stabilize)

    if mclip is not None:
        mask = mclip
        try:
            masked_clip = core.std.MaskedMerge(src,
                                               stabilized_clip,
                                               mask,
                                               first_plane=True)
        except vs.Error:
            raise RuntimeError(MODULE_NAME +
                               ': Something wrong with your mclip. '
                               'Maybe resolution or bit_depth mismatch.')
    elif mtype != 0:
        if mtype == 1 or mtype is 'Canny':
            opencl_device = args.get('opencl_device', 0)
            mthr = 1.2 if mthr is None else mthr
            mthr2 = 8.0 if mthr2 is None else mthr2
            mask = MaskCanny(clip,
                             sigma=mthr,
                             t_h=mthr2,
                             lthresh=mlthresh,
                             mpand=mpand,
                             opencl=opencl,
                             opencl_devices=opencl_device).out()
        elif mtype == 2 or mtype is 'Sobel':
            mthr = 1.2 if mthr is None else mthr
            mthr2 = 48 if mthr2 is None else mthr2
            mask = MaskSobel(clip,
                             sigma=mthr,
                             binarize=mthr2,
                             lthresh=mlthresh,
                             mpand=mpand).out()
        elif mtype == 3 or mtype is 'prewitt':
            mthr = 62 if mthr is None else mthr
            mask = MaskPrewitt(clip,
                               factor=mthr,
                               lthresh=mlthresh,
                               mpand=mpand).out()
        else:
            raise ValueError(MODULE_NAME + ': unknown mtype.')
        masked_clip = core.std.MaskedMerge(src, stabilized_clip, mask)
    else:
        masked_clip = stabilized_clip

    if txtmask > 0 and clip.format.color_family is not vs.GRAY:
        text_mask = FadeTextMask(clip, lthr=txtmask, fade_nums=txtfade).out()
        txt_protected_clip = core.std.MaskedMerge(masked_clip,
                                                  src,
                                                  text_mask,
                                                  first_plane=True)
    else:
        txt_protected_clip = masked_clip

    if clip.format.bits_per_sample > 8 and down8 is True:
        clamped_clip = mvf.LimitFilter(src,
                                       txt_protected_clip,
                                       thr=1.0,
                                       elast=2.0)
    else:
        clamped_clip = txt_protected_clip

    try:
        if showmask == -1:
            return text_mask
        elif showmask == 1:
            return mask
        elif showmask == 2:
            return core.std.StackVertical([
                core.std.ShufflePlanes([mask, core.std.BlankClip(src)],
                                       [0, 1, 2], vs.YUV), src
            ])
        elif showmask == 3:
            return core.std.Interleave([
                core.std.ShufflePlanes([mask, core.std.BlankClip(src)],
                                       [0, 1, 2], vs.YUV), src
            ])
        else:
            return clamped_clip
    except UnboundLocalError:
        raise RuntimeError(MODULE_NAME +
                           ': No mask to show if you don\'t have one.')
예제 #28
0
def sharpaamcmod(orig,
                 dark=20,
                 thin=10,
                 sharp=0,
                 smooth=0,
                 stabilize=False,
                 tradius=2,
                 aapel=2,
                 aaov=None,
                 aablk=None,
                 aatype='sangnom'):
    """Ported from: http://forum.doom9.org/showthread.php?p=1673928

    Args:
        dark      = Line darkening amount, 0-256.
        thin      = optional line thinning amount, 0-256.
        sharp     = Postsharpening
        smooth    = Postsmoothing
        stabilize = Use post stabilization with Motion Compensation
        Tradius   = Temporal radius for Mdegrain (1, 2 or 3)
        aapel     = Accuracy of the motion estimation (Value can only be 1, 2 or 4. 1 means a precision to the pixel.
                    2 means a precision to half a pixel, 4 means a precision to quarter a pixel, produced by spatial
                    interpolation (better but slower).)
        aaov      = Block overlap value (horizontal). Must be even and less than block size.
        aablk     = Size of a block (horizontal). It's either 4, 8 or 16 ( default is 8 ).
                    Larger blocks are less sensitive to noise, are faster, but also less accurate.
        aatype    = Use sangnom or eedi2 for anti-aliasing
    """
    core = vs.get_core()

    # Vars and stuff

    w = orig.width
    h = orig.height

    if w > 1100 and aaov is None:
        aaov = 8
    else:
        aaov = 4

    if w > 1100 and aablk is None:
        aablk = 16
    else:
        aablk = 8

    _max = (1 << orig.format.bits_per_sample) - 1
    _mid = (1 << orig.format.bits_per_sample) / 2

    aatype = aatype.lower()

    # Mask

    m = core.std.ShufflePlanes(orig, planes=0, colorfamily=vs.GRAY)

    m = core.std.Expr(
        core.std.Expr([
            core.std.Convolution(m, [5, 10, 5, 0, 0, 0, -5, -10, -5],
                                 divisor=4,
                                 saturate=False),
            core.std.Convolution(
                m, [5, 0, -5, 10, 0, -10, 5, 0, -5], divisor=4, saturate=False)
        ], ['x y max']),
        ['x {_mid} / 0.86 pow {_max} *'.format(_max=_max, _mid=_mid)])

    # darkening and thining work different than in the original script because of effort

    if dark != 0 or thin != 0:
        preaa = haf.FastLineDarkenMOD(orig, strength=dark, thinning=thin)
    else:
        preaa = orig

    # Antialiasing

    if aatype == 'sangnom':
        aa = sangnomaa(preaa)
    elif aatype == 'eedi2':
        aa = ediaa(preaa)
    else:
        raise ValueError('Wrong aatype, it should be "sangnom" or "eedi2".')

    # Post sharpen

    if sharp == 0 and smooth == 0:
        postsh = aa
    else:
        postsh = haf.LSFmod(aa,
                            edgemode=1,
                            strength=sharp,
                            overshoot=1,
                            soft=smooth)

    # Merge results

    merged = core.std.MaskedMerge(orig, postsh, m, planes=0)

    # Motion compensate AA clip

    sdiff = core.std.MakeDiff(orig, merged)

    origsuper = core.mv.Super(orig, pel=aapel)
    sdiffsuper = core.mv.Super(sdiff, pel=aapel, levels=1)

    fvec3 = core.mv.Analyse(origsuper,
                            delta=3,
                            isb=False,
                            blksize=aablk,
                            overlap=aaov)
    fvec2 = core.mv.Analyse(origsuper,
                            delta=2,
                            isb=False,
                            blksize=aablk,
                            overlap=aaov)
    fvec1 = core.mv.Analyse(origsuper,
                            delta=1,
                            isb=False,
                            blksize=aablk,
                            overlap=aaov)
    bvec1 = core.mv.Analyse(origsuper,
                            delta=1,
                            isb=True,
                            blksize=aablk,
                            overlap=aaov)
    bvec2 = core.mv.Analyse(origsuper,
                            delta=2,
                            isb=True,
                            blksize=aablk,
                            overlap=aaov)
    bvec3 = core.mv.Analyse(origsuper,
                            delta=3,
                            isb=True,
                            blksize=aablk,
                            overlap=aaov)

    if tradius > 0:
        sdd = core.mv.Degrain1(clip=sdiff,
                               super=sdiffsuper,
                               mvbw=bvec1,
                               mvfw=fvec1)
    if tradius > 1:
        sdd = core.mv.Degrain2(clip=sdiff,
                               super=sdiffsuper,
                               mvbw=bvec1,
                               mvfw=fvec1,
                               mvbw2=bvec2,
                               mvfw2=fvec2)
    if tradius > 2:
        sdd = core.mv.Degrain3(clip=sdiff,
                               super=sdiffsuper,
                               mvbw=bvec1,
                               mvfw=fvec1,
                               mvbw2=bvec2,
                               mvfw2=fvec2,
                               mvbw3=bvec3,
                               mvfw3=fvec3)

    reduct = 0.4
    tmp = core.std.Expr(
        [sdiff, sdd],
        'x {_mid} - abs y {_mid} - abs < x y ?'.format(_mid=_mid))
    sdd = core.std.Merge(tmp, sdd, [1.0 - reduct, 0])

    return core.std.MakeDiff(orig, sdd) if stabilize is True else merged
예제 #29
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
예제 #30
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)