示例#1
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut

    edges = core.edgefixer.ContinuityFixer(src, *[[2, 1, 1]] * 4)
    out = depth(edges, 32)

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

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

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

    deband = dumb3kdbv2(out, 22, 24)
    deband = core.std.MaskedMerge(deband, out, detail_mask)

    deband_b = dumb3kdbv2(out, 24, 64)
    deband_b = core.std.MaskedMerge(deband_b, out, detail_light_mask)
    deband = lvf.rfs(deband, deband_b, [(414, 496)])

    out = deband

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

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

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

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

    # Variables
    opstart, opend = 8296, 10452
    eptitle_s, eptitle_e = 10453, 10572
    edstart, edend = 31528, 33685
    preview_s, preview_e = 33686, src.num_frames - 1
    h = 720
    w = get_w(h)

    edges = core.edgefixer.ContinuityFixer(src, *[[2, 1, 1]] * 4)
    out = depth(edges, 32)

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

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

    descale = core.descale.Debilinear(y, w, h)

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

    antialias = sraa_eedi3(upscale, 9)

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

    merged = vdf.merge_chroma(downscale, out)
    merged = lvf.rfs(merged, out, [(opstart, opend), (eptitle_s, eptitle_e),
                                   (preview_s, preview_e)])
    out = depth(merged, 16)

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

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

    deband = dumb3kdbv2(out, 22, 24)
    deband = core.std.MaskedMerge(deband, out, detail_mask)

    deband_b = dumb3kdbv2(out, 24, 64)
    deband_b = core.std.MaskedMerge(deband_b, out, detail_light_mask)
    deband = lvf.rfs(deband, deband_b, [(opstart + 414, opstart + 496)])

    out = deband

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

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

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

    ref = depth(src, 16)
    rescale_mask = vdf.drm(ref, 720, 'bilinear', mthr=30, sw=0, sh=0)
    rescale_mask = vdf.region_mask(rescale_mask, *[10] * 4)
    rescale_mask = hvf.mt_expand_multi(rescale_mask,
                                       mode='ellipse',
                                       sw=4,
                                       sh=4)
    rescale_mask = rescale_mask.std.Binarize(scale_value(
        100, 8, 16)).std.Inflate().std.Convolution([*[1] * 9])

    dehalo_ref = gf.MaskedDHA(ref,
                              rx=1.65,
                              ry=1.65,
                              darkstr=0.15,
                              brightstr=1.0,
                              maskpull=48,
                              maskpush=140)
    dehalo_mask_a = vdf.region_mask(rescale_mask, top=650, right=200)

    credit = out
    dehalo_range_a = [(18, 130), (1291, 1355), (14691, 14846), (15126, 15189)]
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, rescale_mask,
                                                  0),
                     [(131, 220), (400, 505), (817, 899), (1766, 1809),
                      (1925, 2041), (4033, 4116), (4342, 4453), (4964, 5031),
                      (6422, 6515), (7848, 7978),
                      (10606, 10728), (11619, 11701), (15339, 15457),
                      (edstart, edend)] + dehalo_range_a)
    credit = lvf.rfs(
        credit, core.std.MaskedMerge(credit, dehalo_ref, dehalo_mask_a, 0),
        dehalo_range_a)

    out = credit

    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2])
示例#3
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)
示例#4
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src += src[-1]

    # Variables
    opstart, opend = 2206, 4362
    eptitle_s, eptitle_e = 4363, 4482
    edstart, edend = 31528, 33685
    preview_s, preview_e = 33686, src.num_frames - 1
    h = 720
    w = get_w(h)

    edges = core.edgefixer.ContinuityFixer(src, *[[2, 1, 1]] * 4)
    out = depth(edges, 32)

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

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

    descale = core.descale.Debilinear(y, w, h)

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

    antialias = sraa_eedi3(upscale, 9)

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

    merged = vdf.merge_chroma(downscale, out)
    merged = lvf.rfs(merged, out, [(opstart, opend), (eptitle_s, eptitle_e),
                                   (preview_s, preview_e)])
    out = depth(merged, 16)

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

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

    deband = dumb3kdbv2(out, 22, 24)
    deband = core.std.MaskedMerge(deband, out, detail_mask)
    out = deband

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

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

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

    ref = depth(src, 16)
    rescale_mask = vdf.drm(ref, 720, 'bilinear', mthr=30, sw=0, sh=0)
    rescale_mask = vdf.region_mask(rescale_mask, *[10] * 4)
    rescale_mask = hvf.mt_expand_multi(rescale_mask,
                                       mode='ellipse',
                                       sw=4,
                                       sh=4)
    rescale_mask = rescale_mask.std.Binarize(scale_value(
        100, 8, 16)).std.Inflate().std.Convolution([*[1] * 9])

    dehalo_ref = gf.MaskedDHA(ref,
                              rx=1.65,
                              ry=1.65,
                              darkstr=0.15,
                              brightstr=1.0,
                              maskpull=48,
                              maskpush=140)
    dehalo_mask_b = vdf.region_mask(rescale_mask, right=400)

    credit = out
    dehalo_range_b = [(18, 101), (16853, 16917)]
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, rescale_mask,
                                                  0),
                     [(126, 160), (1722, 1761), (7749, 7795), (8189, 8232),
                      (8445, 8504), (9020, 9067), (9727, 9768), (12430, 12520),
                      (12876, 12971), (13608, 13646), (15833, 15879),
                      (20526, 20586), (20783, 20823), (21193, 21239),
                      (23812, 23854), (24018, 24059),
                      (edstart, edend)] + dehalo_range_b)

    credit = lvf.rfs(
        credit, core.std.MaskedMerge(credit, dehalo_ref, dehalo_mask_b, 0),
        dehalo_range_b)
    out = credit

    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2])
