aboutsummaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorDH42017-06-07 12:00:35 -0500
committerDH42017-06-07 12:00:35 -0500
commitfed9481d9a43d6274a036b2e46908ebdb316b387 (patch)
tree0d3594b421b6e89dbaa0bdb9f880cfe045ee8944 /components
parente6beca94a383ab916baf294ec2d703a47b4117fc (diff)
parentc946133da99a3bb1bf3565a19a12c641c8f77ed9 (diff)
Merge branch 'feature-newgui' of github.com:djfun/audio-visualizer-python into feature-newgui
Diffstat (limited to 'components')
-rw-r--r--components/__base__.py10
-rw-r--r--components/video.py42
2 files changed, 32 insertions, 20 deletions
diff --git a/components/__base__.py b/components/__base__.py
index 94ac6f2..4fdf31f 100644
--- a/components/__base__.py
+++ b/components/__base__.py
@@ -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()
diff --git a/components/video.py b/components/video.py
index 67a96dd..b28b81e 100644
--- a/components/video.py
+++ b/components/video.py
@@ -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):