VideoDubber / edit.py
Suparnpreet's picture
Upload 7 files
2c1eba3 verified
raw
history blame
1.08 kB
from moviepy.editor import VideoFileClip, AudioFileClip
def mute_and_add_audio(video_file_path, audio_file_path, output_file_path):
try:
# Load the video file
video = VideoFileClip(video_file_path)
# Load the new audio file
new_audio = AudioFileClip(audio_file_path)
# Set the new audio to the video (mute the original audio)
video_with_new_audio = video.set_audio(new_audio)
# Write the result to the output file
video_with_new_audio.write_videofile(output_file_path, codec='libx264', audio_codec='aac')
print(f"Video with new audio saved to {output_file_path}")
except Exception as e:
print(f"An error occurred: {e}")
# # Example usage
# if __name__ == "__main__":
# # Path to the video file
# video_file = "video.mp4"
#
# # Path to the new audio file
# audio_file = "output.wav"
#
# # Path to save the output video file
# output_file = "output_video.mp4"
#
# mute_and_add_audio(video_file, audio_file, output_file)