简体   繁体   English

如何在不下载整个文件的情况下计算远程位置的 MP3 文件的持续时间?

[英]How do I calculate the duration 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.我们有一个巨大的 MP3 文件存储库,存储在我们的 Amazon S3 CDN 上。 We never cared to store the duration 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.我不确定是否在所有文件中都设置了 TLEN ID3 信息,但我知道所有文件的比特率都是 128kbps。

Since I know the number of mp3 is very large, I don't want to download the entire file for calculating its audio length.由于我知道mp3的数量非常多,我不想下载整个文件来计算其音频长度。 I was wondering if there was a smarter way to do this.我想知道是否有更聪明的方法来做到这一点。

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.几乎所有的 mp3 文件在文件的开头都有 Xing/VBRi 帧,可以用来计算文件的持续时间,下载量很少。

In PHP you would probably:在 PHP 中,您可能会:

  • read the first 10 bytes to get the size of the id3 part读取前 10 个字节以获取 id3 部分的大小
  • read n amount of bytes where n is id3 part length读取 n 个字节,其中 n 是 id3 部分长度
  • read the amount of bytes required for Xing/VBRi frame读取 Xing/VBRi 帧所需的字节数
  • parse and close connection解析并关闭连接

Read http://www.codeproject.com/Articles/8295/MPEG-Audio-Frame-Header#XINGHeader for how to parse Xing and VBRi frame.阅读http://www.codeproject.com/Articles/8295/MPEG-Audio-Frame-Header#XINGHeader了解如何解析 Xing 和 VBRi 帧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM