Contents
Problem: NoBackendError
I’m trying to load “mp3” files in librosa by the following line.
data, _ = librosa.core.load(file_path, sr=16000)[0]
My filepath is ‘data/fma_small/000/000002.mp3’
OS: Ubuntu 18.04
And I encountered this error:
Traceback (most recent call last):
File "/home/yixin/anaconda3/lib/python3.7/multiprocessing/pool.py", line 121, in worker
result = (True, func(*args, **kwds))
File "audio_encoder/audio_processing.py", line 76, in save
data = load_audio_file(path)
File "audio_encoder/audio_processing.py", line 23, in load_audio_file
data, _ = librosa.load(file_path, sr=16000)[0] # , sr=16000
File "/home/yixin/anaconda3/lib/python3.7/site-packages/librosa/core/audio.py", line 163, in load
y, sr_native = __audioread_load(path, offset, duration, dtype)
File "/home/yixin/anaconda3/lib/python3.7/site-packages/librosa/core/audio.py", line 187, in __audioread_load
with audioread.audio_open(path) as input_file:
File "/home/yixin/anaconda3/lib/python3.7/site-packages/audioread/__init__.py", line 116, in audio_open
raise NoBackendError()
audioread.exceptions.NoBackendError
Solution
After read the similar issues, the most reasonable explanation is audioread does not support mp3 initially.
In this case, we have to install extra packages, that is ffmpeg.
These are librosa official guides:
audioread and MP3 support
To fuel audioread with more audio-decoding power (e.g., for reading MP3 files), you may need to
install either ffmpeg or GStreamer.Note that on some platforms, audioread needs at least one of the
programs to work properly.If you are using Anaconda, install ffmpeg by calling
bash conda install -c conda-forge ffmpeg
If you are not using Anaconda, here are some common commands for
different operating systems:
- Linux (apt-get):
apt-get install ffmpeg or apt-get install ffmpeg
orapt-get install gstreamer1.0-plugins-base gstreamer1.0-plugins-ugly
- Linux (yum):
yum install ffmpeg
oryum install gstreamer1.0-plugins-base gstreamer1.0-plugins-ugly
- Mac:
brew install ffmpeg
orbrew install gstreamer
- Windows: download binaries from this website
Then I followed the instruction of installing ffmpeg.
However, the error remains the same!
This is the real solution to NoBackendError despite a backend (specifically FFmpeg) being installed
Method 1
After installing ffmpeg, you have check whether it works correctly.
Type in terminal:
ffmpeg
It shows:
Then the crucial step:
ln -s ~/anaconda3/lib/libopenh264.so ~/anaconda3/lib/libopenh264.so.5
The error indicates this library libopenh264.so.5
cannot be found.
We create a link between the real path of the library and where your ffmpeg calls it.
It depends on where you install ffmpeg, for example, you installed in your anaconda environment py38,
you need this command instead of the line above
ln -s ~/anaconda3/lib/libopenh264.so ~/anaconda3/envs/py38/lib/libopenh264.so.5
Remember to change to your own directory!!!
Then ffmpeg works!
Now run your code! No error!
Method 2
which ffmpeg找到安装的位置
cd进入/home/ubuntu/miniconda3/envs/pytorch_cpu/lib/python3.5/site-packages/audioread
文件夹
找到ffdec.py文件, 发现在ffdec.py 33行
COMMANDS = ('ffmpeg', 'avconv')
33行改成
COMMANDS = ('/home/yourlocation/anaconda3/bin/ffmpeg', 'avconv')
References
https://github.com/librosa/librosa#audioread