Spaces:
Running
on
T4
Running
on
T4
Update app.py
Browse files
app.py
CHANGED
@@ -1,53 +1,54 @@
|
|
1 |
import gradio as gr
|
2 |
import subprocess
|
3 |
-
import os
|
4 |
from uuid import uuid4
|
5 |
|
6 |
-
def
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
def merge_videos(video1_path, video2_path):
|
14 |
output_filename = f"{uuid4()}_merged.mp4"
|
15 |
-
|
16 |
-
# Altura e largura desejadas para o vídeo de saída
|
17 |
-
desired_height = 1280
|
18 |
-
desired_width = 720
|
19 |
-
|
20 |
-
# Comando ffmpeg ajustado para usar h264_nvenc para aceleração por hardware
|
21 |
ffmpeg_cmd = (
|
22 |
f'ffmpeg -i "{video1_path}" -i "{video2_path}" '
|
23 |
-
f'-filter_complex '
|
24 |
-
f'
|
25 |
-
f'fps=fps=30[v0]
|
26 |
-
f'[1:v]scale={desired_width}:{desired_height}:force_original_aspect_ratio=decrease,pad={desired_width}:{desired_height}:(ow-iw)/2:(oh-ih)/2,'
|
27 |
-
f'fps=fps=30[v1];'
|
28 |
-
f'[v0][v1]vstack=inputs=2[v]" '
|
29 |
-
f'-map "[v]" -c:v h264_nvenc -preset fast {output_filename}'
|
30 |
)
|
31 |
-
|
32 |
try:
|
33 |
subprocess.run(ffmpeg_cmd, shell=True, check=True, capture_output=True)
|
|
|
34 |
except subprocess.CalledProcessError as e:
|
35 |
-
|
36 |
-
if "Cannot load libnvidia-encode.so.1" in e.stderr.decode():
|
37 |
-
print("NVENC não disponível. Verifique a instalação dos drivers da NVIDIA e se sua GPU suporta NVENC.")
|
38 |
-
raise
|
39 |
-
|
40 |
-
return output_filename
|
41 |
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
-
|
53 |
-
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import subprocess
|
|
|
3 |
from uuid import uuid4
|
4 |
|
5 |
+
def check_gpu_info():
|
6 |
+
try:
|
7 |
+
gpu_info = subprocess.run(['nvidia-smi'], text=True, capture_output=True, check=True)
|
8 |
+
return gpu_info.stdout
|
9 |
+
except subprocess.CalledProcessError as e:
|
10 |
+
return f"Erro ao executar nvidia-smi: {e.stderr}"
|
11 |
+
|
12 |
+
def check_nvenc_availability():
|
13 |
+
try:
|
14 |
+
nvenc_check = subprocess.run(['ffmpeg', '-codecs'], text=True, capture_output=True, check=True)
|
15 |
+
h264_status = "Disponível" if "h264_nvenc" in nvenc_check.stdout else "Não disponível"
|
16 |
+
hevc_status = "Disponível" if "hevc_nvenc" in nvenc_check.stdout else "Não disponível"
|
17 |
+
return f"NVENC para H.264: {h264_status}\nNVENC para HEVC (H.265): {hevc_status}"
|
18 |
+
except subprocess.CalledProcessError as e:
|
19 |
+
return f"Erro ao verificar codecs: {e.stderr}"
|
20 |
|
21 |
def merge_videos(video1_path, video2_path):
|
22 |
output_filename = f"{uuid4()}_merged.mp4"
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
ffmpeg_cmd = (
|
24 |
f'ffmpeg -i "{video1_path}" -i "{video2_path}" '
|
25 |
+
f'-filter_complex "[0:v]scale=720:1280:force_original_aspect_ratio=decrease,pad=720:1280:(ow-iw)/2:(oh-ih)/2,'
|
26 |
+
f'fps=fps=30[v0];[1:v]scale=720:1280:force_original_aspect_ratio=decrease,pad=720:1280:(ow-iw)/2:(oh-ih)/2,'
|
27 |
+
f'fps=fps=30[v1];[v0][v1]vstack=inputs=2[v]" -map "[v]" -c:v libx264 -preset fast {output_filename}'
|
|
|
|
|
|
|
|
|
28 |
)
|
|
|
29 |
try:
|
30 |
subprocess.run(ffmpeg_cmd, shell=True, check=True, capture_output=True)
|
31 |
+
return output_filename
|
32 |
except subprocess.CalledProcessError as e:
|
33 |
+
return f"Erro ao mesclar vídeos: {e.stderr}"
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
+
with gr.Blocks() as app:
|
36 |
+
gr.Markdown("## Ferramentas de Diagnóstico e Processamento de Vídeo")
|
37 |
+
with gr.Tab("Diagnóstico"):
|
38 |
+
with gr.Row():
|
39 |
+
gpu_info_btn = gr.Button("Verificar Informações da GPU")
|
40 |
+
nvenc_availability_btn = gr.Button("Verificar Disponibilidade do NVENC")
|
41 |
+
gpu_info_output = gr.Textbox(label="Informações da GPU")
|
42 |
+
nvenc_availability_output = gr.Textbox(label="Disponibilidade do NVENC")
|
43 |
+
gpu_info_btn.click(check_gpu_info, [], gpu_info_output)
|
44 |
+
nvenc_availability_btn.click(check_nvenc_availability, [], nvenc_availability_output)
|
45 |
+
|
46 |
+
with gr.Tab("Processamento de Vídeo"):
|
47 |
+
with gr.Column():
|
48 |
+
video1_input = gr.Video(label="Vídeo 1")
|
49 |
+
video2_input = gr.Video(label="Vídeo 2")
|
50 |
+
merge_btn = gr.Button("Mesclar Vídeos")
|
51 |
+
merge_output = gr.Video(label="Vídeo Mesclado")
|
52 |
+
merge_btn.click(merge_videos, [video1_input, video2_input], merge_output)
|
53 |
|
54 |
+
app.launch()
|
|