欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

关于pydub AudioSegment处理mp3文件的一系列的坑

程序员文章站 2023-12-23 22:55:28
首先报错:E:\Anaconda_all\lib\site-packages\pydub\utils.py:170: RuntimeWarning: Couldn’t find ffmpeg or avconv - defaulting to ffmpeg, but may not workwarn(“Couldn’t find ffmpeg or avconv - defaulting to ffmpeg, but may not work”, RuntimeWarning)E:\Anaconda_...

首先报错:
E:\Anaconda_all\lib\site-packages\pydub\utils.py:170: RuntimeWarning: Couldn’t find ffmpeg or avconv - defaulting to ffmpeg, but may not work
warn(“Couldn’t find ffmpeg or avconv - defaulting to ffmpeg, but may not work”, RuntimeWarning)
E:\Anaconda_all\lib\site-packages\pydub\utils.py:198: RuntimeWarning: Couldn’t find ffprobe or avprobe - defaulting to ffprobe, but may not work
warn(“Couldn’t find ffprobe or avprobe - defaulting to ffprobe, but may not work”, RuntimeWarning)
以及 filenotfound

  1. 首先要想使用pydub库,需要先安装ffmpeg
  2. 其次,安装ffmpeg用pip install并没有什么用,需要去官网,下载静态文件,然后将ffmpeg文件的bin目录添加到路径
  3. 依然还是没有用,可能是anaconda的原因?将Anaconda_all\lib\site-packages\pydub\utils.py,里面的which函数的路径处理部分后面加上:
envdir_list.append(r'D:\ffmpeg-20200628-4cfcfb3-win64-static\bin')#添加这一行,注意里面的路径是ffmpeg.exe所在的路径
  1. 虽然不报警告了,但依然notfound
  2. 于是尝试根据网上的回答,在代码中手动加上ffmpeg的路径,依然不行
  3. 最后直接把bin文件里面的ffmpeg,ffprobe等三个exe复制到当前目录,成功了。。。

兴高采烈开始处理mp3,结果又报错:

Traceback (most recent call last):
  File "f:\officialschool\project\trymp3.py", line 13, in <module>
    genSong()
  File "f:\officialschool\project\trymp3.py", line 7, in genSong
    song = AudioSegment.from_mp3(path + 'z.mp3')
  File "E:\Anaconda_all\lib\site-packages\pydub\audio_segment.py", line 738, in from_mp3
    return cls.from_file(file, 'mp3', parameters=parameters)
  File "E:\Anaconda_all\lib\site-packages\pydub\audio_segment.py", line 725, in from_file
    p.returncode, p_err.decode(errors='ignore') ))
pydub.exceptions.CouldntDecodeError: Decoding failed. ffmpeg returned error code: 1

Output from ffmpeg/avlib:

ffmpeg version git-2020-06-28-4cfcfb3 Copyright (c) 2000-2020 the FFmpeg developers

  built with gcc 9.3.1 (GCC) 20200621

  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libgsm --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf

  libavutil      56. 55.100 / 56. 55.100

  libavcodec     58. 93.100 / 58. 93.100

  libavformat    58. 47.100 / 58. 47.100

  libavdevice    58. 11.100 / 58. 11.100

  libavfilter     7. 86.100 /  7. 86.100

  libswscale      5.  8.100 /  5.  8.100

  libswresample   3.  8.100 /  3.  8.100

  libpostproc    55.  8.100 / 55.  8.100

[mp3 @ 0000013f1498cf40] Invalid frame size (627): Could not seek to 1298.

F:/officialschool/project/music/z.mp3: Invalid argument
  1. 一开始代码中是相对路径,有人说需要是绝对路径,改了,无用
  2. 有人说from_mp3函数不行,需要是from_file,无用
  3. 最后发现是自己mp3文件的时期,换了一个文件就可以了。。

awsl
AWSL
AWSL

本文地址:https://blog.csdn.net/weixin_44489823/article/details/107140113

上一篇:

下一篇: