from moviepy.audio.AudioClip import CompositeAudioClip from moviepy.editor import VideoFileClip from moviepy.video.io.ImageSequenceClip import ImageSequenceClip
video1 = VideoFileClip("video1.mp4") video2 = VideoFileClip("video2.mp4")
min_frames = int(min(video1.duration * video1.fps, video2.duration * video2.fps))
clips = []
for i in range(min_frames): clips.append(video1.get_frame(i / video1.fps)) clips.append(video2.get_frame(i / video2.fps))
final_clip = ImageSequenceClip(clips, fps=60)
audio_clip1 = video1.audio.subclip(0, min_frames / video1.fps) audio_clip2 = video2.audio.subclip(0, min_frames / video2.fps) combined_audio = CompositeAudioClip([audio_clip1, audio_clip2])
final_clip = final_clip.set_audio(combined_audio)
final_clip.write_videofile("result_video.mp4")
|