kitzeslab / opensoundscape

Open source, scalable software for the analysis of bioacoustic recordings
http://opensoundscape.org
MIT License
127 stars 14 forks source link

Warning: Xing stream size off by more than 1%, fuzzy seeking may be even more fuzzy than by design! #708

Open louisfh opened 1 year ago

louisfh commented 1 year ago

These warnings/errors are being raised on reading some mp3 files.

[src/libmpg123/layer3.c:INT123_do_layer3():1801] error: dequantization failed!
[src/libmpg123/layer3.c:INT123_do_layer3():1773] error: part2_3_length (3360) too large for available bit count (3240)
Warning: Xing stream size off by more than 1%, fuzzy seeking may be even more fuzzy than by **design!**

I tried converting some mp3 files that raise this warning to WAV by doing:

a = Audio.from_file("file1.mp3")
a.save("file2.WAV")

And they still raise the warning.

louisfh commented 1 year ago

https://sourceforge.net/p/mpg123/bugs/275/ This discussion suggests it is an issue that libmpg123 encounters if the LAME/Xing header for an mp3 file does not match the file contents. e.g. if a Variable bitrate file has constant bit rate information in the Xing header.

sammlapp commented 10 months ago

Reproducible example with an audio file, and specific version numbers for librosa, libmpg123 (if used by librosa), or whatever underlying package is relevant

louisfh commented 9 months ago

Mp3 file from here: https://xeno-canto.org/157067

Warning is being raised by librosa (or something under the hood that librosa uses, like audioread). Using librosa 0.10.1:

import librosa
broke_file = "/path/to/157067.mp3"
librosa.load(broke_file)

raises the warning. We could filter warnings at the point of loading audio.

louisfh commented 9 months ago

It's not really an us problem, but it is an annoying thing for users to see flooding their stdout. Hiding warnings (or some subset of them? If that's possible) might be helpful for helping new users not to be overwhelmed.

sammlapp commented 2 months ago

let's find a way to filter it out as specifically as possible

louisfh commented 3 weeks ago

I have tried wrapping the librosa.load call in our Audio module with a warnings filter, e.g.:

        ## Load samples ##
        # ignore the Xing warnings from librosa here
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            samples, sr = librosa.load(
                path,
                sr=sample_rate,
                res_type=resample_type,
                mono=True,
                offset=offset,
                duration=duration,
                dtype=None,
            )

But I still can't silence the warning. @sammlapp I don't think I understand how Warnings are handled well enough to fix this issue.

louisfh commented 3 weeks ago

I also tried wrapping the import statements with the warning filter, e.g.

with warnings.catch_warnings():
    # ignore  all warnings
    warnings.simplefilter("ignore")
    import librosa
    import librosa.core.audio
    import soundfile
louisfh commented 3 weeks ago

OK it looks like the problem might be that libmpg123 is printing directly to stderr. It's a C library, not a python package, so I assume the Python warnings system is not going to catch these. You should be able to catch this with redirect_stderr, but apparently that doesn't work either. https://github.com/bastibe/python-soundfile/issues/435