如何在不下载的情况下确定.mp3比特率? [英] How to determine .mp3 bit rate without downloading it?

查看:191
本文介绍了如何在不下载的情况下确定.mp3比特率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网络上有一个.mp3文件列表,我希望获得质量最高的文件. 多媒体文件的质量等于它们的比特率.

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)

如果我将这些文件放在本地,这些事情会很容易,但是我想通过HTTP获取此信息并确定哪个文件的质量最高.

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.

我可以从HTTP标头中获得音轨的长度吗?如果不是,是否可以仅获取描述长度/比特率的比特,而不是下载整个文件?

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?

我正在用python编写代码,但是问题很笼统,因此我没有将其标记为python问题.

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

推荐答案

假设远程服务器运行良好,则可以向文件发出HEAD请求并检查

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.

编辑:MP3由多个帧组成,每个帧可以具有不同的比特率(VBR).轨道长度是根据这些帧中每个帧的比特率计算得出的,而不是根据存储的长度本身来计算的.如果要可靠地获得比特率,则需要两个来获取整个文件并获取每个帧的比特率.可能可以抓取文件的前几个KB并从第一帧读取比特率,但这并不总是在文件中的同一点(例如,由于ID3标签的位置等).

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.).

这篇关于如何在不下载的情况下确定.mp3比特率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