Image to MP4 UI Script

#convert_image_to_mp4_ui.py
  
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
  
import sys
import os
import math
import ffmpeg_scripts
import inspect
  
class Convert_to_mp4_UI(QDialog):
    def __init__(self, parent=None):
        QDialog.__init__(self, parent)
        
        # Ensure our window stays in front.
        self.setWindowFlags(Qt.WindowStaysOnTopHint)
        self.setWindowTitle("ffmpeg Image Sequence to MP4")
        
        self.srcImagesPath = ''
  
        # Create the main vertical layout.
        vlayout = QVBoxLayout()
        self.setLayout(vlayout)
  
        #Upper Panel
        
        self.addPathPanel(vlayout)
        
        self.addVideoRes(vlayout)
        
        self.addFrameRate(vlayout)
  
        #ensure Path Panel is at top
        #and Button at bottom
        vlayout.addStretch()
                
        #Lower Panel
        self.addButtonPanel(vlayout)
                
        
        self.setFixedSize(500, 200)
        self.show()
        
#---------------------------------------------------------
  
    def addVideoRes(self, parentLayout):
        hlayout = QHBoxLayout()
        label1 = QLabel(self)
        label1.setText('Video Resolution')
        hlayout.addWidget(label1)
        #
        combo = QComboBox(self)
        combo.addItem("540p")        # index = 0
        combo.addItem("720p")         # index = 1
        combo.addItem("1080p")        # index = 2
        combo.addItem("Custom")        # index = 3
        combo.activated[int].connect(self.resAction)
        hlayout.addWidget(combo)
        #
        self.resTextX = QLineEdit()
        self.resTextX.setFixedSize(50, 25)
        self.resTextX.setEnabled(False)
        self.resTextX.setText('960')
        hlayout.addWidget(self.resTextX)
        #
        label3 = QLabel(self)
        label3.setText('x')
        hlayout.addWidget(label3)
        #
        self.resTextY = QLineEdit()
        self.resTextY.setFixedSize(50, 25)
        self.resTextY.setEnabled(False)
        self.resTextY.setText('540')
        hlayout.addWidget(self.resTextY)
        #
        hlayout.addStretch()
        parentLayout.addLayout(hlayout)
#---------------------------------------------------------
  
    def addFrameRate(self, parentLayout):
        hlayout = QHBoxLayout()
        label = QLabel(self)
        label.setText('Frame Rate')
        hlayout.addWidget(label)
        #
        combo = QComboBox(self)
        combo.addItem("30 fps")    # index = 0
        combo.addItem("24 fps") # index = 1
        combo.addItem("15 fps")    # index = 2
        combo.addItem("Custom")    # index = 3
        combo.activated[int].connect(self.fpsAction)
        hlayout.addWidget(combo)
        #
        self.fpsEdit = QLineEdit(self)
        self.fpsEdit.setFixedSize(40, 25)
        self.fpsEdit.setEnabled(False)
        hlayout.addWidget(self.fpsEdit)
        self.fpsEdit.setText('30')
        #
        label2 = QLabel(self)
        label2.setText('fps')
        hlayout.addWidget(label2)
        #
        hlayout.addStretch()
        parentLayout.addLayout(hlayout)
#---------------------------------------------------------
  
    def addPathPanel(self, parentLayout):
        hlayout = QHBoxLayout()
        label = QLabel(self)
        label.setText('Source Images')
        hlayout.addWidget(label)
        #
        self.pathText = QLineEdit()
        self.pathText.setText('Select first image in sequence')
        self.pathText.textChanged[str].connect(self.pathChangedAction)
        hlayout.addWidget(self.pathText)
        #
        self.browseButton = QPushButton("Browse")
        self.browseButton.clicked.connect(self.browseAction)
        hlayout.addWidget(self.browseButton)
        #
        parentLayout.addLayout(hlayout)
        
#---------------------------------------------------------
    def browseAction(self):
        fileDialog = QFileDialog.getOpenFileName(self, filter='*.jpg')
        self.srcImagesPath = fileDialog[0]
        if fileDialog[0] !='':
            self.pathText.setText(fileDialog[0])
        else:
            self.pathText.setText('Browse Cancelled')
#---------------------------------------------------------
    def addButtonPanel(self, parentLayout):
        self.button = QPushButton("Write ffmpeg Script")
        self.button.clicked.connect(self.doitAction)
        self.button.setEnabled(False)
        hlayout = QHBoxLayout()
        hlayout.addStretch()            #ensure button pushed right.
        hlayout.addWidget(self.button)
        parentLayout.addLayout(hlayout)
#---------------------------------------------------------
    def fpsAction(self, index):
        self.fpsEdit.setEnabled(False)
        if index == 0:
            self.fpsEdit.setText('30')
        elif index == 1:
            self.fpsEdit.setText('24')
        elif index == 2:
            self.fpsEdit.setText('15')
        else:
            self.fpsEdit.setEnabled(True)
#---------------------------------------------------------
    def resAction(self, index):
        self.resTextX.setEnabled(False)
        self.resTextY.setEnabled(False)
        if index == 0:
            self.resTextX.setText('960')
            self.resTextY.setText('540')
        elif index == 1:
            self.resTextX.setText('1080')
            self.resTextY.setText('720')
        elif index == 2:
            self.resTextX.setText('1920')
            self.resTextY.setText('1080')
        else:
            self.resTextX.setEnabled(True)
            self.resTextY.setEnabled(True)
        
#---------------------------------------------------------
    def pathChangedAction(self, text):
        self.srcImagesPath = ''
        if os.path.exists(text) == (False):
            self.button.setEnabled(False)
        else:
            self.button.setEnabled(True)
            self.srcImagesPath = text
        
#---------------------------------------------------------
    def doitAction(self):
        if self.srcImagesPath !='':
            parentdir = os.path.dirname(self.srcImagesPath)
            imagename = os.path.basename(self.srcImagesPath)
            root, ext = os.path.splitext (imagename)
            index = imagename.find(".")
            imagename = imagename[:index]
            width = self.resTextX.text()
            height = self.resTextY.text()
            fps = self.fpsEdit.text()
            if os.name == 'nt':
                fullpath = ffmpeg_scripts.WIN_convert_seq_to_mpeg(parentdir, imagename + '.bat', imagename,  ext, fps, width, height )
                #print (fullpath)
# ========================================================                
if __name__ == '__main__':
    # Create the Qt Application
    app = QApplication(sys.argv)
    demo =  Convert_to_mp4_UI() # <<-- Create an instance
    demo.show()
    sys.exit(app.exec_())