from moviepy.video.io.VideoFileClip import VideoFileClip
def extract_clips(video_file, clip_duration, clip_start_times):
clip_list = []
with VideoFileClip(video_file) as video:
for start_time in clip_start_times:
clip = video.subclip(start_time, start_time + clip_duration)
clip_list.append(clip)
return clip_list
video_file = "path/to/your/video.mp4"
clip_duration = 5 # duration of each clip in seconds
clip_start_times = [0, 10, 20] # start times of each clip in seconds
clips = extract_clips(video_file, clip_duration, clip_start_times)
# save the clips to disk
for i, clip in enumerate(clips):
clip.write_videofile("clip_{}.mp4".format(i))
2条答案
按热度按时间qv7cva1a1#
ig9co6j12#
要做到这一点,你可以看这个非常有用的youtube视频:https://www.youtube.com/watch?v=Q2d1tYvTjRw
它教你如何使用moviepy,你应该可以在视频的帮助下做到这一点希望它有帮助!!!