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
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
Share Improve this question asked Feb 15 at 6:50 YahiaYahia 415 bronze badges 1- What happens if you use the default audio_codec 'libmp3lame' instead of 'aac'? – dev_light Commented Feb 15 at 8:32
1 Answer
Reset to default 0A 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 :)