audioread: NoBackendError despite a backend (specifically FFmpeg) being installed

Hello!

This is my first time posting an issue, so please cut me some slack if I’m not following some protocol!

I was trying to use python’s librosa package on Windows 10 and encountered the following issue.

After running x, _ = librosa.load('data/fma_small/000/000002.mp3', sr = None) I receive this stack trace:

---------------------------------------------------------------------------
NoBackendError                            Traceback (most recent call last)
<ipython-input-2-15a8daa0e7fd> in <module>()
      1 start, end = 7, 17
      2 filename = utils.get_audio_path(AUDIO_DIR, 2)
----> 3 x, sr = librosa.load(filename, sr = None, mono = True)

Q:\Program Files\Anaconda3\lib\site-packages\librosa\core\audio.py in load(path, sr, mono, offset, duration, dtype, res_type)
    105 
    106     y = []
--> 107     with audioread.audio_open(os.path.realpath(path)) as input_file:
    108         sr_native = input_file.samplerate
    109         n_channels = input_file.channels

Q:\Program Files\Anaconda3\lib\site-packages\audioread\__init__.py in audio_open(path)
    112 
    113     # All backends failed!
--> 114     raise NoBackendError()

NoBackendError:

Out of curiosity, I also tried to run audioread.ffdec.FFmpegAudioFile('data/fma_small/000/000002.mp3') (since I know that FFmpeg is installed) but I received:

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
Q:\Program Files\Anaconda3\lib\site-packages\audioread\ffdec.py in __init__(self, filename, block_size)
    126                 stderr=subprocess.PIPE,
--> 127                 stdin=self.devnull,
    128             )

Q:\Program Files\Anaconda3\lib\site-packages\audioread\ffdec.py in popen_multiple(commands, command_args, *args, **kwargs)
     88         try:
---> 89             return subprocess.Popen(cmd, *args, **kwargs)
     90         except OSError:

Q:\Program Files\Anaconda3\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds)
    946                                 errread, errwrite,
--> 947                                 restore_signals, start_new_session)
    948         except:

Q:\Program Files\Anaconda3\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
   1223                                          cwd,
-> 1224                                          startupinfo)
   1225             finally:

FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

NotInstalledError                         Traceback (most recent call last)
<ipython-input-6-be3b460211e8> in <module>()
----> 1 audioread.ffdec.FFmpegAudioFile(filename)

Q:\Program Files\Anaconda3\lib\site-packages\audioread\ffdec.py in __init__(self, filename, block_size)
    129 
    130         except OSError:
--> 131             raise NotInstalledError()
    132 
    133         finally:

NotInstalledError:

Again, I have FFmpeg installed, and ffmpeg works as a command in cmd.

Is anyone able to spot the problem?

Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 48 (32 by maintainers)

Most upvoted comments

Not really, no. I eventually started calling ffmpeg via subprocess.Popen and am pretty happy with more explicit control for my purposes.

import shlex
import subprocess

import numpy as np


def decoder(path, duration=3.0, channels=2, sample_rate=44100, dtype=np.float32):
    formats = {np.int16: 's16le', np.float32: 'f32le'}
    args = f'''
    ffmpeg 
    -v error
    -n
    -i "{path}" 
    -f {formats[dtype]} 
    -ac {channels} 
    -ar {sample_rate} 
    -
    '''
    args = shlex.split(args)

    buffer_size = int(channels * np.dtype(dtype).itemsize * duration * sample_rate)

    with subprocess.Popen(args, stdout=subprocess.PIPE) as pipe:
        while True:
            buffer = pipe.stdout.read(buffer_size)
            audio = np.frombuffer(buffer, dtype=dtype)
            audio = np.reshape(audio, (-1, channels))
            yield audio
            if len(buffer) < buffer_size:
                break


for x in decoder('piano.wav'):
    print(x.shape)
from IPython.display import Audio

audio = np.concatenate(list(decoder('piano.wav')))
Audio(audio.T, rate=44100)

If you’re having trouble with audioread you could of course try libsoundfile and see if that works:

import soundfile as sf

y, sr = sf.read('audio.ogg')

YES, “fixed” it.

Following this intuition of the PATH environment variable behaving differently from the rest of my system I just copied ffmpeg to the parent folder of the directory and it worked! And then I realized I hardly ever close PyCharm, so I restarted it and it works! This issue also happens with terminals (environment variables don’t take effect unless you open a new one). I m having same problems , despite installing ffmpeg. please give me a solution.

my code was: D = [] # Dataset for row in valid_data.itertuples(): y, sr = librosa.load(‘F:\paper\Bangla ASR\segmented/augmented 1/’ + (row.path))
ps = librosa.feature.mfcc(y=y, sr=sr, n_mfcc=52) if ps.shape != (52, 130): continue D.append( (ps, row.classID) )


NoBackendError Traceback (most recent call last) <ipython-input-6-91f60cabb456> in <module> 1 D = [] # Dataset 2 for row in valid_data.itertuples(): ----> 3 y, sr = librosa.load(‘F:\paper\Bangla ASR\segmented/augmented 1/’ + (row.path)) 4 ps = librosa.feature.mfcc(y=y, sr=sr, n_mfcc=52) 5 if ps.shape != (52, 130): continue

~.conda\envs\RaffaelEnv\lib\site-packages\librosa\core\audio.py in load(path, sr, mono, offset, duration, dtype, res_type) 117 118 y = [] –> 119 with audioread.audio_open(os.path.realpath(path)) as input_file: 120 sr_native = input_file.samplerate 121 n_channels = input_file.channels

~.conda\envs\RaffaelEnv\lib\site-packages\audioread_init_.py in audio_open(path) 114 115 # All backends failed! –> 116 raise NoBackendError()

NoBackendError:

N.B: I restarted jupyter notebook so many times but still problem exists

Yes, I get this error if my audio fiels are corrupt or truncated. Note that I also get it sometimes if I load non-corrupt audio files in a multi-threaded context, for example in a pytorch batch data loader which AFAICT is not support, so that is also a possible way of getting this “catch all” error"

Yeah, it would be interesting to explore a redesign of the error messages. The tricky thing is that we want to support automatic fallback between different backends, so if one backend can’t be used, we don’t want to immediately stop with a backend-specific error. But perhaps “aggregate” errors like NoBackendError could accumulate some context from each backend that failed?

YES, “fixed” it.

Following this intuition of the PATH environment variable behaving differently from the rest of my system I just copied ffmpeg to the parent folder of the directory and it worked! And then I realized I hardly ever close PyCharm, so I restarted it and it works! This issue also happens with terminals (environment variables don’t take effect unless you open a new one).

@uipo78 maybe you had this same problem?

@carlthome it could be an OutOfMemory. Audioread just expects an OSError and there are a whole bunch of different exceptions that are OSErrors. You could debug that line or just change the code with what I proposed and see what gets printed.