文件(尤其是音频文件)内部是如何组织的?
我尝试理解:苹果正在谈论音频文件中的“数据包”,并且有一个名为 AudioFileReadPackets 的奇特函数,它需要很多参数。其中一项指定“起始数据包”,另一项指定您要读取的数据包的数量。
所以我想象一个音频文件在内部看起来像这样:它由很多数据包组成。如果它是具有可变比特率格式的音频文件,则每个数据包可能具有不同的大小。如果文件具有恒定的比特率格式,则每个数据包的大小相同。所以音频文件就像一辆装满盒子的卡车,每个盒子都包含一些有趣的东西。
这是正确的吗?它适用于任何类型的文件吗?这就是文件的实际样子吗?
I try to grok that: Apple is talking about "packets" in audio files, and there is a fancy function called AudioFileReadPackets which takes a lot of arguments. One of them specifies the "start packet", and another one the number of packets which you want to read.
So I imagine an audio file to look like this, internally: It's made up of a lot of packets. If it's an audio file which has an variable bit rate format, then every packet may have a different size. If the file has an constant bit rate format, then every packet is the same size. So an audio file is like a truck full of boxes, and every box contains some interesting stuff.
Is that correct? Does it apply to any kind of file? Is this how files actually look like?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这个问题(即使有“特别是音频文件”的资格)太宽泛了;不同的文件格式是不同的!
因此,要回答这个问题,您首先必须指定特定的文件类型;那么问题的答案总是要看它的规格。专有格式可能没有公开可用的规范。
许多文件的规范(官方和逆向工程)可以在出色的 Wotsit's Format 网站上找到。
Apple iTunes 和其他应用程序使用的 AAC 由 ISO/IEC 13818 定义-7:2006。该文件将花费您 252 瑞士法郎(约合 233 美元)!您必须真正有兴趣(商业上)才能支付该费用,而不是使用现有的 AAC 编解码器。
“数据包”是数据传输中常用的术语,因此可能比音频文件更适用于音频流,其中“帧”可能更合适,或者对于一般的数据文件“记录”,但术语很灵活因为它意味着写它的人认为它意味着什么!如果有足够多的人滥用一个术语,它本质上就会被重新定义(或多重定义)来表示这个意思,所以我不会太在意这个。作者确实怀疑使用它来定义一个单元,该单元在一个文件中具有已定义的格式,该文件具有多个按顺序重复的此类单元。
The question (even with the "especially audio files" qualification) is far too broad; different file formats are, well, different!
So to answer the question you will first have to specify a particular file type; then the answer to the question will invariably to look at its specification. Proprietary formats may not have a publicly available specification.
Specifications for many files (official and reverse engineered) can be found at the brilliant Wotsit's Format site.
AAC used by Apple iTunes and others is defined by ISO/IEC 13818-7:2006. The document will cost you 252 Swiss Francs (about US$233)! You'd have to be really interested (commercially) to pay that rather than use an existing AAC Codec.
"Packet" is a term commonly used in data transmission, so may be more applicable to audio streaming than audio files, where a "frame" may be more appropriate, or for data files in general a "record", but the terminology is flexible because it means whatever the person that wrote it thought it meant! If enough people misuse a term, it essentially becomes redefined (or multiply defined) to mean that, so I would not get too hung up on that. The author was do doubt using it to define a unit that has a defined format within a file that has multiple such units repeated sequentially.
“数据包”在我看来像是苹果特有的术语。我只是进行了大量的阅读和编码来处理 WAV 和 MP3 文件,我不相信我曾经见过“数据包”这个术语。
"Packet" looks to me like Apple-specific terminology. I just did a lot of reading and coding to process WAV and MP3 files and I don't believe I saw the term "packet" once.
文件包含创建它们的应用程序选择放置在其中的任何内容。文件本质上是字节序列。任何进一步的组织都是由创建它们的程序进行的语义区别。认为所有文件都包含相同结构是不正确的。
也就是说,某些数据存储问题足够相似,可以通过类似的方式解决,并且模式开始出现。将数据拆分为记录或数据包就是一个例子。
Files contain whatever the application that created them chose to place in them. Files are essentially a sequence of bytes. Any further organisation is a semantic distinction made by the program that created them. It is untrue to think of all files containing the same structure.
That said, certain data storage problems are similar enough to be solved in similar ways, and patterns start to emerge. Splitting data into records or packets is an example of that.
这几乎就是音频文件的样子:一系列数据块或帧。 AudioFileReadPacketData 和 AudioFileReadPackets 使您免受细节的影响,例如,帧可能有多大(以字节为单位)(因为您可能正在读取 WAV 文件,该文件的结构与 MP3 文件不同,或者您的 MP3 文件使用可变位速度)。
帧的概念一般不适用于任何文件,但您不会使用音频文件服务 API 来访问任何旧文件。
That's pretty much what audio files look like: a series of chunks of data, or frames. AudioFileReadPacketData and AudioFileReadPackets shield you from the details of, for instance, how big a frame might be in bytes (because you might be reading from a WAV file, which has a different structure to an MP3 file, or your MP3 file uses a variable bit rate).
The concept of frames doesn't apply in general to any file, but then you wouldn't be using the Audio File Services API to access just any old file.
对于 MP3(以及 MP1、MP2),文件由帧组成。是的,您的理解是正确的 - VBR 文件中的数据包具有不同的大小。如果没记错的话,WAV 文件中的数据包具有相同的长度(我 11 年前编写了一个解码器/播放器)。
For MP3 (and MP1, MP2) the file consists of frames. And yes, your understanding is correct - in VBR files packets have different size. In WAV files packets have the same length if memory serves (I wrote a decoder / player 11 years ago,).