示例#5
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut

    # Variables
    opstart, opend = 6161, 8319
    eptitle_s, eptitle_e = 8320, 8439
    edstart, edend = 31170, 33326
    preview_s, preview_e = 33687, src.num_frames - 1
    h = 720
    w = get_w(h)

    edges = core.edgefixer.ContinuityFixer(src, *[[2, 1, 1]] * 4)
    out = depth(edges, 32)

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

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

    descale = core.descale.Debilinear(y, w, h)

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

    antialias = sraa_eedi3(upscale, 9)

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

    merged = vdf.merge_chroma(downscale, out)
    merged = lvf.rfs(merged, out, [(opstart, opend), (eptitle_s, eptitle_e),
                                   (preview_s, preview_e)])
    out = depth(merged, 16)

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

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

    deband = dumb3kdbv2(out, 22, 24)
    deband = core.std.MaskedMerge(deband, out, detail_mask)
    out = deband

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

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

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

    ref = depth(src, 16)
    rescale_mask = vdf.drm(ref, 720, 'bilinear', mthr=30, sw=0, sh=0)
    rescale_mask = vdf.region_mask(rescale_mask, *[10] * 4)
    rescale_mask = hvf.mt_expand_multi(rescale_mask,
                                       mode='ellipse',
                                       sw=4,
                                       sh=4)
    rescale_mask = rescale_mask.std.Binarize(scale_value(
        100, 8, 16)).std.Inflate().std.Convolution([*[1] * 9])

    dehalo_ref = gf.MaskedDHA(ref,
                              rx=1.65,
                              ry=1.65,
                              darkstr=0.15,
                              brightstr=1.0,
                              maskpull=48,
                              maskpush=140)
    dehalo_mask_a = vdf.region_mask(rescale_mask, top=650)
    dehalo_mask_b = vdf.region_mask(rescale_mask, right=400)

    credit = out
    dehalo_range_a = [(25, 205), (518, 612), (2090, 2172), (14449, 14537)]
    dehalo_range_b = [(3893, 3981)]
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, rescale_mask,
                                                  0),
                     [(2197, 2252), (4072, 4129), (4409, 4527), (5390, 5484),
                      (8473, 8603), (8610, 8669), (9826, 9909), (10666, 10713),
                      (12088, 12507), (14943, 15052), (17988, 18136),
                      (18897, 18976),
                      (edstart, edend)] + dehalo_range_a + dehalo_range_b)
    credit = lvf.rfs(
        credit, core.std.MaskedMerge(credit, dehalo_ref, dehalo_mask_a, 0),
        dehalo_range_a)
    credit = lvf.rfs(
        credit, core.std.MaskedMerge(credit, dehalo_ref, dehalo_mask_b, 0),
        dehalo_range_b)
    out = credit

    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2])
