diff --git a/core.py b/core.py
index 92d5421..900a98f 100644
--- a/core.py
+++ b/core.py
@@ -42,7 +42,8 @@ def parseBaseImage(self, backgroundImage, preview=False):
else:
return self.getVideoFrames(backgroundImage, preview)
- def drawBaseImage(self, backgroundFile, titleText, titleFont, fontSize, alignment, xOffset, yOffset):
+ def drawBaseImage(self, backgroundFile, titleText, titleFont, fontSize, alignment,\
+ xOffset, yOffset, textColor, visColor):
if backgroundFile == '':
im = Image.new("RGB", (1280, 720), "black")
else:
@@ -62,7 +63,7 @@ def drawBaseImage(self, backgroundFile, titleText, titleFont, fontSize, alignmen
font = titleFont
font.setPixelSize(fontSize)
painter.setFont(font)
- painter.setPen(QColor(255, 255, 255))
+ painter.setPen(QColor(*textColor))
yPosition = yOffset
@@ -86,13 +87,15 @@ def drawBaseImage(self, backgroundFile, titleText, titleFont, fontSize, alignmen
strio.seek(0)
return Image.open(strio)
- def drawBars(self, spectrum, image):
+ def drawBars(self, spectrum, image, color):
imTop = Image.new("RGBA", (1280, 360))
draw = ImageDraw.Draw(imTop)
+ r, g, b = color
+ color2 = (r, g, b, 50)
for j in range(0, 63):
- draw.rectangle((10 + j * 20, 325, 10 + j * 20 + 20, 325 - spectrum[j * 4] * 1 - 10), fill=(255, 255, 255, 50))
- draw.rectangle((15 + j * 20, 320, 15 + j * 20 + 10, 320 - spectrum[j * 4] * 1), fill="white")
+ draw.rectangle((10 + j * 20, 325, 10 + j * 20 + 20, 325 - spectrum[j * 4] * 1 - 10), fill=color2)
+ draw.rectangle((15 + j * 20, 320, 15 + j * 20 + 10, 320 - spectrum[j * 4] * 1), fill=color)
imBottom = imTop.transpose(Image.FLIP_TOP_BOTTOM)
@@ -191,3 +194,17 @@ def getVideoFrames(self, videoPath, firstOnly=False):
shell=True
)
return sorted([os.path.join(self.tempDir, f) for f in os.listdir(self.tempDir)])
+
+ @staticmethod
+ def RGBFromString(string):
+ ''' turns an RGB string like "255, 255, 255" into a tuple '''
+ try:
+ tup = tuple([int(i) for i in string.split(',')])
+ if len(tup) != 3:
+ raise ValueError
+ for i in tup:
+ if i > 255 or i < 0:
+ raise ValueError
+ return tup
+ except:
+ return (255, 255, 255)
diff --git a/main.py b/main.py
index 163ec3b..9f608d8 100644
--- a/main.py
+++ b/main.py
@@ -15,7 +15,7 @@
class Command(QtCore.QObject):
- videoTask = QtCore.pyqtSignal(str, str, QFont, int, int, int, int, str, str)
+ videoTask = QtCore.pyqtSignal(str, str, QFont, int, int, int, int, tuple, tuple, str, str)
def __init__(self):
QtCore.QObject.__init__(self)
@@ -28,12 +28,24 @@ def __init__(self):
self.parser.add_argument('-t', '--text', dest='text', help='title text', required=True)
self.parser.add_argument('-f', '--font', dest='font', help='title font', required=False)
self.parser.add_argument('-s', '--fontsize', dest='fontsize', help='title font size', required=False)
+ self.parser.add_argument('-c', '--textcolor', dest='textcolor', help='title text color in r,g,b format', required=False)
+ self.parser.add_argument('-C', '--viscolor', dest='viscolor', help='visualization color in r,g,b format', required=False)
self.parser.add_argument('-x', '--xposition', dest='xposition', help='x position', required=False)
self.parser.add_argument('-y', '--yposition', dest='yposition', help='y position', required=False)
self.parser.add_argument('-a', '--alignment', dest='alignment', help='title alignment', required=False, type=int, choices=[0, 1, 2])
self.args = self.parser.parse_args()
self.settings = QSettings('settings.ini', QSettings.IniFormat)
+
+ # load colours as tuples from comma-separated strings
+ self.textColor = core.Core.RGBFromString(self.settings.value("textColor", '255, 255, 255'))
+ self.visColor = core.Core.RGBFromString(self.settings.value("visColor", '255, 255, 255'))
+ if self.args.textcolor:
+ self.textColor = core.Core.RGBFromString(self.args.textcolor)
+ if self.args.viscolor:
+ self.visColor = core.Core.RGBFromString(self.args.viscolor)
+
+ # font settings
if self.args.font:
self.font = QFont(self.args.font)
else:
@@ -43,7 +55,6 @@ def __init__(self):
self.fontsize = int(self.args.fontsize)
else:
self.fontsize = int(self.settings.value("fontSize", 35))
-
if self.args.alignment:
self.alignment = int(self.args.alignment)
else:
@@ -75,6 +86,8 @@ def __init__(self):
self.alignment,
self.textX,
self.textY,
+ self.textColor,
+ self.visColor,
self.args.input,
self.args.output)
@@ -89,23 +102,27 @@ def cleanUp(self):
self.settings.setValue("fontSize", str(self.fontsize))
self.settings.setValue("xPosition", str(self.textX))
self.settings.setValue("yPosition", str(self.textY))
+ self.settings.setValue("visColor", '%s,%s,%s' % self.visColor)
+ self.settings.setValue("textColor", '%s,%s,%s' % self.textColor)
sys.exit(0)
class Main(QtCore.QObject):
- newTask = QtCore.pyqtSignal(str, str, QFont, int, int, int, int)
+ newTask = QtCore.pyqtSignal(str, str, QFont, int, int, int, int, tuple, tuple)
processTask = QtCore.pyqtSignal()
- videoTask = QtCore.pyqtSignal(str, str, QFont, int, int, int, int, str, str)
+ videoTask = QtCore.pyqtSignal(str, str, QFont, int, int, int, int, tuple, tuple, str, str)
def __init__(self, window):
-
QtCore.QObject.__init__(self)
# print('main thread id: {}'.format(QtCore.QThread.currentThreadId()))
self.window = window
self.core = core.Core()
-
self.settings = QSettings('settings.ini', QSettings.IniFormat)
+
+ # load colors as tuples from a comma-separated string
+ self.textColor = core.Core.RGBFromString(self.settings.value("textColor", '255, 255, 255'))
+ self.visColor = core.Core.RGBFromString(self.settings.value("visColor", '255, 255, 255'))
self.previewQueue = Queue()
@@ -133,8 +150,11 @@ def __init__(self, window):
window.pushButton_selectBackground.setText("Select Background Image")
window.label_font.setText("Title Font")
window.label_alignment.setText("Title Options")
+ window.label_colorOptions.setText("Colors")
window.label_fontsize.setText("Fontsize")
window.label_title.setText("Title Text")
+ window.label_textColor.setText("Text:")
+ window.label_visColor.setText("Visualizer:")
window.pushButton_createVideo.setText("Create Video")
window.groupBox_create.setTitle("Create")
window.groupBox_settings.setTitle("Settings")
@@ -146,6 +166,14 @@ def __init__(self, window):
window.fontsizeSpinBox.setValue(35)
window.textXSpinBox.setValue(70)
window.textYSpinBox.setValue(375)
+ window.lineEdit_textColor.setText('%s,%s,%s' % self.textColor)
+ window.lineEdit_visColor.setText('%s,%s,%s' % self.visColor)
+ window.pushButton_textColor.clicked.connect(lambda: self.pickColor('text'))
+ window.pushButton_visColor.clicked.connect(lambda: self.pickColor('vis'))
+ btnStyle = "QPushButton { background-color : %s; outline: none; }" % QColor(*self.textColor).name()
+ window.pushButton_textColor.setStyleSheet(btnStyle)
+ btnStyle = "QPushButton { background-color : %s; outline: none; }" % QColor(*self.visColor).name()
+ window.pushButton_visColor.setStyleSheet(btnStyle)
titleFont = self.settings.value("titleFont")
if not titleFont == None:
@@ -170,6 +198,8 @@ def __init__(self, window):
window.textXSpinBox.valueChanged.connect(self.drawPreview)
window.textYSpinBox.valueChanged.connect(self.drawPreview)
window.fontsizeSpinBox.valueChanged.connect(self.drawPreview)
+ window.lineEdit_textColor.textChanged.connect(self.drawPreview)
+ window.lineEdit_visColor.textChanged.connect(self.drawPreview)
self.drawPreview()
@@ -179,13 +209,14 @@ def cleanUp(self):
self.timer.stop()
self.previewThread.quit()
self.previewThread.wait()
-
+
self.settings.setValue("titleFont", self.window.fontComboBox.currentFont().toString())
self.settings.setValue("alignment", str(self.window.alignmentComboBox.currentIndex()))
self.settings.setValue("fontSize", str(self.window.fontsizeSpinBox.value()))
self.settings.setValue("xPosition", str(self.window.textXSpinBox.value()))
self.settings.setValue("yPosition", str(self.window.textYSpinBox.value()))
- sys.exit(0)
+ self.settings.setValue("visColor", self.window.lineEdit_visColor.text())
+ self.settings.setValue("textColor", self.window.lineEdit_textColor.text())
def openInputFileDialog(self):
inputDir = self.settings.value("inputDir", expanduser("~"))
@@ -237,6 +268,8 @@ def createAudioVisualisation(self):
self.window.alignmentComboBox.currentIndex(),
self.window.textXSpinBox.value(),
self.window.textYSpinBox.value(),
+ core.Core.RGBFromString(self.window.lineEdit_textColor.text()),
+ core.Core.RGBFromString(self.window.lineEdit_visColor.text()),
self.window.label_input.text(),
self.window.label_output.text())
@@ -258,7 +291,9 @@ def drawPreview(self):
self.window.fontsizeSpinBox.value(),
self.window.alignmentComboBox.currentIndex(),
self.window.textXSpinBox.value(),
- self.window.textYSpinBox.value())
+ self.window.textYSpinBox.value(),
+ core.Core.RGBFromString(self.window.lineEdit_textColor.text()),
+ core.Core.RGBFromString(self.window.lineEdit_visColor.text()))
# self.processTask.emit()
def showPreviewImage(self, image):
@@ -267,6 +302,18 @@ def showPreviewImage(self, image):
self.window.label_preview.setPixmap(self._previewPixmap)
+ def pickColor(self, colorTarget):
+ color = QtGui.QColorDialog.getColor()
+ if color.isValid():
+ RGBstring = '%s,%s,%s' % (str(color.red()), str(color.green()), str(color.blue()))
+ btnStyle = "QPushButton { background-color : %s; outline: none; }" % color.name()
+ if colorTarget == 'text':
+ self.window.lineEdit_textColor.setText(RGBstring)
+ window.pushButton_textColor.setStyleSheet(btnStyle)
+ elif colorTarget == 'vis':
+ self.window.lineEdit_visColor.setText(RGBstring)
+ window.pushButton_visColor.setStyleSheet(btnStyle)
+
if len(sys.argv) > 1:
# command line mode
app = QtGui.QApplication(sys.argv, False)
diff --git a/main.ui b/main.ui
index f18df44..c2892c5 100644
--- a/main.ui
+++ b/main.ui
@@ -336,7 +336,7 @@
-
-
-
+
200
@@ -364,12 +364,108 @@
-
-
+
+
+
+
+
+ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
+
+
+
+ -
+
+
+
+ 32
+ 32
+
+
+
+
+
+
+
+ 32
+ 32
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
+ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
+
+
+
+ -
+
+
+
+ 32
+ 32
+
+
+
+
+
+
+
+ 32
+ 32
+
+
+
+
+ -
+
+ -
+
+
-
+
+
+
+ 200
+ 0
+
+
+
+
+ 200
+ 16777215
+
+
+
+
+ 200
+ 0
+
+
+
+ QFrame::NoFrame
+
+
+
+
+
+
+ -
+
+
+
+
diff --git a/preview_thread.py b/preview_thread.py
index 5bad653..041d39e 100644
--- a/preview_thread.py
+++ b/preview_thread.py
@@ -19,8 +19,9 @@ def __init__(self, parent=None, queue=None):
self.queue = queue
- @pyqtSlot(str, str, QtGui.QFont, int, int, int, int)
- def createPreviewImage(self, backgroundImage, titleText, titleFont, fontSize, alignment, xOffset, yOffset):
+ @pyqtSlot(str, str, QtGui.QFont, int, int, int, int, tuple, tuple)
+ def createPreviewImage(self, backgroundImage, titleText, titleFont, fontSize,\
+ alignment, xOffset, yOffset, textColor, visColor):
# print('worker thread id: {}'.format(QtCore.QThread.currentThreadId()))
dic = {
"backgroundImage": backgroundImage,
@@ -29,7 +30,9 @@ def createPreviewImage(self, backgroundImage, titleText, titleFont, fontSize, al
"fontSize": fontSize,
"alignment": alignment,
"xoffset": xOffset,
- "yoffset": yOffset
+ "yoffset": yOffset,
+ "textColor" : textColor,
+ "visColor" : visColor
}
self.queue.put(dic)
@@ -59,11 +62,12 @@ def process(self):
nextPreviewInformation["fontSize"],
nextPreviewInformation["alignment"],
nextPreviewInformation["xoffset"],
- nextPreviewInformation["yoffset"])
-
+ nextPreviewInformation["yoffset"],
+ nextPreviewInformation["textColor"],
+ nextPreviewInformation["visColor"])
spectrum = numpy.fromfunction(lambda x: 0.008*(x-128)**2, (255,), dtype="int16")
- im = self.core.drawBars(spectrum, im)
+ im = self.core.drawBars(spectrum, im, nextPreviewInformation["visColor"])
self._image = ImageQt(im)
self._previewImage = QtGui.QImage(self._image)
diff --git a/video_thread.py b/video_thread.py
index bd832be..6f71d38 100644
--- a/video_thread.py
+++ b/video_thread.py
@@ -19,8 +19,9 @@ def __init__(self, parent=None):
self.core = core.Core()
- @pyqtSlot(str, str, QtGui.QFont, int, int, int, int, str, str)
- def createVideo(self, backgroundImage, titleText, titleFont, fontSize, alignment, xOffset, yOffset, inputFile, outputFile):
+ @pyqtSlot(str, str, QtGui.QFont, int, int, int, int, tuple, tuple, str, str)
+ def createVideo(self, backgroundImage, titleText, titleFont, fontSize, alignment,\
+ xOffset, yOffset, textColor, visColor, inputFile, outputFile):
# print('worker thread id: {}'.format(QtCore.QThread.currentThreadId()))
def getBackgroundAtIndex(i):
return self.core.drawBaseImage(
@@ -30,7 +31,9 @@ def getBackgroundAtIndex(i):
fontSize,
alignment,
xOffset,
- yOffset)
+ yOffset,
+ textColor,
+ visColor)
progressBarValue = 0
self.progressBarUpdate.emit(progressBarValue)
@@ -97,9 +100,9 @@ def getBackgroundAtIndex(i):
smoothConstantUp,
lastSpectrum)
if imBackground != None:
- im = self.core.drawBars(lastSpectrum, imBackground)
+ im = self.core.drawBars(lastSpectrum, imBackground, visColor)
else:
- im = self.core.drawBars(lastSpectrum, getBackgroundAtIndex(bgI))
+ im = self.core.drawBars(lastSpectrum, getBackgroundAtIndex(bgI), visColor)
if bgI < len(backgroundFrames)-1:
bgI += 1
@@ -124,6 +127,7 @@ def getBackgroundAtIndex(i):
# out_pipe.terminate() # don't terminate ffmpeg too early
out_pipe.wait()
print("Video file created")
+ self.core.deleteTempDir()
self.progressBarUpdate.emit(100)
self.progressBarSetText.emit('100%')
self.videoCreated.emit()