5
0

vivy: tv: 13

This commit is contained in:
louis f 2021-06-23 22:52:58 -04:00
parent f9bf2c3202
commit 5387d8ff11
Signed by: louis
GPG Key ID: 44D7E1DE4E23D6F2
2 changed files with 170 additions and 0 deletions
Vivy/13
yt_common/yt_common

143
Vivy/13/13.vpy Normal file

@ -0,0 +1,143 @@
import vapoursynth as vs
from vivy_common import (VivyConfig, VivySource, antialias, deband, denoise,
finalize, fsrcnnx_rescale, letterbox_edgefix, letterbox_refix, regrain)
from yt_common.automation import SelfRunner
from yt_common.deband import gray_mask
from yt_common.chapters import Chapter
from yt_common.source import waka_replace
from lvsfunc.mask import BoundingBox
from lvsfunc.types import Range
from lvsfunc.util import replace_ranges
from lvsfunc.dehardsub import HardsubLine, HardsubSignFade, HardsubMask, bounded_dehardsub
from awsmfunc import bbmod
from vsutil import scale_value
from vsutil import Range as CRange
import lvsfunc as lvf
from debandshit import f3kbilateral
from vsutil import iterate
from typing import List, Optional
import os
core = vs.core
EPNUM: int = int(os.path.basename(os.path.splitext(__file__)[0]))
CONFIG: VivyConfig = VivyConfig(EPNUM)
SOURCE: VivySource = VivySource(CONFIG)
CHAPTERS: List[Chapter] = [
Chapter("Intro", 0),
Chapter("OP", 1990),
Chapter("Part A", 4149),
Chapter("Part B", 16378),
Chapter("Credits", 30657),
Chapter("Outro", 32390),
]
WAKA_REPLACE: List[List[Range]] = [
[(30657, 31496)],
[],
]
SIGNS_RU: List[HardsubMask] = [
HardsubLine([
(1996, 4110),
(21898, 24539),
(24975, 28802),
], ((283, 844), (1349, 204))),
HardsubLine([
(1529, 1570),
]),
HardsubSignFade([
(1906, 1989),
(22928, 22951),
]),
]
CREDITS: List[Range] = [
(30657, 32377),
]
NOSCALE: List[Range] = [
]
NOSCALE += CREDITS
AA_NONE: List[Range] = [
]
AA_NONE += CREDITS
AA_STRONGER: List[Range] = [
]
LETTERBOX: List[Range] = [
(33393, 33545),
]
LETTERBOX_FADES: List[Range] = [
]
DUMBSHIT_DEBAND: List[Range] = [
(29745, 29870),
]
def credits_ef(clip: vs.VideoNode, ranges: Optional[List[Range]] = None) -> vs.VideoNode:
assert clip.format is not None
black = scale_value(0, 8, clip.format.bits_per_sample, scale_offsets=True,
range_in=CRange.FULL, range=CRange.LIMITED)
y = clip.std.ShufflePlanes(0, vs.GRAY)
y_crop = y.std.Crop(left=1050, top=55, right=98, bottom=55)
y_bb = bbmod(y_crop, top=2, bottom=2, left=3, right=2)
y_aa = antialias(y_bb)
y_border = y_aa.std.AddBorders(left=1050, top=55, right=98, bottom=55, color=black)
y_mask = BoundingBox((1049, 54), (774, 972)).get_mask(y_border)
y_fix = core.std.MaskedMerge(y, y_border, y_mask)
fixed = core.std.ShufflePlanes([y_fix, clip], [0, 1, 2], vs.YUV)
return replace_ranges(clip, fixed, ranges)
def colored_deband(clip: vs.VideoNode, deb_ref: vs.VideoNode, ranges: Optional[List[Range]] = None
) -> vs.VideoNode:
deband_strong = iterate(clip.std.ShufflePlanes(0, vs.GRAY),
lambda c: f3kbilateral(c, range=12, y=80), 2) # type: ignore
deband_strong_u = iterate(clip.std.ShufflePlanes(1, vs.GRAY),
lambda c: f3kbilateral(c, range=12, y=40), 2) # type: ignore
deband_strong_v = iterate(clip.std.ShufflePlanes(2, vs.GRAY),
lambda c: f3kbilateral(c, range=12, y=40), 2) # type: ignore
db_yeet = core.std.ShufflePlanes([deband_strong, deband_strong_u, deband_strong_v], [0, 0, 0], vs.YUV)
db_yeet = core.std.MaskedMerge(db_yeet, clip, lvf.mask.detail_mask(clip))
cmask = gray_mask(db_yeet, y=(0.165, 0.3))
db_cmask = core.std.MaskedMerge(deb_ref, db_yeet, cmask)
return replace_ranges(deb_ref, db_cmask, ranges)
def filter_basic() -> vs.VideoNode:
wakas, ref = SOURCE.dhs_source()
waka = wakas[0]
waka, wakas = waka_replace(waka, wakas[1:], WAKA_REPLACE)
src = bounded_dehardsub(waka, ref, SIGNS_RU, wakas)
src.set_output(1)
return src
def filter() -> vs.VideoNode:
src = filter_basic()
den = denoise(src)
rescale = fsrcnnx_rescale(den, NOSCALE)
edgefix = letterbox_edgefix(rescale, crops=LETTERBOX, fades=LETTERBOX_FADES)
deb = deband(edgefix)
deb = colored_deband(edgefix, deb, DUMBSHIT_DEBAND)
aa = antialias(deb, stronger=AA_STRONGER, noaa=AA_NONE)
refix = letterbox_refix(aa, deb, LETTERBOX)
cfix = credits_ef(refix, CREDITS)
grain = regrain(cfix)
final = finalize(grain)
final.set_output(0)
return final
if __name__ == "__main__":
SelfRunner(CONFIG, SOURCE, filter, filter_basic, chapters=CHAPTERS)
else:
filter()