示例#6
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut

    # Variables
    opstart, opend = 2038, 4196
    eptitle_s, eptitle_e = 4197, 4316
    edstart, edend = 31530, 33687
    preview_s, preview_e = 33688, src.num_frames - 1
    h = 720
    w = get_w(h)

    edges = core.edgefixer.ContinuityFixer(src, *[[2, 1, 1]] * 4)
    out = depth(edges, 32)

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

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

    descale = core.descale.Debilinear(y, w, h)

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

    antialias = sraa_eedi3(upscale, 9)

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

    merged = vdf.merge_chroma(downscale, out)
    merged = lvf.rfs(merged, out, [(opstart, opend), (eptitle_s, eptitle_e),
                                   (preview_s, preview_e)])
    out = depth(merged, 16)

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

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

    deband = dumb3kdbv2(out, 22, 24)
    deband = core.std.MaskedMerge(deband, out, detail_mask)

    deband_b = dumb3kdbv2(out, 24, 64)
    deband_b = core.std.MaskedMerge(deband_b, out, detail_light_mask)
    deband = lvf.rfs(deband, deband_b, [(opstart + 414, opstart + 496)])

    out = deband

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

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

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

    ref = depth(src, 16)
    rescale_mask = vdf.drm(ref, 720, 'bilinear', mthr=30, sw=0, sh=0)
    rescale_mask = vdf.region_mask(rescale_mask, *[10] * 4)
    rescale_mask = hvf.mt_expand_multi(rescale_mask,
                                       mode='ellipse',
                                       sw=4,
                                       sh=4)
    rescale_mask = rescale_mask.std.Binarize(scale_value(
        100, 8, 16)).std.Inflate().std.Convolution([*[1] * 9])

    credit = out
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, rescale_mask,
                                                  0), [(8993, 9066),
                                                       (20104, 20223),
                                                       (edstart, edend)])

    out = credit

    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2])
示例#7
0
    def main(self) -> vs.VideoNode:
        """Vapoursynth filtering"""
        src = JPBD.clip_cut
        src = depth(src, 16)
        src_cru = WEB_CRU.clip_cut
        src_aod = WEB_AOD.clip_cut

        # Dehardsubbing using .ass file
        masksub = Mask.hardsub_mask(src_aod.std.BlankClip(), SUB, FONTDIR)
        dehardsub = core.std.MaskedMerge(src_aod, src_cru, masksub)
        src_web = dehardsub

        # AoD is poorly rescaled
        src_y, src_cru_y, src_web_y = map(get_y, [src, src_cru, src_web])

        thr = 10
        src_web_y = core.std.Expr([src_web_y, src_cru_y],
                                  f'x y - abs {thr} < x y * sqrt y ?')
        src_web_y = depth(src_web_y, 16)

        ringrid = core.rgvs.Repair(src_web_y,
                                   src_web_y.std.Convolution([1] * 9), 11)
        ringrid = core.std.Expr([ringrid, src_web_y], 'x y min')

        # Remove ringing with AoD+CR
        ring_mask = Mask.ringing_mask(src_y)
        bdweb = core.std.MaskedMerge(src_y, ringrid, ring_mask)
        bdweb = lvf.rfs(bdweb, src_web_y, [(64, 1413), (32034, 33195),
                                           (33465, 33881), (34174, 34524)])
        out = vdf.misc.merge_chroma(bdweb, src)

        # ranges_frames = [
        #     (64, 131), (215, 292), (339, 410), (444, 515), (566, 657),
        #     (695, 786), (903, 971), (977, 1045), (1058, 1153), (1278, 1335),
        #     (1355, 1413)
        # ]
        # cm = partial(vdf.mask.region_mask, clip=out.std.BlankClip(format=vs.GRAY16, color=65535))

        # credit_mask = [
        #     cm()
        # ]

        # Restore BD changes
        dering_src = hvf.EdgeCleaner(src, 20, hot=True)

        diff_mask = Mask.diff_mask((src, src_cru), brz=4750.0)
        bdchanges = out
        bdchanges = lvf.rfs(bdchanges, dering_src, [(882, 902), (5596, 5701),
                                                    (9909, 10064),
                                                    (11804, 11864)])
        bdchanges = lvf.rfs(bdchanges,
                            core.std.MaskedMerge(out, dering_src, diff_mask),
                            [(2534, 2682), (2840, 2887), (3188, 3271),
                             (3818, 3859), (3986, 4087), (4499, 4618),
                             (5009, 5088), (14736, 14801), (15744, 15872),
                             (17106, 17135), (17913, 18143), (24247, 24438),
                             (33196, 33329), (34021, 34173)])
        # return bdchanges, diff_mask
        out = bdchanges

        ref = Denoise.ref_denoise(get_y(out), tr=1)
        denoise = Denoise.hybrid_denoise(depth(out, 32),
                                         knlm_h=0.15,
                                         sigma=1,
                                         knlm_args=dict(d=1, a=3, s=3),
                                         bm3d_args=dict(ref=depth(ref, 32)))
        denoise = depth(denoise, 16)
        out = denoise

        pre = get_y(out)

        # Remove haloing
        dehalo = gf.MaskedDHA(pre,
                              rx=1.4,
                              ry=1.4,
                              darkstr=0.1,
                              brightstr=1.0,
                              maskpull=40,
                              maskpush=255)
        bila = core.bilateral.Bilateral(dehalo, sigmaS=1, sigmaR=0.08)
        dehalorp = core.rgvs.Repair(dehalo, bila, 13)
        dehalo = core.std.MaskedMerge(dehalo, dehalorp,
                                      ring_mask.std.Maximum(), 0)
        dehalo = core.std.Expr([dehalo, pre], 'x y min')
        out = dehalo

        # Antialiasing sraaaaaaaaaa
        lineart = vdf.mask.ExPrewitt().get_mask(out, 4000,
                                                7500).std.Convolution([1] * 25)
        aaa = AA().upscaled_sraaaaaaaaaa(out, height=1620)
        out = aaa

        unwarp = self.line_darkening(out, 0.075).warp.AWarpSharp2(depth=-1)
        out = unwarp

        motion = hvf.SMDegrain(out, tr=3, thSADC=600, RefineMotion=True)
        masked = core.std.MaskedMerge(out, motion, lineart)
        out = masked

        mergechroma = vdf.misc.merge_chroma(out, denoise)
        out = mergechroma

        db_mask = Mask.deband_mask(out, (4000, 4000, 4000), (2000, 2000, 2000))

        deband_1 = vdf.deband.dumb3kdb(out, 17, [36, 48])
        deband_2 = vdf.deband.dumb3kdb(out,
                                       17,
                                       30,
                                       sample_mode=4,
                                       use_neo=True)
        deband_d = vdf.deband.dumb3kdb(out, 17, 65)

        th_lo, th_hi = 22 << 8, 28 << 8
        strength = f'{th_hi} x - {th_hi} {th_lo} - /'
        deband = core.std.Expr(
            [out.std.Convolution([1] * 9), deband_1, deband_2], [
                f'x {th_lo} > x {th_hi} < and z ' + strength + ' * y 1 ' +
                strength + f' - * + x {th_lo} <= z y ? ?',
                'x y * sqrt x z * sqrt * y * z * 0.25 pow'
            ])

        deband = lvf.rfs(deband, deband_d, [(3920, 3985)])
        deband = core.std.MaskedMerge(deband, out, db_mask)
        out = deband

        ref = get_y(out).std.PlaneStats()
        adgmask_a = ref.adg.Mask(25)
        adgmask_b = ref.adg.Mask(10)

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

        stgrain_b = sizedgrn(out,
                             0.2,
                             0.1,
                             1.15,
                             sharp=80,
                             static=True,
                             fade_edges=False,
                             protect_neutral=False,
                             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,
                           fade_edges=False,
                           protect_neutral=False,
                           seed=333)
        dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a)
        grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain))
        out = grain

        if int(NUM) != 12:
            while out.num_frames < 34646:
                out += out[-1]

        return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2],
                                          [0, 1, 2])
