Yaroslav commited on
Commit
e35e748
·
verified ·
1 Parent(s): 0f99c8e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -66
app.py CHANGED
@@ -1,73 +1,31 @@
1
- import cv2
2
- import subprocess
3
  import gradio as gr
 
4
 
5
- def interpolate_video(input_file, output_file):
6
- # Проверка пути к входному видео
7
- cap = cv2.VideoCapture(input_file)
8
- if not cap.isOpened():
9
- return False, "Ошибка: не удалось открыть входное видео."
10
-
11
- # Получение информации о входном видео
12
- fps = cap.get(cv2.CAP_PROP_FPS)
13
- total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
14
-
15
- # Закрытие объекта VideoCapture
16
- cap.release()
17
-
18
- # Проверка на корректность значений FPS
19
- if fps <= 0 or total_frames <= 0:
20
- return False, "Ошибка: некорректное видео или не удалось определить FPS/количество кадров."
21
-
22
- # Новый FPS
23
- new_fps = 60
24
-
25
- # Команда для FFmpeg
26
- command = [
27
- 'ffmpeg',
28
- '-i', input_file,
29
- '-filter:v', f'fps={new_fps}',
30
- output_file
31
- ]
32
-
33
- try:
34
- # Запуск FFmpeg через subprocess
35
- result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
36
-
37
- # Проверка результата
38
- if result.returncode != 0:
39
- return False, f"Ошибка FFmpeg: {result.stderr}"
40
-
41
- return True, f"Интерполяция завершена успешно! Видео сохранено в {output_file}"
42
- except Exception as e:
43
- return False, f"Произошла ошибка: {str(e)}"
44
 
45
- # Интерфейс Gradio
46
- with gr.Blocks() as iface:
47
- gr.Markdown("# Интерполяция видео до 60 FPS")
48
-
49
- with gr.Row():
50
- input_file = gr.File(label="Выберите входное видео")
51
- output_file = gr.Textbox(label="Введите имя выходного файла (с .mp4)")
52
-
53
- with gr.Row():
54
- submit_button = gr.Button("Отправить")
55
- clear_button = gr.Button("Очистить")
56
-
57
- success_output = gr.Checkbox(label="Успешно")
58
- message_output = gr.Textbox(label="Сообщение")
59
-
60
- submit_button.click(
61
- fn=interpolate_video,
62
- inputs=[input_file, output_file],
63
- outputs=[success_output, message_output]
64
- )
65
-
66
- clear_button.click(
67
- fn=lambda: (False, ""),
68
- inputs=[],
69
- outputs=[success_output, message_output]
70
  )
71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  if __name__ == "__main__":
73
  iface.launch()
 
 
 
1
  import gradio as gr
2
+ import ffmpeg
3
 
4
+ def interpolate_video(video, fps):
5
+ input_path = video.name
6
+ output_path = "interpolated_video.mp4"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
+ # Команда ffmpeg для интерполяции кадров
9
+ (
10
+ ffmpeg
11
+ .input(input_path)
12
+ .filter('fps', fps=fps, round='up')
13
+ .output(output_path)
14
+ .run(overwrite_output=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  )
16
 
17
+ return output_path
18
+
19
+ iface = gr.Interface(
20
+ fn=interpolate_video,
21
+ inputs=[
22
+ gr.File(label="Upload Video"),
23
+ gr.Slider(minimum=24, maximum=60, step=1, value=60, label="Frame Rate (FPS)")
24
+ ],
25
+ outputs=gr.Video(label="Interpolated Video"),
26
+ title="Frame Interpolation App",
27
+ description="Upload a video and adjust the slider to set the target frame rate (FPS) for interpolation."
28
+ )
29
+
30
  if __name__ == "__main__":
31
  iface.launch()