import tkinter as tk
import tkinter.filedialog as tk_fd
import subprocess

ffmpeg_path = "C:\\Users\\username\\Downloads\\ffmpeg-20160428-git-78baa45-win64-static\\bin\\ffmpeg.exe"

class Application(tk.Frame):

    def __init__(self, master=None):
        super().__init__(master)
        self.pack()
        
        self.mp3_path = ''
        self.pic_path = ''
        self.output_path = ''
        
        self.create_widgets()
                
    def create_widgets(self):
        self.Source1 = tk.Button(self, text = "mp3", command = lambda: self.open_mp3()).pack()
        self.Sourse2 = tk.Button(self, text = "pic", command = lambda: self.open_pic()).pack()
        self.Start = tk.Button(self, text="Start", fg="red",command= lambda: self.start()).pack()

    def open_mp3(self):
        op = tk_fd.askopenfile(mode='rb',title='Choose a mp3', filetypes = [("music", "*.mp3")])
        path = (str(op.name).replace("""/""","""\\""")) #this is path to music source #have to do smth with russian chars
        print("Path to mp3 is - " + path)
        self.mp3_path = path
    
    def open_pic(self):
        op = tk_fd.askopenfile(mode='rb',title='Choose a picture', filetypes = [("picture", "*.jpeg; *.bmp; *.jpg; *.png")])#filetypes = ("music", "*.mp3") #filetypes = (("Template files", "*.tplate"),("HTML files", "*.html;*.htm"),("All files", "*.*"))
        path = (str(op.name).replace("""/""","""\\""")) #this is path to pic source #have to do smth with russian chars
        print("Path to pic is - " + path)
        self.pic_path = path
        
    def start(self):
        op = tk_fd.asksaveasfilename(title = "Choose where to save", filetypes = [("webm", "*.webm;")])
        path = (str(op).replace("""/""","""\\""")+(".webm")) #this is path to webm output #have to do smth with russian chars
        print("Path to webm is - " + path)
        self.output_path = path
        
        subprocess.call(ffmpeg_path + self.parse_setting())
        
    def parse_setting(self):
        #there must be smth to parse when settings will be done
        settings = " -r 1 -loop 1 -i {} -i {} -c:v vp8 -c:a opus -b:a 128k -b:v 0 -crf 16 -g 360 -shortest {}".format(self.pic_path, self.mp3_path, self.output_path)
        print((ffmpeg_path + settings))
        return(settings)


root = tk.Tk()
root.geometry("800x600")
root.title("GUI: mp3 + pic = webm")
app = Application(master=root)
app.mainloop()