AU格式解析
扩展名:au,snd
公司:Sun
AU又称SUD,是一种简单的PCM文件被广泛应用于Sun系统。这种格式的组成由原始数据紧跟在文件头之后。
下面是文件头数据结构,所有字段按大段字节序排列:
magic 32 bits ".snd" data_start 32 absolute file offset of first sample data_size 32 size of sample data, 0 means unspecified sample_format 32 sample format code, see below sample_rate 32 sample rate in samples/second channels 32 number of channels
The header may be followed by a chunk of arbitrary data if the data_start field is greater than 24.
The sample format codes are:
0 unspecified 1 8-bit mu-law 2 8-bit signed linear 3 16-bit signed linear 4 24-bit signed linear 5 32-bit signed linear 6 floating-point 7 double precision float 8 fragmented sampled data 9 unknown 10 DSP program 11 8-bit fixed-point 12 16-bit fixed-point 13 24-bit fixed-point 14 32-bit fixed-point 15 unknown 16 non-audio data 17 mu-law squelch 18 16-bit linear with emphasis 19 16-bit linear with compression 20 16-bit linear with emphasis and compression 21 Music Kit DSP commands 22 Music Kit DSP samples 23 G.721 ADPCM 24 G.722 ADPCM 25 G.723 ADPCM 26 5-bit G.723 ADPCM 27 8-bit a-law
其实ffmpeg中au.c只对1,2,3,4,5,6,7,24,27,这几种采样格式编码做了处理。由上可知AU格式的数据部分是经过压缩的PCM数据或者ADPCM数据,而且是一种有损压缩,一般压缩比在2:1左右。
关于bits_per_sample,是根据PCM类型来确定的,下面给出ffmpeg中定义的所有PCM类型,ADPCM就不给出了:
8位采样
AV_CODEC_ID_PCM_ALAW
AV_CODEC_ID_PCM_MULAW
AV_CODEC_ID_PCM_S8
AV_CODEC_ID_PCM_S8_PLANAR
AV_CODEC_ID_PCM_U8
AV_CODEC_ID_PCM_ZORK
16位采样
AV_CODEC_ID_PCM_S16BE
AV_CODEC_ID_PCM_S16BE_PLANAR
AV_CODEC_ID_PCM_S16LE //此为WAV格式中PCM数据的类型
AV_CODEC_ID_PCM_S16LE_PLANAR
AV_CODEC_ID_PCM_U16BE
AV_CODEC_ID_PCM_U16LE
24位采样
AV_CODEC_ID_PCM_S24DAUD
AV_CODEC_ID_PCM_S24BE
AV_CODEC_ID_PCM_S24LE
AV_CODEC_ID_PCM_S24LE_PLANAR
AV_CODEC_ID_PCM_U24BE
AV_CODEC_ID_PCM_U24LE
32位采样
AV_CODEC_ID_PCM_S32BE
AV_CODEC_ID_PCM_S32LE
AV_CODEC_ID_PCM_S32LE_PLANAR
AV_CODEC_ID_PCM_U32BE
AV_CODEC_ID_PCM_U32LE
AV_CODEC_ID_PCM_F32BE
AV_CODEC_ID_PCM_F32LE
64位采样
AV_CODEC_ID_PCM_F64BE
AV_CODEC_ID_PCM_F64LE
还有一些关于ADPCM的请见ffmpeg中utils.c
可以通过已知量计算得到的量:
如PCM是AV_CODEC_ID_PCM_MULAW,即sample_format为1,
则采样位数bps = 8(bits_per_sample),
比特率bit_rate = channels * sample_rate * bps
总播放时间duration = data_size / bit_rate
块对齐block_align = (bps * channels / 8) > 1 ?(bps * channels / 8) : 1
AU格式的seek公式如下
若为PCM数据:
pos = seektime * sample_rate * (bps / 8) *channels + data_start
若为ADPCM数据:
pos_tmp = seektime * byterate / blockalign //注意是byterate,即bit_rate*8
pos = pos_tmp * blockalign + data_start
存在的疑惑:已知AU中PCM数据是经过压缩的PCM数据或者ADPCM数据,且根据压缩方法不同其类型也各不相同,那么将它们解压缩的时候该用什么方法呢?会像ADPCM一样利用一些已知的表么?