關於pydub AudioSegment處理mp3文件的一系列的坑

首先報錯:
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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章