Teste3 / app.py
AlexandreScriptsMT's picture
Update app.py
4436f52 verified
raw
history blame
1.18 kB
import gradio as gr
import subprocess
import uuid
import os
# Diretório para salvar os vídeos convertidos
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.
"""
# Nome único para o MP4
output_name = f"{uuid.uuid4()}.mp4"
output_path = os.path.join(OUTPUT_DIR, output_name)
# Comando 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
# Interface Gradio
iface = gr.Interface(
fn=webm_to_mp4,
inputs=gr.File(file_types=[".webm"]),
outputs=gr.File(),
title="WebM → MP4 Converter",
description="Envie um vídeo WebM e receba o MP4 pronto para download.",
api_name="convert" # ← CRUCIAL para App Builder
)
# Inicializa o app
iface.launch()