Updated shakalizator

This commit is contained in:
BarsTiger
2022-03-21 11:55:15 +02:00
parent 85c6fc2c69
commit 8fad79715f

View File

@@ -1,4 +1,6 @@
import subprocess, sys, os, shutil import subprocess
import sys
import os
try: try:
import ffmpeg import ffmpeg
@@ -18,6 +20,7 @@ except:
subprocess.check_call([sys.executable, "-m", "pip", "install", 'PyQt5']) subprocess.check_call([sys.executable, "-m", "pip", "install", 'PyQt5'])
from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object): class Ui_MainWindow(object):
def setupUi(self, MainWindow): def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow") MainWindow.setObjectName("MainWindow")
@@ -75,6 +78,7 @@ class Ui_MainWindow(object):
self.imgbutton.setText(_translate("MainWindow", "Shakalize image")) self.imgbutton.setText(_translate("MainWindow", "Shakalize image"))
self.vidbutton.setText(_translate("MainWindow", "Shakalize video")) self.vidbutton.setText(_translate("MainWindow", "Shakalize video"))
class Ui_VideoWindow(object): class Ui_VideoWindow(object):
def setupUi(self, MainWindow): def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow") MainWindow.setObjectName("MainWindow")
@@ -230,12 +234,14 @@ class Ui_VideoWindow(object):
_translate = QtCore.QCoreApplication.translate _translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Video Shakalizator")) MainWindow.setWindowTitle(_translate("MainWindow", "Video Shakalizator"))
self.bassboostNadpis.setText(_translate("MainWindow", "Bassboost")) self.bassboostNadpis.setText(_translate("MainWindow", "Bassboost"))
self.VideoQualNadpis.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" self.VideoQualNadpis.setHtml(_translate("MainWindow",
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n" "p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n" "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Video quality</p></body></html>")) "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Video quality</p></body></html>"))
self.SoundQualNadpis.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" self.SoundQualNadpis.setHtml(_translate("MainWindow",
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n" "p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n" "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
@@ -254,7 +260,8 @@ class Ui_VideoWindow(object):
soundquality = self.soundQualTsiframi.value() soundquality = self.soundQualTsiframi.value()
bassboostlvl = self.bassboostTsiframi.value() bassboostlvl = self.bassboostTsiframi.value()
pathToVid = self.pathToVideo.toPlainText() pathToVid = self.pathToVideo.toPlainText()
pathToOutput = os.path.split(str(pathToVid))[0] + "/" + os.path.splitext(os.path.basename(pathToVid))[0] + "_shakalized.mp4" pathToOutput = os.path.split(str(pathToVid))[0] + "/" + os.path.splitext(os.path.basename(pathToVid))[
0] + "_shakalized.mp4"
shakal_video(pathToVid, pathToOutput, soundquality, vidquality, bassboostlvl) shakal_video(pathToVid, pathToOutput, soundquality, vidquality, bassboostlvl)
def vidqualSyncFromSlider(self): def vidqualSyncFromSlider(self):
@@ -266,6 +273,7 @@ class Ui_VideoWindow(object):
def bassSyncFromDial(self): def bassSyncFromDial(self):
self.bassboostTsiframi.setValue(int(self.bassboostlevel.value() / 10) + 1) self.bassboostTsiframi.setValue(int(self.bassboostlevel.value() / 10) + 1)
class Ui_PictureWindow(object): class Ui_PictureWindow(object):
def setupUi(self, MainWindow): def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow") MainWindow.setObjectName("MainWindow")
@@ -307,14 +315,16 @@ class Ui_PictureWindow(object):
def retranslateUi(self, MainWindow): def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate _translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.opisanie.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" self.opisanie.setHtml(_translate("MainWindow",
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n" "p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n" "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:48pt;\">Shakalizator</span></p>\n" "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:48pt;\">Shakalizator</span></p>\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:14pt;\">media files quality lowering program based on python, ffmpeg, pillow libs and PyQT5 UI</span></p>\n" "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:14pt;\">media files quality lowering program based on python, ffmpeg, pillow libs and PyQT5 UI</span></p>\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:24pt;\">Shakalize picture menu</span></p></body></html>")) "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:24pt;\">Shakalize picture menu</span></p></body></html>"))
self.pathToPict.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" self.pathToPict.setHtml(_translate("MainWindow",
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n" "p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n" "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
@@ -331,10 +341,8 @@ class Ui_PictureWindow(object):
imgquality = self.quailty.value() imgquality = self.quailty.value()
shakal_img(imgname, imgquality) shakal_img(imgname, imgquality)
def shakal_video(video_full_path, output_file_name, audio_bitrate, video_bitrate, bass):
# audio_bitrate min 20, shakal 30, max 300
# video_bitrate min 100, shakal 150, max 1500
def shakal_video(video_full_path, output_file_name, audio_bitrate, video_bitrate, bass):
audio_bitrate = audio_bitrate * 1000 audio_bitrate = audio_bitrate * 1000
video_bitrate = video_bitrate * 1000 video_bitrate = video_bitrate * 1000
@@ -350,12 +358,16 @@ def shakal_video(video_full_path, output_file_name, audio_bitrate, video_bitrate
print("Finished shakalizing!") print("Finished shakalizing!")
def shakal_img(imagename, img_quality): def shakal_img(imagename, img_quality):
image = Image.open(imagename) image = Image.open(imagename)
saveas = str(os.path.splitext(imagename)[0]) + "_shakalized.jpg" print(os.path.splitext(imagename))
image.save(saveas, "JPEG", quality=img_quality) saveas = str(os.path.splitext(imagename)[0]) + "_shakalized" + str(os.path.splitext(imagename)[1])
image.save(saveas, os.path.splitext(imagename)[1][1:] if os.path.splitext(imagename)[1][1:] != 'jpg' else 'JPEG',
quality=img_quality)
print("Shakalized to quality {0}!".format(img_quality)) print("Shakalized to quality {0}!".format(img_quality))
app = QtWidgets.QApplication(sys.argv) app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow() MainWindow = QtWidgets.QMainWindow()
@@ -370,12 +382,15 @@ PictureWindow = QtWidgets.QMainWindow()
uipict = Ui_PictureWindow() uipict = Ui_PictureWindow()
uipict.setupUi(PictureWindow) uipict.setupUi(PictureWindow)
def launchvidmenu(): def launchvidmenu():
VideoWindow.show() VideoWindow.show()
def launchpicmenu(): def launchpicmenu():
PictureWindow.show() PictureWindow.show()
uimain.vidbutton.clicked.connect(launchvidmenu) uimain.vidbutton.clicked.connect(launchvidmenu)
uimain.imgbutton.clicked.connect(launchpicmenu) uimain.imgbutton.clicked.connect(launchpicmenu)