说时迟,那时快,立马开干~~~
当然需要先下载一个转换的工具:ffmpeg.exe,大家可以自己上网搜一下,安装一下,将下面代码里的ffmpeg.exe路径替换成你自己的路径即可。
[Python] 纯文本查看 复制代码
#coding=utf-8
import subprocess
import sys
import os
import glob
from concurrent.futures import ThreadPoolExecutor
def addCommand(input_file, output_file):
command = [
'E:/Codes/M4STool/M4STool/ffmpeg.exe',
'-y',
'-i', input_file, # 输入文件路径
'-vn', # 去除视频流
'-f', 'mp3', # 输出格式mp3
'-ac', '2', # 设置音频通道数为2(立体声)
'-b:a', '128k', # 设置音频比特率为128k
output_file # 输出文件路径
]
return command
# 使用示例
from_path = 'E:/QLDownload/斗罗大陆'
save_path = 'D:/斗罗大陆1-mp3'
if __name__=="__main__":
try:
commands = []
# 使用glob模块找到所有qlv文件
qlv_files = glob.glob(os.path.join(from_path, "*.qlv"))
# 遍历并处理每个mp3文件
for qlv_file in qlv_files:
print(f"处理文件: {qlv_file}")
qlv_filename = os.path.basename(qlv_file)
mp3_filename = qlv_filename.replace(" 1080P(高清SDR).qlv", ".mp3")
input_qlv_file = from_path + "/" + qlv_filename
output_mp3_file = save_path + "/" + mp3_filename
commands.append(addCommand(input_qlv_file, output_mp3_file))
# 使用ThreadPoolExecutor来并发执行命令, 5个5个的转换
with ThreadPoolExecutor(max_workers=5) as executor:
futures = [executor.submit(subprocess.run, command, shell=True) for command in commands]
# 等待所有的命令执行完成
for future in futures:
print(future.result())
except Exception as ex:
print(ex)