08.10.2023, 10:42
The following script is working
but because I commented "ctypes.memmove" so that the pipe is not used. I think that the problems are:
1) the buffersize should be increased to allow the encoder to encode at least some seconds of movie
2) I'm not sure the copy of plane is correct
I'm working on these issues...
import vapoursynth as vs
from vapoursynth import core
import subprocess
import ctypes
ffmpeg = r'E:\VideoTest\TestSubs\ffmpeg.exe'
NVEnc = r'E:\VideoTest\TestSubs\NVEncC64.exe'
source_path=r'E:\VideoTest\TestSubs\TestVideo.mp4'
# Loading Plugins
core.std.LoadPlugin(path="E:/VideoTest/TestSubs/BestSource.dll") #from https://forum.doom9.org/showthread.php?t=184255
# source: 'TestVideo.mp4'
# current color space: YUV420P8, bit depth: 8, resolution: 1280x536, fps: 25, color matrix: 470bg, yuv luminance scale: limited, scanorder: progressive
# this clip is not not needed, just to get width and height get width and height
clip = core.bs.VideoSource(source="E:/VideoTest/TestSubs/TestVideo.mp4")
# 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
# set output frame rate to 25fps (progressive)
clip = core.std.AssumeFPS(clip=clip, fpsnum=25, fpsden=1)
#clip = core.std.BlankClip(clip)
w = clip.width
h = clip.height
Ysize = w * h
UVsize = w * h//4
frame_len = Ysize + 2*UVsize #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',
'--vpp-resize spline36',
'--output-res 720x304',
]
#command = [NVEnc, '--avhw','--input', source_path, '-c raw', '--lossless', '-output-csp yuv420', '--output-depth 8', '--output-format raw', '--output -']
command = [ ffmpeg, '--input', source_path,'-vcodec', 'rawvideo', '-pix_fmt', 'yuv420p', '-f', 'rawvideo', '-']
#core.log_message(2,' '.join(NVEnc_cmd))
pipe = subprocess.Popen(command, stdout = subprocess.PIPE, bufsize=frame_len)
def load_frame(n,f):
vs_frame = f.copy()
try:
#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()
but because I commented "ctypes.memmove" so that the pipe is not used. I think that the problems are:
1) the buffersize should be increased to allow the encoder to encode at least some seconds of movie
2) I'm not sure the copy of plane is correct
I'm working on these issues...