5
0

vivy: tv: common: upstream dehardsubbing utility to lvsfunc

This commit is contained in:
louis f 2021-04-17 20:52:22 -04:00
parent 69c3ddaa61
commit e144906b11
Signed by: louis
GPG Key ID: 44D7E1DE4E23D6F2
7 changed files with 60 additions and 126 deletions

View File

@ -1,12 +1,15 @@
import vapoursynth as vs
from lvsfunc.types import Range
from lvsfunc.dehardsub import HardsubSign, bounded_dehardsub
from typing import List
import os
import sys
sys.path.append("..")
from vivy_common import (HardsubSign, Range, bounded_dehardsub, antialias, deband, denoise, # noqa: E402
from vivy_common import (SelfRunner, antialias, deband, denoise, # noqa: E402
finalize, fsrcnnx_rescale, letterbox_edgefix, source)
core = vs.core
@ -37,14 +40,27 @@ LETTERBOX: List[Range] = [
(659, 14071)
]
waka, ref = source(EPNUM)
waka = waka[:37301] + core.std.BlankClip(waka, length=6) + waka[37301:]
src = bounded_dehardsub(waka, ref, SIGNS_RU)
rescale = fsrcnnx_rescale(src, NOSCALE)
den = denoise(rescale)
deb = deband(den)
aa = antialias(deb, NOAA)
edgefix = letterbox_edgefix(aa, LETTERBOX)
final = finalize(edgefix)
final.set_output()
def filter_basic() -> vs.VideoNode:
waka, ref = source(EPNUM)
waka = waka[:37301] + core.std.BlankClip(waka, length=6) + waka[37301:]
src = bounded_dehardsub(waka, ref, SIGNS_RU)
return src
def filter() -> vs.VideoNode:
src = filter_basic()
rescale = fsrcnnx_rescale(src, NOSCALE)
den = denoise(rescale)
deb = deband(den)
aa = antialias(deb, NOAA)
edgefix = letterbox_edgefix(aa, LETTERBOX)
final = finalize(edgefix)
final.set_output()
return final
if __name__ == "__main__":
SelfRunner(EPNUM, filter, filter_basic)
else:
filter()

View File

@ -1,13 +1,16 @@
import vapoursynth as vs
from lvsfunc.types import Range
from lvsfunc.dehardsub import HardsubSign, bounded_dehardsub
from typing import List
import os
import sys
sys.path.append("..")
from vivy_common import (HardsubSign, Range, bounded_dehardsub, antialias, deband, denoise, # noqa: E402
finalize, fsrcnnx_rescale, source)
from vivy_common import (SelfRunner, antialias, deband, denoise, finalize, # noqa: E402
fsrcnnx_rescale, source)
core = vs.core
@ -45,13 +48,26 @@ PIXELSHIT: List[Range] = [
NOSCALE: List[Range] = CREDITS + PIXELSHIT
NOAA: List[Range] = PIXELSHIT
waka, ref = source(EPNUM)
waka = waka[:32344] + waka[32349:]
src = bounded_dehardsub(waka, ref, SIGNS_RU)
rescale = fsrcnnx_rescale(src, NOSCALE)
den = denoise(rescale)
deb = deband(den)
aa = antialias(deb, NOAA)
final = finalize(aa)
final.set_output()
def filter_basic() -> vs.VideoNode:
waka, ref = source(EPNUM)
waka = waka[:32344] + waka[32349:]
src = bounded_dehardsub(waka, ref, SIGNS_RU)
return src
def filter() -> vs.VideoNode:
src = filter_basic()
rescale = fsrcnnx_rescale(src, NOSCALE)
den = denoise(rescale)
deb = deband(den)
aa = antialias(deb, NOAA)
final = finalize(aa)
final.set_output()
return final
if __name__ == "__main__":
SelfRunner(EPNUM, filter, filter_basic)
else:
filter()

View File

@ -1,12 +1,15 @@
import vapoursynth as vs
from lvsfunc.types import Range
from lvsfunc.dehardsub import HardsubSign, bounded_dehardsub
from typing import List
import os
import sys
sys.path.append("..")
from vivy_common import (HardsubSign, Range, SelfRunner, bounded_dehardsub, antialias, deband, denoise, # noqa: E402
from vivy_common import (SelfRunner, antialias, deband, denoise, # noqa: E402
finalize, fsrcnnx_rescale, letterbox_edgefix, source)
core = vs.core

View File

@ -1,3 +1,2 @@
from .dehardsub import HardsubSign, bounded_dehardsub, get_all_masks # noqa: F401
from .filter import antialias, deband, denoise, finalize, fsrcnnx_rescale, letterbox_edgefix # noqa: F401
from .util import Range, SelfRunner, glob_crc, source # noqa: F401
from .util import SelfRunner, glob_crc, source # noqa: F401

View File

@ -1,97 +0,0 @@
import vapoursynth as vs
import kagefunc as kgf
import lvsfunc as lvf
from typing import List, NamedTuple, Optional, Tuple, Union
from .util import Range
core = vs.core
class Position(NamedTuple):
x: int
y: int
class Size(NamedTuple):
x: int
y: int
class BoundingBox():
pos: Position
size: Size
def __init__(self, pos: Position, size: Size):
self.pos = pos
self.size = size
class HardsubSign():
range: Range
bound: Optional[BoundingBox]
refframe: Optional[int]
highpass: int
expand: int
def __init__(self,
range: Range,
bound: Union[BoundingBox, Tuple[Tuple[int, int], Tuple[int, int]], None],
refframe: Optional[int] = None, highpass: int = 5000, expand: int = 8):
self.range = range
self.refframe = refframe
self.highpass = highpass
self.expand = expand
if bound is None:
self.bound = None
elif isinstance(bound, BoundingBox):
self.bound = bound
else:
self.bound = BoundingBox(Position(bound[0][0], bound[0][1]), Size(bound[1][0], bound[1][1]))
def _hardsub_mask(self, hrdsb: vs.VideoNode, ref: vs.VideoNode) -> vs.VideoNode:
if self.refframe is not None:
mask = kgf.hardsubmask_fades(hrdsb[self.refframe], ref[self.refframe],
highpass=self.highpass, expand_n=self.expand)
else:
mask = kgf.hardsubmask_fades(hrdsb, ref, highpass=self.highpass, expand_n=self.expand)
assert isinstance(mask, vs.VideoNode)
return mask
def _bound_mask(self, ref: vs.VideoNode) -> vs.VideoNode:
if self.bound is not None:
mask = kgf.squaremask(ref, self.bound.size.x, self.bound.size.y,
self.bound.pos.x, self.bound.pos.y)
else:
mask = kgf.squaremask(ref, ref.width, ref.height, 0, 0)
assert isinstance(mask, vs.VideoNode)
return mask
def get_mask(self, hrdsb: vs.VideoNode, ref: vs.VideoNode) -> vs.VideoNode:
bm = self._bound_mask(ref)
hm = self._hardsub_mask(hrdsb, ref)
return core.std.MaskedMerge(core.std.BlankClip(hm), hm, bm)
def get_all_masks(hrdsb: vs.VideoNode, ref: vs.VideoNode, signs: List[HardsubSign]) -> vs.VideoNode:
"""
Scenefiltering helper, not used in encode
"""
assert ref.format is not None
mask = core.std.BlankClip(ref, format=ref.format.replace(color_family=vs.GRAY, subsampling_w=0, subsampling_h=0).id)
for sign in signs:
mask = lvf.misc.replace_ranges(mask, core.std.Expr([mask, sign.get_mask(hrdsb, ref)], 'x y +'), [sign.range])
return mask
def bounded_dehardsub(hrdsb: vs.VideoNode, ref: vs.VideoNode, signs: List[HardsubSign]) -> vs.VideoNode:
bound = hrdsb
for sign in signs:
bound = lvf.misc.replace_ranges(bound,
core.std.MaskedMerge(bound, ref, sign.get_mask(hrdsb, ref)),
[sign.range])
return bound

View File

@ -4,11 +4,10 @@ import lvsfunc as lvf
import vardefunc as vdf
from awsmfunc import bbmod
from lvsfunc.types import Range
from mvsfunc import BM3D
from typing import List, Optional
from .util import Range
import os
import vsutil

View File

@ -14,8 +14,6 @@ from typing import Any, BinaryIO, Callable, List, Optional, Sequence, Tuple, Uni
core = vs.core
Range = Union[int, Tuple[int, int]]
TITLE: str = "Vivy"
TITLE_LONG: str = f"{TITLE} - Fluorite Eye's Song"
RESOLUTION: int = 1080