Spaces:
Sleeping
Sleeping
AndreySokolov01
commited on
Commit
•
430d36b
1
Parent(s):
8e9d454
Update app.py
Browse files
app.py
CHANGED
@@ -1,36 +1,30 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
-
import ffmpeg
|
3 |
-
from math import ceil
|
4 |
|
5 |
-
def split_video(
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
segments = []
|
11 |
-
for i in range(num_segments):
|
12 |
-
start_time = i * duration
|
13 |
-
end_time = min((i + 1) * duration, video_duration)
|
14 |
-
output_video = f"segment_{i+1}.mp4"
|
15 |
-
|
16 |
-
stream = ffmpeg.input(input_video)
|
17 |
-
stream = ffmpeg.trim(stream, start=start_time, end=end_time)
|
18 |
-
stream = ffmpeg.output(stream, output_video)
|
19 |
-
ffmpeg.run(stream, overwrite_output=True)
|
20 |
-
|
21 |
-
segments.append(output_video)
|
22 |
-
|
23 |
-
return segments
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
title="Video Splitter",
|
33 |
-
description="
|
34 |
)
|
35 |
|
36 |
-
|
|
|
|
1 |
+
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
+
output_files = []
|
11 |
+
for part in range(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(output_filename, codec="libx264", audio_codec="aac")
|
17 |
+
output_files.append(output_filename)
|
18 |
+
|
19 |
+
return output_files
|
20 |
+
|
21 |
+
iface = gr.Interface(
|
22 |
+
fn=split_video,
|
23 |
+
inputs=[gr.inputs.File(type="file", label="Upload Video"), gr.inputs.Slider(minimum=2, maximum=10, default=2, label="Number of Parts")],
|
24 |
+
outputs=gr.outputs.Files(label="Download Split Videos"),
|
25 |
title="Video Splitter",
|
26 |
+
description="Upload your video and select how many parts you want to split it into."
|
27 |
)
|
28 |
|
29 |
+
if __name__ == "__main__":
|
30 |
+
iface.launch()
|