File size: 1,078 Bytes
67388d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import cv2 as cv
import numpy as np
import gradio as gr
import os

def process_video(input_video):
    output_path = "car_output.mp4"
    
    cap = cv.VideoCapture(input_video)
    fourcc = cv.VideoWriter_fourcc(*"mp4v")
    fps = int(cap.get(cv.CAP_PROP_FPS))
    width = int(cap.get(cv.CAP_PROP_FRAME_WIDTH))
    height = int(cap.get(cv.CAP_PROP_FRAME_HEIGHT))
    out = cv.VideoWriter(output_path, fourcc, fps, (width, height))

    while cap.isOpened():
        ret, frame = cap.read()
        if not ret:
            break

        b, g, r = cv.split(frame)
        rgb_frame = cv.merge((r, g, b))
        out.write(rgb_frame)

    cap.release()
    out.release()

    return output_path

gr.Interface(
    fn=process_video,
    inputs=gr.Video(label="Upload a video"),
    outputs=gr.Video(label="Processed Video Output"),
    title="RGB Channel Swap Video Processor",
    description="This app reads a video, swaps the BGR to RGB channel, and shows the processed video.",
    allow_flagging="never"  # Disable flag button
).launch()