示例#8
0
    def main(self) -> vs.VideoNode:
        """Vapoursynth filtering"""
        src = JPBD.clip_cut
        src = depth(src, 16)

        ring_mask = Mask.ringing_mask(get_y(src))
        dering_src = hvf.EdgeCleaner(src, 20, hot=True)
        out = dering_src

        ref = Denoise.ref_denoise(get_y(out), tr=1)
        denoise = Denoise.hybrid_denoise(depth(out, 32),
                                         knlm_h=0.15,
                                         sigma=1,
                                         knlm_args=dict(d=1, a=3, s=3),
                                         bm3d_args=dict(ref=depth(ref, 32)))
        denoise = depth(denoise, 16)
        out = denoise

        pre = get_y(out)

        # Remove haloing
        dehalo = gf.MaskedDHA(pre,
                              rx=1.4,
                              ry=1.4,
                              darkstr=0.1,
                              brightstr=1.0,
                              maskpull=40,
                              maskpush=255)
        bila = core.bilateral.Bilateral(dehalo, sigmaS=1, sigmaR=0.08)
        dehalorp = core.rgvs.Repair(dehalo, bila, 13)
        dehalo = core.std.MaskedMerge(dehalo, dehalorp,
                                      ring_mask.std.Maximum(), 0)
        dehalo = core.std.Expr([dehalo, pre], 'x y min')
        out = dehalo

        # Antialiasing sraaaaaaaaaa
        lineart = vdf.mask.ExPrewitt().get_mask(out, 4000,
                                                7500).std.Convolution([1] * 25)
        aaa = AA().upscaled_sraaaaaaaaaa(out, height=1620)
        out = aaa

        unwarp = self.line_darkening(out, 0.075).warp.AWarpSharp2(depth=-1)
        out = unwarp

        motion = hvf.SMDegrain(out, tr=3, thSADC=600, RefineMotion=True)
        masked = core.std.MaskedMerge(out, motion, lineart)
        out = masked

        mergechroma = vdf.misc.merge_chroma(out, denoise)
        out = mergechroma

        db_mask = Mask.deband_mask(out, (4000, 4000, 4000), (2000, 2000, 2000))

        deband_1 = vdf.deband.dumb3kdb(out, 17, [36, 48])
        deband_2 = vdf.deband.dumb3kdb(out,
                                       17,
                                       30,
                                       sample_mode=4,
                                       use_neo=True)
        deband_a = vdf.placebo.deband(out,
                                      22,
                                      threshold=8,
                                      iterations=3,
                                      grain=0)

        th_lo, th_hi = 22 << 8, 28 << 8
        strength = f'{th_hi} x - {th_hi} {th_lo} - /'
        deband = core.std.Expr(
            [out.std.Convolution([1] * 9), deband_1, deband_2], [
                f'x {th_lo} > x {th_hi} < and z ' + strength + ' * y 1 ' +
                strength + f' - * + x {th_lo} <= z y ? ?',
                'x y * sqrt x z * sqrt * y * z * 0.25 pow'
            ])

        deband = lvf.rfs(deband, deband_a, [(OPSTART + 1382, OPSTART + 1433)])
        deband = core.std.MaskedMerge(deband, out, db_mask)
        out = deband

        ref = get_y(out).std.PlaneStats()
        adgmask_a = ref.adg.Mask(25)
        adgmask_b = ref.adg.Mask(10)

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

        stgrain_b = sizedgrn(out,
                             0.2,
                             0.1,
                             1.15,
                             sharp=80,
                             static=True,
                             fade_edges=False,
                             protect_neutral=False,
                             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,
                           fade_edges=False,
                           protect_neutral=False,
                           seed=333)
        dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a)
        grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain))
        out = grain

        if int(NUM) != 12:
            while out.num_frames < 2160:
                out += out[-1]

        return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2],
                                          [0, 1, 2])
