Encoding AAC Audio using AudioRecord and MediaCodec on Android

前端 未结 2 1589
既然无缘
既然无缘 2020-12-13 05:46

I am trying to encode aac audio using android AudioRecord and MediaCodec. I have created a encoder class very similar to (Encoding H.264 from camera with Android MediaCodec)

相关标签:
2条回答
  • 2020-12-13 06:21

    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

    0 讨论(0)
  • 2020-12-13 06: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.

    0 讨论(0)
提交回复
热议问题