Spaces:
Runtime error
Runtime error
AndreySokolov01
commited on
Commit
•
df0b7b9
1
Parent(s):
8bfa01c
Update app.py
Browse files
app.py
CHANGED
@@ -3,32 +3,33 @@ import moviepy.editor as mp
|
|
3 |
from math import ceil
|
4 |
|
5 |
def split_video(input_video, duration):
|
6 |
-
video_clip = mp.VideoFileClip(input_video)
|
7 |
-
video_duration = video_clip.duration
|
8 |
-
num_segments = ceil(video_duration / duration)
|
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_{
|
15 |
|
16 |
-
|
17 |
-
|
|
|
18 |
|
19 |
-
segments.append(output_video)
|
20 |
|
21 |
-
return segments
|
22 |
|
23 |
interface = gr.Interface(
|
24 |
-
split_video,
|
25 |
-
inputs=[
|
26 |
-
gr.File(label="Upload Video"),
|
27 |
-
gr.Number(label="Segment Duration (seconds)"),
|
28 |
-
],
|
29 |
-
outputs=gr.Files(label="Video Segments"),
|
30 |
-
title="Video Splitter",
|
31 |
-
description="Split a video into equal-duration segments.
|
32 |
)
|
33 |
|
34 |
-
interface.launch()
|
|
|
3 |
from math import ceil
|
4 |
|
5 |
def split_video(input_video, duration):
|
6 |
+
video_clip = mp.VideoFileClip(input_video)
|
7 |
+
video_duration = video_clip.duration
|
8 |
+
num_segments = ceil(video_duration / duration)
|
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 = mp.VideoFileClip(input_video)
|
17 |
+
stream = stream.subclip(start_time, end_time)
|
18 |
+
stream.write_videofile(output_video, codec='libx264', threads=4)
|
19 |
|
20 |
+
segments.append(output_video)
|
21 |
|
22 |
+
return segments
|
23 |
|
24 |
interface = gr.Interface(
|
25 |
+
split_video,
|
26 |
+
inputs=[
|
27 |
+
gr.File(label="Upload Video"),
|
28 |
+
gr.Number(label="Segment Duration (seconds)"),
|
29 |
+
],
|
30 |
+
outputs=gr.Files(label="Video Segments"),
|
31 |
+
title="Video Splitter",
|
32 |
+
description="Split a video into equal-duration segments.",
|
33 |
)
|
34 |
|
35 |
+
interface.launch()
|