Spaces:
Runtime error
Runtime error
AndreySokolov01
commited on
Commit
•
1107c78
1
Parent(s):
a0ad634
Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,39 @@
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import ffmpeg
|
|
|
3 |
|
4 |
-
def
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
interface = gr.Interface(
|
13 |
-
|
14 |
inputs=[
|
15 |
gr.File(label="Upload Video"),
|
16 |
-
gr.Number(label="
|
17 |
-
gr.Number(label="End Time (seconds)"),
|
18 |
],
|
19 |
-
outputs=gr.
|
20 |
-
title="Video
|
21 |
-
description="
|
22 |
)
|
23 |
|
24 |
-
interface.launch()
|
|
|
1 |
+
Понял, вам нужно разделить видеофайл на равные промежутки времени, заданные пользователем. Вот исправленный код, который должен выполнять эту задачу:
|
2 |
+
|
3 |
+
```python
|
4 |
import gradio as gr
|
5 |
import ffmpeg
|
6 |
+
from math import ceil
|
7 |
|
8 |
+
def split_video(input_video, duration):
|
9 |
+
video_info = ffmpeg.probe(input_video)
|
10 |
+
video_duration = float(video_info['format']['duration'])
|
11 |
+
num_segments = ceil(video_duration / duration)
|
12 |
+
|
13 |
+
segments = []
|
14 |
+
for i in range(num_segments):
|
15 |
+
start_time = i * duration
|
16 |
+
end_time = min((i + 1) * duration, video_duration)
|
17 |
+
output_video = f"segment_{i+1}.mp4"
|
18 |
+
|
19 |
+
stream = ffmpeg.input(input_video)
|
20 |
+
stream = ffmpeg.trim(stream, start=start_time, end=end_time)
|
21 |
+
stream = ffmpeg.output(stream, output_video)
|
22 |
+
ffmpeg.run(stream, overwrite_output=True)
|
23 |
+
|
24 |
+
segments.append(output_video)
|
25 |
+
|
26 |
+
return segments
|
27 |
|
28 |
interface = gr.Interface(
|
29 |
+
split_video,
|
30 |
inputs=[
|
31 |
gr.File(label="Upload Video"),
|
32 |
+
gr.Number(label="Segment Duration (seconds)"),
|
|
|
33 |
],
|
34 |
+
outputs=gr.Files(label="Video Segments"),
|
35 |
+
title="Video Splitter",
|
36 |
+
description="Split a video into equal-duration segments.",
|
37 |
)
|
38 |
|
39 |
+
interface.launch()
|