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
From cb04c950d48ac7c7fa9b95b3c39d9a8fb6c5bae0 Mon Sep 17 00:00:00 2001
From: tassaron
Date: Thu, 18 May 2017 19:54:48 -0400
Subject: added back in spaces deleted by my editor
---
core.py | 7 +++----
video_thread.py | 4 ++--
2 files changed, 5 insertions(+), 6 deletions(-)
(limited to 'video_thread.py')
diff --git a/core.py b/core.py
index ea17edf..8fd95f9 100644
--- a/core.py
+++ b/core.py
@@ -56,9 +56,8 @@ class Core():
im = im.resize((1280, 720), Image.ANTIALIAS)
self._image = ImageQt(im)
-
+
self._image1 = QtGui.QImage(self._image)
-
painter = QPainter(self._image1)
font = titleFont
font.setPointSizeF(fontSize)
@@ -97,7 +96,7 @@ class Core():
imBottom = imTop.transpose(Image.FLIP_TOP_BOTTOM)
-
+
im = Image.new("RGB", (1280, 720), "black")
im.paste(image, (0, 0))
im.paste(imTop, (0, 0), mask=imTop)
@@ -114,7 +113,7 @@ class Core():
'-ac', '1', # mono (set to '2' for stereo)
'-']
in_pipe = sp.Popen(command, stdout=sp.PIPE, stderr=sp.DEVNULL, bufsize=10**8)
-
+
completeAudioArray = numpy.empty(0, dtype="int16")
while True:
diff --git a/video_thread.py b/video_thread.py
index 6bad504..1c466fc 100644
--- a/video_thread.py
+++ b/video_thread.py
@@ -40,7 +40,7 @@ class Worker(QtCore.QObject):
imBackground = None
self.progressBarUpdate.emit(0)
-
+
completeAudioArray = self.core.readAudioFile(inputFile)
# test if user has libfdk_aac
@@ -72,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)
--
cgit v1.2.3
From e77199219521ab819730574c17a819c7e2bfe84d Mon Sep 17 00:00:00 2001
From: tassaron
Date: Sun, 21 May 2017 22:44:48 -0400
Subject: more loading feedback
---
main.py | 4 ++++
main.ui | 5 ++++-
video_thread.py | 15 ++++++++++-----
3 files changed, 18 insertions(+), 6 deletions(-)
(limited to 'video_thread.py')
diff --git a/main.py b/main.py
index 69a01dd..ac7acbc 100644
--- a/main.py
+++ b/main.py
@@ -147,6 +147,7 @@ class Main(QtCore.QObject):
self.videoWorker.moveToThread(self.videoThread)
self.videoWorker.videoCreated.connect(self.videoCreated)
self.videoWorker.progressBarUpdate.connect(self.progressBarUpdated)
+ self.videoWorker.progressBarSetText.connect(self.progressBarSetText)
self.videoThread.start()
self.videoTask.emit(self.window.label_background.text(),
@@ -163,6 +164,9 @@ class Main(QtCore.QObject):
def progressBarUpdated(self, value):
self.window.progressBar_create.setValue(value)
+ def progressBarSetText(self, value):
+ self.window.progressBar_create.setFormat(value)
+
def videoCreated(self):
self.videoThread.quit()
self.videoThread.wait()
diff --git a/main.ui b/main.ui
index 5b71d1c..c500905 100644
--- a/main.ui
+++ b/main.ui
@@ -386,7 +386,10 @@
24
- false
+ true
+
+
+ Qt::AlignCenter
diff --git a/video_thread.py b/video_thread.py
index 1c466fc..bd832be 100644
--- a/video_thread.py
+++ b/video_thread.py
@@ -11,6 +11,7 @@ class Worker(QtCore.QObject):
videoCreated = pyqtSignal()
progressBarUpdate = pyqtSignal(int)
+ progressBarSetText = pyqtSignal(str)
def __init__(self, parent=None):
QtCore.QObject.__init__(self)
@@ -31,6 +32,10 @@ class Worker(QtCore.QObject):
xOffset,
yOffset)
+ progressBarValue = 0
+ self.progressBarUpdate.emit(progressBarValue)
+ self.progressBarSetText.emit('Loading background image…')
+
backgroundFrames = self.core.parseBaseImage(backgroundImage)
if len(backgroundFrames) < 2:
# the base image is not a video so we can draw it now
@@ -38,9 +43,8 @@ class Worker(QtCore.QObject):
else:
# base images will be drawn while drawing the audio bars
imBackground = None
-
- self.progressBarUpdate.emit(0)
-
+
+ self.progressBarSetText.emit('Loading audio file…')
completeAudioArray = self.core.readAudioFile(inputFile)
# test if user has libfdk_aac
@@ -79,9 +83,8 @@ class Worker(QtCore.QObject):
smoothConstantDown = 0.08
smoothConstantUp = 0.8
lastSpectrum = None
- progressBarValue = 0
sampleSize = 1470
-
+
numpy.seterr(divide='ignore')
bgI = 0
for i in range(0, len(completeAudioArray), sampleSize):
@@ -110,6 +113,7 @@ class Worker(QtCore.QObject):
if progressBarValue + 1 <= (i / len(completeAudioArray)) * 100:
progressBarValue = numpy.floor((i / len(completeAudioArray)) * 100)
self.progressBarUpdate.emit(progressBarValue)
+ self.progressBarSetText.emit('%s%%' % str(int(progressBarValue)))
numpy.seterr(all='print')
@@ -121,4 +125,5 @@ class Worker(QtCore.QObject):
out_pipe.wait()
print("Video file created")
self.progressBarUpdate.emit(100)
+ self.progressBarSetText.emit('100%')
self.videoCreated.emit()
--
cgit v1.2.3