How do I calculate the length of an MP3 file in a remote location without downloading the entire file?

I run an independent music website. We have a huge repository of MP3 files stored on our Amazon S3 CDN. We never cared to store the size of the audio in the database while uploading.

Now, I need the length of each of these files in minutes and seconds. I am not sure if the TLEN ID3 info is set in all the files, but I know for a fact that all files are 128kbps bit rate.

Since I the number of mp3 is very large, I don't want to download the entire file for calculating it's audio length. I was wondering if there was a smarter way to do this.

Answers


Almost all mp3 files have Xing/VBRi frame at the beginning of the file that can be used to calculate the duration of the file with very little download.

In PHP you would probably:

  • read the first 10 bytes to get the size of the id3 part
  • read n amount of bytes where n is id3 part length
  • read the amount of bytes required for Xing/VBRi frame
  • parse and close connection

Read http://www.codeproject.com/Articles/8295/MPEG-Audio-Frame-Header#XINGHeader for how to parse Xing and VBRi frame.


Need Your Help

sbt build file dependency syntax(or pattern)

scala build sbt

i just started to learn scala and the build tool I use is sbt. Here I have to write dependencies for each sample project. I copied some dependencies from internet and pasted, but I don't get the sy...

Auto building Clojurescript files for Compojure app

clojure leiningen clojurescript cljsbuild

I have a web application where i'm using Compojure on the server and Clojurescript on the client. I'm using the leing-cljsbuild plugin to automatically compile cljs files to js.