WolframRhodium / muvsfunc

Muonium's VapourSynth functions
75 stars 19 forks source link

Speedup with znedi3 and/or nnedi3cl? #31

Open Selur opened 3 years ago

Selur commented 3 years ago

Instead of just using normal nnedi3 would be nice if

WolframRhodium commented 3 years ago

Implemented by (https://github.com/WolframRhodium/muvsfunc/commit/35dcd8bd3ed1be785bc0fd2433d9971d6ae983ed). Now you may use your custom nnedi3 implementation via

import muvsfunc
muvsfunc.nnedi3 = core.znedi3.nnedi3

# ...
Selur commented 3 years ago

Works, thanks! 👍

Selur commented 3 years ago

Correction -> does not work, accidentally I also loaded the normal nnedi3.

# Imports
import os
import sys
import vapoursynth as vs
# getting Vapoursynth core
core = vs.core
# Import scripts folder
scriptPath = 'I:/Hybrid/64bit/vsscripts'
sys.path.append(os.path.abspath(scriptPath))
# Loading Plugins
core.std.LoadPlugin(path="I:/Hybrid/64bit/vsfilters/ResizeFilter/nnedi3/NNEDI3CL.dll")
core.std.LoadPlugin(path="I:/Hybrid/64bit/vsfilters/Support/fmtconv.dll")
core.std.LoadPlugin(path="I:/Hybrid/64bit/vsfilters/SourceFilter/LSmashSource/vslsmashsource.dll")
# Import scripts
import muvsfunc
# source: 'G:\TestClips&Co\files\Drone_rocky.mov'
# current color space: YUV420P8, bit depth: 8, resolution: 3840x2160, fps: 23.976, color matrix: 709, yuv luminance scale: limited, scanorder: progressive
# Loading G:\TestClips&Co\files\Drone_rocky.mov using LibavSMASHSource
clip = core.lsmas.LibavSMASHSource(source="G:/TestClips&Co/files/Drone_rocky.mov")
# making sure input color matrix is set as 709
clip = core.resize.Point(clip, matrix_in_s="709",range_s="limited")
# making sure frame rate is set to 23.976
clip = core.std.AssumeFPS(clip=clip, fpsnum=24000, fpsden=1001)
# Setting color range to TV (limited) range.
clip = core.std.SetFrameProp(clip=clip, prop="_ColorRange", intval=1)
original = clip
# Resizing: 3840x2160 -> 720x406
muvsfunc.nnedi3 = core.nnedi3cl.NNEDI3CL
clip = muvsfunc.SSIM_downsample(clip=clip, w=720, h=406, smooth=1, use_fmtc=True, gamma=False, fulls=False, fulld=False)
original = core.resize.Bicubic(clip=original, width=720, height=406)
# adjusting output color from: YUV420P8 to YUV420P10 for x265Model
clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, range_s="limited")
# adjusting for FilterView
if (original.format.id != clip.format.id):
  if (original.format.color_family == vs.RGB and clip.format.color_family != vs.RGB):
    original = core.resize.Bicubic(clip=original, format=clip.format.id, matrix_s="709", range_s="limited")
  elif (original.format.color_family == clip.format.color_family):
    original = core.resize.Bicubic(clip=original, format=clip.format.id, range_s="limited")
  else:
    original = core.resize.Bicubic(clip=original, format=clip.format.id, matrix_in_s="709", range_s="limited")
original = core.text.Text(clip=original,text="Original")
clip = core.text.Text(clip=clip,text="Filtered")
stacked = core.std.StackHorizontal([original,clip])
# set output frame rate to 23.976fps
stacked = core.std.AssumeFPS(clip=stacked, fpsnum=24000, fpsden=1001)
# Output
stacked.set_output()

returns:

Failed to evaluate the script:
Python exception: No attribute with the name nnedi3 exists. Did you mistype a plugin namespace?

Traceback (most recent call last):
  File "src\cython\vapoursynth.pyx", line 2242, in vapoursynth.vpy_evaluateScript
  File "src\cython\vapoursynth.pyx", line 2243, in vapoursynth.vpy_evaluateScript
  File "E:\Temp\tempPreviewVapoursynthFile18_03_07_079.vpy", line 15, in <module>
    import muvsfunc
  File "I:\Hybrid\64bit\vsscripts\muvsfunc.py", line 86, in <module>
    nnedi3: Callable[..., vs.VideoNode] = core.nnedi3.nnedi3
  File "src\cython\vapoursynth.pyx", line 1891, in vapoursynth._CoreProxy.__getattr__
  File "src\cython\vapoursynth.pyx", line 1754, in vapoursynth.Core.__getattr__
AttributeError: No attribute with the name nnedi3 exists. Did you mistype a plugin namespace?

line 86 in muvsfunc.py is:

nnedi3: Callable[..., vs.VideoNode] = core.nnedi3.nnedi3

same error happens with:

