import gradio as gr import subprocess import os import tempfile def convert_webm_to_mp4(webm_file): """ Recebe um arquivo WebM, converte para MP4 usando ffmpeg e retorna o caminho do MP4. """ if webm_file is None: return None # Cria um arquivo temporário para o MP4 with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmp: mp4_path = tmp.name try: # Executa a conversão com ffmpeg subprocess.run( [ "ffmpeg", "-y", # sobrescrever se existir "-i", webm_file.name, "-c:v", "libx264", "-preset", "fast", "-pix_fmt", "yuv420p", mp4_path ], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE ) return mp4_path except subprocess.CalledProcessError as e: print("Erro ao converter vídeo:", e.stderr.decode()) return None # --- Gradio Blocks --- with gr.Blocks() as app: with gr.Row(): webm_input = gr.Video(label="WebM Input") mp4_output = gr.Video(label="MP4 Output") convert_btn = gr.Button("Convert WebM to MP4") convert_btn.click(fn=convert_webm_to_mp4, inputs=webm_input, outputs=mp4_output) # Executa o app app.launch(server_name="0.0.0.0", server_port=7860, share=False)