I'm trying to encode
Audio data:
to some AAC by MediaCodec
The codec configuration is a bit confusing, but so far I did as follows at least with no error.
codec = MediaCodec.createEncoderByType("audio/mp4a-latm");
MediaFormat format = new MediaFormat();
format.setString(MediaFormat.KEY_MIME, "audio/mp4a-latm");
format.setInteger(MediaFormat.KEY_CHANNEL_COUNT, 1);
format.setInteger(MediaFormat.KEY_SAMPLE_RATE, 44100);
format.setInteger(MediaFormat.KEY_BIT_RATE, 1*44100*16);
format.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectHE);
codec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
Here's only my guess so if you find it wrong please tell me so.
KEY_CHANNEL_COUNT
= 1 corresponds to the audio source attribute: Monoral Channel = 1
,
KEY_SAMPLE_RATE
= 44100 to the audio source attribute: Sample rate = 44100 Hz
,
and since the audio source attribute is PCM_16BIT, KEY_BIT_RATE
should be 1*44100*16
.
Am I correct? I try to find documentation, but could not find on the web. Thanks.
For the encoders, KEY_BIT_RATE
refers to the desired output bit rate, not the input bit rate. The official doc is here, but the descriptions are a bit terse.
The CTS EncoderTest encodes audio. It's not much to go on, but it has the basic elements.