Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,53 +1,40 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
import moviepy.editor as mp
|
| 3 |
-
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
|
| 4 |
|
| 5 |
-
def split_video(
|
| 6 |
-
|
| 7 |
-
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
end = start + 1
|
| 28 |
-
while end <= duration and video.subclip(start, end).size < target_size:
|
| 29 |
-
end += 1
|
| 30 |
-
clips.append(video.subclip(start, end))
|
| 31 |
-
start = end
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
output_filename = f"split_{i + 1}.mp4"
|
| 36 |
-
clip.write_videofile(output_filename)
|
| 37 |
-
output_files.append(output_filename)
|
| 38 |
-
|
| 39 |
-
return output_files
|
| 40 |
-
|
| 41 |
-
iface = gr.Interface(
|
| 42 |
-
fn=split_video,
|
| 43 |
inputs=[
|
| 44 |
gr.File(label="Upload Video"),
|
| 45 |
-
gr.
|
| 46 |
-
gr.Textbox(label="Split Value (comma-separated for Free Split and Time Split, number for Average Split and Size Split)"),
|
| 47 |
],
|
| 48 |
-
outputs=gr.Files(label="
|
| 49 |
title="Video Splitter",
|
| 50 |
-
|
| 51 |
Split your video file into multiple parts using different methods:
|
| 52 |
1. Free Split: Specify a list of comma-separated time stamps to split the video into segments.
|
| 53 |
2. Average Split: Enter the number of parts to divide the video into, with each segment having equal duration.
|
|
@@ -56,5 +43,4 @@ iface = gr.Interface(
|
|
| 56 |
""",
|
| 57 |
)
|
| 58 |
|
| 59 |
-
|
| 60 |
-
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import ffmpeg
|
| 3 |
+
from math import ceil
|
| 4 |
import moviepy.editor as mp
|
|
|
|
| 5 |
|
| 6 |
+
def split_video(input_video, duration):
|
| 7 |
+
if not input_video:
|
| 8 |
+
raise ValueError("No video file provided.")
|
| 9 |
|
| 10 |
+
video_info = ffmpeg.probe(input_video)
|
| 11 |
+
video_duration = float(video_info['format']['duration'])
|
| 12 |
+
num_segments = ceil(video_duration / duration)
|
| 13 |
+
|
| 14 |
+
segments = []
|
| 15 |
+
for i in range(num_segments):
|
| 16 |
+
start_time = i * duration
|
| 17 |
+
end_time = min((i + 1) * duration, video_duration)
|
| 18 |
+
output_video = f"segment_{i+1}.mp4"
|
| 19 |
+
|
| 20 |
+
stream = ffmpeg.input(input_video)
|
| 21 |
+
stream = ffmpeg.trim(stream, start=start_time, end=end_time)
|
| 22 |
+
stream = ffmpeg.output(stream, output_video)
|
| 23 |
+
ffmpeg.run(stream, overwrite_output=True)
|
| 24 |
+
|
| 25 |
+
segments.append(output_video)
|
| 26 |
+
|
| 27 |
+
return segments
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
interface = gr.Interface(
|
| 30 |
+
split_video,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
inputs=[
|
| 32 |
gr.File(label="Upload Video"),
|
| 33 |
+
gr.Number(label="Segment Duration (seconds)"),
|
|
|
|
| 34 |
],
|
| 35 |
+
outputs=gr.Files(label="Video Segments"),
|
| 36 |
title="Video Splitter",
|
| 37 |
+
description="""
|
| 38 |
Split your video file into multiple parts using different methods:
|
| 39 |
1. Free Split: Specify a list of comma-separated time stamps to split the video into segments.
|
| 40 |
2. Average Split: Enter the number of parts to divide the video into, with each segment having equal duration.
|
|
|
|
| 43 |
""",
|
| 44 |
)
|
| 45 |
|
| 46 |
+
interface.launch()
|
|
|