Spaces:
Runtime error
Runtime error
File size: 1,287 Bytes
af1695b 61689d0 af1695b 4436f52 61689d0 af1695b 61689d0 4436f52 af1695b 61689d0 4436f52 af1695b 32b1f1e 61689d0 af1695b 4436f52 61689d0 | 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 | import gradio as gr
import subprocess
import uuid
import os
# Diretório onde os vídeos convertidos serão salvos
OUTPUT_DIR = "outputs"
os.makedirs(OUTPUT_DIR, exist_ok=True)
def webm_to_mp4(video_file):
"""
Recebe um arquivo WebM, converte para MP4 e retorna o caminho do arquivo.
"""
# Gera nome único para o MP4
output_name = f"{uuid.uuid4()}.mp4"
output_path = os.path.join(OUTPUT_DIR, output_name)
# Executa o ffmpeg para converter WebM -> MP4
subprocess.run(
[
"ffmpeg",
"-y", # sobrescrever se já existir
"-i", video_file, # arquivo de entrada
"-movflags", "faststart",
"-pix_fmt", "yuv420p",
output_path
],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
)
return output_path
# Cria a interface Gradio
iface = gr.Interface(
fn=webm_to_mp4,
inputs=gr.File(file_types=[".webm"]),
outputs=gr.File(),
title="Conversor WebM → MP4",
description="Envie um arquivo WebM e receba o MP4 pronto para download.",
api_name="convert" # ← CRUCIAL para POST externo
)
# Inicializa o app
iface.launch(
server_name="0.0.0.0", # necessário no Hugging Face Space
server_port=7860
) |