|
import cv2 |
|
import os |
|
import gradio as gr |
|
from super_slo import SuperSlo |
|
|
|
|
|
model = SuperSlo() |
|
|
|
|
|
def increase_fps(input_video_path, target_fps=60): |
|
output_path = "output.mp4" |
|
cap = cv2.VideoCapture(input_video_path) |
|
input_fps = cap.get(cv2.CAP_PROP_FPS) |
|
frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)) |
|
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) |
|
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) |
|
codec = cv2.VideoWriter_fourcc(*"mp4v") |
|
|
|
if input_fps >= target_fps: |
|
cap.release() |
|
return input_video_path |
|
|
|
ratio = target_fps / input_fps |
|
output = cv2.VideoWriter(output_path, codec, target_fps, (width, height)) |
|
|
|
ret, prev_frame = cap.read() |
|
|
|
if not ret: |
|
cap.release() |
|
output.release() |
|
raise ValueError("Не удалось прочитать кадры из видео.") |
|
|
|
while True: |
|
ret, next_frame = cap.read() |
|
if not ret: |
|
break |
|
|
|
for i in range(1, int(ratio)): |
|
alpha = i / ratio |
|
intermediate_frame = model.interpolate(prev_frame, next_frame, alpha) |
|
output.write(intermediate_frame) |
|
|
|
output.write(next_frame) |
|
prev_frame = next_frame |
|
|
|
cap.release() |
|
output.release() |
|
|
|
return output_path |
|
|
|
def process_video(video_path): |
|
return increase_fps(video_path) |
|
|
|
interface = gr.Interface( |
|
fn=process_video, |
|
inputs=gr.Video(label="Загрузите видео для обработки"), |
|
outputs=gr.Video(label="Видео с увеличенным FPS"), |
|
title="Увеличение FPS до 60", |
|
description="Этот инструмент увеличивает частоту кадров видео до 60 FPS с использованием оптического потока. Загрузите видео с низким FPS, чтобы получить плавный результат.", |
|
examples=[] |
|
) |
|
|
|
if __name__ == "__main__": |
|
interface.launch() |