[英]Add audio to video using moviepy
Title basically explains it.标题基本上解释了它。 Trying to add audio to a video.尝试将音频添加到视频中。 I have a sequence of mp3 files that I want to play sequentially during the video.我有一系列 mp3 文件,我想在视频中按顺序播放。 There're no errors or anything with the code but when I run the code theres still no audio in the video.代码没有错误或任何内容,但是当我运行代码时,视频中仍然没有音频。 Just a recreation of the old video with no audio (the original video doesnt have audio either).只是对没有音频的旧视频的再现(原始视频也没有音频)。
video = VideoFileClip("finished_video.mp4")
title_clip = AudioFileClip("title.mp3")
audio_list = [title_clip]
for x in range(1, counter):
audio = AudioFileClip("p{}.mp3".format(x))
audio_list.append(audio)
video.set_audio(audio_list)
video.write_videofile("new_filename.mp4")
it works for me这个对我有用
from moviepy.editor import *
videoclip = VideoFileClip("sample.mp4")
audioclip = AudioFileClip("sample_audio.mp3")
new_audioclip = CompositeAudioClip([audioclip])
videoclip.audio = new_audioclip
videoclip.write_videofile("output.mp4")
use CompositeAudioClip to merge both files.使用 CompositeAudioClip 合并两个文件。
I had the same issue.我遇到过同样的问题。 It seems like set_audio()
doesn't actually set it, but returns the new video combined with the audio.似乎set_audio()
实际上并没有设置它,而是返回了与音频相结合的新视频。
This is the way I did it:这是我做的方式:
final_video = video.set_audio(audio_list)
final_video.write_videofile("new_filename.mp4")
Hope that helps !希望有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.