Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ import os
|
|
2 |
import moviepy.editor as mp
|
3 |
import gradio as gr
|
4 |
|
5 |
-
def split_video(video_file, parts):
|
6 |
video = mp.VideoFileClip(video_file.name)
|
7 |
duration = video.duration
|
8 |
part_duration = duration / parts
|
@@ -12,8 +12,31 @@ def split_video(video_file, parts):
|
|
12 |
start_time = part * part_duration
|
13 |
end_time = (part + 1) * part_duration
|
14 |
part_clip = video.subclip(start_time, end_time)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
output_filename = f"part_{part + 1}.mp4"
|
16 |
-
part_clip.write_videofile(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
output_files.append(output_filename)
|
18 |
|
19 |
return output_files
|
@@ -21,12 +44,17 @@ def split_video(video_file, parts):
|
|
21 |
iface = gr.Interface(
|
22 |
fn=split_video,
|
23 |
inputs=[
|
24 |
-
gr.File(label="Upload Video"),
|
25 |
-
gr.Slider(minimum=2, maximum=10, value=2, label="Number of Parts")
|
|
|
|
|
|
|
|
|
26 |
],
|
27 |
outputs=gr.Files(label="Download Split Videos"),
|
28 |
title="Video Splitter",
|
29 |
description="Upload your video and select how many parts you want to split it into."
|
30 |
)
|
|
|
31 |
if __name__ == "__main__":
|
32 |
iface.launch()
|
|
|
2 |
import moviepy.editor as mp
|
3 |
import gradio as gr
|
4 |
|
5 |
+
def split_video(video_file, parts, resolution, quality, audio_enabled, volume):
|
6 |
video = mp.VideoFileClip(video_file.name)
|
7 |
duration = video.duration
|
8 |
part_duration = duration / parts
|
|
|
12 |
start_time = part * part_duration
|
13 |
end_time = (part + 1) * part_duration
|
14 |
part_clip = video.subclip(start_time, end_time)
|
15 |
+
|
16 |
+
# Настройка параметров кодирования
|
17 |
+
if quality == "Низкое":
|
18 |
+
bitrate = "1M"
|
19 |
+
elif quality == "Среднее":
|
20 |
+
bitrate = "2M"
|
21 |
+
else:
|
22 |
+
bitrate = "4M"
|
23 |
+
|
24 |
+
# Настройка параметров звука
|
25 |
+
if not audio_enabled:
|
26 |
+
part_clip.audio = None
|
27 |
+
else:
|
28 |
+
part_clip.audio = part_clip.audio.volumex(volume)
|
29 |
+
|
30 |
+
# Сохранение видео
|
31 |
output_filename = f"part_{part + 1}.mp4"
|
32 |
+
part_clip.write_videofile(
|
33 |
+
output_filename,
|
34 |
+
codec="libx264",
|
35 |
+
audio_codec="aac",
|
36 |
+
bitrate=bitrate,
|
37 |
+
preset="medium",
|
38 |
+
ffmpeg_params=["-vf", f"scale={resolution}"],
|
39 |
+
)
|
40 |
output_files.append(output_filename)
|
41 |
|
42 |
return output_files
|
|
|
44 |
iface = gr.Interface(
|
45 |
fn=split_video,
|
46 |
inputs=[
|
47 |
+
gr.File(label="Upload Video"),
|
48 |
+
gr.Slider(minimum=2, maximum=10, value=2, label="Number of Parts"),
|
49 |
+
gr.Dropdown(choices=["720p", "1080p", "4K"], label="Resolution"),
|
50 |
+
gr.Dropdown(choices=["Низкое", "Среднее", "Высокое"], label="Качество"),
|
51 |
+
gr.Checkbox(label="Включить звук"),
|
52 |
+
gr.Slider(minimum=0, maximum=2, value=1, label="Громкость"),
|
53 |
],
|
54 |
outputs=gr.Files(label="Download Split Videos"),
|
55 |
title="Video Splitter",
|
56 |
description="Upload your video and select how many parts you want to split it into."
|
57 |
)
|
58 |
+
|
59 |
if __name__ == "__main__":
|
60 |
iface.launch()
|