File size: 916 Bytes
82e48c9
cdb3457
 
 
82e48c9
 
 
 
 
 
 
 
cdb3457
82e48c9
 
 
 
 
 
cdb3457
82e48c9
 
cdb3457
82e48c9
cdb3457
82e48c9
 
 
 
 
cdb3457
 
82e48c9
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
import cv2
import gradio as gr
import os

def convert_to_grayscale(video_file):
    cap = cv2.VideoCapture(video_file)
    output_file = "output.mp4"
    width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
    height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
    fps = int(cap.get(cv2.CAP_PROP_FPS))
    fourcc = cv2.VideoWriter_fourcc(*'mp4v')
    out = cv2.VideoWriter(output_file, fourcc, fps, (width, height), isColor=False)
    
    while(cap.isOpened()):
        ret, frame = cap.read()
        if not ret:
            break
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        out.write(gray)
    
    cap.release()
    out.release()
    
    return output_file

demo = gr.Interface(
    fn=convert_to_grayscale,
    title="Video Upload and Display",
    inputs=gr.Video(label="Upload Video", height=500, width=500),
    outputs=gr.Video(label="Grayscale Video", height=500, width=500),
)

demo.launch()