简体   繁体   中英

How to set bit rate in audio queue

I'm using speak here code for audio recording with audio format kAudioFormatMPEG4AAC. How can i change bit rate to 96K, 128K or 320K?

Regards, John

I'm not sure if you can do this directly using AudioQueue by setting a parameter. However, I think the following approach will work:

  • Setup your AudioQueue to record to linear PCM
  • Setup an ExtAudioFile with a client data format matching the AudioQueue and a file data format of AAC
  • Set the desired AAC bitrate by getting the AudioConverter associated with the ExtAudioFile (kExtAudioFileProperty_AudioConverter) and set the converter's bitrate (kAudioConverterEncodeBitRate).

I haven't tried this on iOS, but if the AAC encoder is using a hardware codec I doubt you will be able to set the bitrate. AudioFormat.h gives some methods to determine which codecs are hardware vs. software and ways to request one implementation vs. another.

The fact is, AudioQueue is using the same backend as AudioConverter, although there is no key for bitRate in AudioQueueProperty enom, you can still borrow them from converter. Get the bit rate like this:

AudioQueueGetProperty(mQueue, kAudioConverterEncodeBitRate, &bitRate, &propertySize);

and set it like this:

AudioQueueSetProperty(mQueue, kAudioConverterEncodeBitRate, &bitRate, propertySize);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM