Teste3 / app.py
AlexandreScriptsMT's picture
Update app.py
e7a363a verified
raw
history blame
1.21 kB
import gradio as gr
import subprocess
import tempfile
import os
def convert_webm_to_mp4(webm_file):
if webm_file is None:
return None
tmp_dir = tempfile.mkdtemp()
mp4_path = os.path.join(tmp_dir, "output.mp4")
try:
subprocess.run(
[
"ffmpeg",
"-y",
"-i", webm_file,
"-c:v", "libx264",
"-preset", "fast",
"-crf", "23",
mp4_path
],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
except subprocess.CalledProcessError as e:
return f"Erro ao converter: {e.stderr.decode()}"
return mp4_path
# --- Interface Gradio ---
with gr.Blocks() as demo:
gr.Markdown("## WebM → MP4 Converter")
# <-- aqui removemos 'type' -->
webm_input = gr.Video(label="Upload WebM")
mp4_output = gr.File(label="Download MP4")
convert_btn = gr.Button("Convert to MP4")
convert_btn.click(fn=convert_webm_to_mp4, inputs=[webm_input], outputs=[mp4_output])
# Rodar app
if __name__ == "__main__":
demo.launch(server_name="0.0.0.0", server_port=7860, share=True)