File size: 2,613 Bytes
b90e544
 
 
 
3c7a869
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b90e544
 
 
03b2a1f
0bc0ba6
3c7a869
 
 
03b2a1f
0b5347b
 
3c7a869
0b5347b
3c7a869
fae2fca
3c7a869
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d996af4
3c7a869
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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()