Performance Tuning. FIXME: Video component frames are rendered out of order. Video component creates a severe performance bottleneck.

This commit is contained in:
DH4 2017-06-05 04:54:58 -05:00
parent e58a1d0b2d
commit be18deece5
3 changed files with 22 additions and 23 deletions

View File

@ -36,8 +36,6 @@ class Component(__base__.Component):
frame = Image.new("RGBA", (self.width, self.height), (0, 0, 0, 0)) frame = Image.new("RGBA", (self.width, self.height), (0, 0, 0, 0))
if frame1: if frame1:
im = Image.open(frame1) im = Image.open(frame1)
self.realSize = im.size
im = self.resize(im)
frame.paste(im) frame.paste(im)
if not self.working: if not self.working:
self.staticFrame = frame self.staticFrame = frame
@ -61,11 +59,9 @@ class Component(__base__.Component):
return self.staticFrame return self.staticFrame
# make a new frame # make a new frame
width, height = self.realSize width = self.width
image = numpy.fromstring(byteFrame, dtype='uint8') height = self.height
image = image.reshape((width, height, 4)) image = Image.frombytes('RGBA', (width, height), byteFrame)
image = Image.frombytes('RGBA', (width, height), image, 'raw', 'RGBa')
image = self.resize(image)
self.staticFrame = image self.staticFrame = image
return self.staticFrame return self.staticFrame
@ -80,7 +76,7 @@ class Component(__base__.Component):
def pickVideo(self): def pickVideo(self):
imgDir = self.settings.value("backgroundDir", os.path.expanduser("~")) imgDir = self.settings.value("backgroundDir", os.path.expanduser("~"))
filename = QtGui.QFileDialog.getOpenFileName(self.page, filename = QtGui.QFileDialog.getOpenFileName(self.page,
"Choose Video", imgDir, "Video Files (*.mp4)") "Choose Video", imgDir, "Video Files (*.mp4 *.mov)")
if filename: if filename:
self.settings.setValue("backgroundDir", os.path.dirname(filename)) self.settings.setValue("backgroundDir", os.path.dirname(filename))
self.page.lineEdit_video.setText(filename) self.page.lineEdit_video.setText(filename)
@ -97,10 +93,11 @@ class Component(__base__.Component):
# get a preview frame # get a preview frame
subprocess.call( \ subprocess.call( \
'%s -i "%s" -y %s "%s"' % ( \ '%s -i "%s" -y %s %s "%s"' % ( \
self.parent.core.FFMPEG_BIN, self.parent.core.FFMPEG_BIN,
self.videoPath, self.videoPath,
'-ss 10 -vframes 1', '-ss 10 -vframes 1',
'-filter:v scale='+str(self.width)+':'+str(self.height),
os.path.join(self.parent.core.tempDir, filename) os.path.join(self.parent.core.tempDir, filename)
), ),
shell=True shell=True
@ -114,16 +111,18 @@ class Component(__base__.Component):
command = [ command = [
self.parent.core.FFMPEG_BIN, self.parent.core.FFMPEG_BIN,
'-thread_queue_size', '512',
'-i', self.videoPath, '-i', self.videoPath,
'-f', 'image2pipe', '-f', 'image2pipe',
'-pix_fmt', 'rgba', '-pix_fmt', 'rgba',
'-filter:v', 'scale='+str(self.width)+':'+str(self.height),
'-vcodec', 'rawvideo', '-', '-vcodec', 'rawvideo', '-',
] ]
# pipe in video frames from ffmpeg # pipe in video frames from ffmpeg
in_pipe = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, bufsize=10**8) in_pipe = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, bufsize=10**8)
width, height = self.realSize #width, height = self.realSize
self.chunkSize = 4*width*height self.chunkSize = 4*self.width*self.height
return in_pipe return in_pipe

View File

@ -243,7 +243,7 @@ class Main(QtCore.QObject):
inputDir = self.settings.value("inputDir", expanduser("~")) inputDir = self.settings.value("inputDir", expanduser("~"))
fileName = QtGui.QFileDialog.getOpenFileName(self.window, fileName = QtGui.QFileDialog.getOpenFileName(self.window,
"Open Music File", inputDir, "Music Files (*.mp3 *.wav *.ogg *.flac)"); "Open Music File", inputDir, "Music Files (*.mp3 *.wav *.ogg *.fla *.aac)");
if not fileName == "": if not fileName == "":
self.settings.setValue("inputDir", os.path.dirname(fileName)) self.settings.setValue("inputDir", os.path.dirname(fileName))
@ -253,7 +253,7 @@ class Main(QtCore.QObject):
outputDir = self.settings.value("outputDir", expanduser("~")) outputDir = self.settings.value("outputDir", expanduser("~"))
fileName = QtGui.QFileDialog.getSaveFileName(self.window, fileName = QtGui.QFileDialog.getSaveFileName(self.window,
"Set Output Video File", outputDir, "Video Files (*.mkv *.mp4)"); "Set Output Video File", outputDir, "Video Files (*.mp4 *.mov *.mkv *.avi *.webm *.flv)");
if not fileName == "": if not fileName == "":
self.settings.setValue("outputDir", os.path.dirname(fileName)) self.settings.setValue("outputDir", os.path.dirname(fileName))

View File

@ -37,20 +37,19 @@ class Worker(QtCore.QObject):
def renderNode(self): def renderNode(self):
while not self.stopped: while not self.stopped:
i = self.compositeQueue.get() i = self.compositeQueue.get()
frame = None
frame = Image.new(
"RGBA",
(self.width, self.height),
(0, 0, 0, 0)
)
for compNo, comp in reversed(list(enumerate(self.components))): for compNo, comp in reversed(list(enumerate(self.components))):
if compNo in self.staticComponents and self.staticComponents[compNo] != None: if compNo in self.staticComponents and self.staticComponents[compNo] != None:
frame = Image.alpha_composite(frame, self.staticComponents[compNo]) if frame is None:
frame = self.staticComponents[compNo]
else:
frame = Image.alpha_composite(frame, self.staticComponents[compNo])
else: else:
frame = Image.alpha_composite(frame, comp.frameRender(compNo, i[0], i[1])) if frame is None:
frame = comp.frameRender(compNo, i[0], i[1])
# frame.paste(compFrame, mask=compFrame) else:
frame = Image.alpha_composite(frame, comp.frameRender(compNo, i[0], i[1]))
self.renderQueue.put([i[0], frame]) self.renderQueue.put([i[0], frame])
self.compositeQueue.task_done() self.compositeQueue.task_done()
@ -98,6 +97,7 @@ class Worker(QtCore.QObject):
ffmpegCommand = [ ffmpegCommand = [
self.core.FFMPEG_BIN, self.core.FFMPEG_BIN,
'-thread_queue_size', '512',
'-y', # (optional) means overwrite the output file if it already exists. '-y', # (optional) means overwrite the output file if it already exists.
'-f', 'rawvideo', '-f', 'rawvideo',
'-vcodec', 'rawvideo', '-vcodec', 'rawvideo',