示例#9
0
    def main(self) -> vs.VideoNode:
        """Vapoursynth filtering"""
        src = JPBD.clip_cut
        src = depth(src, 16)
        src_cru = WEB_CRU.clip_cut
        src_aod = WEB_AOD.clip_cut


        # Dehardsubbing using .ass file
        masksub = Mask.hardsub_mask(src_aod.std.BlankClip(), SUB, FONTDIR)
        dehardsub = core.std.MaskedMerge(src_aod, src_cru, masksub)
        src_web = dehardsub


        # AoD is poorly rescaled
        src_y, src_cru_y, src_web_y = map(get_y, [src, src_cru, src_web])

        thr = 10
        src_web_y = core.std.Expr([src_web_y, src_cru_y], f'x y - abs {thr} < x y * sqrt y ?')
        src_web_y = depth(src_web_y, 16)

        ringrid = core.rgvs.Repair(src_web_y, src_web_y.std.Convolution([1]*9), 11)
        ringrid = core.std.Expr([ringrid, src_web_y], 'x y min')

        # Remove ringing with AoD+CR
        ring_mask = Mask.ringing_mask(src_y)
        bdweb = core.std.MaskedMerge(src_y, ringrid, ring_mask)
        bdweb = lvf.rfs(bdweb, src_web_y, [(793, 1503), (1696, 2301), (32121, 34164), (34472, 34523)])
        out = vdf.misc.merge_chroma(bdweb, src)



        # Restore BD changes
        dering_src = hvf.EdgeCleaner(src, 20, hot=True)

        diff_mask = Mask.diff_mask((src, src_cru), brz=4750.0)
        bdchanges = core.std.MaskedMerge(out, dering_src, diff_mask)
        bdchanges = lvf.rfs(out, bdchanges, [(9419, 9512), (17731, 17865)])
        bdchanges = lvf.rfs(bdchanges, dering_src, [(14977, 15078), (15382, 15540), (23311, 23346)])
        # return bdchanges, diff_mask
        out = bdchanges




        ref = Denoise.ref_denoise(get_y(out), tr=1)
        denoise = Denoise.hybrid_denoise(
            depth(out, 32), knlm_h=0.15, sigma=1,
            knlm_args=dict(d=1, a=3, s=3), bm3d_args=dict(ref=depth(ref, 32))
        )
        denoise = depth(denoise, 16)
        out = denoise



        pre = get_y(out)


        # Remove haloing
        dehalo = gf.MaskedDHA(pre, rx=1.4, ry=1.4, darkstr=0.1, brightstr=1.0, maskpull=40, maskpush=255)
        bila = core.bilateral.Bilateral(dehalo, sigmaS=1, sigmaR=0.08)
        dehalorp = core.rgvs.Repair(dehalo, bila, 13)
        dehalo = core.std.MaskedMerge(dehalo, dehalorp, ring_mask.std.Maximum(), 0)
        dehalo = core.std.Expr([dehalo, pre], 'x y min')
        out = dehalo




        # Antialiasing sraaaaaaaaaa
        lineart = vdf.mask.ExPrewitt().get_mask(out, 4000, 7500).std.Convolution([1] * 25)
        aaa = AA().upscaled_sraaaaaaaaaa(out, height=1620)
        out = aaa




        unwarp = self.line_darkening(out, 0.075).warp.AWarpSharp2(depth=-1)
        out = unwarp


        motion = hvf.SMDegrain(out, tr=3, thSADC=600, RefineMotion=True)
        masked = core.std.MaskedMerge(out, motion, lineart)
        out = masked




        mergechroma = vdf.misc.merge_chroma(out, denoise)
        out = mergechroma


        db_mask = Mask.deband_mask(out, (4000, 4000, 4000), (2000, 2000, 2000))

        deband_1 = vdf.deband.dumb3kdb(out, 17, [36, 48])
        deband_2 = vdf.deband.dumb3kdb(out, 17, 30, sample_mode=4, use_neo=True)
        deband_x = vdf.placebo.deband(out, 28, 4, iterations=3, grain=0)

        th_lo, th_hi = 22 << 8, 28 << 8
        strength = f'{th_hi} x - {th_hi} {th_lo} - /'
        deband = core.std.Expr(
            [out.std.Convolution([1]*9), deband_1, deband_2],
            [f'x {th_lo} > x {th_hi} < and z ' + strength + ' * y 1 ' + strength + f' - * + x {th_lo} <= z y ? ?',
             'x y * sqrt x z * sqrt * y * z * 0.25 pow'])

        deband = lvf.rfs(deband, deband_x, [(6688, 6714)])
        deband = core.std.MaskedMerge(deband, out, db_mask)
        out = deband



        ref = get_y(out).std.PlaneStats()
        adgmask_a = ref.adg.Mask(25)
        adgmask_b = ref.adg.Mask(10)

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

        stgrain_b = sizedgrn(out, 0.2, 0.1, 1.15, sharp=80, static=True, fade_edges=False, protect_neutral=False, 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, fade_edges=False, protect_neutral=False, seed=333)
        dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a)
        grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain))
        out = grain


        if int(NUM) != 12:
            while out.num_frames < 34646:
                out += out[-1]

        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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2])
