笔者最近用到从视频文件中提取其中的音频,并裁剪其中指定一段,具体代码如下:
import moviepy.editor as mp
def extract_audio(videos_file_path):
my_clip=mp.VideoFileClip(videos_file_path)
return my_clip
if __name__ == '__main__':
file_Path="111.mp4"
#音频提取
my_clip=extract_audio(file_Path)
my_clip.audio.write_audiofile("音频.mp3")
#音频裁剪
clip2=my_clip.subclip(0,20)
clip2.audio.write_audiofile("1.mp3")