My clip is 14 minutes long. The sound sometimes can last up to an hour or more. I don't want to make the clip an hour long for example. When I have to make that clip.set_duration(audio.duration)
it's easy, but how can I make that when the original clip ends, it loops and goes on?
Asked
Active
Viewed 161 times
0

khelwood
- 55,782
- 14
- 81
- 108

Adas Adasiek
- 3
- 3
-
How can the sound last an hour if the clip is only 14 minutes long? – mkrieger1 Apr 07 '23 at 21:11
-
@mkrieger1 It's more about the fact that there are two separate audio.mp3 and video.mp4 files – Adas Adasiek Apr 07 '23 at 21:13
1 Answers
0
If you want to loop the audio to match the duration of the video clip can use below code
from pydub import AudioSegment
audio = AudioSegment.from_file("audio.mp3", format="mp3")
audio_length = len(audio)
desired_length = 14 * 60 * 1000
num_loops = desired_length // audio_length + 1
looped_audio = audio * num_loops
looped_audio.export("looped_audio.mp3", format="mp3")
The same idea can be applied to loop the video so that it lasts as long as the audio
from moviepy.video.io.VideoFileClip import VideoFileClip
video = VideoFileClip("video.mp4")
video_duration = video.duration
audio_duration = 61
num_loops = int(audio_duration / video_duration) + 1
looped_video = video.repeat(num_loops)
looped_video.write_videofile("looped_video.mp4")

mkrieger1
- 19,194
- 5
- 54
- 65

Ferhat Mousavi
- 124
- 8
-
Can it be used in reverse? To loop the video so that it lasts as long as the sound? – Adas Adasiek Apr 07 '23 at 21:15