pythonmoviepy

Why it's not adding a sound (the path of files are correct, and the audio of file is working but it doesnt output it)(moviepy v1.0.3)


import moviepy.editor as mpe
my_clip = mpe.VideoFileClip('output.mp4')
audio_background = mpe.AudioFileClip('ayah.mp3')
final_clip = my_clip.set_audio(audio_background)
final_clip.write_videofile('final_output.mp4', codec='libx264', audio_codec='aac')

It outputs the the video without a sound i tried to change the ayah.mp3 to wav but it doesn't work


Solution

  • A common solution people have had online to fix similar issues is explicitly matching the audio clip's length to the videos. Sometimes, they're not exactly the same length and it messes up movie.py.

    import moviepy.editor as mpe
    my_clip = mpe.VideoFileClip('output.mp4')
    audio_background = mpe.AudioFileClip('ayah.mp3').set_duration(my_clip.duration)
    final_clip = my_clip.set_audio(audio_background)
    final_clip.write_videofile('final_output.mp4', codec='libx264', audio_codec='aac', audio_bitrate='192k')
    

    If that doesn't fix it, you should probably try a different audio codec.

    And make sure that the sound file isn't corrupt or silent itself, sometimes the weirdest problems have the simplest solutions.

    Hope this helps :)