5

I'm writing an extension for google chrome. And I have a situation: I've got a link for mp3 file, and I could play it. I could extract duration of it..

But how could I calculate bitrate? Is it possible through some properties? Or through some calculations using file size? If second - how to get filesize?

Thanks.

ValeriiVasin
  • 8,628
  • 11
  • 58
  • 78

1 Answers1

6

Update:

Do a HEAD request and get the filesize from the Content-Length header. Since you know the duration, you can then calculate the bitrate.

Research:

Here I want to share some of my research.

You probably already know this -- the bitrate is stored inside according to the MP3 format specification. But I'm sure you would rather not read the file and deal with all that yourself! Hopefully you can find tools or API's to help. With that in mind...

  • I looked around for public web APIs that will extract info for MP3's but didn't find anything that jumped out at me.

  • If you can find a version of ExifTool that you can access from Chrome, it has an API to calculate bitrate.

  • There is a Javascript library called SoundManager that looked promising, but it does not accurately calculate bitrate.

  • I looked at the Web Audio API but did not see any mention of reading MP3 files in particular, and therefore no way to extract bitrate.

David J.
  • 31,569
  • 22
  • 122
  • 174
  • I've been looking everywhere to find the answer to a very similar question to this. I'm hoping to use JS/HTML5 to extract the mp3 audio information, like bitrate, samplerate, etc. Is there a way to just get all that information? I don't even need to read it, I just want to identify files uniquely. – Z2VvZ3Vp May 02 '15 at 18:58
  • why not use arrayBuffer to read byte data and get the info yourself – Kitanga Nday Aug 06 '19 at 15:26