Spaces:
Runtime error
Runtime error
AndreySokolov01
commited on
Commit
•
a76b13e
1
Parent(s):
2b7f3dd
Update app.py
Browse files
app.py
CHANGED
@@ -1,36 +1,34 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
from math import ceil
|
4 |
|
5 |
def split_video(input_video, duration):
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
return segments
|
24 |
|
25 |
interface = gr.Interface(
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
)
|
35 |
|
36 |
interface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
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_{(i+1).zfill(2)}.mp4"
|
15 |
+
|
16 |
+
video_segment = video_clip.subclip(start_time, end_time)
|
17 |
+
video_segment.write_videofile(output_video, codec='libx264', threads=4)
|
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. The segments will be named 'segment_01.mp4', 'segment_02.mp4', etc.",
|
32 |
)
|
33 |
|
34 |
interface.launch()
|