File size: 1,289 Bytes
ec2de63
 
20bee2f
 
ec2de63
 
 
 
 
 
 
 
20bee2f
ec2de63
 
bbce39c
 
cef68e0
 
 
 
ec2de63
 
 
bbce39c
 
 
 
 
 
 
 
 
 
 
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
import subprocess
import sys
import gradio as gr

def install_opencv():
    try:
        import cv2
        print("OpenCV is already installed.")
    except ImportError:
        print("Installing OpenCV...")
        subprocess.check_call([sys.executable, "-m", "pip", "install", "opencv-python"])
        print("OpenCV installation completed.")

def extract_clip(video_path, clip_start, clip_duration):
    # ... (rest of your extract_clip function)

def display_frames(frames):
    num_cols = 4  # Number of columns in the image grid
    num_rows = (len(frames) + num_cols - 1) // num_cols
    grid_image = cv2.hconcat([cv2.hconcat(frames[i:i+num_cols]) for i in range(0, len(frames), num_cols)])
    return grid_image

# Install OpenCV if not already installed
install_opencv()

# Create Gradio interface
video_input = gr.inputs.Video(type="file")
start_input = gr.inputs.Number(default=5, label="Start Time (seconds)")
duration_input = gr.inputs.Number(default=3, label="Duration (seconds)")
image_output = gr.outputs.Image(type="pil")

gr.Interface(fn=lambda video, start, duration: display_frames(extract_clip(video, start, duration)),
             inputs=[video_input, start_input, duration_input],
             outputs=image_output,
             title="Extract Video Clip").launch()