Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import ffmpeg
|
3 |
+
import os
|
4 |
+
from tempfile import NamedTemporaryFile
|
5 |
+
|
6 |
+
def interpolate_video(input_file, fps):
|
7 |
+
output_path = "framer_interpolated.mp4"
|
8 |
+
|
9 |
+
# Интерполяция кадров с использованием фильтра minterpolate, сохраняя звук
|
10 |
+
(
|
11 |
+
ffmpeg
|
12 |
+
.input(input_file)
|
13 |
+
.filter('minterpolate', fps=fps)
|
14 |
+
.output(output_path, acodec='copy')
|
15 |
+
.run(overwrite_output=True)
|
16 |
+
)
|
17 |
+
|
18 |
+
return output_path
|
19 |
+
|
20 |
+
# Заголовок приложения
|
21 |
+
st.title("Framer! - Frame interpolation with FFmpeg")
|
22 |
+
st.write("Upload a video and adjust the slider to set the target frame rate (FPS) for interpolation.")
|
23 |
+
|
24 |
+
# Загрузка видеофайла
|
25 |
+
uploaded_file = st.file_uploader("Upload Video", type=["mp4", "avi", "mov", "mkv"])
|
26 |
+
|
27 |
+
# Слайдер для выбора FPS
|
28 |
+
fps = st.slider("Frame Rate (FPS)", min_value=24, max_value=60, value=60, step=1)
|
29 |
+
|
30 |
+
if uploaded_file is not None:
|
31 |
+
# Сохранение загруженного видео во временный файл
|
32 |
+
with NamedTemporaryFile(delete=False, suffix=".mp4") as temp_file:
|
33 |
+
temp_file.write(uploaded_file.read())
|
34 |
+
temp_file_path = temp_file.name
|
35 |
+
|
36 |
+
# Кнопка для запуска интерполяции
|
37 |
+
if st.button("Interpolate Video"):
|
38 |
+
st.write("Processing your video...")
|
39 |
+
output_path = interpolate_video(temp_file_path, fps)
|
40 |
+
|
41 |
+
# Отображение результата
|
42 |
+
st.success("Video interpolation complete!")
|
43 |
+
st.video(output_path)
|
44 |
+
|
45 |
+
# Удаление временного файла
|
46 |
+
os.remove(temp_file_path)
|
47 |
+
else:
|
48 |
+
st.info("Please upload a video to get started.")
|