moviepy对视频中音频的提取、删除、添加

提取视频中的音频 

from moviepy.editor import *
video_path = 'my_video.avi'   #视频地址
audio_path = 'my_audio.mp3'   #提取音频保存位置
video = VideoFileClip(video_path)
video.audio.write_audiofile(audio_path)

将一段视频中的音频删除,保存为无声视频

old_video = '有声音.avi'
new_video = '无声音.avi'

video = VideoFileClip(old_video)
video = video.without_audio()  #删除声音,返回新的视频对象,原有对象不更改
video.write_videofile(new_video)

给一段没有声音的视频添加音频

old_video = '无声音.avi'
mp3path = 'audio.mp3'
new_video = '有声音.avi'

video = VideoFileClip(video_path)
audio_clip = AudioFileClip(mp3path)
video = video.set_audio(audio_clip)
video.write_videofile(new_video)

 

你可能感兴趣的:(moviepy,python,python)