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

Duration double #13

Closed tumbelin closed 4 years ago

tumbelin commented 5 years ago

Hi, Thanks for this, it could be help but and getting some weirds results, When I tried to get duration from a file I got the double of duration, but I noticed this depends on the bit rate of the file. Files with bit rate like 64 kbit/s I have to divide by 2 to get the right answer, and for mp3's with bit rate 128 or 192 kbps the info is right without any manipulation

sachin-imark commented 5 years ago

I'm getting double duration, Anyone can help about this issue.

wapmorgan commented 5 years ago

@tumbelin Can you provide a sample of this file or this happens with any file with 64 kb/s bitrate? @sachin-imark Please, provide a sample.

sachin-imark commented 5 years ago

Hello @tumbelin

$audio = new Mp3Info($request->file('song'), true); $duration = ($audio->duration)*1000; //duration in milliseconds

File Bit Rate from file property: 124kbps

Audio bitrate using below code : 64 kb/s echo 'Audio bitrate: '.($audio->bitRate / 1000).' kb/s'.PHP_EOL;

Sometimes it's getting the right duration of a song, But sometimes I'm getting double duration,

Please provide me a better solution for this.

tumbelin commented 5 years ago

@wapmorgan @sachin-imark yes, this happens with any file below 128kb/s, What I had to do is put a condition to work with only 128kb/s files

$audio = new Mp3Info($audio); if($audio->bitRate/1000 >= 128){ ........ }else{ //message your file doesn't have the minimum bitrate quality }

sachin-imark commented 5 years ago

Hi @wapmorgan @tumbelin ,

As per requirements, I need to upload a file less than 128kbps bitrate quality as well, In that case, it's giving the issue, So please let me know about the solution which I can implement.

Thanks

tumbelin commented 5 years ago

hahaha @sachin-imark, I'm not the developer of this library, I opened the issue, text to @wapmorgan for solutions

sachin-imark commented 5 years ago

Hi @wapmorgan ,

Please have a look at this issue. and please provide a solution.

Thanks

wapmorgan commented 5 years ago

@tumbelin Please, if you have files with 64k bitrate, upload here to make some tests. I have only two files with 64k bitrate, and only one is scanned with invalid duration.

Discovered problem. That file, really, is not 64kbps. It has VBR (first frame is 64kbps, but next ones is 128kbps), which leads to invalid duration. This library reads only first frame to minimize parsing time and make calculations based on it. Usually, audio with variable-bitrate has a special mark "Xing", which makes calculations work in another way. But this file does not have this tag. I don't know, which the best way to fix this problem. The simplies way it to read 2 first frames and if they are different, read all frames and calculate or make predictions on second frame.

tumbelin commented 5 years ago

Hi @wapmorgan ,I use this link (https://audio.online-convert.com/convert-to-mp3) to convert files I need into mp3, there you can specify the bit rate

sachin-imark commented 5 years ago

Hello @tumbelin

$audio = new Mp3Info($request->file('song'), true); $duration = ($audio->duration)*1000; //duration in milliseconds

File Bit Rate from file property: 124kbps

Audio bitrate using below code : 64 kb/s echo 'Audio bitrate: '.($audio->bitRate / 1000).' kb/s'.PHP_EOL;

Sometimes it's getting the right duration of a song, But sometimes I'm getting double duration,

Please provide me a better solution for this.

@wapmorgan Please have a look into this.

Thanks

wapmorgan commented 4 years ago

Need a file sample to fix.

wapmorgan commented 4 years ago

Adjusted calculation for VBR files. Check out dev-master and try again.

wapmorgan commented 4 years ago

Closing due to oldness