Update app.py
Browse files
app.py
CHANGED
@@ -6,8 +6,13 @@ st.title("Video Playback and Duplication")
|
|
6 |
|
7 |
# Функция для конвертации видео в формат MP4 с кодеком H.264
|
8 |
def convert_to_mp4(input_path, output_path):
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
# Загрузка видеофайла
|
13 |
uploaded_file = st.file_uploader("Choose a video...", type=["mp4", "avi", "mov", "mkv"])
|
@@ -22,13 +27,20 @@ if uploaded_file is not None:
|
|
22 |
with open(input_video_path, "wb") as f:
|
23 |
f.write(uploaded_file.getbuffer())
|
24 |
|
25 |
-
#
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
-
#
|
29 |
-
st.
|
30 |
-
|
31 |
-
|
32 |
-
# Дублирование и воспроизведение видео
|
33 |
-
st.video(output_video_path, start_time=0)
|
34 |
-
st.write("Duplicated Video (Converted)")
|
|
|
6 |
|
7 |
# Функция для конвертации видео в формат MP4 с кодеком H.264
|
8 |
def convert_to_mp4(input_path, output_path):
|
9 |
+
try:
|
10 |
+
video_clip = VideoFileClip(input_path)
|
11 |
+
video_clip.write_videofile(output_path, codec="libx264", audio_codec="aac")
|
12 |
+
return True
|
13 |
+
except Exception as e:
|
14 |
+
st.error(f"Error converting video: {e}")
|
15 |
+
return False
|
16 |
|
17 |
# Загрузка видеофайла
|
18 |
uploaded_file = st.file_uploader("Choose a video...", type=["mp4", "avi", "mov", "mkv"])
|
|
|
27 |
with open(input_video_path, "wb") as f:
|
28 |
f.write(uploaded_file.getbuffer())
|
29 |
|
30 |
+
# Проверка типа файла и конвертация при необходимости
|
31 |
+
file_type = uploaded_file.type.split('/')[1]
|
32 |
+
if file_type in ['mp4', 'webm', 'ogg']:
|
33 |
+
st.video(input_video_path, start_time=0)
|
34 |
+
st.write("Original Video")
|
35 |
+
else:
|
36 |
+
if convert_to_mp4(input_video_path, output_video_path):
|
37 |
+
st.success("Video converted successfully!")
|
38 |
+
st.video(output_video_path, start_time=0)
|
39 |
+
st.write("Original Video (Converted)")
|
40 |
+
else:
|
41 |
+
st.error("Failed to convert video.")
|
42 |
|
43 |
+
# Кнопка для генерации и воспроизведения дублированного видео
|
44 |
+
if st.button('Generate'):
|
45 |
+
st.video(output_video_path if file_type not in ['mp4', 'webm', 'ogg'] else input_video_path, start_time=0)
|
46 |
+
st.write("Duplicated Video")
|
|
|
|
|
|