File size: 2,235 Bytes
feac5ab e35e748 dbc5df6 1ce5c4e e9dc948 e35e748 e9dc948 1ce5c4e dbc5df6 e35e748 2f1b8b0 e35e748 dbc5df6 0f99c8e e9dc948 dbc5df6 1ce5c4e dbc5df6 e35e748 1ce5c4e e35e748 1ce5c4e e35e748 dbc5df6 1ce5c4e dbc5df6 1ce5c4e 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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
import gradio as gr
import ffmpeg
import os
import time
def interpolate_video(video, fps):
input_path = video.name
output_path = "interpolated_video.mp4"
# Проверяем входное видео
try:
probe = ffmpeg.probe(input_path)
total_duration = float(probe['format']['duration'])
except ffmpeg.Error as e:
return f"Ошибка при анализе видео: {e}"
# Начинаем процесс интерполяции
process = (
ffmpeg
.input(input_path)
.filter('minterpolate', fps=fps)
.output(output_path)
.overwrite_output()
.run_async(pipe_stdout=True, pipe_stderr=True)
)
progress = 0
while process.poll() is None:
time.sleep(0.5) # Обновление каждые 0.5 секунды
# Чтение строки stderr
stderr_line = process.stderr.readline().decode('utf-8').strip()
if "time=" in stderr_line:
try:
# Парсим текущий прогресс
time_match = stderr_line.split("time=")[-1].split(" ")[0]
h, m, s = map(float, time_match.split(":"))
current_time = h * 3600 + m * 60 + s
progress = (current_time / total_duration) * 100
except Exception:
pass
yield f"Прогресс: {progress:.2f}%"
process.wait()
if os.path.exists(output_path):
return output_path
else:
return "Ошибка в обработке видео."
# Интерфейс Gradio
iface = gr.Interface(
fn=interpolate_video,
inputs=[
gr.File(label="Загрузить видео"),
gr.Slider(minimum=24, maximum=60, step=1, value=60, label="Частота кадров (FPS)")
],
outputs=[
gr.Video(label="Интерполированное видео"),
gr.Text(label="Прогресс обработки")
],
title="Приложение для интерполяции видео",
description="Загрузите видео и выберите желаемую частоту кадров (FPS)."
)
if __name__ == "__main__":
iface.launch() |