changed video init to use keywords
This commit is contained in:
parent
231af74ea2
commit
c946133da9
|
@ -84,3 +84,13 @@ class Component:
|
|||
def reset(self):
|
||||
self.canceled = False
|
||||
'''
|
||||
|
||||
class BadComponentInit(Exception):
|
||||
def __init__(self, arg, name):
|
||||
string = \
|
||||
'''################################
|
||||
Mandatory argument "%s" not specified
|
||||
in %s instance initialization
|
||||
###################################'''
|
||||
print(string % (arg, name))
|
||||
quit()
|
||||
|
|
|
@ -5,37 +5,38 @@ import subprocess
|
|||
import threading
|
||||
from queue import PriorityQueue
|
||||
from . import __base__
|
||||
|
||||
|
||||
|
||||
class Video:
|
||||
'''Video Component Frame-Fetcher'''
|
||||
def __init__(
|
||||
self, ffmpeg, videoPath, width, height,
|
||||
frameRate, chunkSize, parent, loopVideo):
|
||||
def __init__(self, **kwargs):
|
||||
mandatoryArgs = ['ffmpeg', 'videoPath', 'width', 'height',
|
||||
'frameRate', 'chunkSize', 'parent']
|
||||
for arg in mandatoryArgs:
|
||||
try:
|
||||
exec('self.%s = kwargs[arg]' % arg)
|
||||
except KeyError:
|
||||
raise __base__.BadComponentInit(arg, self.__doc__)
|
||||
|
||||
self.parent = parent
|
||||
self.chunkSize = chunkSize
|
||||
self.size = (width, height)
|
||||
self.frameNo = -1
|
||||
self.currentFrame = 'None'
|
||||
if loopVideo:
|
||||
if 'loopVideo' in kwargs and kwargs['loopVideo']:
|
||||
self.loopValue = '-1'
|
||||
else:
|
||||
self.loopValue = '0'
|
||||
self.command = [
|
||||
ffmpeg,
|
||||
self.ffmpeg,
|
||||
'-thread_queue_size', '512',
|
||||
'-r', frameRate,
|
||||
'-r', str(self.frameRate),
|
||||
'-stream_loop', self.loopValue,
|
||||
'-i', videoPath,
|
||||
'-i', self.videoPath,
|
||||
'-f', 'image2pipe',
|
||||
'-pix_fmt', 'rgba',
|
||||
'-filter:v', 'scale='+str(width)+':'+str(height),
|
||||
'-filter:v', 'scale='+str(self.width)+':'+str(self.height),
|
||||
'-vcodec', 'rawvideo', '-',
|
||||
]
|
||||
|
||||
self.frameBuffer = PriorityQueue()
|
||||
self.frameBuffer.maxsize = int(frameRate)
|
||||
self.frameBuffer.maxsize = self.frameRate
|
||||
self.finishedFrames = {}
|
||||
|
||||
self.thread = threading.Thread(
|
||||
|
@ -49,13 +50,13 @@ class Video:
|
|||
while True:
|
||||
if num in self.finishedFrames:
|
||||
image = self.finishedFrames.pop(num)
|
||||
return Image.frombytes('RGBA', self.size, image)
|
||||
return Image.frombytes('RGBA', (self.width, self.height), image)
|
||||
i, image = self.frameBuffer.get()
|
||||
self.finishedFrames[i] = image
|
||||
self.frameBuffer.task_done()
|
||||
|
||||
def fillBuffer(self):
|
||||
self.pipe = subprocess.Popen(
|
||||
pipe = subprocess.Popen(
|
||||
self.command, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.DEVNULL, bufsize=10**8
|
||||
)
|
||||
|
@ -69,7 +70,7 @@ class Video:
|
|||
self.frameBuffer.put((self.frameNo-1, self.lastFrame))
|
||||
continue
|
||||
|
||||
self.currentFrame = self.pipe.stdout.read(self.chunkSize)
|
||||
self.currentFrame = pipe.stdout.read(self.chunkSize)
|
||||
if len(self.currentFrame) != 0:
|
||||
self.frameBuffer.put((self.frameNo, self.currentFrame))
|
||||
self.lastFrame = self.currentFrame
|
||||
|
@ -117,9 +118,10 @@ class Component(__base__.Component):
|
|||
height = int(self.worker.core.settings.value('outputHeight'))
|
||||
self.chunkSize = 4*width*height
|
||||
self.video = Video(
|
||||
self.parent.core.FFMPEG_BIN, self.videoPath,
|
||||
width, height, self.settings.value("outputFrameRate"),
|
||||
self.chunkSize, self.parent, self.loopVideo
|
||||
ffmpeg=self.parent.core.FFMPEG_BIN, videoPath=self.videoPath,
|
||||
width=width, height=height, chunkSize=self.chunkSize,
|
||||
frameRate=int(self.settings.value("outputFrameRate")),
|
||||
parent=self.parent, loopVideo=self.loopVideo
|
||||
)
|
||||
|
||||
def frameRender(self, moduleNo, arrayNo, frameNo):
|
||||
|
|
Reference in New Issue