quodlibet / mutagen

Python module for handling audio metadata

Home Page:https://mutagen.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OGG Vorbis: wrong (playback) duration / length reported on opus audio

ewaldc opened this issue · comments

First of all: a huge "thank you" for this great library!

Mutagen version: 1.46.0
Python version: 3.10
Problem: audio length reported by mutagen does not correspond with real playback duration as measured with stopwatch and reported by tools like MediaInfo, OpusTools (opusinfo) etc. as well as media players (e.g. VLC and many others). The error is bigger with larger files e.g. ~4 to ~6 seconds on 6 minutes

Code

    def audio_file_duration(audio_file):
        if (path_exists(audio_file)):
            _file = mutagen.File(audio_file)
            if _file is not None and _file.info is not None:
                return _file.info.length, _file.info.length * 1000
        return None, 0

UPDATE
I have been able to reproduce the errors. There were 2 root causes:

  • In some cases, silence at the end of an Opus audio file is not counted, but this is not a mutagen issue. Other tools like mediainfo report the same length. I have added code to detect these situations.
  • In some cases, Mutagen's OggPage.find_last returns the wrong page, but the corruption happens in one of the supporting byte IO libraries, not mutagen. The actual root of the problem could end up being in my code as it happens only on very long lists of audio samples (100000+). I was confused because it always seemed to go wrong on the same audio files, but when shuffling the sample lists, it became obvious that it was not related to particular audio files.

Hence, I will close this issue as Mutagen is not at fault.

Closing issue as not directly caused by Mutagen