Spaces:
Running
on
T4
Running
on
T4
import gradio as gr | |
import subprocess | |
from uuid import uuid4 | |
def check_gpu_info(): | |
try: | |
gpu_info = subprocess.run(['nvidia-smi'], text=True, capture_output=True, check=True) | |
return gpu_info.stdout | |
except subprocess.CalledProcessError as e: | |
return f"Erro ao executar nvidia-smi: {e.stderr}" | |
def check_nvenc_availability(): | |
try: | |
nvenc_check = subprocess.run(['ffmpeg', '-codecs'], text=True, capture_output=True, check=True) | |
h264_status = "Disponível" if "h264_nvenc" in nvenc_check.stdout else "Não disponível" | |
hevc_status = "Disponível" if "hevc_nvenc" in nvenc_check.stdout else "Não disponível" | |
return f"NVENC para H.264: {h264_status}\nNVENC para HEVC (H.265): {hevc_status}" | |
except subprocess.CalledProcessError as e: | |
return f"Erro ao verificar codecs: {e.stderr}" | |
def merge_videos(video1_path, video2_path): | |
output_filename = f"{uuid4()}_merged.mp4" | |
ffmpeg_cmd = ( | |
f'ffmpeg -i "{video1_path}" -i "{video2_path}" ' | |
f'-filter_complex "[0:v]scale=720:1280:force_original_aspect_ratio=decrease,pad=720:1280:(ow-iw)/2:(oh-ih)/2,' | |
f'fps=fps=30[v0];[1:v]scale=720:1280:force_original_aspect_ratio=decrease,pad=720:1280:(ow-iw)/2:(oh-ih)/2,' | |
f'fps=fps=30[v1];[v0][v1]vstack=inputs=2[v]" -map "[v]" -c:v libx264 -preset fast {output_filename}' | |
) | |
try: | |
subprocess.run(ffmpeg_cmd, shell=True, check=True, capture_output=True) | |
return output_filename | |
except subprocess.CalledProcessError as e: | |
return f"Erro ao mesclar vídeos: {e.stderr}" | |
with gr.Blocks() as app: | |
gr.Markdown("## Ferramentas de Diagnóstico e Processamento de Vídeo") | |
with gr.Tab("Diagnóstico"): | |
with gr.Row(): | |
gpu_info_btn = gr.Button("Verificar Informações da GPU") | |
nvenc_availability_btn = gr.Button("Verificar Disponibilidade do NVENC") | |
gpu_info_output = gr.Textbox(label="Informações da GPU") | |
nvenc_availability_output = gr.Textbox(label="Disponibilidade do NVENC") | |
gpu_info_btn.click(check_gpu_info, [], gpu_info_output) | |
nvenc_availability_btn.click(check_nvenc_availability, [], nvenc_availability_output) | |
with gr.Tab("Processamento de Vídeo"): | |
with gr.Column(): | |
video1_input = gr.Video(label="Vídeo 1") | |
video2_input = gr.Video(label="Vídeo 2") | |
merge_btn = gr.Button("Mesclar Vídeos") | |
merge_output = gr.Video(label="Vídeo Mesclado") | |
merge_btn.click(merge_videos, [video1_input, video2_input], merge_output) | |
app.launch() | |