|
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() |
|
|
|
|
|
frames = np.array(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 |
|
|
|
|
|
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") |
|
|
|
|
|
start_button.click(interpolate_frames, inputs=[video_input, num_interpolations], outputs=video_output) |
|
|
|
|
|
if __name__ == "__main__": |
|
demo.launch(show_error=True) |