安装依赖

pip install multiprocessing
pip install moviepy.editor

代码

from multiprocessing import Pool
from moviepy.editor import AudioFileClip
import os

'''
Auth: Kenvie
Date: 2022/09/13
Desc: 批量提取视频中的音频,将多个视频文件放在文件夹内,将该文件夹地址填入path变量
'''

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'C:\Users\admin\Desktop\新建文件夹'
    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()
最后修改:2024 年 06 月 24 日
如果觉得我的文章对你有用,请随意赞赏