python ffmpeg tkinter

Solutions on MaxInterview for python ffmpeg tkinter by the best coders in the world

showing results for - "python ffmpeg tkinter"
Sabri
29 Mar 2019
1#FFPMEG Converter GUI
2import tkinter,subprocess,os
3from tkinter import filedialog,messagebox
4from tkinter import *
5class FFConvert:
6    
7    def convert(self):
8        
9        self.btnConvert['state'] = 'disabled'
10        self.btn['state']='disabled'
11        if self.file:
12            self.txt.delete(0.0,END)
13            self.txt.insert(0.0,'File: '+self.filename+'\n')
14            ext = self.b.getvar(name='contain') #self.container.get()
15            self.txt.insert(END,"Converted Container: "+ext+"\n\n Please Wait...")
16            print('contain = '+self.b.getvar(name='contain'))
17            cmd=subprocess.run("ffmpeg -i \""+self.file.name+"\" -codec copy -y \""+self.file.name+'.'+ext+"\"",shell=True)
18            self.txt.insert(END,cmd)
19            if cmd.returncode==0:
20                messagebox.showinfo("Done!","Complete")
21                self.txt.delete(0.0,END)
22                self.txt.insert(END,'DONE!')
23                self.btnConvert['state']='normal'
24                self.btn['state']='normal'
25            else:
26                messagebox.showerror("ERROR!","Oops, Error X(")
27                self.btn['state']='normal'
28                self.btnConvert['state']='normal'
29            print(cmd.stdout)
30            print('RESULT: '+str(cmd.returncode))
31            
32    def fileopen(self):
33        
34        self.file =  filedialog.askopenfile(filetypes=[('all files', '.*'),('AVI', '.avi'),('MP4','.mp4'),('M4P','.m4p'),('MKV','.mkv'),('WMV','.wmv')])
35        if self.file:
36            self.filename = self.file.name
37            print('File: '+self.filename)
38            self.btnConvert['state']='normal'
39
40    def __init__(self):
41        
42        self.gui = Tk()
43        self.gui.geometry(newGeometry="300x200")
44        self.gui.resizable(width=True, height=True)
45        self.gui.title("FFMPEG Converter")
46        self.file = None
47        self.btn=Button(self.gui,text='Open...',command=self.fileopen)
48        self.btn.pack(anchor=E)
49        self.container = StringVar()
50        self.container.initialize('avi')
51        self.container.set('avi')
52        self.containers = [("AVI", 'avi'),
53                      ("MP4", 'mp4'),
54                      ("MKV", 'mkv'),
55                      ("WMV", 'wmv'),
56                      ("MP3",'mp3'),]  
57        for cont, mode in self.containers:
58            self.b=Radiobutton(self.gui,indicatoron=1,value=mode,variable='contain',text=cont)
59            self.b.pack(anchor=W)
60        self.btnConvert = Button(self.gui,text='Convert...',command=self.convert,state='disabled')
61        self.btnConvert.pack(anchor=E)
62        self.txt=Text(self.gui)
63        self.txt.pack(anchor=E)
64        self.gui.mainloop()
65    
66myConvert = FFConvert()
similar questions
queries leading to this page
python ffmpeg tkinter