Spaces:
Runtime error
Runtime error
File size: 1,076 Bytes
2c1eba3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
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)
|