wapmorgan / Mp3Info

The fastest PHP library to extract mp3 meta information (duration, bitrate, samplerate and so on) and tags (id3v1, id3v2).
https://wapmorgan.github.io/Mp3Info/
GNU Lesser General Public License v3.0
139 stars 41 forks source link

Wrong duration for VBR encoded MP3s #16

Closed kadai closed 3 years ago

kadai commented 4 years ago

Greetings,

First of all, thank you for the work you have been doing with this library. I have found it very useful. And while so, I have come across a little bug.

If a MP3 is encoded as VBR with a set quality, the duration of the track is not properly calculated by the class.

For example, I have found that a track that should have a duration of 1:34 (~94 secs) it is reported to last ~56.89 seconds instead.

This does not affect tracks that are not VBR encoded.

Further looking into the code, I found out that Quality is used to calculate the $samples_per_second in the lines 295 to 297 in MP3Info.php:

if ($this->isVbr && isset($this->vbrProperties['quality'])) {
    $samples_in_second = floor($samples_in_second * $this->vbrProperties['quality'] / 100);
}

After doing some tests, I found out that the "time" difference was related to the quality. In my case, the MP3 had a quality of 60, so the time was 60% shorter than expected.

I am using the dev-master version of the library.

Thanks in advance.

wapmorgan commented 4 years ago

This way of calculation had a purpose. Please, provide an example of mp3 to test it

kadai commented 4 years ago

I have attached one of the files that gives me issues.

I created this file using LameXP (that uses Lame CLI if I am not wrong) with the next settings:

Then I tagged the track with Clementine, MP3Tag and TagScanner... and after that I eventually applied normalization.

test_audio.zip

I suspect that maybe it has to do with the fact it uses ABR (A variant of VBR) and probably supplies aditional information to detect it.

ghasrfakhri commented 3 years ago

I have exactly same problem. I attached two sample files.

5f9027d3cc122.zip 5f9028549dca7.zip

MakamuEvans commented 3 years ago

Any working solution to this?

au-lait77 commented 3 years ago

anyone a solution? have the same problem that the duration is not correct with VBR.

wapmorgan commented 3 years ago

Fixed in 0.0.6 release