示例#11
0
    def main(self) -> vs.VideoNode:
        """Vapoursynth filtering"""
        src = JPBD.clip_cut
        src = depth(src, 16)
        src_cru = WEB_CRU.clip_cut
        src_aod = WEB_AOD.clip_cut

        # Dehardsubbing using .ass file
        masksub = Mask.hardsub_mask(src_aod.std.BlankClip(), SUB, FONTDIR)
        dehardsub = core.std.MaskedMerge(src_aod, src_cru, masksub)
        src_web = dehardsub

        # AoD is poorly rescaled
        src_y, src_cru_y, src_web_y = map(get_y, [src, src_cru, src_web])

        thr = 10
        src_web_y = core.std.Expr([src_web_y, src_cru_y],
                                  f'x y - abs {thr} < x y * sqrt y ?')
        src_web_y = depth(src_web_y, 16)

        ringrid = core.rgvs.Repair(src_web_y,
                                   src_web_y.std.Convolution([1] * 9), 11)
        ringrid = core.std.Expr([ringrid, src_web_y], 'x y min')

        # Remove ringing with AoD+CR
        ring_mask = Mask.ringing_mask(src_y)
        bdweb = core.std.MaskedMerge(src_y, ringrid, ring_mask)
        out = vdf.misc.merge_chroma(bdweb, src)

        # Restore BD changes
        dering_src = hvf.EdgeCleaner(src, 20, hot=True)

        diff_mask = Mask.diff_mask((src, src_cru), brz=4750.0)
        bdchanges = core.std.MaskedMerge(out, dering_src, diff_mask)
        bdchanges = lvf.rfs(out, bdchanges, [(4455, 4607), (4876, 5078),
                                             (5199, 5246), (5958, 6035),
                                             (6894, 7076), (7275, 7406),
                                             (7653, 7784), (7863, 7970),
                                             (8142, 8348), (8784, 9065),
                                             (9276, 9800), (10613, 10720),
                                             (10739, 10780), (10949, 10969),
                                             (11105, 11230), (11924, 12289),
                                             (12865, 12891), (13139, 13213),
                                             (15520, 15733), (19160, 19243),
                                             (20351, 20422), (24824, 24979),
                                             (26357, 26527), (27920, 28000),
                                             (29576, 29659), (29780, 29881),
                                             (30128, 30271), (30644, 30763),
                                             (31776, 31811), (32522, 32641)])
        # return bdchanges, diff_mask
        out = bdchanges

        ref = Denoise.ref_denoise(get_y(out), tr=1)
        denoise = Denoise.hybrid_denoise(depth(out, 32),
                                         knlm_h=0.15,
                                         sigma=1,
                                         knlm_args=dict(d=1, a=3, s=3),
                                         bm3d_args=dict(ref=depth(ref, 32)))
        denoise = depth(denoise, 16)
        out = denoise

        pre = get_y(out)

        # Remove haloing
        dehalo = gf.MaskedDHA(pre,
                              rx=1.4,
                              ry=1.4,
                              darkstr=0.1,
                              brightstr=1.0,
                              maskpull=40,
                              maskpush=255)
        bila = core.bilateral.Bilateral(dehalo, sigmaS=1, sigmaR=0.08)
        dehalorp = core.rgvs.Repair(dehalo, bila, 13)
        dehalo = core.std.MaskedMerge(dehalo, dehalorp,
                                      ring_mask.std.Maximum(), 0)
        dehalo = core.std.Expr([dehalo, pre], 'x y min')
        out = dehalo

        # Antialiasing sraaaaaaaaaa
        lineart = vdf.mask.ExPrewitt().get_mask(out, 4000,
                                                7500).std.Convolution([1] * 25)
        aaa = AA().upscaled_sraaaaaaaaaa(out, height=1620)
        out = aaa

        unwarp = self.line_darkening(out, 0.075).warp.AWarpSharp2(depth=-1)
        out = unwarp

        motion = hvf.SMDegrain(out, tr=3, thSADC=600, RefineMotion=True)
        masked = core.std.MaskedMerge(out, motion, lineart)
        out = masked

        mergechroma = vdf.misc.merge_chroma(out, denoise)
        out = mergechroma

        ref = depth(src_cru, 16)
        cred_mask = Mask.credits_mask(src, JPBD_NCOP.clip_cut,
                                      JPBD_NCED.clip_cut, OPSTART, OPEND,
                                      EDSTART, EDEND)
        cred = out
        cred = lvf.rfs(cred, core.std.MaskedMerge(cred, ref, cred_mask, 0),
                       [(OPSTART, OPEND), (EDSTART, EDEND)])
        out = cred

        db_mask = Mask.deband_mask(out, (4000, 4000, 4000), (2000, 2000, 2000))

        deband_1 = vdf.deband.dumb3kdb(out, 17, [36, 48])
        deband_2 = vdf.deband.dumb3kdb(out,
                                       17,
                                       30,
                                       sample_mode=4,
                                       use_neo=True)
        deband_a = vdf.placebo.deband(out,
                                      22,
                                      threshold=8,
                                      iterations=3,
                                      grain=0)
        import rekt
        deband_c = rekt.rekt_fast(out,
                                  lambda x: vdf.placebo.deband(x, 18, 6, 2, 0),
                                  bottom=600)
        deband_d = vdf.deband.dumb3kdb(out, 17, 65)

        th_lo, th_hi = 22 << 8, 28 << 8
        strength = f'{th_hi} x - {th_hi} {th_lo} - /'
        deband = core.std.Expr(
            [out.std.Convolution([1] * 9), deband_1, deband_2], [
                f'x {th_lo} > x {th_hi} < and z ' + strength + ' * y 1 ' +
                strength + f' - * + x {th_lo} <= z y ? ?',
                'x y * sqrt x z * sqrt * y * z * 0.25 pow'
            ])

        deband = lvf.rfs(deband, deband_a, [(OPSTART + 1382, OPSTART + 1433)])
        deband = lvf.rfs(deband, deband_c, [(12362, 12391)])
        deband = lvf.rfs(deband, deband_d, [(14789, 15025)])
        deband = core.std.MaskedMerge(deband, out, db_mask)
        out = deband

        ref = get_y(out).std.PlaneStats()
        adgmask_a = ref.adg.Mask(25)
        adgmask_b = ref.adg.Mask(10)

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

        stgrain_b = sizedgrn(out,
                             0.2,
                             0.1,
                             1.15,
                             sharp=80,
                             static=True,
                             fade_edges=False,
                             protect_neutral=False,
                             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,
                           fade_edges=False,
                           protect_neutral=False,
                           seed=333)
        dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a)
        grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain))
        out = grain

        if int(NUM) != 12:
            while out.num_frames < 34646:
                out += out[-1]

        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 += 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])
