From ff818836dd2221c544afe1fcc17369b17f90b0db Mon Sep 17 00:00:00 2001 From: tassaron Date: Thu, 18 May 2017 19:14:27 -0400 Subject: added ability to use an mp4 as the background might not be the best way to do this (dumping all the video frames to a temp location), but it works for clips of a few minutes or less --- video_thread.py | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'video_thread.py') diff --git a/video_thread.py b/video_thread.py index 1d1d44b..6bad504 100644 --- a/video_thread.py +++ b/video_thread.py @@ -21,18 +21,26 @@ class Worker(QtCore.QObject): @pyqtSlot(str, str, QtGui.QFont, int, int, int, int, str, str) def createVideo(self, backgroundImage, titleText, titleFont, fontSize, alignment, xOffset, yOffset, inputFile, outputFile): # print('worker thread id: {}'.format(QtCore.QThread.currentThreadId())) - - imBackground = self.core.drawBaseImage( - backgroundImage, - titleText, - titleFont, - fontSize, - alignment, - xOffset, - yOffset) + def getBackgroundAtIndex(i): + return self.core.drawBaseImage( + backgroundFrames[i], + titleText, + titleFont, + fontSize, + alignment, + xOffset, + yOffset) + + backgroundFrames = self.core.parseBaseImage(backgroundImage) + if len(backgroundFrames) < 2: + # the base image is not a video so we can draw it now + imBackground = getBackgroundAtIndex(0) + else: + # base images will be drawn while drawing the audio bars + imBackground = None self.progressBarUpdate.emit(0) - + completeAudioArray = self.core.readAudioFile(inputFile) # test if user has libfdk_aac @@ -64,7 +72,7 @@ class Worker(QtCore.QObject): ffmpegCommand.append('-2') ffmpegCommand.append(outputFile) - + out_pipe = sp.Popen(ffmpegCommand, stdin=sp.PIPE,stdout=sys.stdout, stderr=sys.stdout) @@ -75,7 +83,7 @@ class Worker(QtCore.QObject): sampleSize = 1470 numpy.seterr(divide='ignore') - + bgI = 0 for i in range(0, len(completeAudioArray), sampleSize): # create video for output lastSpectrum = self.core.transformData( @@ -85,7 +93,12 @@ class Worker(QtCore.QObject): smoothConstantDown, smoothConstantUp, lastSpectrum) - im = self.core.drawBars(lastSpectrum, imBackground) + if imBackground != None: + im = self.core.drawBars(lastSpectrum, imBackground) + else: + im = self.core.drawBars(lastSpectrum, getBackgroundAtIndex(bgI)) + if bgI < len(backgroundFrames)-1: + bgI += 1 # write to out_pipe try: -- cgit v1.2.3