I'm trying to make a program in Python and PyQt for video encoding and I have a problem.
I do not know how to get a variable with the path of a file and then send it to FFmpeg .
I have built a basic window with three buttons, one to choose the file, another to choose the path of the outgoing file and another to start the encoding. To this last one now I only ask you to print the variable that has the path of the file to be able to see and verify that this variable is fine.
If I execute the first button, b1_clicked()
, it works fine and even prints the path of the file, but if I execute the third button also to print that variable, it gives error:
Traceback (most recent call last):
File "/home/salva/PycharmProjects/test1/encoder3.py", line 40, in b3_clicked
print (fileinput)
NameError: name 'fileinput' is not defined
I need that variable to be able to send FFmpeg the video that I want to encode (I'll see how).
On that button 3 FFmpeg will act later when you know how to do it.
This is what I'm doing for now before I start with FFmpeg : (I'm updating)
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import subprocess
fileinput = ''
def window():
app = QApplication(sys.argv)
win = QDialog()
b1 = QPushButton(win)
b1.setText("Select file")
b1.move(50,20)
b1.clicked.connect(b1_clicked)
b2 = QPushButton(win)
b2.setText("Output file")
b2.move(50,50)
b2.clicked.connect(b2_clicked)
b3 = QPushButton(win)
b3.setText("Encode!")
b3.move(50,80)
b3.clicked.connect(b3_clicked)
win.setGeometry(100,100,200,200)
win.setWindowTitle("Encoder")
win.show()
sys.exit(app.exec_())
def b1_clicked():
fileinput = QFileDialog.getOpenFileName(None, "Selecciona archivo a convertir", "/home/salva", "video files (*.avi *.mkv *.mp4 *.mov *.mpg);; All files (*)")
print (fileinput)
def b2_clicked():
filesaved = QFileDialog.getSaveFileName(None, "Archivo de salida", "/home/salva", "video files (*.avi *.mkv *.mp4 *.mov *.mpg);; All files (*)")
print (filesaved)
def b3_clicked():
print (fileinput)
if __name__ == '__main__':
window()