File size: 1,397 Bytes
af1695b
33c4afa
69005d5
 
af1695b
37d5502
 
69005d5
37d5502
33c4afa
69005d5
ad45296
69005d5
 
 
ad45296
37d5502
69005d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37d5502
69005d5
 
ad45296
69005d5
 
 
 
 
1c02b32
69005d5
 
1c02b32
69005d5
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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)