How to calculate the length of an MP3 file at a remote location without downloading the entire file?

I am launching an independent music site. We have a huge repository of MP3 files stored on our Amazon S3 CDN CD. We never cared to keep the size of the audio in the database at boot time.

Now I need the length of each of these files in minutes. I am not sure that the TLEN ID3 information is installed in all files, but I know that all files have a speed of 128 kbps.

Since I have a very large mp3 number, I don’t want to download the whole file to calculate its sound length. I was wondering if there is a more reasonable way to do this.

+4
source share
1 answer

Almost all mp3 files have a Xing / VBRi-frame at the beginning of the file, which can be used to calculate the duration of the file with a very small load.

In PHP, you are probably:

  • read the first 10 bytes to get the id3 part size
  • read n number of bytes, where n is id3 length length
  • read the number of bytes needed for the Xing / VBRi frame
  • Parsing and closing a connection

Read http://www.codeproject.com/Articles/8295/MPEG-Audio-Frame-Header#XINGHeader for parsing Xing and VBRi frames.

+4
source

All Articles