Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,29 +3,43 @@ import subprocess
|
|
| 3 |
import uuid
|
| 4 |
import os
|
| 5 |
|
|
|
|
| 6 |
OUTPUT_DIR = "outputs"
|
| 7 |
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
| 8 |
|
| 9 |
-
def webm_to_mp4(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
output_name = f"{uuid.uuid4()}.mp4"
|
| 11 |
output_path = os.path.join(OUTPUT_DIR, output_name)
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
return output_path
|
| 23 |
|
| 24 |
-
|
|
|
|
| 25 |
fn=webm_to_mp4,
|
| 26 |
inputs=gr.File(file_types=[".webm"]),
|
| 27 |
outputs=gr.File(),
|
| 28 |
-
|
|
|
|
|
|
|
| 29 |
)
|
| 30 |
|
| 31 |
-
app
|
|
|
|
|
|
| 3 |
import uuid
|
| 4 |
import os
|
| 5 |
|
| 6 |
+
# Diretório para salvar os vídeos convertidos
|
| 7 |
OUTPUT_DIR = "outputs"
|
| 8 |
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
| 9 |
|
| 10 |
+
def webm_to_mp4(video_file):
|
| 11 |
+
"""
|
| 12 |
+
Recebe um arquivo WebM, converte para MP4 e retorna o caminho do arquivo.
|
| 13 |
+
"""
|
| 14 |
+
# Nome único para o MP4
|
| 15 |
output_name = f"{uuid.uuid4()}.mp4"
|
| 16 |
output_path = os.path.join(OUTPUT_DIR, output_name)
|
| 17 |
|
| 18 |
+
# Comando ffmpeg para converter WebM → MP4
|
| 19 |
+
subprocess.run(
|
| 20 |
+
[
|
| 21 |
+
"ffmpeg",
|
| 22 |
+
"-y", # sobrescrever se já existir
|
| 23 |
+
"-i", video_file, # arquivo de entrada
|
| 24 |
+
"-movflags", "faststart",
|
| 25 |
+
"-pix_fmt", "yuv420p",
|
| 26 |
+
output_path
|
| 27 |
+
],
|
| 28 |
+
stdout=subprocess.DEVNULL,
|
| 29 |
+
stderr=subprocess.DEVNULL
|
| 30 |
+
)
|
| 31 |
|
| 32 |
return output_path
|
| 33 |
|
| 34 |
+
# Interface Gradio
|
| 35 |
+
iface = gr.Interface(
|
| 36 |
fn=webm_to_mp4,
|
| 37 |
inputs=gr.File(file_types=[".webm"]),
|
| 38 |
outputs=gr.File(),
|
| 39 |
+
title="WebM → MP4 Converter",
|
| 40 |
+
description="Envie um vídeo WebM e receba o MP4 pronto para download.",
|
| 41 |
+
api_name="convert" # ← CRUCIAL para App Builder
|
| 42 |
)
|
| 43 |
|
| 44 |
+
# Inicializa o app
|
| 45 |
+
iface.launch()
|