bastibe / python-soundfile

SoundFile is an audio library based on libsndfile, CFFI, and NumPy
BSD 3-Clause "New" or "Revised" License
676 stars 105 forks source link

Cannot open Ogg FLAC file: unknown error in flac decoder #424

Open nukemiko opened 6 months ago

nukemiko commented 6 months ago

Try to open an Ogg FLAC file with soundfile:

In [1]: import soundfile

In [2]: soundfile.__version__
Out[2]: '0.12.1'

In [3]: soundfile.__libsndfile_version__
Out[3]: '1.2.2'

In [4]: sf = soundfile.SoundFile('oggflac.ogg')
---------------------------------------------------------------------------
LibsndfileError                           Traceback (most recent call last)
Cell In[4], line 1
----> 1 sf = soundfile.SoundFile('oggflac.ogg')

File /usr/lib/python3.11/site-packages/soundfile.py:658, in SoundFile.__init__(self, file, mode, samplerate, channels, subtype, endian, format, closefd)
    655 self._mode = mode
    656 self._info = _create_info_struct(file, mode, samplerate, channels,
    657                                  format, subtype, endian)
--> 658 self._file = self._open(file, mode_int, closefd)
    659 if set(mode).issuperset('r+') and self.seekable():
    660     # Move write position to 0 (like in Python file objects)
    661     self.seek(0)

File /usr/lib/python3.11/site-packages/soundfile.py:1216, in SoundFile._open(self, file, mode_int, closefd)
   1213 if file_ptr == _ffi.NULL:
   1214     # get the actual error code
   1215     err = _snd.sf_error(file_ptr)
-> 1216     raise LibsndfileError(err, prefix="Error opening {0!r}: ".format(self.name))
   1217 if mode_int == _snd.SFM_WRITE:
   1218     # Due to a bug in libsndfile version <= 1.0.25, frames != 0
   1219     # when opening a named pipe in SFM_WRITE mode.
   1220     # See http://github.com/erikd/libsndfile/issues/77.
   1221     self._info.frames = 0

LibsndfileError: Error opening 'oggflac.ogg': Error : unknown error in flac decoder.

In [5]:
$ > file oggflac.ogg 
oggflac.ogg: Ogg data, FLAC audio
bastibe commented 6 months ago

This error originates in libsndfile, and will need to be dealt with on their end. It may be a malformed FLAC file (check with a known-good one), or a bug in libflac, as called by libsndfile. It may also have been fixed already, as our libsndfile is outdated by about half a year. Work is ongoing on a new version, hopefully to be released in the next few weeks.