Spaces:
Sleeping
Sleeping
AndreySokolov01
commited on
Commit
•
289931f
1
Parent(s):
abdd75f
Update app.py
Browse files
app.py
CHANGED
@@ -3,45 +3,16 @@ import os
|
|
3 |
import gradio as gr
|
4 |
|
5 |
def split_video(video_path, split_duration):
|
6 |
-
|
7 |
-
frame_rate = video_capture.get(cv2.CAP_PROP_FPS)
|
8 |
-
|
9 |
-
total_frames = int(video_capture.get(cv2.CAP_PROP_FRAME_COUNT))
|
10 |
-
total_duration = int(video_capture.get(cv2.CAP_PROP_FRAME_COUNT)) / frame_rate
|
11 |
-
|
12 |
-
num_parts = total_duration // split_duration
|
13 |
-
print(f"Total duration: {total_duration} seconds")
|
14 |
-
print(f"Splitting into {num_parts} parts of {split_duration} seconds each")
|
15 |
-
|
16 |
-
head, tail = os.path.split(video_path)
|
17 |
-
video_filename = tail.split('.')[0]
|
18 |
-
output_path = os.path.join(head, video_filename)
|
19 |
-
|
20 |
-
for i in range(num_parts):
|
21 |
-
start_frame = int(i * split_duration * frame_rate)
|
22 |
-
end_frame = int((i + 1) * split_duration * frame_rate)
|
23 |
-
output_filename = f"{output_path}_part{i+1}.mp4"
|
24 |
-
|
25 |
-
output_file = cv2.VideoWriter(output_filename, cv2.VideoWriter_fourcc(*'MP4V'), frame_rate, (int(video_capture.get(3)), int(video_capture.get(4))))
|
26 |
-
|
27 |
-
video_capture.set(cv2.CAP_PROP_POS_FRAMES, start_frame)
|
28 |
-
|
29 |
-
while video_capture.get(1):
|
30 |
-
success, frame = video_capture.read()
|
31 |
-
if not success:
|
32 |
-
break
|
33 |
-
if start_frame <= int(video_capture.get(cv2.CAP_PROP_POS_FRAMES)) < end_frame:
|
34 |
-
output_file.write(frame)
|
35 |
-
|
36 |
-
output_file.release()
|
37 |
-
|
38 |
-
video_capture.release()
|
39 |
|
40 |
iface = gr.Interface(
|
41 |
fn=split_video,
|
42 |
title="Split Video by Time",
|
43 |
description="Split a video into multiple parts based on specified duration.",
|
44 |
-
inputs=[
|
|
|
|
|
|
|
45 |
outputs=[gr.File(file_type="mp4", label="Video Parts")],
|
46 |
live=True
|
47 |
)
|
|
|
3 |
import gradio as gr
|
4 |
|
5 |
def split_video(video_path, split_duration):
|
6 |
+
#... rest of your code...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
iface = gr.Interface(
|
9 |
fn=split_video,
|
10 |
title="Split Video by Time",
|
11 |
description="Split a video into multiple parts based on specified duration.",
|
12 |
+
inputs=[
|
13 |
+
gr.inputs.File(type="video", label="Select Video File"),
|
14 |
+
gr.Number(default=5, label="Split Duration (seconds)")
|
15 |
+
],
|
16 |
outputs=[gr.File(file_type="mp4", label="Video Parts")],
|
17 |
live=True
|
18 |
)
|