#2521·moviepy

Match Video to Audio Duration Feature

Author: ghostCreated Sep 24, 2025Updated Sep 16, 2026
Labelsfeature-requestaudio

I made a script to loop and trim a video to the duration of the audio. Also works with still images (jpg, png). Still need to test more use cases, like concatened videos / audio.

`from moviepy import *

video = VideoFileClip(r"C:\path_to_image_or_video.mp4") audio = AudioFileClip(r"C:\path_to_audio.mp3")

Loop Video

num_loops = int(audio.duration // video.duration) + 1

video_loops = [video] * num_loops looped_video = concatenate_videoclips(video_loops)

Trim Video

final_clip = looped_video.subclipped(0, audio.duration).with_audio(audio)

final_clip.write_videofile("output_video.mp4")`