Yaroslav commited on
Commit
7463d83
·
verified ·
1 Parent(s): 1ce5c4e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -44
app.py CHANGED
@@ -1,65 +1,30 @@
1
  import gradio as gr
2
  import ffmpeg
3
- import os
4
- import time
5
 
6
  def interpolate_video(video, fps):
7
  input_path = video.name
8
  output_path = "interpolated_video.mp4"
9
 
10
- # Проверяем входное видео
11
- try:
12
- probe = ffmpeg.probe(input_path)
13
- total_duration = float(probe['format']['duration'])
14
- except ffmpeg.Error as e:
15
- return f"Ошибка при анализе видео: {e}"
16
-
17
- # Начинаем процесс интерполяции
18
- process = (
19
  ffmpeg
20
  .input(input_path)
21
  .filter('minterpolate', fps=fps)
22
  .output(output_path)
23
- .overwrite_output()
24
- .run_async(pipe_stdout=True, pipe_stderr=True)
25
  )
26
 
27
- progress = 0
28
- while process.poll() is None:
29
- time.sleep(0.5) # Обновление каждые 0.5 секунды
30
- # Чтение строки stderr
31
- stderr_line = process.stderr.readline().decode('utf-8').strip()
32
- if "time=" in stderr_line:
33
- try:
34
- # Парсим текущий прогресс
35
- time_match = stderr_line.split("time=")[-1].split(" ")[0]
36
- h, m, s = map(float, time_match.split(":"))
37
- current_time = h * 3600 + m * 60 + s
38
- progress = (current_time / total_duration) * 100
39
- except Exception:
40
- pass
41
- yield f"Прогресс: {progress:.2f}%"
42
-
43
- process.wait()
44
 
45
- if os.path.exists(output_path):
46
- return output_path
47
- else:
48
- return "Ошибка в обработке видео."
49
-
50
- # Интерфейс Gradio
51
  iface = gr.Interface(
52
  fn=interpolate_video,
53
  inputs=[
54
- gr.File(label="Загрузить видео"),
55
- gr.Slider(minimum=24, maximum=60, step=1, value=60, label="Частота кадров (FPS)")
56
- ],
57
- outputs=[
58
- gr.Video(label="Интерполированное видео"),
59
- gr.Text(label="Прогресс обработки")
60
  ],
61
- title="Приложение для интерполяции видео",
62
- description="Загрузите видео и выберите желаемую частоту кадров (FPS)."
 
63
  )
64
 
65
  if __name__ == "__main__":
 
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
+ # Интерполяция кадров с использованием фильтра minterpolate
9
+ (
 
 
 
 
 
 
 
10
  ffmpeg
11
  .input(input_path)
12
  .filter('minterpolate', fps=fps)
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__":