Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Converte video .ts para .mp4
- # Necessário ter instalado o FFMPEG
- # Data: 27/08/2024
- import tkinter as tk
- from tkinter import filedialog, messagebox
- from tkinter.ttk import Progressbar
- import threading
- import subprocess
- import os
- import time
- def convert_video(ts_file, mp4_file, progress_callback):
- command = ['ffmpeg', '-i', ts_file, '-c:v', 'copy', '-c:a', 'copy', mp4_file]
- process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
- while True:
- output = process.stderr.read(1)
- if output == '' and process.poll() is not None:
- break
- if output:
- progress_callback()
- process.wait()
- def start_conversion():
- ts_file = filedialog.askopenfilename(title="Selecione o arquivo .ts", filetypes=[("TS files", "*.ts")])
- if not ts_file:
- return
- mp4_file = ts_file.rsplit('.', 1)[0] + ".mp4"
- def update_progress():
- current_value = progress_bar['value']
- if current_value < 100:
- progress_bar['value'] = current_value + 1
- percent.set(f"{progress_bar['value']}%")
- window.update_idletasks()
- def run_conversion():
- progress_bar['value'] = 0
- try:
- convert_video(ts_file, mp4_file, update_progress)
- messagebox.showinfo("Sucesso", "Conversão realizada com sucesso!")
- # Abrir a pasta onde o arquivo foi salvo
- os.startfile(os.path.dirname(mp4_file))
- # Excluir o arquivo .ts
- os.remove(ts_file)
- except Exception as e:
- messagebox.showerror("Erro", f"Erro na conversão: {str(e)}")
- conversion_thread = threading.Thread(target=run_conversion)
- conversion_thread.start()
- # Configuração da interface
- window = tk.Tk()
- window.title("Conversor de Vídeo TS para MP4")
- # Definindo o tamanho da janela
- window_width = 400
- window_height = 200
- # Calculando a posição x e y para centralizar a janela
- screen_width = window.winfo_screenwidth()
- screen_height = window.winfo_screenheight()
- position_x = int((screen_width - window_width) / 2)
- position_y = int((screen_height - window_height) / 2)
- # Configurando a geometria da janela com posição centralizada
- window.geometry(f"{window_width}x{window_height}+{position_x}+{position_y}")
- percent = tk.StringVar()
- percent.set("0%")
- progress_bar = Progressbar(window, orient="horizontal", length=300, mode="determinate", maximum=100)
- progress_bar.pack(pady=20)
- percent_label = tk.Label(window, textvariable=percent)
- percent_label.pack()
- button = tk.Button(window, text="Escolher arquivo", command=start_conversion)
- button.pack(pady=20)
- window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement