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).zfill(2)}.mp4" video_segment = video_clip.subclip(start_time, end_time) video_segment.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. The segments will be named 'segment_01.mp4', 'segment_02.mp4', etc.", ) interface.launch()