Yaroslav
Update app.py
dbc5df6 verified
raw
history blame
1.68 kB
import gradio as gr
import ffmpeg
import time
import os
def interpolate_video(video, fps):
input_path = video.name
output_path = "interpolated_video.mp4"
# Интерполяция кадров с использованием фильтра minterpolate
process = (
ffmpeg
.input(input_path)
.filter('minterpolate', fps=fps)
.output(output_path)
.overwrite_output()
.run_async(pipe_stdout=True, pipe_stderr=True)
)
# Вставим progress bar
total_duration = float(ffmpeg.probe(input_path)['format']['duration'])
progress = 0
while process.poll() is None:
time.sleep(0.5) # Обновление каждые 0.5 секунды
stderr_output = process.stderr.read().decode('utf-8')
if "frame=" in stderr_output:
current_time = float(stderr_output.split('time=')[-1].split(' ')[0].replace(':','')) # Извлечение текущего времени кадра
progress = (current_time / total_duration) * 100
yield progress # Обновление значения progress bar
process.wait()
return output_path
iface = gr.Interface(
fn=interpolate_video,
inputs=[
gr.File(label="Upload Video"),
gr.Slider(minimum=24, maximum=60, step=1, value=60, label="Frame Rate (FPS)")
],
outputs=[
gr.Video(label="Interpolated Video"),
gr.Progress(label="Processing Progress")
],
title="Frame Interpolation App",
description="Upload a video and adjust the slider to set the target frame rate (FPS) for interpolation."
)
if __name__ == "__main__":
iface.launch()