Spaces:
Runtime error
Runtime error
AndreySokolov01
commited on
Commit
•
709adea
1
Parent(s):
55eaf15
Update app.py
Browse files
app.py
CHANGED
@@ -1,54 +1,24 @@
|
|
1 |
-
pip install opencv-python
|
2 |
-
|
3 |
-
import cv2
|
4 |
-
import os
|
5 |
import gradio as gr
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
head, tail = os.path.split(video_path)
|
19 |
-
video_filename = tail.split('.')[0]
|
20 |
-
output_path = os.path.join(head, video_filename)
|
21 |
-
|
22 |
-
for i in range(num_parts):
|
23 |
-
start_frame = int(i * split_duration * frame_rate)
|
24 |
-
end_frame = int((i + 1) * split_duration * frame_rate)
|
25 |
-
output_filename = f"{output_path}_part{i+1}.mp4"
|
26 |
-
|
27 |
-
output_file = cv2.VideoWriter(output_filename, cv2.VideoWriter_fourcc(*'MP4V'), frame_rate, (int(video_capture.get(3)), int(video_capture.get(4))))
|
28 |
-
|
29 |
-
video_capture.set(cv2.CAP_PROP_POS_FRAMES, start_frame)
|
30 |
-
|
31 |
-
while video_capture.get(1):
|
32 |
-
success, frame = video_capture.read()
|
33 |
-
if not success:
|
34 |
-
break
|
35 |
-
if start_frame <= int(video_capture.get(cv2.CAP_PROP_POS_FRAMES)) < end_frame:
|
36 |
-
output_file.write(frame)
|
37 |
-
|
38 |
-
output_file.release()
|
39 |
-
|
40 |
-
video_capture.release()
|
41 |
-
|
42 |
-
iface = gr.Interface(
|
43 |
-
fn=split_video,
|
44 |
-
title="Split Video by Time",
|
45 |
-
description="Split a video into multiple parts based on specified duration.",
|
46 |
inputs=[
|
47 |
-
gr.
|
48 |
-
gr.Number(
|
|
|
49 |
],
|
50 |
-
outputs=
|
51 |
-
|
|
|
52 |
)
|
53 |
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import ffmpeg
|
3 |
+
|
4 |
+
def trim_video(input_video, start_time, end_time):
|
5 |
+
output_video = f"{start_time}_{end_time}.mp4"
|
6 |
+
stream = ffmpeg.input(input_video)
|
7 |
+
stream = ffmpeg.trim(stream, start=start_time, end=end_time)
|
8 |
+
stream = ffmpeg.output(stream, output_video)
|
9 |
+
ffmpeg.run(stream, overwrite_output=True)
|
10 |
+
return output_video
|
11 |
+
|
12 |
+
interface = gr.Interface(
|
13 |
+
trim_video,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
inputs=[
|
15 |
+
gr.File(label="Upload Video"),
|
16 |
+
gr.Number(label="Start Time (seconds)"),
|
17 |
+
gr.Number(label="End Time (seconds)"),
|
18 |
],
|
19 |
+
outputs=gr.File(label="Trimmed Video"),
|
20 |
+
title="Video Trimmer",
|
21 |
+
description="Trim videos by specifying start and end times.",
|
22 |
)
|
23 |
|
24 |
+
interface.launch()
|