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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -15
app.py CHANGED
@@ -2,9 +2,9 @@ import cv2
2
  import subprocess
3
  import gradio as gr
4
 
5
- def interpolate_video(input_path, output_path):
6
  # Проверка пути к входному видео
7
- cap = cv2.VideoCapture(input_path)
8
  if not cap.isOpened():
9
  return False, "Ошибка: не удалось открыть входное видео."
10
 
@@ -25,9 +25,9 @@ def interpolate_video(input_path, output_path):
25
  # Команда для FFmpeg
26
  command = [
27
  'ffmpeg',
28
- '-i', input_path,
29
  '-filter:v', f'fps={new_fps}',
30
- output_path
31
  ]
32
 
33
  try:
@@ -38,21 +38,36 @@ def interpolate_video(input_path, output_path):
38
  if result.returncode != 0:
39
  return False, f"Ошибка FFmpeg: {result.stderr}"
40
 
41
- return True, "Интерполяция завершена успешно!"
42
  except Exception as e:
43
  return False, f"Произошла ошибка: {str(e)}"
44
 
45
  # Интерфейс Gradio
46
- iface = gr.Interface(
47
- fn=interpolate_video,
48
- inputs=[
49
- gr.Textbox(label="Введите путь к входному видео"),
50
- gr.Textbox(label="Введите путь к выходному видео")
51
- ],
52
- outputs=[gr.Checkbox(label="Успешно"), gr.Textbox(label="Сообщение")],
53
- title="Интерполяция видео до 60 FPS",
54
- description="Приложение для увеличения частоты кадров видео до 60 FPS."
55
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
  if __name__ == "__main__":
58
  iface.launch()
 
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
 
 
25
  # Команда для FFmpeg
26
  command = [
27
  'ffmpeg',
28
+ '-i', input_file,
29
  '-filter:v', f'fps={new_fps}',
30
+ output_file
31
  ]
32
 
33
  try:
 
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()