This question was asked a few times a couple of years ago, but none of the solutions seem to work.
This code creates a video output.mp4
which is the same as video.mp4
, but it doesn't have any sound from audio.mp3
even when video.mp4
has sound in the first place.
import moviepy.editor as mp
audio = mp.AudioFileClip("audio_output/audio.mp3")
video1 = mp.VideoFileClip("video.mp4")
final = video1.set_audio(audio)
final.write_videofile("output.mp4")
If anyone knows of alternative methods without using moviepy please let me know! (Or if you know why this isn't working)
Your code seems to be correct for replacing the audio of the video with the provided audio file using
moviepy
. However, there can be various reasons why it might not work, such as incompatible audio formats or issues within themoviepy
library itself.Here's how you can replace the audio of a video using
ffmpeg
as another method: