Yaroslav
commited on
hi superslo
Browse files
app.py
CHANGED
@@ -1,6 +1,10 @@
|
|
1 |
import cv2
|
2 |
import os
|
3 |
import gradio as gr
|
|
|
|
|
|
|
|
|
4 |
|
5 |
# Функция для увеличения FPS
|
6 |
def increase_fps(input_video_path, target_fps=60):
|
@@ -12,12 +16,10 @@ def increase_fps(input_video_path, target_fps=60):
|
|
12 |
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
13 |
codec = cv2.VideoWriter_fourcc(*"mp4v")
|
14 |
|
15 |
-
# Проверка: если входное FPS >= 60, просто копируем файл
|
16 |
if input_fps >= target_fps:
|
17 |
cap.release()
|
18 |
-
return input_video_path
|
19 |
|
20 |
-
# Расчет коэффициента интерполяции
|
21 |
ratio = target_fps / input_fps
|
22 |
output = cv2.VideoWriter(output_path, codec, target_fps, (width, height))
|
23 |
|
@@ -28,26 +30,17 @@ def increase_fps(input_video_path, target_fps=60):
|
|
28 |
output.release()
|
29 |
raise ValueError("Не удалось прочитать кадры из видео.")
|
30 |
|
31 |
-
prev_frame_gray = cv2.cvtColor(prev_frame, cv2.COLOR_BGR2GRAY)
|
32 |
-
|
33 |
while True:
|
34 |
ret, next_frame = cap.read()
|
35 |
if not ret:
|
36 |
break
|
37 |
|
38 |
-
next_frame_gray = cv2.cvtColor(next_frame, cv2.COLOR_BGR2GRAY)
|
39 |
-
|
40 |
-
# Оптический поток
|
41 |
-
flow = cv2.calcOpticalFlowFarneback(prev_frame_gray, next_frame_gray, None, 0.5, 3, 15, 3, 5, 1.2, 0)
|
42 |
-
|
43 |
for i in range(1, int(ratio)):
|
44 |
alpha = i / ratio
|
45 |
-
|
46 |
-
intermediate_frame = cv2.remap(prev_frame, flow_intermediate, None, cv2.INTER_LINEAR)
|
47 |
output.write(intermediate_frame)
|
48 |
|
49 |
output.write(next_frame)
|
50 |
-
prev_frame_gray = next_frame_gray
|
51 |
prev_frame = next_frame
|
52 |
|
53 |
cap.release()
|
@@ -55,7 +48,6 @@ def increase_fps(input_video_path, target_fps=60):
|
|
55 |
|
56 |
return output_path
|
57 |
|
58 |
-
# Gradio интерфейс
|
59 |
def process_video(video_path):
|
60 |
return increase_fps(video_path)
|
61 |
|
@@ -64,13 +56,9 @@ interface = gr.Interface(
|
|
64 |
inputs=gr.Video(label="Загрузите видео для обработки"),
|
65 |
outputs=gr.Video(label="Видео с увеличенным FPS"),
|
66 |
title="Увеличение FPS до 60",
|
67 |
-
description=
|
68 |
-
"Этот инструмент увеличивает частоту кадров видео до 60 FPS с использованием "
|
69 |
-
"оптического потока. Загрузите видео с низким FPS, чтобы получить плавный результат."
|
70 |
-
),
|
71 |
examples=[]
|
72 |
)
|
73 |
|
74 |
-
# Запуск интерфейса
|
75 |
if __name__ == "__main__":
|
76 |
interface.launch()
|
|
|
1 |
import cv2
|
2 |
import os
|
3 |
import gradio as gr
|
4 |
+
from super_slo import SuperSlo
|
5 |
+
|
6 |
+
# Инициализация модели SuperSlo для интерполяции
|
7 |
+
model = SuperSlo()
|
8 |
|
9 |
# Функция для увеличения FPS
|
10 |
def increase_fps(input_video_path, target_fps=60):
|
|
|
16 |
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
17 |
codec = cv2.VideoWriter_fourcc(*"mp4v")
|
18 |
|
|
|
19 |
if input_fps >= target_fps:
|
20 |
cap.release()
|
21 |
+
return input_video_path
|
22 |
|
|
|
23 |
ratio = target_fps / input_fps
|
24 |
output = cv2.VideoWriter(output_path, codec, target_fps, (width, height))
|
25 |
|
|
|
30 |
output.release()
|
31 |
raise ValueError("Не удалось прочитать кадры из видео.")
|
32 |
|
|
|
|
|
33 |
while True:
|
34 |
ret, next_frame = cap.read()
|
35 |
if not ret:
|
36 |
break
|
37 |
|
|
|
|
|
|
|
|
|
|
|
38 |
for i in range(1, int(ratio)):
|
39 |
alpha = i / ratio
|
40 |
+
intermediate_frame = model.interpolate(prev_frame, next_frame, alpha)
|
|
|
41 |
output.write(intermediate_frame)
|
42 |
|
43 |
output.write(next_frame)
|
|
|
44 |
prev_frame = next_frame
|
45 |
|
46 |
cap.release()
|
|
|
48 |
|
49 |
return output_path
|
50 |
|
|
|
51 |
def process_video(video_path):
|
52 |
return increase_fps(video_path)
|
53 |
|
|
|
56 |
inputs=gr.Video(label="Загрузите видео для обработки"),
|
57 |
outputs=gr.Video(label="Видео с увеличенным FPS"),
|
58 |
title="Увеличение FPS до 60",
|
59 |
+
description="Этот инструмент увеличивает частоту кадров видео до 60 FPS с использованием оптического потока. Загрузите видео с низким FPS, чтобы получить плавный результат.",
|
|
|
|
|
|
|
60 |
examples=[]
|
61 |
)
|
62 |
|
|
|
63 |
if __name__ == "__main__":
|
64 |
interface.launch()
|