对AAC格式的音频处理时都涉及到一些参数配置,之前经常忘记,特此做个记录。
最好的方式当然是去认真读一下spec。
下面就直接结合ffmpeg中代码的实现来说:
const int avpriv_mpeg4audio_sample_rates[16] = {96000, 88200, 64000, 48000, 44100, 32000,
24000, 22050, 16000, 12000, 11025, 8000, 7350
};
const uint8_t ff_mpeg4audio_channels[8] = {
0, 1, 2, 3, 4, 5, 6, 8
};
enum AudioObjectType {
AOT_NULL,
// Support? Name
AOT_AAC_MAIN, ///< Y Main
AOT_AAC_LC, ///< Y Low Complexity
AOT_AAC_SSR, ///< N (code in SoC repo) Scalable Sample Rate
AOT_AAC_LTP, ///< Y Long Term Prediction
AOT_SBR, ///< Y Spectral Band Replication
AOT_AAC_SCALABLE, ///< N Scalable
AOT_TWINVQ, ///< N Twin Vector Quantizer
AOT_CELP, ///< N Code Excited Linear Prediction
AOT_HVXC, ///< N Harmonic Vector eXcitation Coding
AOT_TTSI = 12, ///< N Text-To-Speech Interface
AOT_MAINSYNTH, ///< N Main Synthesis
AOT_WAVESYNTH, ///< N Wavetable Synthesis
在ffmpeg处理时和Android MediaCodec中用到Decoder-specific information from ESDS
1 ffmpeg中对应ACodec的extradata
2 Android MediaCodec中对应CSD buffer #0
从ffmpegaac_adtstoasc_filter函数可以看出其含义
init_put_bits(&pb, avctx->extradata, avctx->extradata_size);
put_bits(&pb, 5, hdr.object_type);
put_bits(&pb, 4, hdr.sampling_index);
put_bits(&pb, 4, hdr.chan_config);
put_bits(&pb, 1, 0); //frame length - 1024 samples
put_bits(&pb, 1, 0); //does not depend on core coder
put_bits(&pb, 1, 0); //is not extension
一般是2个字节,
1 最高5位对应AudioObjectType,实际上aac profile类型
2 下面4位是index,采样率定义参照avpriv_mpeg4audio_sample_rates数组
3 下面4位是index chan_config定义声道数,参照ff_mpeg4audio_channels数组
举例:0x12 0x10
profile:AAC_LC
sample_rates:44100
channels:2
另外ADTS格式怎么转换成ESDS需要个数可以参考
avpriv_aac_parse_header函数
网上也有大量文章,实现怎么增加ADTS头的文章,再此就不详述了。