Yaroslav
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,35 @@
|
|
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 |
-
.
|
|
|
15 |
)
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
return output_path
|
18 |
|
19 |
iface = gr.Interface(
|
@@ -22,7 +38,10 @@ iface = gr.Interface(
|
|
22 |
gr.File(label="Upload Video"),
|
23 |
gr.Slider(minimum=24, maximum=60, step=1, value=60, label="Frame Rate (FPS)")
|
24 |
],
|
25 |
-
outputs=
|
|
|
|
|
|
|
26 |
title="Frame Interpolation App",
|
27 |
description="Upload a video and adjust the slider to set the target frame rate (FPS) for interpolation."
|
28 |
)
|
|
|
1 |
import gradio as gr
|
2 |
import ffmpeg
|
3 |
+
import time
|
4 |
+
import os
|
5 |
|
6 |
def interpolate_video(video, fps):
|
7 |
input_path = video.name
|
8 |
output_path = "interpolated_video.mp4"
|
9 |
|
10 |
# Интерполяция кадров с использованием фильтра minterpolate
|
11 |
+
process = (
|
12 |
ffmpeg
|
13 |
.input(input_path)
|
14 |
.filter('minterpolate', fps=fps)
|
15 |
.output(output_path)
|
16 |
+
.overwrite_output()
|
17 |
+
.run_async(pipe_stdout=True, pipe_stderr=True)
|
18 |
)
|
19 |
|
20 |
+
# Вставим progress bar
|
21 |
+
total_duration = float(ffmpeg.probe(input_path)['format']['duration'])
|
22 |
+
progress = 0
|
23 |
+
while process.poll() is None:
|
24 |
+
time.sleep(0.5) # Обновление каждые 0.5 секунды
|
25 |
+
stderr_output = process.stderr.read().decode('utf-8')
|
26 |
+
if "frame=" in stderr_output:
|
27 |
+
current_time = float(stderr_output.split('time=')[-1].split(' ')[0].replace(':','')) # Извлечение текущего времени кадра
|
28 |
+
progress = (current_time / total_duration) * 100
|
29 |
+
yield progress # Обновление значения progress bar
|
30 |
+
|
31 |
+
process.wait()
|
32 |
+
|
33 |
return output_path
|
34 |
|
35 |
iface = gr.Interface(
|
|
|
38 |
gr.File(label="Upload Video"),
|
39 |
gr.Slider(minimum=24, maximum=60, step=1, value=60, label="Frame Rate (FPS)")
|
40 |
],
|
41 |
+
outputs=[
|
42 |
+
gr.Video(label="Interpolated Video"),
|
43 |
+
gr.Progress(label="Processing Progress")
|
44 |
+
],
|
45 |
title="Frame Interpolation App",
|
46 |
description="Upload a video and adjust the slider to set the target frame rate (FPS) for interpolation."
|
47 |
)
|