import gradio as gr import ffmpeg from math import ceil import moviepy.editor as mp def split_video(input_video, duration): if not input_video: raise ValueError("No video file provided.") video_info = ffmpeg.probe(input_video) video_duration = float(video_info['format']['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 = ffmpeg.input(input_video) stream = ffmpeg.trim(stream, start=start_time, end=end_time) stream = ffmpeg.output(stream, output_video) ffmpeg.run(stream, overwrite_output=True) 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 your video file into multiple parts using different methods: 1. Free Split: Specify a list of comma-separated time stamps to split the video into segments. 2. Average Split: Enter the number of parts to divide the video into, with each segment having equal duration. 3. Time Split: Provide a list of comma-separated time stamps to split the video, with each segment starting at the specified time. 4. Size Split: Enter the target size of each segment in megabytes. The video will be divided into segments with sizes close to the specified value. """, ) interface.launch()