【Python】程序提取视频中的声音
安装依赖
pip install multiprocessing
pip install moviepy.editor
Python代码
from multiprocessing import Pool
from moviepy.editor import AudioFileClip
import os
def p(path,path1, item):
new_name = item.split('.')[0]+'.mp3'
my_audio_clip = AudioFileClip(path+'\\'+item)
my_audio_clip.write_audiofile(path1+'\\'+new_name)
if __name__ == '__main__':
p = input("请输入路径:")
path = r'/rooot/mp4'
path1 = path + '\已处理'
os.mkdir(path1)
list1 = [files for root, dirs, files in os.walk(path)][0]
num_of_processes = 10
outcome = 6
po = Pool(num_of_processes)
for item in list1:
po.apply_async(p, (path,path1,item,))
po.close()
po.join()
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。