示例#13
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])
示例#14
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut

    # Variables
    h = 720
    w = get_w(h)

    edges = core.edgefixer.ContinuityFixer(src, *[[2, 1, 1]] * 4)
    out = depth(edges, 32)

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

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

    descale = core.descale.Debilinear(y, w, h)

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

    antialias = sraa_eedi3(upscale, 9)

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

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

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

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

    deband = dumb3kdbv2(out, 22, 24)
    deband = core.std.MaskedMerge(deband, out, detail_mask)
    out = deband

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

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

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

    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2])
示例#15
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])
示例#16
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = src.std.SetFrameProp('_Matrix', intval=1)

    # Variables
    edstart, edend = 165528, src.num_frames-1
    h = 844
    w = get_w(h)


    edges_a = core.edgefixer.ContinuityFixer(src, *[[1, 0, 0]]*4)
    edges_b = core.edgefixer.ContinuityFixer(src, [0, 0, 0], [1, 0, 0], [0, 0, 0], [1, 0, 0])
    edges = lvf.rfs(edges_a, edges_b, [(8900, 9001)])
    out = depth(edges, 32)


    ref = hvf.SMDegrain(depth(get_y(out), 16), thSAD=300)
    denoise = hybrid_denoise(out, 0.25, 1.05, dict(a=2, d=1), dict(ref=depth(ref, 32)))
    out = denoise



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


    descale_clips = [core.resize.Bicubic(y, w, h, filter_param_a=1/3, filter_param_b=1/3),
                     core.descale.Debicubic(y, w, h, 0, 1/2),
                     core.descale.Debicubic(y, w, h, 1/3, 1/3)]
    descale = core.std.Expr(descale_clips, 'x y z min max y z max min z min')
    descale_bcsharp = core.descale.Debicubic(y, get_w(842), 842, 0, 1)
    descale_bcsharp = gf.MaskedDHA(depth(descale_bcsharp, 16), rx=1.4, ry=1.4, darkstr=0.05, brightstr=1.0, maskpull=48, maskpush=140)


    upsc_args = dict(shader_file='shaders/FSRCNNX_x2_56-16-4-1.glsl', upscaler_smooth=eedi3_upscale, profile='zastin',
                     sharpener=partial(gf.DetailSharpen, sstr=1.65, power=4, mode=0, med=True))

    upscale = vdf.fsrcnnx_upscale(descale, height=h*2, **upsc_args)
    antialias = sraa_eedi3(upscale, 3, alpha=0.2, beta=0.4, gamma=100, mdis=20, nrad=3)
    downscale_a = muvf.SSIM_downsample(antialias, src.width, src.height, kernel='Bicubic', filter_param_a=0, filter_param_b=0)


    upscale = eedi3_upscale(descale_bcsharp)
    antialias = sraa_eedi3(depth(upscale, 32), 3, alpha=0.2, beta=0.4, gamma=100, mdis=20, nrad=3)
    downscale_b = muvf.SSIM_downsample(antialias, src.width, src.height, kernel='Bicubic', filter_param_a=0, filter_param_b=0)



    downscale = lvf.rfs(downscale_a, downscale_b, [(52931, 53004), (53459, 53696), (54218, 54441),
                                                   (55137, 55254), (55420, 55570)])
    scaled = core.std.MaskedMerge(y, downscale, lineart)

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



    crop = core.std.Crop(out, left=4, right=2)
    fb = core.fb.FillBorders(crop, 1, 1, 0, 0, mode="fillmargins")
    resize = core.resize.Bicubic(fb, 1920)
    out = lvf.rfs(out, resize, [(8900, 9001)])



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

    deband = dumb3kdb(out, 16, 42)
    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.1, 0.05, 1.05, sharp=80, static=True)
    stgrain = core.std.MaskedMerge(out, stgrain, adgmask_b)
    stgrain = core.std.MaskedMerge(out, stgrain, adgmask_a.std.Invert())

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




    ref = depth(src, 16)
    src_c, src_nced = [c.std.BoxBlur(0, 1, 1, 1, 1) for c in [src, JPBD_NCED.src_cut]]
    creditless_mask = vdf.dcm(ref, src_c[edstart:edend+1], src_nced[:edend-edstart+1], edstart, edend, 3, 3).std.Deflate()
    rescale_mask = vdf.drm(ref, h, b=1/3, c=1/3, mthr=30)
    rescale_mask = vdf.region_mask(rescale_mask, 20, 20, 20, 20).std.Binarize(6000).std.Maximum().std.Maximum().std.Inflate()

    credit = out
    credit = lvf.rfs(credit, ref, [(0, 672)])
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, creditless_mask, 0), [(edstart, edend)])
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, rescale_mask[5602], 0), [(5561, 5752)])
    out = credit


    return depth(out, 10).std.Limiter(16<<2, [235<<2, 240<<2])