It would be great to have a way to specify that a specific audio file has to loop all over the duration of the video clip
Would something like this suit your needs ? (that would be the simplest for me):
video = VideoFileClip("myvideo.mp4")
audio = AudioFileClip("myaudio.mp3").loop(duration= video.duration)
video.audio = audio
Yeah, that was what i was thinking to do, but didn't found it in the spec, so great!
It's not there yet ! It will be very soon.
Le 16/04/2014 17:55, nicopace a écrit :
Yeah, that was what i was thinking to do, but didn't found it in the
spec, so great!—
Reply to this email directly or view it on GitHub
https://github.com/Zulko/moviepy/issues/33#issuecomment-40616651.
I know, just saying that it felt natural to me to put it there :)
In case you are still interested, it's done. Now you can write:
from moviepy.editor import (VideoFileClip, AudioFileClip)
videoclip = VideoFileClip("movie.mov")
soundtrack = AudioFileClip("./music.mp3")
videoclip.audio = soundtrack.audio_loop(duration=videoclip.duration)
videoclip.to_videofile('movie_with_music.mp4')
... And if you don't want to reinstall, here is a minimal code:
from moviepy.audio.AudioClip import CompositeAudioClip
import numpy as np
def audio_concatenate(clips):
durations = [c.duration for c in clips]
tt = np.cumsum([0]+durations) # start times, and end time.
newclips= [c.set_start(t) for c,t in zip(clips, tt)]
return CompositeAudioClip(newclips).set_duration(tt[-1])
def audio_loop(clip, duration):
nloops = int( duration/ clip.duration)+1
return audio_concatenate(nloops*[clip]).set_duration(duration)
Great, thanks!
Most helpful comment
... And if you don't want to reinstall, here is a minimal code: