3

I am first decoding an audio with MediaExtractor and MediaCodec class and then encoding it in AAC using MediaCodec class (added adts headers). The generated audio is noticeably slower in speed than the original. The audio also gets a little dim. I am using following preferences to set my encoder:

format.setInteger(MediaFormat.KEY_AAC_PROFILE, 
                      MediaCodecInfo.CodecProfileLevel.AACObjectLC);
format.setInteger(MediaFormat.KEY_SAMPLE_RATE, 44100);
format.setInteger(MediaFormat.KEY_BIT_RATE, 128 * 1024);
format.setInteger(MediaFormat.KEY_CHANNEL_COUNT, 2);

Is there a way I can get a better encoded audio which matches the original audio?

Abdul Qadir
  • 129
  • 10

1 Answers1

0
format.setInteger(MediaFormat.KEY_SAMPLE_RATE, 44100);

What is sample rate of original audio stream? In case original audio has another sampling rate you will get slower or faster audio and to fix it you need to make resampling or not to change sample rate

Marlon
  • 1,473
  • 11
  • 13
  • 1
    The original audio has sampling rate of 48000. So this explains the slower audio since the original sampling rate is higher than the encoded one. Thankyou. You saved me hours!! – Abdul Qadir Jul 15 '14 at 20:03
  • Actually I want to mix/merge different audios together. So it makes sense not to change sample rate of any audio as it should be as it is originally, and just play at a particular time. Is it possible to not change sample rates and mix the audios? – Abdul Qadir Jul 15 '14 at 21:55
  • 2
    no, you can't mix two audios with different sample rate or different channels count. so, you have to do resampling (sample rate conversion) - check here for more info: http://stackoverflow.com/questions/3260424/resample-upsample-sound-frames-from-8khz-to-48khz-java-android or you can try use ffmpeg resampler – Marlon Jul 16 '14 at 07:41