How to determine .mp3 bit rate without downloading it?

梦想与她 提交于 2020-01-02 07:20:13

问题


I have a list of .mp3 files over the web and I would like to get the highest quality file. Quality in multimedia files equals the bit rate of them.

The bit rate itself should be found in the file's headers. If not, length of the audio track could be used too. (Filesize / Track Length = Bit Rate)

These things would be easy if I would have these files locally, but I would like to fetch this information over HTTP and determine which file has the highest quality.

Can I get an audio track's length out of HTTP headers? If not, is it possible to fetch only the bits that describes the length/bit rate instead of downloading the whole file?

I'm writing the code in python, but the question is quite general so I'm not tagging it as a python question.


回答1:


Assuming that the remote server is behaving nicely, you could issue a HEAD request to the file and check the contents of the Content-Length header field. It doesn't give you track length or bit rate but you can get the size of the file.

EDIT: MP3s consist of multiple frames, each of which can be of a different bit rate (VBR). Track length is calculated from the bit rate of each of these frames, rather than the length itself being stored. If you want the bit rate reliably, you'd need two get the whole file and get the bit rate of each of the frames. It may be possible to grab the first few KB of the file and read the bit rate from the first frame, but this is not always at the same point in the file (e.g. due to position of ID3 tag etc.).



来源:https://stackoverflow.com/questions/9046492/how-to-determine-mp3-bit-rate-without-downloading-it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!