如何在不下载的情况下确定 .mp3 比特率?
我在网上有一个 .mp3 文件列表,我想获得最高质量的文件。 多媒体文件的质量等于它们的比特率。
比特率本身应该在文件的标头中找到。如果没有,也可以使用音轨的长度。 (文件大小 / 轨道长度 = 比特率)
如果我在本地拥有这些文件,这些事情会很容易,但我想通过 HTTP 获取此信息并确定哪个文件具有最高质量。
我可以从 HTTP 标头中获取音轨的长度吗?如果没有,是否可以仅获取描述长度/比特率的位,而不是下载整个文件?
我正在用 python 编写代码,但问题非常普遍,所以我不会将其标记为 python 问题。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设远程服务器运行良好,您可以向文件发出
HEAD
请求并检查Content-Length
标头字段。它不会为您提供曲目长度或比特率,但您可以获取文件的大小。编辑:MP3 由多个帧组成,每个帧可以具有不同的比特率 (VBR)。轨道长度是根据每个帧的比特率计算的,而不是存储的长度本身。如果您想要可靠的比特率,则需要两次获取整个文件并获取每个帧的比特率。可以抓取文件的前几 KB 并从第一帧读取比特率,但这并不总是在文件中的同一点(例如,由于 ID3 标签的位置等)。
Assuming that the remote server is behaving nicely, you could issue a
HEAD
request to the file and check the contents of theContent-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.).