Yaroslav commited on
Commit
feac5ab
·
verified ·
1 Parent(s): 4b9964c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -36
app.py CHANGED
@@ -1,41 +1,50 @@
1
- import gradio as gr
2
- import numpy as np
3
  import cv2
 
 
 
4
 
5
- def interpolate_frames(video_file, num_interpolations):
6
- cap = cv2.VideoCapture(video_file)
7
- frames = []
8
- while cap.isOpened():
9
- ret, frame = cap.read()
10
- if not ret:
11
- break
12
- frames.append(frame)
13
- cap.release()
14
-
15
- # Convert frames to numpy array
16
- frames = np.array(frames)
17
-
18
- # Interpolate frames
19
- interpolated_frames = []
20
- for i in range(len(frames) - 1):
21
- for j in range(num_interpolations + 1):
22
- alpha = j / (num_interpolations + 1)
23
- interpolated_frame = cv2.addWeighted(frames[i], 1 - alpha, frames[i + 1], alpha, 0)
24
- interpolated_frames.append(interpolated_frame)
25
-
26
- return interpolated_frames
27
-
28
- # Create a Gradio interface
29
- with gr.Blocks() as demo:
30
- gr.Markdown("## Video Frame Interpolation")
31
- video_input = gr.File(label="Input Video")
32
- num_interpolations = gr.Slider(1, 10, step=1, label="Number of Interpolations")
33
- video_output = gr.Video(label="Interpolated Video")
34
- start_button = gr.Button("Start Interpolation")
35
 
36
- # Define the event listener for the start button
37
- start_button.click(interpolate_frames, inputs=[video_input, num_interpolations], outputs=video_output)
 
 
 
 
 
 
 
 
 
38
 
39
- # Launch the interface
40
  if __name__ == "__main__":
41
- demo.launch(show_error=True)
 
 
 
1
  import cv2
2
+ import numpy as np
3
+ from ffmpeg_python import FFmpeg
4
+ import gradio as gr
5
 
6
+ def interpolate_video(input_path, output_path):
7
+ # Загрузка видео
8
+ cap = cv2.VideoCapture(input_path)
9
+
10
+ # Получение количества кадров и частоты кадров исходного видео
11
+ fps = int(cap.get(cv2.CAP_PROP_FPS))
12
+ total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
13
+
14
+ # Настройка нового FPS
15
+ new_fps = 60
16
+
17
+ # Создание списка команд для ffmpeg
18
+ command = [
19
+ 'ffmpeg',
20
+ '-i', input_path,
21
+ '-filter:v', f'fps={new_fps}',
22
+ output_path
23
+ ]
24
+
25
+ # Запуск процесса интерполяции через ffmpeg
26
+ try:
27
+ process = FFmpeg(command)
28
+ out, err = process.run(capture_stdout=True, capture_stderr=True)
29
+
30
+ if err:
31
+ return False, err.decode('utf-8')
32
+
33
+ return True, "Интерполяция завершена успешно!"
34
+ except Exception as e:
35
+ return False, str(e)
36
 
37
+ # Интерфейс Gradio
38
+ iface = gr.Interface(
39
+ fn=interpolate_video,
40
+ inputs=[
41
+ gr.inputs.Textbox(label="Введите путь к входному видео"),
42
+ gr.inputs.Textbox(label="Введите путь к выходному видео")
43
+ ],
44
+ outputs=[gr.outputs.Boolean(label="Успешность"), gr.outputs.Textbox(label="Сообщение")],
45
+ title="Интерполяция видео до 60 FPS",
46
+ description="Приложение для увеличения частоты кадров видео до 60 FPS."
47
+ )
48
 
 
49
  if __name__ == "__main__":
50
+ iface.launch()