import subprocess
import os
import tkinter as tk
from tkinter import filedialog
import threading

def convert_file(input_file, output_file):
    try:
        subprocess.run(['ffmpeg', '-i', input_file, '-c', 'copy', '-strict', '-2', output_file], check=True)
        print("Conversion completed successfully.")
        result_label.config(text="Conversion completed successfully.", fg="green")
    except subprocess.CalledProcessError as e:
        print("An error occurred:", e)
        result_label.config(text="An error occurred during conversion.", fg="red")


def select_input_file():
    file_path = filedialog.askopenfilename()
    input_entry.delete(0, tk.END)
    input_entry.insert(0, file_path)

def select_output_file():
    file_path = filedialog.asksaveasfilename()
    output_entry.delete(0, tk.END)
    output_entry.insert(0, file_path)

def start_conversion():
    input_file = input_entry.get().strip()
    output_file = output_entry.get().strip()

    if not os.path.isfile(input_file):
        print("Invalid input file.")
        return

    threading.Thread(target=convert_file, args=(input_file, output_file)).start()

# Create GUI
root = tk.Tk()
root.title("File Converter")

input_label = tk.Label(root, text="Input File:")
input_label.grid(row=0, column=0, padx=5, pady=5)

input_entry = tk.Entry(root, width=50)
input_entry.grid(row=0, column=1, columnspan=2, padx=5, pady=5)

input_button = tk.Button(root, text="Browse", command=select_input_file)
input_button.grid(row=0, column=3, padx=5, pady=5)

output_label = tk.Label(root, text="Output File:")
output_label.grid(row=1, column=0, padx=5, pady=5)

output_entry = tk.Entry(root, width=50)
output_entry.grid(row=1, column=1, columnspan=2, padx=5, pady=5)

output_button = tk.Button(root, text="Browse", command=select_output_file)
output_button.grid(row=1, column=3, padx=5, pady=5)

convert_button = tk.Button(root, text="Convert", command=start_conversion)
convert_button.grid(row=2, column=1, columnspan=2, pady=10)

result_label = tk.Label(root, text="", fg="green", font=("Arial", 12))
result_label.grid(row=3, column=0, columnspan=4, padx=5, pady=5)

root.mainloop()

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *