MP4转mp3

python实现:

依赖:

glob,pydub 

"Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work"解决办法:

ffmpeg官网下载
下载 windows 对应的 static 版本。接下来我们把这个 bin 文件夹加入环境变量PATH就好了。

配置完后可以在 cdm 里输入ffmpeg -version进行验证。:

MP4转mp3

 

 

import os
import glob
from pydub import AudioSegment
AudioSegment.converter = r"D:\\ffmmg\\bin\\ffmpeg.exe"  #ffmpeg位置
wenjianjia = []
path = r"C:\Users\chenquan\Desktop\p4batch"  # 需要批量转换的mp4目录位置
for root, dirs, files in os.walk(path):
    wenjianjia.append(root)
wjj = wenjianjia

for dir in wjj:
    video_dir = dir
    extension_list = ('*.mp4', '*.flv')
    i = 1

    os.chdir(video_dir)
    for extension in extension_list:
        for video in glob.glob(extension):
            mp3_filename = os.path.splitext(os.path.basename(video))[0] + '.mp3'
            AudioSegment.from_file(video).export(mp3_filename, format='mp3')
            print('已转码', str(i), '个视频!')
            i += 1

    for infile in glob.glob(os.path.join(video_dir, '*.mp4')):
        os.remove(infile)

 结果:

C:\Python37\python.exe D:/workspace/PandaChecker/src/mp4top3.py
已转码 1 个视频!

.....

.....

已转码 1 6个视频!

上一篇:h5 苹果IOS端 播放mp3 没声音


下一篇:常量池