Python实现批量将MP3音频转为WAV格式详解
程序员文章站
2022-06-16 12:07:32
目录前言环境依赖代码验证一下前言本文提供批量将mp3格式的音频转为wav格式的工具代码,一如既往的实用主义。环境依赖ffmpeg环境安装,可以参考:ffmpy安装:pip install ffmpy...
前言
本文提供批量将mp3格式的音频转为wav格式的工具代码,一如既往的实用主义。
环境依赖
ffmpeg环境安装,可以参考:
ffmpy安装:
pip install ffmpy -i https://pypi.douban.com/simple
代码
不废话,上代码。
#!/user/bin/env python # coding=utf-8 """ @project : batch-pro @author : 剑客阿良_aliang @file : audio_tool.py @ide : pycharm @time : 2021-12-21 14:48:18 """ from ffmpy import ffmpeg import os # mp3转wav def audio_transfor(audio_path: str, output_dir: str): ext = os.path.basename(audio_path).strip().split('.')[-1] if ext != 'mp3': raise exception('format is not mp3') result = os.path.join(output_dir, '{}.{}'.format(os.path.basename(audio_path).strip().split('.')[0], 'wav')) filter_cmd = '-f wav -ac 1 -ar 16000' ff = ffmpeg( inputs={ audio_path: none}, outputs={ result: filter_cmd}) print(ff.cmd) ff.run() return result def handle(audio_dir: str, output_dir: str): for x in os.listdir(audio_dir): audio_transfor(os.path.join(audio_dir, x), output_dir)
代码说明:
1、handle方法主要参数为:音频目录、输出目录。
2、audio_transfor方法主要参数为:音频文件地址、输出目录。
3、主要通过handle方法批量对mp3音频目录进行遍历处理。
4、会对音频文件的后缀进行判断,看是否为mp3。
验证一下
准备了10个mp3文件。
执行代码:
if __name__ == '__main__': handle('c:/users/xx/desktop/test1', 'c:/users/xx/desktop/test2')
执行过程
c:\users\huyi\.conda\envs\ai_detection\python.exe d:/spyder/batch-pro/audio_tool.py ffmpeg -i c:/users/huyi/desktop/test1\1.mp3 -f wav -ac 1 -ar 16000 c:/users/huyi/desktop/test2\1.wav ffmpeg version n4.3.1-20-g8a2acdc6da copyright (c) 2000-2020 the ffmpeg developers built with gcc 9.3-win32 (gcc) 20200320 configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32 --enable-gpl --enable-version3 --disable-debug --enable-iconv --enable-zlib --enable-libxml2 --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-libvmaf --disable-vulkan --enable-libvorbis --enable-amf --enable-libaom --enable-avisynth --enable-libdav1d --enable-ffnvcodec --enable-cuda-llvm --disable-libglslang --enable-libass --enable-libbluray --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvpx --enable-libwebp --enable-libmfx --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librav1e --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libtwolame --enable-libvidstab --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzimg --extra-cflags=-dlibtwolame_static --extra-cxxflags= --extra-ldflags=-pthread --extra-libs=-lgomp libavutil 56. 51.100 / 56. 51.100 libavcodec 58. 91.100 / 58. 91.100 libavformat 58. 45.100 / 58. 45.100 libavdevice 58. 10.100 / 58. 10.100 libavfilter 7. 85.100 / 7. 85.100 libswscale 5. 7.100 / 5. 7.100 libswresample 3. 7.100 / 3. 7.100 libpostproc 55. 7.100 / 55. 7.100 [mp3 @ 000001ad059c4640] estimating duration from bitrate, this may be inaccurate input #0, mp3, from 'c:/users/huyi/desktop/test1\1.mp3': metadata: major_brand : m4a minor_version : 1 compatible_brands: isomiso2m4a mp42 encoder : lavf57.71.100 duration: 00:08:20.95, start: 0.000000, bitrate: 64 kb/s stream #0:0: audio: mp3, 44100 hz, stereo, fltp, 64 kb/s stream mapping: stream #0:0 -> #0:0 (mp3 (mp3float) -> pcm_s16le (native)) press [q] to stop, [?] for help output #0, wav, to 'c:/users/huyi/desktop/test2\1.wav': metadata: major_brand : m4a minor_version : 1 compatible_brands: isomiso2m4a mp42 isft : lavf58.45.100 stream #0:0: audio: pcm_s16le ([1][0][0][0] / 0x0001), 16000 hz, mono, s16, 256 kb/s metadata: encoder : lavc58.91.100 pcm_s16le size= 15655kb time=00:08:20.95 bitrate= 256.0kbits/s speed= 896x video:0kb audio:15655kb subtitle:0kb other streams:0kb global headers:0kb muxing overhead: 0.000487% ffmpeg -i c:/users/huyi/desktop/test1\10.mp3 -f wav -ac 1 -ar 16000 c:/users/huyi/desktop/test2\10.wav ffmpeg version n4.3.1-20-g8a2acdc6da copyright (c) 2000-2020 the ffmpeg developers built with gcc 9.3-win32 (gcc) 20200320 configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32 --enable-gpl --enable-version3 --disable-debug --enable-iconv --enable-zlib --enable-libxml2 --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-libvmaf --disable-vulkan --enable-libvorbis --enable-amf --enable-libaom --enable-avisynth --enable-libdav1d --enable-ffnvcodec --enable-cuda-llvm --disable-libglslang --enable-libass --enable-libbluray --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvpx --enable-libwebp --enable-libmfx --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librav1e --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libtwolame --enable-libvidstab --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzimg --extra-cflags=-dlibtwolame_static --extra-cxxflags= --extra-ldflags=-pthread --extra-libs=-lgomp libavutil 56. 51.100 / 56. 51.100 libavcodec 58. 91.100 / 58. 91.100 libavformat 58. 45.100 / 58. 45.100 libavdevice 58. 10.100 / 58. 10.100 libavfilter 7. 85.100 / 7. 85.100 libswscale 5. 7.100 / 5. 7.100 libswresample 3. 7.100 / 3. 7.100 libpostproc 55. 7.100 / 55. 7.100 [mp3 @ 0000021a839a4640] estimating duration from bitrate, this may be inaccurate input #0, mp3, from 'c:/users/huyi/desktop/test1\10.mp3': metadata: major_brand : m4a minor_version : 1 compatible_brands: isomiso2m4a mp42 encoder : lavf57.71.100 duration: 00:12:50.25, start: 0.000000, bitrate: 64 kb/s stream #0:0: audio: mp3, 44100 hz, stereo, fltp, 64 kb/s stream mapping: stream #0:0 -> #0:0 (mp3 (mp3float) -> pcm_s16le (native)) press [q] to stop, [?] for help output #0, wav, to 'c:/users/huyi/desktop/test2\10.wav': metadata: major_brand : m4a minor_version : 1 compatible_brands: isomiso2m4a mp42 isft : lavf58.45.100 stream #0:0: audio: pcm_s16le ([1][0][0][0] / 0x0001), 16000 hz, mono, s16, 256 kb/s metadata: encoder : lavc58.91.100 pcm_s16le size= 24070kb time=00:12:50.24 bitrate= 256.0kbits/s speed= 862x video:0kb audio:24070kb subtitle:0kb other streams:0kb global headers:0kb muxing overhead: 0.000316% ffmpeg -i c:/users/huyi/desktop/test1\2.mp3 -f wav -ac 1 -ar 16000 c:/users/huyi/desktop/test2\2.wav ffmpeg version n4.3.1-20-g8a2acdc6da copyright (c) 2000-2020 the ffmpeg developers built with gcc 9.3-win32 (gcc) 20200320 configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32 --enable-gpl --enable-version3 --disable-debug --enable-iconv --enable-zlib --enable-libxml2 --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-libvmaf --disable-vulkan --enable-libvorbis --enable-amf --enable-libaom --enable-avisynth --enable-libdav1d --enable-ffnvcodec --enable-cuda-llvm --disable-libglslang --enable-libass --enable-libbluray --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvpx --enable-libwebp --enable-libmfx --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librav1e --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libtwolame --enable-libvidstab --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzimg --extra-cflags=-dlibtwolame_static --extra-cxxflags= --extra-ldflags=-pthread --extra-libs=-lgomp libavutil 56. 51.100 / 56. 51.100 libavcodec 58. 91.100 / 58. 91.100 libavformat 58. 45.100 / 58. 45.100 libavdevice 58. 10.100 / 58. 10.100 libavfilter 7. 85.100 / 7. 85.100 libswscale 5. 7.100 / 5. 7.100 libswresample 3. 7.100 / 3. 7.100 libpostproc 55. 7.100 / 55. 7.100 [mp3 @ 000002900b784640] estimating duration from bitrate, this may be inaccurate input #0, mp3, from 'c:/users/huyi/desktop/test1\2.mp3': metadata: major_brand : m4a minor_version : 1 compatible_brands: isomiso2m4a mp42 encoder : lavf57.71.100 duration: 00:09:36.24, start: 0.000000, bitrate: 64 kb/s stream #0:0: audio: mp3, 44100 hz, stereo, fltp, 64 kb/s stream mapping: stream #0:0 -> #0:0 (mp3 (mp3float) -> pcm_s16le (native)) press [q] to stop, [?] for help output #0, wav, to 'c:/users/huyi/desktop/test2\2.wav': metadata: major_brand : m4a minor_version : 1 compatible_brands: isomiso2m4a mp42 isft : lavf58.45.100 stream #0:0: audio: pcm_s16le ([1][0][0][0] / 0x0001), 16000 hz, mono, s16, 256 kb/s metadata: encoder : lavc58.91.100 pcm_s16le size= 18007kb time=00:09:36.23 bitrate= 256.0kbits/s speed= 879x ffmpeg -i c:/users/huyi/desktop/test1\3.mp3 -f wav -ac 1 -ar 16000 c:/users/huyi/desktop/test2\3.wav video:0kb audio:18007kb subtitle:0kb other streams:0kb global headers:0kb muxing overhead: 0.000423% ffmpeg version n4.3.1-20-g8a2acdc6da copyright (c) 2000-2020 the ffmpeg developers built with gcc 9.3-win32 (gcc) 20200320 configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32 --enable-gpl --enable-version3 --disable-debug --enable-iconv --enable-zlib --enable-libxml2 --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-libvmaf --disable-vulkan --enable-libvorbis --enable-amf --enable-libaom --enable-avisynth --enable-libdav1d --enable-ffnvcodec --enable-cuda-llvm --disable-libglslang --enable-libass --enable-libbluray --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvpx --enable-libwebp --enable-libmfx --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librav1e --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libtwolame --enable-libvidstab --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzimg --extra-cflags=-dlibtwolame_static --extra-cxxflags= --extra-ldflags=-pthread --extra-libs=-lgomp libavutil 56. 51.100 / 56. 51.100 libavcodec 58. 91.100 / 58. 91.100 libavformat 58. 45.100 / 58. 45.100 libavdevice 58. 10.100 / 58. 10.100 libavfilter 7. 85.100 / 7. 85.100 libswscale 5. 7.100 / 5. 7.100 libswresample 3. 7.100 / 3. 7.100 libpostproc 55. 7.100 / 55. 7.100 [mp3 @ 00000238ce244640] estimating duration from bitrate, this may be inaccurate input #0, mp3, from 'c:/users/huyi/desktop/test1\3.mp3': metadata: major_brand : m4a minor_version : 1 compatible_brands: isomiso2m4a mp42 encoder : lavf57.71.100 duration: 00:07:00.73, start: 0.000000, bitrate: 64 kb/s stream #0:0: audio: mp3, 44100 hz, stereo, fltp, 64 kb/s stream mapping: stream #0:0 -> #0:0 (mp3 (mp3float) -> pcm_s16le (native)) press [q] to stop, [?] for help output #0, wav, to 'c:/users/huyi/desktop/test2\3.wav': metadata: major_brand : m4a minor_version : 1 compatible_brands: isomiso2m4a mp42 isft : lavf58.45.100 stream #0:0: audio: pcm_s16le ([1][0][0][0] / 0x0001), 16000 hz, mono, s16, 256 kb/s metadata: encoder : lavc58.91.100 pcm_s16le size= 13148kb time=00:07:00.72 bitrate= 256.0kbits/s speed= 886x video:0kb audio:13148kb subtitle:0kb other streams:0kb global headers:0kb muxing overhead: 0.000579% ffmpeg -i c:/users/huyi/desktop/test1\4.mp3 -f wav -ac 1 -ar 16000 c:/users/huyi/desktop/test2\4.wav ffmpeg version n4.3.1-20-g8a2acdc6da copyright (c) 2000-2020 the ffmpeg developers built with gcc 9.3-win32 (gcc) 20200320 configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32 --enable-gpl --enable-version3 --disable-debug --enable-iconv --enable-zlib --enable-libxml2 --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-libvmaf --disable-vulkan --enable-libvorbis --enable-amf --enable-libaom --enable-avisynth --enable-libdav1d --enable-ffnvcodec --enable-cuda-llvm --disable-libglslang --enable-libass --enable-libbluray --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvpx --enable-libwebp --enable-libmfx --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librav1e --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libtwolame --enable-libvidstab --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzimg --extra-cflags=-dlibtwolame_static --extra-cxxflags= --extra-ldflags=-pthread --extra-libs=-lgomp libavutil 56. 51.100 / 56. 51.100 libavcodec 58. 91.100 / 58. 91.100 libavformat 58. 45.100 / 58. 45.100 libavdevice 58. 10.100 / 58. 10.100 libavfilter 7. 85.100 / 7. 85.100 libswscale 5. 7.100 / 5. 7.100 libswresample 3. 7.100 / 3. 7.100 libpostproc 55. 7.100 / 55. 7.100 [mp3 @ 0000024ada3a4640] estimating duration from bitrate, this may be inaccurate input #0, mp3, from 'c:/users/huyi/desktop/test1\4.mp3': metadata: major_brand : m4a minor_version : 1 compatible_brands: isomiso2m4a mp42 encoder : lavf57.71.100 duration: 00:08:14.58, start: 0.000000, bitrate: 64 kb/s stream #0:0: audio: mp3, 44100 hz, stereo, fltp, 64 kb/s stream mapping: stream #0:0 -> #0:0 (mp3 (mp3float) -> pcm_s16le (native)) press [q] to stop, [?] for help output #0, wav, to 'c:/users/huyi/desktop/test2\4.wav': metadata: major_brand : m4a minor_version : 1 compatible_brands: isomiso2m4a mp42 isft : lavf58.45.100 stream #0:0: audio: pcm_s16le ([1][0][0][0] / 0x0001), 16000 hz, mono, s16, 256 kb/s metadata: encoder : lavc58.91.100 pcm_s16le size= 15456kb time=00:08:14.57 bitrate= 256.0kbits/s speed= 873x video:0kb audio:15456kb subtitle:0kb other streams:0kb global headers:0kb muxing overhead: 0.000493% ffmpeg -i c:/users/huyi/desktop/test1\5.mp3 -f wav -ac 1 -ar 16000 c:/users/huyi/desktop/test2\5.wav ffmpeg version n4.3.1-20-g8a2acdc6da copyright (c) 2000-2020 the ffmpeg developers built with gcc 9.3-win32 (gcc) 20200320 configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32 --enable-gpl --enable-version3 --disable-debug --enable-iconv --enable-zlib --enable-libxml2 --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-libvmaf --disable-vulkan --enable-libvorbis --enable-amf --enable-libaom --enable-avisynth --enable-libdav1d --enable-ffnvcodec --enable-cuda-llvm --disable-libglslang --enable-libass --enable-libbluray --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvpx --enable-libwebp --enable-libmfx --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librav1e --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libtwolame --enable-libvidstab --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzimg --extra-cflags=-dlibtwolame_static --extra-cxxflags= --extra-ldflags=-pthread --extra-libs=-lgomp libavutil 56. 51.100 / 56. 51.100 libavcodec 58. 91.100 / 58. 91.100 libavformat 58. 45.100 / 58. 45.100 libavdevice 58. 10.100 / 58. 10.100 libavfilter 7. 85.100 / 7. 85.100 libswscale 5. 7.100 / 5. 7.100 libswresample 3. 7.100 / 3. 7.100 libpostproc 55. 7.100 / 55. 7.100 [mp3 @ 0000023e42064640] estimating duration from bitrate, this may be inaccurate input #0, mp3, from 'c:/users/huyi/desktop/test1\5.mp3': metadata: major_brand : m4a minor_version : 1 compatible_brands: isomiso2m4a mp42 encoder : lavf57.71.100 duration: 00:07:08.67, start: 0.000000, bitrate: 64 kb/s stream #0:0: audio: mp3, 44100 hz, stereo, fltp, 64 kb/s stream mapping: stream #0:0 -> #0:0 (mp3 (mp3float) -> pcm_s16le (native)) press [q] to stop, [?] for help output #0, wav, to 'c:/users/huyi/desktop/test2\5.wav': metadata: major_brand : m4a minor_version : 1 compatible_brands: isomiso2m4a mp42 isft : lavf58.45.100 stream #0:0: audio: pcm_s16le ([1][0][0][0] / 0x0001), 16000 hz, mono, s16, 256 kb/s metadata: encoder : lavc58.91.100 pcm_s16le size= 13396kb time=00:07:08.66 bitrate= 256.0kbits/s speed= 850x video:0kb audio:13396kb subtitle:0kb other streams:0kb global headers:0kb muxing overhead: 0.000569% ffmpeg -i c:/users/huyi/desktop/test1\6.mp3 -f wav -ac 1 -ar 16000 c:/users/huyi/desktop/test2\6.wav ffmpeg version n4.3.1-20-g8a2acdc6da copyright (c) 2000-2020 the ffmpeg developers built with gcc 9.3-win32 (gcc) 20200320 configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32 --enable-gpl --enable-version3 --disable-debug --enable-iconv --enable-zlib --enable-libxml2 --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-libvmaf --disable-vulkan --enable-libvorbis --enable-amf --enable-libaom --enable-avisynth --enable-libdav1d --enable-ffnvcodec --enable-cuda-llvm --disable-libglslang --enable-libass --enable-libbluray --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvpx --enable-libwebp --enable-libmfx --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librav1e --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libtwolame --enable-libvidstab --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzimg --extra-cflags=-dlibtwolame_static --extra-cxxflags= --extra-ldflags=-pthread --extra-libs=-lgomp libavutil 56. 51.100 / 56. 51.100 libavcodec 58. 91.100 / 58. 91.100 libavformat 58. 45.100 / 58. 45.100 libavdevice 58. 10.100 / 58. 10.100 libavfilter 7. 85.100 / 7. 85.100 libswscale 5. 7.100 / 5. 7.100 libswresample 3. 7.100 / 3. 7.100 libpostproc 55. 7.100 / 55. 7.100 [mp3 @ 0000021c487e4640] estimating duration from bitrate, this may be inaccurate input #0, mp3, from 'c:/users/huyi/desktop/test1\6.mp3': metadata: major_brand : m4a minor_version : 1 compatible_brands: isomiso2m4a mp42 encoder : lavf57.71.100 duration: 00:06:22.93, start: 0.000000, bitrate: 64 kb/s stream #0:0: audio: mp3, 44100 hz, stereo, fltp, 64 kb/s stream mapping: stream #0:0 -> #0:0 (mp3 (mp3float) -> pcm_s16le (native)) press [q] to stop, [?] for help output #0, wav, to 'c:/users/huyi/desktop/test2\6.wav': metadata: major_brand : m4a minor_version : 1 compatible_brands: isomiso2m4a mp42 isft : lavf58.45.100 stream #0:0: audio: pcm_s16le ([1][0][0][0] / 0x0001), 16000 hz, mono, s16, 256 kb/s metadata: encoder : lavc58.91.100 pcm_s16le size= 11967kb time=00:06:22.92 bitrate= 256.0kbits/s speed= 883x video:0kb audio:11967kb subtitle:0kb other streams:0kb global headers:0kb muxing overhead: 0.000637% ffmpeg -i c:/users/huyi/desktop/test1\7.mp3 -f wav -ac 1 -ar 16000 c:/users/huyi/desktop/test2\7.wav ffmpeg version n4.3.1-20-g8a2acdc6da copyright (c) 2000-2020 the ffmpeg developers built with gcc 9.3-win32 (gcc) 20200320 configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32 --enable-gpl --enable-version3 --disable-debug --enable-iconv --enable-zlib --enable-libxml2 --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-libvmaf --disable-vulkan --enable-libvorbis --enable-amf --enable-libaom --enable-avisynth --enable-libdav1d --enable-ffnvcodec --enable-cuda-llvm --disable-libglslang --enable-libass --enable-libbluray --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvpx --enable-libwebp --enable-libmfx --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librav1e --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libtwolame --enable-libvidstab --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzimg --extra-cflags=-dlibtwolame_static --extra-cxxflags= --extra-ldflags=-pthread --extra-libs=-lgomp libavutil 56. 51.100 / 56. 51.100 libavcodec 58. 91.100 / 58. 91.100 libavformat 58. 45.100 / 58. 45.100 libavdevice 58. 10.100 / 58. 10.100 libavfilter 7. 85.100 / 7. 85.100 libswscale 5. 7.100 / 5. 7.100 libswresample 3. 7.100 / 3. 7.100 libpostproc 55. 7.100 / 55. 7.100 [mp3 @ 000001bd2d4e4640] estimating duration from bitrate, this may be inaccurate input #0, mp3, from 'c:/users/huyi/desktop/test1\7.mp3': metadata: major_brand : m4a minor_version : 1 compatible_brands: isomiso2m4a mp42 encoder : lavf57.71.100 duration: 00:08:09.64, start: 0.000000, bitrate: 64 kb/s stream #0:0: audio: mp3, 44100 hz, stereo, fltp, 64 kb/s stream mapping: stream #0:0 -> #0:0 (mp3 (mp3float) -> pcm_s16le (native)) press [q] to stop, [?] for help output #0, wav, to 'c:/users/huyi/desktop/test2\7.wav': metadata: major_brand : m4a minor_version : 1 compatible_brands: isomiso2m4a mp42 isft : lavf58.45.100 stream #0:0: audio: pcm_s16le ([1][0][0][0] / 0x0001), 16000 hz, mono, s16, 256 kb/s metadata: encoder : lavc58.91.100 pcm_s16le size= 15301kb time=00:08:09.63 bitrate= 256.0kbits/s speed= 837x ffmpeg -i c:/users/huyi/desktop/test1\8.mp3 -f wav -ac 1 -ar 16000 c:/users/huyi/desktop/test2\8.wav video:0kb audio:15301kb subtitle:0kb other streams:0kb global headers:0kb muxing overhead: 0.000498% ffmpeg version n4.3.1-20-g8a2acdc6da copyright (c) 2000-2020 the ffmpeg developers built with gcc 9.3-win32 (gcc) 20200320 configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32 --enable-gpl --enable-version3 --disable-debug --enable-iconv --enable-zlib --enable-libxml2 --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-libvmaf --disable-vulkan --enable-libvorbis --enable-amf --enable-libaom --enable-avisynth --enable-libdav1d --enable-ffnvcodec --enable-cuda-llvm --disable-libglslang --enable-libass --enable-libbluray --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvpx --enable-libwebp --enable-libmfx --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librav1e --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libtwolame --enable-libvidstab --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzimg --extra-cflags=-dlibtwolame_static --extra-cxxflags= --extra-ldflags=-pthread --extra-libs=-lgomp libavutil 56. 51.100 / 56. 51.100 libavcodec 58. 91.100 / 58. 91.100 libavformat 58. 45.100 / 58. 45.100 libavdevice 58. 10.100 / 58. 10.100 libavfilter 7. 85.100 / 7. 85.100 libswscale 5. 7.100 / 5. 7.100 libswresample 3. 7.100 / 3. 7.100 libpostproc 55. 7.100 / 55. 7.100 [mp3 @ 0000026043684640] estimating duration from bitrate, this may be inaccurate input #0, mp3, from 'c:/users/huyi/desktop/test1\8.mp3': metadata: major_brand : m4a minor_version : 1 compatible_brands: isomiso2m4a mp42 encoder : lavf57.71.100 duration: 00:08:05.04, start: 0.000000, bitrate: 64 kb/s stream #0:0: audio: mp3, 44100 hz, stereo, fltp, 64 kb/s stream mapping: stream #0:0 -> #0:0 (mp3 (mp3float) -> pcm_s16le (native)) press [q] to stop, [?] for help output #0, wav, to 'c:/users/huyi/desktop/test2\8.wav': metadata: major_brand : m4a minor_version : 1 compatible_brands: isomiso2m4a mp42 isft : lavf58.45.100 stream #0:0: audio: pcm_s16le ([1][0][0][0] / 0x0001), 16000 hz, mono, s16, 256 kb/s metadata: encoder : lavc58.91.100 pcm_s16le size= 15158kb time=00:08:05.04 bitrate= 256.0kbits/s speed= 614x video:0kb audio:15158kb subtitle:0kb other streams:0kb global headers:0kb muxing overhead: 0.000503% ffmpeg -i c:/users/huyi/desktop/test1\9.mp3 -f wav -ac 1 -ar 16000 c:/users/huyi/desktop/test2\9.wav ffmpeg version n4.3.1-20-g8a2acdc6da copyright (c) 2000-2020 the ffmpeg developers built with gcc 9.3-win32 (gcc) 20200320 configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32 --enable-gpl --enable-version3 --disable-debug --enable-iconv --enable-zlib --enable-libxml2 --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-libvmaf --disable-vulkan --enable-libvorbis --enable-amf --enable-libaom --enable-avisynth --enable-libdav1d --enable-ffnvcodec --enable-cuda-llvm --disable-libglslang --enable-libass --enable-libbluray --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvpx --enable-libwebp --enable-libmfx --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librav1e --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libtwolame --enable-libvidstab --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzimg --extra-cflags=-dlibtwolame_static --extra-cxxflags= --extra-ldflags=-pthread --extra-libs=-lgomp libavutil 56. 51.100 / 56. 51.100 libavcodec 58. 91.100 / 58. 91.100 libavformat 58. 45.100 / 58. 45.100 libavdevice 58. 10.100 / 58. 10.100 libavfilter 7. 85.100 / 7. 85.100 libswscale 5. 7.100 / 5. 7.100 libswresample 3. 7.100 / 3. 7.100 libpostproc 55. 7.100 / 55. 7.100 [mp3 @ 0000016a678d4640] estimating duration from bitrate, this may be inaccurate input #0, mp3, from 'c:/users/huyi/desktop/test1\9.mp3': metadata: major_brand : m4a minor_version : 1 compatible_brands: isomiso2m4a mp42 encoder : lavf57.71.100 duration: 00:08:15.12, start: 0.000000, bitrate: 64 kb/s stream #0:0: audio: mp3, 44100 hz, stereo, fltp, 64 kb/s stream mapping: stream #0:0 -> #0:0 (mp3 (mp3float) -> pcm_s16le (native)) press [q] to stop, [?] for help output #0, wav, to 'c:/users/huyi/desktop/test2\9.wav': metadata: major_brand : m4a minor_version : 1 compatible_brands: isomiso2m4a mp42 isft : lavf58.45.100 stream #0:0: audio: pcm_s16le ([1][0][0][0] / 0x0001), 16000 hz, mono, s16, 256 kb/s metadata: encoder : lavc58.91.100 pcm_s16le size= 15473kb time=00:08:15.12 bitrate= 256.0kbits/s speed= 680x video:0kb audio:15473kb subtitle:0kb other streams:0kb global headers:0kb muxing overhead: 0.000492% process finished with exit code 0
结果目录:
ok,没什么问题。
到此这篇关于python实现批量将mp3音频转为wav格式详解的文章就介绍到这了,更多相关python mp3音频转为wav格式内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
上一篇: MySQL(四):备份恢复详解