VideoTrimv2 / app.py
AndreySokolov01's picture
Update app.py
430d36b verified
raw
history blame
1.02 kB
import os
import moviepy.editor as mp
import gradio as gr
def split_video(video_file, parts):
video = mp.VideoFileClip(video_file.name)
duration = video.duration
part_duration = duration / parts
output_files = []
for part in range(parts):
start_time = part * part_duration
end_time = (part + 1) * part_duration
part_clip = video.subclip(start_time, end_time)
output_filename = f"part_{part + 1}.mp4"
part_clip.write_videofile(output_filename, codec="libx264", audio_codec="aac")
output_files.append(output_filename)
return output_files
iface = gr.Interface(
fn=split_video,
inputs=[gr.inputs.File(type="file", label="Upload Video"), gr.inputs.Slider(minimum=2, maximum=10, default=2, label="Number of Parts")],
outputs=gr.outputs.Files(label="Download Split Videos"),
title="Video Splitter",
description="Upload your video and select how many parts you want to split it into."
)
if __name__ == "__main__":
iface.launch()