File size: 1,680 Bytes
feac5ab e35e748 dbc5df6 e9dc948 e35e748 e9dc948 2f1b8b0 dbc5df6 e35e748 2f1b8b0 e35e748 dbc5df6 0f99c8e e9dc948 dbc5df6 e35e748 dbc5df6 e35e748 19f68b8 feac5ab |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
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() |