From a07dd6a54c0faf12770828f49e13d115bf3c2974 Mon Sep 17 00:00:00 2001 From: TNTwise Date: Fri, 11 Oct 2024 20:39:12 -0500 Subject: [PATCH] fix ncnn scdetect --- backend/src/InterpolateNCNN.py | 11 ++++++++++- backend/src/RenderVideo.py | 12 ++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/backend/src/InterpolateNCNN.py b/backend/src/InterpolateNCNN.py index d994c5c4..003440e2 100644 --- a/backend/src/InterpolateNCNN.py +++ b/backend/src/InterpolateNCNN.py @@ -1,4 +1,4 @@ -from rife_ncnn_vulkan_python import Rife +from rife_ncnn_vulkan_python import Rife, wrapped from time import sleep @@ -41,5 +41,14 @@ def process(self, img0, img1, timestep) -> bytes: frame = self.render.process_bytes(img0, img1, timestep) return frame + def normFrame(self,frame:bytes): + return frame + frame = bytearray(frame) + frame = wrapped.Image( + frame, self.width, self.height, 3 + ) + return frame + def uncacheFrame(self): + return self.render.uncache_frame() diff --git a/backend/src/RenderVideo.py b/backend/src/RenderVideo.py index 40d8c1d1..e4c5d49f 100644 --- a/backend/src/RenderVideo.py +++ b/backend/src/RenderVideo.py @@ -105,6 +105,7 @@ def __init__( self.sharedMemoryID = sharedMemoryID self.trt_optimization_level = trt_optimization_level self.rife_trt_mode = rife_trt_mode + self.uncacheNextFrame = False # get video properties early self.getVideoProperties(inputFile) @@ -202,6 +203,13 @@ def renderInterpolate(self, frame, transition=False): img1=self.setupFrame1, timestep=timestep, ) + elif self.ncnn: + self.interpolate( + img0=self.setupFrame0, + img1=self.setupFrame1, + timestep=.5, + ) + self.writeQueue.put(frame) self.onEndOfInterpolateCall() @@ -220,7 +228,7 @@ def render(self): self.renderInterpolate(frame, self.scDetectFunc(frame)) else: self.renderInterpolate(frame, False) - + self.writeQueue.put(frame) else: sleep(1) @@ -307,7 +315,7 @@ def setupInterpolate(self): width=self.width, height=self.height, ) - self.frameSetupFunction = self.returnFrame + self.frameSetupFunction = interpolateRifeNCNN.normFrame self.undoSetup = interpolateRifeNCNN.uncacheFrame self.interpolate = interpolateRifeNCNN.process self.hotReload = interpolateRifeNCNN.hotReload