Encoding AAC Audio using AudioRecord and MediaCodec on Android

China☆狼群 提交于 2019-11-28 17:19:22

You can use Android's MediaMuxer to package the raw streams created by MediaCodec into a .mp4 file. Bonus: AAC packets contained in a .mp4 don't require the ADTS header.

I've got a working example of this technique on Github.

Check "testEncoder" method here for how to use MediaCodec as Encoder properly.

after that In your code,

your input(audio recorder) is configured for single audio channel while your output(ADTS packet header) is set for two channels(chanCfg = 2).

also if you change your input samplerate (currently 44.1khz) you also have to change freqIdx flag in ADTS packet header. check this link for valid values.

And ADTS header profile flag is set to "AAC LC", you can also found this under MediaCodecInfo.CodecProfileLevel. you have set profile = 2 that is MediaCodecInfo.CodecProfileLevel.AACObjectLC

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!