File size: 1,334 Bytes
19f68b8
982688c
e9dc948
 
 
4b9964c
e9dc948
 
 
 
 
 
 
 
 
 
 
 
982688c
e9dc948
 
 
 
 
 
52775ef
e9dc948
 
 
 
4b9964c
e9dc948
52775ef
a05b522
e9dc948
a05b522
 
e9dc948
 
19f68b8
e9dc948
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
import gradio as gr
import numpy as np
import cv2

def interpolate_frames(video_file, num_interpolations):
    cap = cv2.VideoCapture(video_file)
    frames = []
    while cap.isOpened():
        ret, frame = cap.read()
        if not ret:
            break
        frames.append(frame)
    cap.release()

    # Convert frames to numpy array
    frames = np.array(frames)

    # Interpolate frames
    interpolated_frames = []
    for i in range(len(frames) - 1):
        for j in range(num_interpolations + 1):
            alpha = j / (num_interpolations + 1)
            interpolated_frame = cv2.addWeighted(frames[i], 1 - alpha, frames[i + 1], alpha, 0)
            interpolated_frames.append(interpolated_frame)

    return interpolated_frames

# Create a Gradio interface
with gr.Blocks() as demo:
    gr.Markdown("## Video Frame Interpolation")
    video_input = gr.File(label="Input Video")
    num_interpolations = gr.Slider(1, 10, step=1, label="Number of Interpolations")
    video_output = gr.Video(label="Interpolated Video")
    start_button = gr.Button("Start Interpolation")

    # Define the event listener for the start button
    start_button.click(interpolate_frames, inputs=[video_input, num_interpolations], outputs=video_output)

# Launch the interface
if __name__ == "__main__":
    demo.launch(show_error=True)