FLAC格式解析
最新推荐文章于 2024-01-12 13:55:06 发布
b547510
最新推荐文章于 2024-01-12 13:55:06 发布
阅读量6.4k
收藏
5
点赞数
2
CC 4.0 BY-SA版权
分类专栏:
格式解析
文章标签:
flac
demux
格式详解
header分析
帧解析
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/b547510/article/details/11608197
FLAC是一种无损音频压缩格式,通过预测、残差编码等方法实现高效压缩。文章详细介绍了FLAC的架构、帧结构、元数据块、预测方法、残留编码等关键概念,并强调了其在不同场景下的应用和限制。FLAC格式允许根据信号特性灵活选择预测器和残留编码方法,以适应各种音频内容。
摘要生成于
C知道
,由 DeepSeek-R1 满血版支持,
前往体验 >
原文链接:http://xiph.org/flac/format.html#subframe_header
我把原文复制了一遍,后面会加上我对原文的理解,以及一些难点的注释。为了防止原文链接失效(因为之前存的那个就失效了,现在又找到了)所以我把原文也复制了一遍,大家可以对照着注释来看。
This is a detailed description of the FLAC format. There is also a companion document that describes
FLAC-to-Ogg mapping.
For a user-oriented overview, see
About the FLAC Format.
Table of Contents
Acknowledgments
Scope
Architecture
Definitions
Blocking
Interchannel Decorrelation
Prediction
Residual Coding
Format
FLAC Subset
Specification
STREAM
METADATA_BLOCK
METADATA_BLOCK_HEADER
METADATA_BLOCK_DATA
METADATA_BLOCK_STREAMINFO
METADATA_BLOCK_PADDING
METADATA_BLOCK_APPLICATION
METADATA_BLOCK_SEEKTABLE
SEEKPOINT
METADATA_BLOCK_VORBIS_COMMENT
METADATA_BLOCK_CUESHEET
CUESHEET_TRACK
CUESHEET_TRACK_INDEX
METADATA_BLOCK_PICTURE
FRAME
FRAME_HEADER
FRAME_FOOTER
SUBFRAME
SUBFRAME_HEADER
SUBFRAME_CONSTANT
SUBFRAME_FIXED
SUBFRAME_LPC
SUBFRAME_VERBATIM
RESIDUAL
RESIDUAL_CODING_METHOD_PARTITIONED_RICE
RICE_PARTITION
RESIDUAL_CODING_METHOD_PARTITIONED_RICE2
RICE2_PARTITION
Acknowledgments
FLAC owes much to the many people who have advanced the audio compression field so freely. For instance:
A. J. Robinson for his work onShorten; his paper is a good starting point on some of the basic methods used by FLAC. FLAC trivially extends and improves the fixed predictors, LPC coefficient quantization, and Rice coding used in Shorten.
S. W. Golomb and Robert F. Rice; their universal codes are used by FLAC's entropy coder.
N. Levinson and J. Durbin; the reference encoder uses an algorithm developed and refined by them for determining the LPC coefficients from the autocorrelation coefficients.
And of course, Claude Shannon
Scope
It is a known fact that no algorithm can losslessly compress all possible input, so most compressors restrict themselves to a useful domain and try to work as well as possible within that domain. FLAC's domain is audio data. Though it can losslessly
code any input, only certain kinds of input will get smaller. FLAC exploits the fact that audio data typically has a high degree of sample-to-sample correlation.
Within the audio domain, there are many possible subdomains. For example: low bitrate speech, high-bitrate multi-channel music, etc. FLAC itself does not target a specific subdomain but many of the default parameters of the reference encoder are tuned to CD-quality music data (i.e. 44.1kHz, 2 channel, 16 bits per sample). The effect of the encoding parameters on different kinds of audio data will be examined later.
Architecture
Similar to many audio coders, a FLAC encoder has the following stages:
Blocking. The input is broken up into many contiguous blocks. With FLAC, the blocks may vary in size. The optimal size of the block is usually affected by many factors, including the sample rate, spectral characteristics over time, etc. Though FLAC allows the block size to vary within a stream, the reference encoder uses a fixed block size.
Interchannel Decorrelation. In the case of stereo streams, the encoder will create mid and side signals based on the average and difference (respectively) of the left and right channels. The encoder will then pass the best form of the signal to the next stage.
Prediction. The block is passed through a prediction stage where the encoder tries to find a mathematical description (usually an approximate one) of the signal. This description is typically much smaller than the raw signal itself. Since the methods of prediction are known to both the encoder and decoder, only the parameters of the predictor need be included in the compressed stream. FLAC currently uses four different classes of predictors (described in the prediction section), but the format has reserved space for additional methods. FLAC allows the class of predictor to change from block to block, or even within the channels of a block.
Residual coding. If the predictor does not describe the signal exactly, the difference between the original signal and the predicted signal (called the error or residual signal) must be coded losslessy. If the predictor is effective, the residual signal will require fewer bits per sample than the original signal. FLAC currently uses only one method for encoding the residual (see theResidual coding section), but the format has reserved space for additional methods. FLAC allows the residual coding method to change from block to block, or even within the channels of a block.
In addition, FLAC specifies a metadata system, which allows arbitrary information about the stream to be included at the beginning of the stream.
Definitions
Many terms like "block" and "frame" are used to mean different things in differenct encoding schemes. For example, a frame in MP3 corresponds to many samples across several channels, whereas an S/PDIF frame represents just one sample for each channel. The definitions we use for FLAC follow. Note that when we talk about blocks and subblocks we are referring to the raw unencoded audio data that is the input to the encoder, and when we talk about frames and subframes, we are referring to the FLAC-encoded data.
Block: One or more audio samples that span several channels.
Subblock: One or more audio samples within a channel. So a block contains one subblock for each channel, and all subblocks contain the same number of samples.
Blocksize: The number of samples in any of a block's subblocks. For example, a one second block sampled at 44.1KHz has a blocksize of 44100, regardless of the number of channels.
Frame: A frame header plus one or more subframes.
Subframe: A subframe header plus one or more encoded samples from a given channel. All subframes within a frame will contain the same number of samples.
Blocking
The size used for blocking the audio data has a direct effect on the compression ratio. If the block size is too small, the resulting large number of frames mean that excess bits will be wasted on frame headers. If the block size is too large, the characteristics of the signal may vary so much that the encoder will be unable to find a good predictor. In order to simplify encoder/decoder design, FLAC imposes a minimum block size of 16 samples, and a maximum block size of 65535 samples. This range covers the optimal size for all of the audio data FLAC supports.
Currently the reference encoder uses a fixed block size, optimized on the sample rate of the input. Future versions may vary the block size depending on the characteristics of the signal.
Blocked data is passed to the predictor stage one subblock (channel) at a time. Each subblock is independently coded into a subframe, and the subframes are concatenated into a frame. Because each channel is coded separately, it means that one channel of a stereo frame may be encoded as a constant subframe, and the other an LPC subframe.
Interchannel Decorrelation
In stereo streams, many times there is an exploitable amount of correlation between the left and right channels. FLAC allows the frames of stereo streams to have different channel assignments, and an encoder may choose to use the best representation on a frame-by-frame basis.
Independent. The left and right channels are coded independently.
Mid-side. The left and right channels are transformed into mid and side channels. The mid channel is the midpoint (average) of the left and right signals, and the side is the difference signal (left minus right).
Left-side. The left channel and side channel are coded.
Right-side. The right channel and side channel are coded
Surprisingly, the left-side and right-side forms can be the most efficient in many frames, even though the raw number of bits per