Borewit/music-metadata

Duration is different across platforms

Closed this issue · 2 comments

Dear all,

I have found duration in several platforms may have different estimates.

I know that estimating Duration is not easy. Can you help me answer this?

This is my mp3 file, When I use music-metadata it will have 372.19 seconds. And when I use FFMPEG it takes 371,87 seconds.

Do we have a way to sync or which one is correct?

My code example

file.metadata = await mm.parseBlob(event.target.files[0]);

image

![image](https://user-images.githubusercontent.com/66987100/191171583-ceeccb04-9b79-41fc-8a52-7ab293097a0b.png)

image

This file is an example

https://wedding.microvn.net/assets/example.mp3

There many different audio formats, and metadata tags, which also may have differences in utilizing different, or possibly combinations of, metadata headers. MP3 specifically is a lot of variations and is no consistent way to set the duration.

In principal, music-metadata uses the easiest, fastest way to extract the duration. Not necessary the most accurate. Decoding the audio stream, and measuring that is probably the most accurate, which is outside the scope of this module. It's reading metadata, if the artist says Elvis, and song is in reality from Madonna, there is nothing I can do. Same with the duration.

However, in some cases, like CBR (constant-bit-rate), and if there no duration in header data available, a simple calculation over the content is done. Is this calculation correct. I may be off a bit, to be honest I am not entirely sure.

But it is open source code, feel free to suggest code which demonstrates better values.
Plenty of test cases which you could fine tune, or add if you think that is required.

As ffmpeg includes audio decoders, it has the means to better measure duration. If it is providing a more accurate value, I do not know.

Thanks for your information