@ -4,6 +4,8 @@ from enum import Enum
from functools import partial from functools import partial
from typing import Any, Callable, List, Optional, Tuple, Union from typing import Any, Callable, List, Optional, Tuple, Union
from lvsfunc.util import scale_thresh
import vsutil import vsutil
@ -93,3 +95,28 @@ def morpho_mask(clip: vs.VideoNode) -> Tuple[vs.VideoNode, vs.VideoNode]:
grad_mask = core.std.Expr([ymph, yrangesml, ypw], expr="x y z max max") grad_mask = core.std.Expr([ymph, yrangesml, ypw], expr="x y z max max")
return grad_mask, yrangebig return grad_mask, yrangebig
def color_mask(clip: vs.VideoNode, y: Tuple[float, float], u: Tuple[float, float], v: Tuple[float, float]
) -> vs.VideoNode:
expr = f"x {scale_thresh(y[0], clip)} >= x {scale_thresh(y[1], clip)} <= and " # Y bounds check
expr += f"y {scale_thresh(u[0], clip)} >= y {scale_thresh(u[1], clip)} <= and and " # U bounds check
expr += f"z {scale_thresh(v[0], clip)} >= z {scale_thresh(v[1], clip)} <= and and " # V bounds check
expr += f"{scale_thresh(1.0, clip)} 0 ?" # brz
wmask = core.std.Expr(vsutil.split(clip.resize.Bicubic(format=vs.YUV444P16)), expr)
wmask = wmask.std.Inflate().std.Binarize()
wmask_edge = wmask.std.Prewitt().std.Binarize()
wmask = core.std.Expr([wmask, wmask_edge], "x y -") # preserve edges for sharpness
return wmask
def gray_mask(clip: vs.VideoNode, y: Tuple[float, float], cthr: float = 0.02) -> vs.VideoNode:
expr = f"x {scale_thresh(y[0], clip)} >= x {scale_thresh(y[1], clip)} <= and " # Y bounds check
expr += "y z >= and " # U >= V for blue-ish grays
expr += f"y z - abs {scale_thresh(cthr, clip)} <= and " # UV proximity check
expr += f"{scale_thresh(1.0, clip)} 0 ?" # brz
wmask = core.std.Expr(vsutil.split(clip.resize.Bicubic(format=vs.YUV444P16)), expr)
wmask = wmask.std.Inflate().std.Binarize()
wmask_edge = wmask.std.Prewitt().std.Binarize()
wmask = core.std.Expr([wmask, wmask_edge], "x y -") # preserve edges for sharpness
return wmask