Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,42 +1,48 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import tempfile
|
| 3 |
import subprocess
|
| 4 |
-
|
|
|
|
| 5 |
|
| 6 |
def convert_webm_to_mp4(webm_file):
|
| 7 |
"""
|
| 8 |
-
Recebe um arquivo WebM, converte para MP4 e retorna o caminho do MP4.
|
| 9 |
"""
|
| 10 |
if webm_file is None:
|
| 11 |
-
|
| 12 |
-
return "https://sample-videos.com/video123/mp4/240/big_buck_bunny_240p_1mb.mp4"
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
|
|
|
| 16 |
|
| 17 |
try:
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
except subprocess.CalledProcessError as e:
|
| 28 |
-
|
|
|
|
| 29 |
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
fn=convert_webm_to_mp4,
|
| 35 |
-
inputs=gr.Video(label="WebM Input"),
|
| 36 |
-
outputs=gr.Video(label="MP4 Output"),
|
| 37 |
-
allow_flagging="never"
|
| 38 |
-
)
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
iface.launch(server_name="0.0.0.0", server_port=7860, share=True)
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import subprocess
|
| 3 |
+
import os
|
| 4 |
+
import tempfile
|
| 5 |
|
| 6 |
def convert_webm_to_mp4(webm_file):
|
| 7 |
"""
|
| 8 |
+
Recebe um arquivo WebM, converte para MP4 usando ffmpeg e retorna o caminho do MP4.
|
| 9 |
"""
|
| 10 |
if webm_file is None:
|
| 11 |
+
return None
|
|
|
|
| 12 |
|
| 13 |
+
# Cria um arquivo temporário para o MP4
|
| 14 |
+
with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmp:
|
| 15 |
+
mp4_path = tmp.name
|
| 16 |
|
| 17 |
try:
|
| 18 |
+
# Executa a conversão com ffmpeg
|
| 19 |
+
subprocess.run(
|
| 20 |
+
[
|
| 21 |
+
"ffmpeg",
|
| 22 |
+
"-y", # sobrescrever se existir
|
| 23 |
+
"-i", webm_file.name,
|
| 24 |
+
"-c:v", "libx264",
|
| 25 |
+
"-preset", "fast",
|
| 26 |
+
"-pix_fmt", "yuv420p",
|
| 27 |
+
mp4_path
|
| 28 |
+
],
|
| 29 |
+
check=True,
|
| 30 |
+
stdout=subprocess.PIPE,
|
| 31 |
+
stderr=subprocess.PIPE
|
| 32 |
+
)
|
| 33 |
+
return mp4_path
|
| 34 |
except subprocess.CalledProcessError as e:
|
| 35 |
+
print("Erro ao converter vídeo:", e.stderr.decode())
|
| 36 |
+
return None
|
| 37 |
|
| 38 |
+
# --- Gradio Blocks ---
|
| 39 |
+
with gr.Blocks() as app:
|
| 40 |
+
with gr.Row():
|
| 41 |
+
webm_input = gr.Video(label="WebM Input")
|
| 42 |
+
mp4_output = gr.Video(label="MP4 Output")
|
| 43 |
|
| 44 |
+
convert_btn = gr.Button("Convert WebM to MP4")
|
| 45 |
+
convert_btn.click(fn=convert_webm_to_mp4, inputs=webm_input, outputs=mp4_output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
+
# Executa o app
|
| 48 |
+
app.launch(server_name="0.0.0.0", server_port=7860, share=False)
|
|
|