Teste3 / app.py
AlexandreScriptsMT's picture
Update app.py
ad45296 verified
raw
history blame
1.26 kB
import gradio as gr
import tempfile
import subprocess
from pathlib import Path
def convert_webm_to_mp4(webm_file):
"""
Recebe um arquivo WebM, converte para MP4 e retorna o caminho do MP4.
"""
if webm_file is None:
# MP4 dummy se nenhum WebM for enviado
return "https://sample-videos.com/video123/mp4/240/big_buck_bunny_240p_1mb.mp4"
tmp_dir = tempfile.mkdtemp()
mp4_path = Path(tmp_dir) / "output.mp4"
try:
subprocess.run([
"ffmpeg",
"-y",
"-i", webm_file.name,
"-c:v", "libx264",
"-preset", "fast",
"-pix_fmt", "yuv420p",
str(mp4_path)
], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except subprocess.CalledProcessError as e:
return f"Error converting video: {e.stderr.decode()}"
return mp4_path
# Interface explícita, compatível com App Builder
iface = gr.Interface(
fn=convert_webm_to_mp4,
inputs=gr.Video(label="WebM Input"),
outputs=gr.Video(label="MP4 Output"),
allow_flagging="never"
)
if __name__ == "__main__":
# Garantir que a primeira função do Space (Index 0) seja essa
iface.launch(server_name="0.0.0.0", server_port=7860, share=True)