Advertisement
MizunoBrasil

Conversor de TS para MP4

Aug 26th, 2024
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.74 KB | None | 0 0
  1. # Converte video .ts para .mp4
  2. # Necessário ter instalado o FFMPEG
  3. # Data: 27/08/2024
  4.  
  5.  
  6. import tkinter as tk
  7. from tkinter import filedialog, messagebox
  8. from tkinter.ttk import Progressbar
  9. import threading
  10. import subprocess
  11. import os
  12. import time
  13.  
  14. def convert_video(ts_file, mp4_file, progress_callback):
  15.     command = ['ffmpeg', '-i', ts_file, '-c:v', 'copy', '-c:a', 'copy', mp4_file]
  16.    
  17.     process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
  18.    
  19.     while True:
  20.         output = process.stderr.read(1)
  21.         if output == '' and process.poll() is not None:
  22.             break
  23.         if output:
  24.             progress_callback()
  25.    
  26.     process.wait()
  27.  
  28. def start_conversion():
  29.     ts_file = filedialog.askopenfilename(title="Selecione o arquivo .ts", filetypes=[("TS files", "*.ts")])
  30.     if not ts_file:
  31.         return
  32.    
  33.     mp4_file = ts_file.rsplit('.', 1)[0] + ".mp4"
  34.    
  35.     def update_progress():
  36.         current_value = progress_bar['value']
  37.         if current_value < 100:
  38.             progress_bar['value'] = current_value + 1
  39.             percent.set(f"{progress_bar['value']}%")
  40.             window.update_idletasks()
  41.    
  42.     def run_conversion():
  43.         progress_bar['value'] = 0
  44.         try:
  45.             convert_video(ts_file, mp4_file, update_progress)
  46.             messagebox.showinfo("Sucesso", "Conversão realizada com sucesso!")
  47.             # Abrir a pasta onde o arquivo foi salvo
  48.             os.startfile(os.path.dirname(mp4_file))
  49.             # Excluir o arquivo .ts
  50.             os.remove(ts_file)
  51.         except Exception as e:
  52.             messagebox.showerror("Erro", f"Erro na conversão: {str(e)}")
  53.    
  54.     conversion_thread = threading.Thread(target=run_conversion)
  55.     conversion_thread.start()
  56.  
  57. # Configuração da interface
  58. window = tk.Tk()
  59. window.title("Conversor de Vídeo TS para MP4")
  60.  
  61. # Definindo o tamanho da janela
  62. window_width = 400
  63. window_height = 200
  64.  
  65. # Calculando a posição x e y para centralizar a janela
  66. screen_width = window.winfo_screenwidth()
  67. screen_height = window.winfo_screenheight()
  68. position_x = int((screen_width - window_width) / 2)
  69. position_y = int((screen_height - window_height) / 2)
  70.  
  71. # Configurando a geometria da janela com posição centralizada
  72. window.geometry(f"{window_width}x{window_height}+{position_x}+{position_y}")
  73.  
  74. percent = tk.StringVar()
  75. percent.set("0%")
  76.  
  77. progress_bar = Progressbar(window, orient="horizontal", length=300, mode="determinate", maximum=100)
  78. progress_bar.pack(pady=20)
  79.  
  80. percent_label = tk.Label(window, textvariable=percent)
  81. percent_label.pack()
  82.  
  83. button = tk.Button(window, text="Escolher arquivo", command=start_conversion)
  84. button.pack(pady=20)
  85.  
  86. window.mainloop()
  87.  
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement