audioread.exceptions.NoBackendError in librosa

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 or apt-get install gstreamer1.0-plugins-base gstreamer1.0-plugins-ugly
  • Linux (yum): yum install ffmpeg or yum install gstreamer1.0-plugins-base gstreamer1.0-plugins-ugly
  • Mac: brew install ffmpeg or brew 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

https://github.com/beetbox/audioread/issues/54

https://stackoverflow.com/questions/62213783/ffmpeg-error-while-loading-shared-libraries-libopenh264-so-5

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Dr. 卷心菜

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值