Skip to content
The Chat Archive
gpt-4-0314· OpenAI WildChat-4.8M (AI2)

python build a GUI for this import os inputfile = 'input.mkv' outputfile = 'output.mp4'…

  1. User

    python build a GUI for this import os

    input_file = 'input.mkv' output_file = 'output.mp4'

    os.system(f'ffmpeg -i {input_file} -c:v libx264 -x264-params crf=23 -preset medium -c:a copy -movflags +faststart {output_file}') which allows user to select input file select where to save and file name and a convert button plus a progress bar

  2. Assistant

    You can create a simple GUI for this using the Tkinter library in Python. To install Tkinter, you can use the following command:

    pip install tk
    

    Here's a sample code that builds a GUI for your needs:

    import os
    import tkinter as tk
    from tkinter import ttk
    from tkinter import filedialog
    import threading
    import subprocess
    
    def browse_input_file():
        file_path = filedialog.askopenfilename(title="Select an input file", filetypes=[("mkv files", "*.mkv"), ("all files", "*.*")])
        input_path.set(file_path)
    
    def browse_output_file():
        file_path = filedialog.asksaveasfilename(title="Save output file", defaultextension=".mp4", filetypes=[("mp4 files", "*.mp4"), ("all files", "*.*")])
        output_path.set(file_path)
    
    def convert_video():
        input_file = input_path.get()
        output_file = output_path.get()
        command = f'ffmpeg -i "{input_file}" -c:v libx264 -x264-params crf=23 -preset medium -c:a copy -movflags +faststart "{output_file}"'
    
        def run_command():
            process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=True, bufsize=1)
            while True:
                line = process.stdout.readline()
                if not line:
                    break
                progress.set(line.strip())
    
            progress.set("Conversion finished.")
            convert_button["state"] = tk.NORMAL
    
        convert_button["state"] = tk.DISABLED
        threading.Thread(target=run_command).start()
    
    root = tk.Tk()
    root.title("Video Converter")
    
    input_path = tk.StringVar()
    output_path = tk.StringVar()
    progress = tk.StringVar()
    
    input_label = ttk.Label(root, text="Input file:")
    input_label.grid(row=0, column=0, padx=(10, 5), pady=(10, 5))
    input_entry = ttk.Entry(root, textvariable=input_path, width=40)
    input_entry.grid(row=0, column=1, padx=(5, 5), pady=(10, 5))
    input_button = ttk.Button(root, text="Browse", command=browse_input_file)
    input_button.grid(row=0, column=2, padx=(5, 10), pady=(10, 5))
    
    output_label = ttk.Label(root, text="Output file:")
    output_label.grid(row=1, column=0, padx=(10, 5), pady=(5, 5))
    output_entry = ttk.Entry(root, textvariable=output_path, width=40)
    output_entry.grid(row=1, column=1, padx=(5, 5), pady=(5, 5))
    output_button = ttk.Button(root, text="Browse", command=browse_output_file)
    output_button.grid(row=1, column=2, padx=(5, 10), pady=(5, 5))
    
    convert_button = ttk.Button(root, text="Convert", command=convert_video)
    convert_button.grid(row=2, column=1, pady=(10, 5))
    
    progress_label = ttk.Label(root, textvariable=progress)
    progress_label.grid(row=3, column=0, columnspan=3, pady=(5, 10))
    
    root.mainloop()
    

    This code creates a simple GUI with 2 browse buttons for selecting input and output files, a convert button to start the conversion, and a label to show the progress.