-
-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect MP3 duration #412
Labels
bug
Something isn't working
Comments
Thanks for the super detailed report! Your fix works nicely. While testing this, I found out that files without VBR headers have durations that are slightly off as well. I'll look into that tomorrow and get this fixed in 0.20.1. |
Serial-ATA
added a commit
that referenced
this issue
Jul 2, 2024
For files with a VBR header: Thanks to @naglis for correcting the length calculation. (issue: #412) For files without a VBR header: `rev_search_for_frame_header` would get tripped up on files with trailing data that looked like a frame sync (ex. 0xFFFF). This would also result in durations that are slightly off. For now, VBR streams are still assumed to be CBR. I have not seen a file this does not work for yet. Eventually it would be nice to have more accurate calculation, but that will require we read the *entire* file.
Serial-ATA
added a commit
that referenced
this issue
Jul 2, 2024
For files with a VBR header: Thanks to @naglis for correcting the length calculation. (issue: #412) For files without a VBR header: `rev_search_for_frame_header` would get tripped up on files with trailing data that looked like a frame sync (ex. 0xFFFF). This would also result in durations that are slightly off. For now, VBR streams are still assumed to be CBR. I have not seen a file this does not work for yet. Eventually it would be nice to have more accurate calculation, but that will require we read the *entire* file.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reproducer
To reproduce, I am using a file filled with 10 minutes (600s) silence generated by
ffmpeg
using this command (the file is also attached):ffprobe
on the generated file says the duration is600.137143
seconds:However, running lofty's
tag_reader
example from dde24d5 prints:which is off by 3 seconds.
After digging in the code I believe it is because here we lose the fractional part from
frame_time
, since it is computed separately as an integer before multiplying by the number of frames.If I change the
length
computation to multiply by the number of frames before dividing by sample rate:I get the correct duration:
Summary
First of all, I'd like to thank you for this library. I really appreciate all the work that you put into it.
I am using it in context of audiobooks where single-file audiobooks can be quite long, and have noticed that the duration of MP3 files returned by lofty was incorrect (when comparing to the duration returned by other tools, like ffmpeg). This led to some weird results when the audiobook playback position was seemingly greater than the length of the audiobook and where a chapter was supposed to start after the audiobook had already ended. FWIW, from my limited testing with MP4/FLAC/OPUS/OGG, all those file formats returned the correct duration.
E.g. for an MP3 file of 14.5 hours, the duration returned by lofty would be ~4 minutes shorter.
Expected behavior
The duration of MP3 files of known duration returned by lofty should be correct and match the duration returned by other libraries/tools.
Assets
silence.zip
The text was updated successfully, but these errors were encountered: