Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No audio when adding Mp3 to VideoFileClip MoviePy

I'm trying to add an mp3 audio file to a video clip that I'm creating out of images with MoviePy. When the script runs it creates the mp4 file and plays successfully, however there's no audio. I'm not really sure why and can't seem to find a ton of documentation around this in general. MoviePy is pretty new to me so any help would be appreciated - thank-you!

def make_video(images):
    image_clips = []
    for img in images:
        if not os.path.exists(img):
            raise FileNotFoundError(img)
        ic = ImageClip(img).set_duration(3)
        image_clips.append(ic)

    video = concatenate(image_clips, method="compose")
    video.set_audio(AudioFileClip("audio.mp3")) 
    video.write_videofile("mp4_with_audio.mp4", fps=60, codec="mpeg4")
like image 803
damaniel Avatar asked Nov 28 '22 22:11

damaniel


1 Answers

This worked for me:

clip.write_videofile(out_path, 
                     codec='libx264', 
                     audio_codec='aac', 
                     temp_audiofile='temp-audio.m4a', 
                     remove_temp=True
                     )

Found it here: https://github.com/Zulko/moviepy/issues/51

like image 153
racket99 Avatar answered Dec 04 '22 04:12

racket99