Spaces:
Runtime error
Runtime error
File size: 992 Bytes
20bee2f a76b13e 1107c78 709adea 1107c78 df0b7b9 a76b13e df0b7b9 a76b13e df0b7b9 a76b13e df0b7b9 a76b13e df0b7b9 709adea df0b7b9 abdd75f df0b7b9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
import gradio as gr
import moviepy.editor as mp
from math import ceil
def split_video(input_video, duration):
video_clip = mp.VideoFileClip(input_video)
video_duration = video_clip.duration
num_segments = ceil(video_duration / duration)
segments = []
for i in range(num_segments):
start_time = i * duration
end_time = min((i + 1) * duration, video_duration)
output_video = f"segment_{i+1}.mp4"
stream = mp.VideoFileClip(input_video)
stream = stream.subclip(start_time, end_time)
stream.write_videofile(output_video, codec='libx264', threads=4)
segments.append(output_video)
return segments
interface = gr.Interface(
split_video,
inputs=[
gr.File(label="Upload Video"),
gr.Number(label="Segment Duration (seconds)"),
],
outputs=gr.Files(label="Video Segments"),
title="Video Splitter",
description="Split a video into equal-duration segments.",
)
interface.launch()
|