Compare commits
2 Commits
eefc597138
...
e2a47f8716
Author | SHA1 | Date | |
---|---|---|---|
e2a47f8716 | |||
4f5a6d9044 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -21,3 +21,4 @@ ffmpeg2pass*.log
|
|||||||
**/.vspreview/
|
**/.vspreview/
|
||||||
**/results/
|
**/results/
|
||||||
**/__pycache__/
|
**/__pycache__/
|
||||||
|
**/*.egg-info/
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
import vapoursynth as vs
|
import vapoursynth as vs
|
||||||
|
|
||||||
|
from vivy_common import (VivyConfig, VivySource, antialias, deband, denoise,
|
||||||
|
finalize, fsrcnnx_rescale, letterbox_edgefix)
|
||||||
|
|
||||||
from yt_common.automation import SelfRunner
|
from yt_common.automation import SelfRunner
|
||||||
from yt_common.source import waka_replace
|
from yt_common.source import waka_replace
|
||||||
|
|
||||||
@ -9,11 +12,6 @@ from lvsfunc.dehardsub import HardsubSign, HardsubMask, bounded_dehardsub
|
|||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
sys.path.append("..")
|
|
||||||
|
|
||||||
from vivy_common import (VivyConfig, VivySource, antialias, deband, denoise, # noqa: E402
|
|
||||||
finalize, fsrcnnx_rescale, letterbox_edgefix)
|
|
||||||
|
|
||||||
core = vs.core
|
core = vs.core
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
import vapoursynth as vs
|
import vapoursynth as vs
|
||||||
|
|
||||||
|
from vivy_common import (VivyConfig, VivySource, antialias, deband, denoise, finalize,
|
||||||
|
fsrcnnx_rescale)
|
||||||
|
|
||||||
from yt_common.automation import SelfRunner
|
from yt_common.automation import SelfRunner
|
||||||
from yt_common.source import waka_replace
|
from yt_common.source import waka_replace
|
||||||
|
|
||||||
@ -9,11 +12,6 @@ from lvsfunc.dehardsub import HardsubMask, HardsubSign, bounded_dehardsub
|
|||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
sys.path.append("..")
|
|
||||||
|
|
||||||
from vivy_common import (VivyConfig, VivySource, antialias, deband, denoise, finalize, # noqa: E402
|
|
||||||
fsrcnnx_rescale)
|
|
||||||
|
|
||||||
core = vs.core
|
core = vs.core
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
import vapoursynth as vs
|
import vapoursynth as vs
|
||||||
|
|
||||||
|
from vivy_common import (VivyConfig, VivySource, antialias, deband, denoise,
|
||||||
|
finalize, fsrcnnx_rescale, letterbox_edgefix)
|
||||||
|
|
||||||
from yt_common.automation import SelfRunner
|
from yt_common.automation import SelfRunner
|
||||||
from yt_common.source import waka_replace
|
from yt_common.source import waka_replace
|
||||||
|
|
||||||
@ -9,11 +12,6 @@ from lvsfunc.dehardsub import HardsubMask, HardsubLine, HardsubSign, bounded_deh
|
|||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
sys.path.append("..")
|
|
||||||
|
|
||||||
from vivy_common import (VivyConfig, VivySource, antialias, deband, denoise, # noqa: E402
|
|
||||||
finalize, fsrcnnx_rescale, letterbox_edgefix)
|
|
||||||
|
|
||||||
core = vs.core
|
core = vs.core
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
import vapoursynth as vs
|
import vapoursynth as vs
|
||||||
|
|
||||||
|
from vivy_common import (VivyConfig, VivySource, antialias, deband, denoise,
|
||||||
|
finalize, fsrcnnx_rescale, letterbox_edgefix)
|
||||||
|
|
||||||
from yt_common.automation import SelfRunner
|
from yt_common.automation import SelfRunner
|
||||||
from yt_common.source import waka_replace
|
from yt_common.source import waka_replace
|
||||||
|
|
||||||
@ -9,11 +12,6 @@ from lvsfunc.dehardsub import HardsubLine, HardsubSign, HardsubMask, bounded_deh
|
|||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
sys.path.append("..")
|
|
||||||
|
|
||||||
from vivy_common import (VivyConfig, VivySource, antialias, deband, denoise, # noqa: E402
|
|
||||||
finalize, fsrcnnx_rescale, letterbox_edgefix)
|
|
||||||
|
|
||||||
core = vs.core
|
core = vs.core
|
||||||
|
|
||||||
|
25
Vivy/setup.py
Executable file
25
Vivy/setup.py
Executable file
@ -0,0 +1,25 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import setuptools
|
||||||
|
|
||||||
|
name = "vivy_common"
|
||||||
|
version = "0.0.0"
|
||||||
|
release = "0.0.0"
|
||||||
|
|
||||||
|
setuptools.setup(
|
||||||
|
name=name,
|
||||||
|
version=release,
|
||||||
|
author="louis",
|
||||||
|
author_email="louis@poweris.moe",
|
||||||
|
description="yametetomete vivy common module",
|
||||||
|
packages=["vivy_common"],
|
||||||
|
classifiers=[
|
||||||
|
"Programming Language :: Python :: 3",
|
||||||
|
"License :: OSI Approved :: MIT License",
|
||||||
|
"Operating System :: OS Independent",
|
||||||
|
],
|
||||||
|
package_data={
|
||||||
|
'vivy_common': ['py.typed', 'workraw-settings', 'final-settings', 'shaders/FSRCNNX_x2_56-16-4-1.glsl'],
|
||||||
|
},
|
||||||
|
python_requires='>=3.8',
|
||||||
|
)
|
@ -49,7 +49,7 @@ def deband(clip: vs.VideoNode) -> vs.VideoNode:
|
|||||||
|
|
||||||
|
|
||||||
def antialias(clip: vs.VideoNode, noaa: Optional[List[Range]] = None) -> vs.VideoNode:
|
def antialias(clip: vs.VideoNode, noaa: Optional[List[Range]] = None) -> vs.VideoNode:
|
||||||
clamp = antialiasing.sraa_clamp(clip, mask=antialiasing.aa_mask_strong(clip))
|
clamp = antialiasing.sraa_clamp(clip, mask=antialiasing.mask_strong(clip))
|
||||||
return lvf.misc.replace_ranges(clamp, clip, noaa) if noaa else clamp
|
return lvf.misc.replace_ranges(clamp, clip, noaa) if noaa else clamp
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,34 +2,19 @@ import vapoursynth as vs
|
|||||||
|
|
||||||
import vsutil
|
import vsutil
|
||||||
|
|
||||||
from kagefunc import kirsch
|
from havsfunc import SMDegrain
|
||||||
from lvsfunc.aa import clamp_aa, upscaled_sraa
|
from lvsfunc.aa import nnedi3, clamp_aa, upscaled_sraa
|
||||||
|
from lvsfunc.kernels import Bicubic
|
||||||
from lvsfunc.misc import replace_ranges, scale_thresh
|
from lvsfunc.misc import replace_ranges, scale_thresh
|
||||||
from lvsfunc.types import Range
|
from lvsfunc.types import Range
|
||||||
|
|
||||||
from typing import Any, Dict, List, Optional, Union
|
from typing import Callable, List, Optional, Union
|
||||||
|
|
||||||
|
|
||||||
core = vs.core
|
core = vs.core
|
||||||
|
|
||||||
|
|
||||||
def nnedi3(clip: vs.VideoNode, opencl: bool = False) -> vs.VideoNode:
|
def mask_weak(clip: vs.VideoNode) -> vs.VideoNode:
|
||||||
nnedi3_args: Dict[str, Any] = dict(field=0, dh=True, nsize=3, nns=3, qual=1)
|
|
||||||
|
|
||||||
y = vsutil.get_y(clip)
|
|
||||||
|
|
||||||
def _nnedi3(clip: vs.VideoNode) -> vs.VideoNode:
|
|
||||||
return clip.nnedi3cl.NNEDI3CL(**nnedi3_args) if opencl \
|
|
||||||
else clip.nnedi3.nnedi3(**nnedi3_args)
|
|
||||||
|
|
||||||
aa = _nnedi3(y.std.Transpose())
|
|
||||||
aa = aa.resize.Spline36(height=clip.width, src_top=0.5).std.Transpose()
|
|
||||||
aa = _nnedi3(aa)
|
|
||||||
aa = aa.resize.Spline36(height=clip.height, src_top=0.5)
|
|
||||||
return aa
|
|
||||||
|
|
||||||
|
|
||||||
def aa_mask_weak(clip: vs.VideoNode) -> vs.VideoNode:
|
|
||||||
# use bilateral to smear the noise as much as possible without destroying lines
|
# use bilateral to smear the noise as much as possible without destroying lines
|
||||||
pre = vsutil.get_y(clip).bilateral.Bilateral(sigmaS=5, sigmaR=0.75)
|
pre = vsutil.get_y(clip).bilateral.Bilateral(sigmaS=5, sigmaR=0.75)
|
||||||
# frei-chen edge detection
|
# frei-chen edge detection
|
||||||
@ -39,20 +24,20 @@ def aa_mask_weak(clip: vs.VideoNode) -> vs.VideoNode:
|
|||||||
.std.Maximum().std.Convolution([1]*9)
|
.std.Maximum().std.Convolution([1]*9)
|
||||||
|
|
||||||
|
|
||||||
def aa_mask_strong(clip: vs.VideoNode) -> vs.VideoNode:
|
def mask_strong(clip: vs.VideoNode) -> vs.VideoNode:
|
||||||
mask: vs.VideoNode = kirsch(vsutil.get_y(clip)).std.Binarize(scale_thresh(0.25, clip)) \
|
mask: vs.VideoNode = SMDegrain(vsutil.get_y(clip), tr=3, thSAD=500, RefineMotion=True, prefilter=4) \
|
||||||
.std.Maximum().std.Convolution([1]*9)
|
.std.Prewitt().std.Binarize(scale_thresh(0.25, clip)).std.Maximum().std.Convolution([1]*9)
|
||||||
return mask
|
return mask
|
||||||
|
|
||||||
|
|
||||||
def aa_mask(clip: vs.VideoNode, weak: Union[Range, List[Range], None] = None) -> vs.VideoNode:
|
def combine_mask(clip: vs.VideoNode, weak: Union[Range, List[Range], None] = None) -> vs.VideoNode:
|
||||||
weak = weak or []
|
return replace_ranges(mask_strong(clip), mask_weak(clip), weak or [])
|
||||||
return replace_ranges(aa_mask_strong(clip), aa_mask_weak(clip), weak)
|
|
||||||
|
|
||||||
|
|
||||||
def sraa_clamp(clip: vs.VideoNode, mask: Optional[vs.VideoNode] = None,
|
def sraa_clamp(clip: vs.VideoNode, mask: Optional[vs.VideoNode] = None,
|
||||||
strength: float = 3, opencl: bool = False) -> vs.VideoNode:
|
strength: float = 2, opencl: bool = False,
|
||||||
sraa = upscaled_sraa(clip, rfactor=1.3, opencl=opencl,
|
postprocess: Optional[Callable[[vs.VideoNode], vs.VideoNode]] = None) -> vs.VideoNode:
|
||||||
downscaler=lambda c, w, h: c.resize.Bicubic(w, h, filter_param_a=0, filter_param_b=1/2))
|
sraa = upscaled_sraa(clip, rfactor=1.3, opencl=opencl, downscaler=Bicubic(b=0, c=1/2).scale)
|
||||||
|
sraa = postprocess(sraa) if postprocess else sraa
|
||||||
clamp = clamp_aa(clip, nnedi3(clip, opencl=opencl), sraa, strength=strength)
|
clamp = clamp_aa(clip, nnedi3(clip, opencl=opencl), sraa, strength=strength)
|
||||||
return core.std.MaskedMerge(clip, clamp, mask, planes=0) if mask else clamp
|
return core.std.MaskedMerge(clip, clamp, mask, planes=0) if mask else clamp
|
||||||
|
@ -3,6 +3,8 @@ import vapoursynth as vs
|
|||||||
import acsuite
|
import acsuite
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
|
import random
|
||||||
|
import shutil
|
||||||
import string
|
import string
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
@ -217,9 +219,16 @@ class SelfRunner():
|
|||||||
parser.add_argument("-f", "--force", help="Overwrite existing intermediaries", action="store_true")
|
parser.add_argument("-f", "--force", help="Overwrite existing intermediaries", action="store_true")
|
||||||
parser.add_argument("-a", "--audio", type=str, help="Force audio file")
|
parser.add_argument("-a", "--audio", type=str, help="Force audio file")
|
||||||
parser.add_argument("-x", "--suffix", type=str, help="Change the suffix of the mux")
|
parser.add_argument("-x", "--suffix", type=str, help="Change the suffix of the mux")
|
||||||
parser.add_argument("-c", "--no-chapters", help="No chapters in premux", action="store_true")
|
parser.add_argument("-c", "--comparison", help="Output a comparison between workraw and final",
|
||||||
|
action="store_true")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.comparison and workraw_filter:
|
||||||
|
log.status("Generating comparison...")
|
||||||
|
gencomp(10, "comp", src=workraw_filter(), final=final_filter())
|
||||||
|
log.status("Comparison generated.")
|
||||||
|
return
|
||||||
|
|
||||||
self.workraw = args.workraw if workraw_filter else False
|
self.workraw = args.workraw if workraw_filter else False
|
||||||
self.suffix = args.suffix if args.suffix is not None else "workraw" if self.workraw else "premux"
|
self.suffix = args.suffix if args.suffix is not None else "workraw" if self.workraw else "premux"
|
||||||
|
|
||||||
@ -263,7 +272,7 @@ class SelfRunner():
|
|||||||
try:
|
try:
|
||||||
log.status("--- MUXING FILE ---")
|
log.status("--- MUXING FILE ---")
|
||||||
if self._mux(f"{self.config.title.lower()}_{self.config.epnum:02d}_{self.suffix}.mkv",
|
if self._mux(f"{self.config.title.lower()}_{self.config.epnum:02d}_{self.suffix}.mkv",
|
||||||
not args.no_chapters and start == 0 and end == self.clip.num_frames) != 0:
|
start == 0 and end == self.clip.num_frames) != 0:
|
||||||
raise Exception("mkvmerge failed")
|
raise Exception("mkvmerge failed")
|
||||||
except Exception:
|
except Exception:
|
||||||
log.error("--- MUXING FAILED ---")
|
log.error("--- MUXING FAILED ---")
|
||||||
@ -300,3 +309,25 @@ class SelfRunner():
|
|||||||
|
|
||||||
print("+ " + " ".join(mkvtoolnix_args))
|
print("+ " + " ".join(mkvtoolnix_args))
|
||||||
return subprocess.call(mkvtoolnix_args)
|
return subprocess.call(mkvtoolnix_args)
|
||||||
|
|
||||||
|
|
||||||
|
def gencomp(num: int = 10, path: str = "comp", matrix: str = "709", **clips: vs.VideoNode) -> None:
|
||||||
|
lens = set(c.num_frames for c in clips.values())
|
||||||
|
if len(lens) != 1:
|
||||||
|
raise ValueError("gencomp: 'Clips must be equal length!'")
|
||||||
|
|
||||||
|
frames = random.sample(range(lens.pop()), num)
|
||||||
|
|
||||||
|
if os.path.exists(path):
|
||||||
|
shutil.rmtree(path)
|
||||||
|
|
||||||
|
os.makedirs(path)
|
||||||
|
|
||||||
|
for name, clip in clips.items():
|
||||||
|
log.status(f"Rendering clip {name}")
|
||||||
|
splice = clip[frames[0]]
|
||||||
|
for f in frames[1:]:
|
||||||
|
splice += clip[f]
|
||||||
|
splice = splice.resize.Bicubic(format=vs.RGB24, matrix_in_s=matrix) \
|
||||||
|
.imwri.Write("PNG", os.path.join(path, f"{name}%0{len(str(num))}d.png"))
|
||||||
|
[splice.get_frame(f) for f in range(splice.num_frames)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user