Merge branch 'tassaron2-master'
This commit is contained in:
commit
5487319dc1
27
core.py
27
core.py
|
@ -42,7 +42,8 @@ class Core():
|
|||
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 @@ class Core():
|
|||
font = titleFont
|
||||
font.setPixelSize(fontSize)
|
||||
painter.setFont(font)
|
||||
painter.setPen(QColor(255, 255, 255))
|
||||
painter.setPen(QColor(*textColor))
|
||||
|
||||
yPosition = yOffset
|
||||
|
||||
|
@ -86,13 +87,15 @@ class Core():
|
|||
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 @@ class Core():
|
|||
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)
|
||||
|
|
65
main.py
65
main.py
|
@ -15,7 +15,7 @@ import preview_thread, core, video_thread
|
|||
|
||||
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 @@ class Command(QtCore.QObject):
|
|||
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 @@ class Command(QtCore.QObject):
|
|||
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 @@ class Command(QtCore.QObject):
|
|||
self.alignment,
|
||||
self.textX,
|
||||
self.textY,
|
||||
self.textColor,
|
||||
self.visColor,
|
||||
self.args.input,
|
||||
self.args.output)
|
||||
|
||||
|
@ -89,23 +102,27 @@ class Command(QtCore.QObject):
|
|||
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 @@ class Main(QtCore.QObject):
|
|||
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 @@ class Main(QtCore.QObject):
|
|||
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 @@ class Main(QtCore.QObject):
|
|||
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 @@ class Main(QtCore.QObject):
|
|||
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 @@ class Main(QtCore.QObject):
|
|||
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 @@ class Main(QtCore.QObject):
|
|||
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 @@ class Main(QtCore.QObject):
|
|||
|
||||
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)
|
||||
|
|
100
main.ui
100
main.ui
|
@ -336,7 +336,7 @@
|
|||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_title">
|
||||
<widget class="QLabel" name="label_colorOptions">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
|
@ -364,12 +364,108 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_title"/>
|
||||
<widget class="QLabel" name="label_textColor">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_textColor">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="MaximumSize" stdset="0">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_textColor"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_visColor">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_visColor">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="MaximumSize" stdset="0">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_visColor"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_7">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_title">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="baseSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_title"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
@ -19,8 +19,9 @@ class Worker(QtCore.QObject):
|
|||
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 @@ class Worker(QtCore.QObject):
|
|||
"fontSize": fontSize,
|
||||
"alignment": alignment,
|
||||
"xoffset": xOffset,
|
||||
"yoffset": yOffset
|
||||
"yoffset": yOffset,
|
||||
"textColor" : textColor,
|
||||
"visColor" : visColor
|
||||
}
|
||||
self.queue.put(dic)
|
||||
|
||||
|
@ -59,11 +62,12 @@ class Worker(QtCore.QObject):
|
|||
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)
|
||||
|
|
|
@ -19,8 +19,9 @@ class Worker(QtCore.QObject):
|
|||
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 @@ class Worker(QtCore.QObject):
|
|||
fontSize,
|
||||
alignment,
|
||||
xOffset,
|
||||
yOffset)
|
||||
yOffset,
|
||||
textColor,
|
||||
visColor)
|
||||
|
||||
progressBarValue = 0
|
||||
self.progressBarUpdate.emit(progressBarValue)
|
||||
|
@ -97,9 +100,9 @@ class Worker(QtCore.QObject):
|
|||
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 @@ class Worker(QtCore.QObject):
|
|||
# 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()
|
||||
|
|
Reference in New Issue