# Imports
import os
import sys
import vapoursynth as vs
# getting Vapoursynth core
core = vs.core
# Import scripts folder
scriptPath = 'I:/Hybrid/64bit/vsscripts'
sys.path.append(os.path.abspath(scriptPath))
# Loading Plugins
core.std.LoadPlugin(path="I:/Hybrid/64bit/vsfilters/ResizeFilter/nnedi3/vsznedi3.dll")
core.std.LoadPlugin(path="I:/Hybrid/64bit/vsfilters/Support/fmtconv.dll")
core.std.LoadPlugin(path="I:/Hybrid/64bit/vsfilters/SourceFilter/LSmashSource/vslsmashsource.dll")
# Import scripts
import muvsfunc
# source: 'G:\TestClips&Co\files\Drone_rocky.mov'
# current color space: YUV420P8, bit depth: 8, resolution: 3840x2160, fps: 23.976, color matrix: 709, yuv luminance scale: limited, scanorder: progressive
# Loading G:\TestClips&Co\files\Drone_rocky.mov using LibavSMASHSource
clip = core.lsmas.LibavSMASHSource(source="G:/TestClips&Co/files/Drone_rocky.mov")
# making sure input color matrix is set as 709
clip = core.resize.Point(clip, matrix_in_s="709",range_s="limited")
# making sure frame rate is set to 23.976
clip = core.std.AssumeFPS(clip=clip, fpsnum=24000, fpsden=1001)
# Setting color range to TV (limited) range.
clip = core.std.SetFrameProp(clip=clip, prop="_ColorRange", intval=1)
original = clip
# Resizing: 3840x2160 -> 720x406
muvsfunc.nnedi3 = core.znedi3.nnedi3
clip = muvsfunc.SSIM_downsample(clip=clip, w=720, h=406, smooth=1, use_fmtc=True, gamma=False, fulls=False, fulld=False)
original = core.resize.Bicubic(clip=original, width=720, height=406)
# adjusting output color from: YUV420P8 to YUV420P10 for x265Model
clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, range_s="limited")
# adjusting for FilterView
if (original.format.id != clip.format.id):
  if (original.format.color_family == vs.RGB and clip.format.color_family != vs.RGB):
    original = core.resize.Bicubic(clip=original, format=clip.format.id, matrix_s="709", range_s="limited")
  elif (original.format.color_family == clip.format.color_family):
    original = core.resize.Bicubic(clip=original, format=clip.format.id, range_s="limited")
  else:
    original = core.resize.Bicubic(clip=original, format=clip.format.id, matrix_in_s="709", range_s="limited")
original = core.text.Text(clip=original,text="Original")
clip = core.text.Text(clip=clip,text="Filtered")
stacked = core.std.StackHorizontal([original,clip])
# set output frame rate to 23.976fps
stacked = core.std.AssumeFPS(clip=stacked, fpsnum=24000, fpsden=1001)
# Output
stacked.set_output()
Selur commented 3 years ago

even using:

# Imports
import os
import sys
import vapoursynth as vs
# getting Vapoursynth core
core = vs.core
# Import scripts folder
scriptPath = 'I:/Hybrid/64bit/vsscripts'
sys.path.append(os.path.abspath(scriptPath))
# Loading Plugins
core.std.LoadPlugin(path="I:/Hybrid/64bit/vsfilters/ResizeFilter/nnedi3/NNEDI3CL.dll")
core.std.LoadPlugin(path="I:/Hybrid/64bit/vsfilters/SourceFilter/LSmashSource/vslsmashsource.dll")

clip = core.lsmas.LibavSMASHSource(source="G:/TestClips&Co/files/Drone_rocky.mov")

# Import scripts
import muvsfunc

muvsfunc.nnedi3 = core.nnedi3cl.NNEDI3CL
# Output
clip.set_output()

gives me:

Failed to evaluate the script:
Python exception: No attribute with the name nnedi3 exists. Did you mistype a plugin namespace?

Traceback (most recent call last):
  File "src\cython\vapoursynth.pyx", line 2242, in vapoursynth.vpy_evaluateScript
  File "src\cython\vapoursynth.pyx", line 2243, in vapoursynth.vpy_evaluateScript
  File "E:\Temp\tempPreviewVapoursynthFile18_36_20_084.vpy", line 17, in <module>
    import muvsfunc
  File "I:\Hybrid\64bit\vsscripts\muvsfunc.py", line 86, in <module>
    nnedi3: Callable[..., vs.VideoNode] = core.nnedi3.nnedi3
  File "src\cython\vapoursynth.pyx", line 1891, in vapoursynth._CoreProxy.__getattr__
  File "src\cython\vapoursynth.pyx", line 1754, in vapoursynth.Core.__getattr__
AttributeError: No attribute with the name nnedi3 exists. Did you mistype a plugin namespace?

seems like the Callable thing doesn't work as intended or I misunderstood how to use it. :)

WolframRhodium commented 3 years ago

The script assumes that vanilla nnedi3 is installed. It can be lifted if that is not desired. Anyway your script seems not using nnedi3 and it won't benefit from the change.

Selur commented 3 years ago

Okay, I get what you mean, so I have to load nnedi3 even it it's not used.

Anyway your script seems not using nnedi3 and it won't benefit from the change.

you are right SSIM_downsample does use nnedi3_resample GammaToLinear and LinearToGamma but those don't even use nnedi3. :) (Silly me, didn't look into the functions. :) )