Spaces:
Runtime error
Runtime error
AndreySokolov01
commited on
Commit
•
0739edf
1
Parent(s):
8e9d454
Update app.py
Browse files
app.py
CHANGED
@@ -8,9 +8,9 @@ def split_video(input_video, 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 =
|
14 |
output_video = f"segment_{i+1}.mp4"
|
15 |
|
16 |
stream = ffmpeg.input(input_video)
|
@@ -19,6 +19,19 @@ def split_video(input_video, duration):
|
|
19 |
ffmpeg.run(stream, overwrite_output=True)
|
20 |
|
21 |
segments.append(output_video)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
return segments
|
24 |
|
@@ -30,7 +43,7 @@ interface = gr.Interface(
|
|
30 |
],
|
31 |
outputs=gr.Files(label="Video Segments"),
|
32 |
title="Video Splitter",
|
33 |
-
description="Split a video into equal-duration segments.",
|
34 |
)
|
35 |
|
36 |
-
interface.launch()
|
|
|
8 |
num_segments = ceil(video_duration / duration)
|
9 |
|
10 |
segments = []
|
11 |
+
for i in range(num_segments - 1):
|
12 |
start_time = i * duration
|
13 |
+
end_time = (i + 1) * duration
|
14 |
output_video = f"segment_{i+1}.mp4"
|
15 |
|
16 |
stream = ffmpeg.input(input_video)
|
|
|
19 |
ffmpeg.run(stream, overwrite_output=True)
|
20 |
|
21 |
segments.append(output_video)
|
22 |
+
|
23 |
+
# Обработка последнего сегмента
|
24 |
+
remaining_duration = video_duration - (num_segments - 1) * duration
|
25 |
+
start_time = (num_segments - 1) * duration
|
26 |
+
end_time = video_duration
|
27 |
+
output_video = f"segment_{num_segments}.mp4"
|
28 |
+
|
29 |
+
stream = ffmpeg.input(input_video)
|
30 |
+
stream = ffmpeg.trim(stream, start=start_time, end=end_time)
|
31 |
+
stream = ffmpeg.output(stream, output_video)
|
32 |
+
ffmpeg.run(stream, overwrite_output=True)
|
33 |
+
|
34 |
+
segments.append(output_video)
|
35 |
|
36 |
return segments
|
37 |
|
|
|
43 |
],
|
44 |
outputs=gr.Files(label="Video Segments"),
|
45 |
title="Video Splitter",
|
46 |
+
description="Split a video into equal-duration segments. The last segment can be of unequal duration.",
|
47 |
)
|
48 |
|
49 |
+
interface.launch()
|