01.10.2023, 13:31
Hello Selur,
as you know NVEnc is an encoder that includes a lot of GPU optimized filters.
It could be useful to have the possibility to view the preview of these filters.
Unfortunately being included in the encoder is not possible to see them in the Vapoursynth preview window.
A workaround could be to write a script that provide the output of NVEnc.
I found few information on this topic in internet and the only one that I consider useful is in this post: https://forum.doom9.org/showthread.php?t=165771&page=203
I tried to adapt the script to NVEnc and I wrote the following code
Unfortunately the result is not very good, I think the the problem is related to the wrong computation of: Ysize, UVsize
You can download the complete example here: https://filebin.net/sotms5i2chuhw6mo
I hope that you are able to fix it.
Thanks,
Dan
as you know NVEnc is an encoder that includes a lot of GPU optimized filters.
It could be useful to have the possibility to view the preview of these filters.
Unfortunately being included in the encoder is not possible to see them in the Vapoursynth preview window.
A workaround could be to write a script that provide the output of NVEnc.
I found few information on this topic in internet and the only one that I consider useful is in this post: https://forum.doom9.org/showthread.php?t=165771&page=203
I tried to adapt the script to NVEnc and I wrote the following code
Code:
import vapoursynth as vs
from vapoursynth import core
import subprocess
import ctypes
NVEnc = r'E:\VideoTest\TestSubs\NVEncC64.exe'
source_path=r'E:\VideoTest\TestSubs\TestSubs-1.mp4'
# Loading Plugins
core.std.LoadPlugin(path="D:/Programs/Hybrid/64bit/vsfilters/SourceFilter/LSmashSource/vslsmashsource.dll")
# current color space: YUV420P10, bit depth: 10, resolution: 1920x800, fps: 25, color matrix: 470bg, yuv luminance scale: limited, scanorder: progressive
# Loading E:\VideoTest\TestSubs\TestSubs-1.mp4 using LWLibavSource
clip = core.lsmas.LWLibavSource(source="E:/VideoTest/TestSubs/TestSubs-1.mp4", format="YUV420P8", stream_index=0, cache=0, fpsnum=25, prefer_hw=0) #this clip is not not needed, just to get width and height
# Setting detected color matrix (470bg).
clip = core.std.SetFrameProps(clip, _Matrix=5)
# Setting color transfer info (470bg), when it is not set
clip = clip if not core.text.FrameProps(clip,'_Transfer') else core.std.SetFrameProps(clip, _Transfer=5)
# Setting color primaries info (BT.709), when it is not set
clip = clip if not core.text.FrameProps(clip,'_Primaries') else core.std.SetFrameProps(clip, _Primaries=1)
# Setting color range to TV (limited) range.
clip = core.std.SetFrameProp(clip=clip, prop="_ColorRange", intval=1)
# making sure frame rate is set to 25
clip = core.std.AssumeFPS(clip=clip, fpsnum=25, fpsden=1)
clip = core.std.SetFrameProp(clip=clip, prop="_FieldBased", intval=0) # progressive
# adjusting output color from: YUV420P8 to YUV420P10 for x265Model
clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, range_s="limited")
# set output frame rate to 25fps (progressive)
clip = core.std.AssumeFPS(clip=clip, fpsnum=25, fpsden=1)
clipB = core.std.BlankClip(clip)
w = clip.width
h = clip.height
Ysize = w * h
UVsize = w * h//4
frame_len = w * h * 3 // 2 #YUV420
nvenc_filters = [
'--vpp-pmd apply_count=3,strength=100,threshold=100',
'--vpp-unsharp radius=4,weight=0.5,threshold=10',
'--vpp-smooth quality=4,qp=60,prec=fp32',
'--vpp-tweak brightness=0.01,contrast=1.01,gamma=0.98,saturation=1.35,hue=-2,swapuv=false',
'--vpp-deband range=15,sample=1,thre=15,dither=15,seed=1234,blurfirst=off,rand_each_frame=off',
]
NVEnc_cmd = [NVEnc,
'--avhw',
'--input', source_path,
'--lossless',
'--output-format raw',
'--output -', # output pipe
]
core.log_message(2,' '.join(NVEnc_cmd))
pipe = subprocess.Popen(NVEnc_cmd, stdout = subprocess.PIPE, bufsize=frame_len)
def load_frame(n,f):
try:
vs_frame = f.copy()
for i, size in enumerate([Ysize, UVsize, UVsize]):
ctypes.memmove(vs_frame.get_write_ptr(i), pipe.stdout.read(size), size)
pipe.stdout.flush()
except Exception as e:
raise ValueError(repr(e))
return vs_frame
try:
clip = core.std.ModifyFrame(clip, clip, load_frame)
except ValueError as e:
pipe.terminate()
print(e)
clip.set_output()
Unfortunately the result is not very good, I think the the problem is related to the wrong computation of: Ysize, UVsize
You can download the complete example here: https://filebin.net/sotms5i2chuhw6mo
I hope that you are able to fix it.
Thanks,
Dan