Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import subprocess | |
| import tempfile | |
| import os | |
| def convert_webm_to_mp4(webm_file): | |
| """ | |
| Recebe um arquivo WebM, converte para MP4 usando ffmpeg, | |
| e retorna o caminho do MP4 pronto para download. | |
| """ | |
| if webm_file is None: | |
| return None | |
| # Criar arquivo temporário para o MP4 | |
| tmp_dir = tempfile.mkdtemp() | |
| mp4_path = os.path.join(tmp_dir, "output.mp4") | |
| # Comando ffmpeg para conversão | |
| try: | |
| subprocess.run( | |
| [ | |
| "ffmpeg", | |
| "-y", # sobrescreve se existir | |
| "-i", webm_file, # input | |
| "-c:v", "libx264", # codec de vídeo | |
| "-preset", "fast", | |
| "-crf", "23", # qualidade | |
| mp4_path # output | |
| ], | |
| 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") | |
| webm_input = gr.Video(label="Upload WebM", type="filepath") # apenas caminho do arquivo | |
| 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__": | |
| # share=True cria link público temporário (útil para testes) | |
| demo.launch(server_name="0.0.0.0", server_port=7860, share=True) | |