2

I have a 1 second PCM data which I write into an AAC file successfully.

However, I can not control the bitrate of the output file.

Here is the configuration of my AAC codec:

AudioStreamBasicDescription clientFormat = {0};

clientFormat.mSampleRate         = 44100;
clientFormat.mFormatID           = kAudioFormatMPEG4AAC;
clientFormat.mFormatFlags        = kMPEG4Object_AAC_Main;
clientFormat.mChannelsPerFrame   = 2;
clientFormat.mBytesPerPacket     = 0;
clientFormat.mBytesPerFrame      = 0;
clientFormat.mFramesPerPacket    = 1024;
clientFormat.mBitsPerChannel     = 0;
clientFormat.mReserved           = 0;

As far as I researched other examples this is the proper way to set the bitrate:

AudioConverterRef acRef;
UInt32 acsize = sizeof(acRef);
UInt32 bitRateIn = 96000;

ExtAudioFileGetProperty(audiofileRef, kExtAudioFileProperty_AudioConverter,
                                                         &acsize, &acRef);

AudioConverterSetProperty(acRef, kAudioConverterEncodeBitRate,
                                              sizeof(UInt32), &bitRateIn);

After this I write my data to the file.

As the file is 1 second and the bitrate is 96kbit/s the output file should be around 96/8 = 12 kilobyte. But the output file is around 62 kilobyte.

After getting this strange behaviour I opened the file using MediaInfo and it had 3 different bitrates:

Nominal bitrate - 96kb/s (this is what I have set)

Bitrate - 48kb/s

Overall bitrate - 476kb/s

mediainfo

Here the file size corresponds to the Overall bitrate as 476/8 = 59 kilobyte (the rest is metadata and headers).

How can I set the bitrate correctly?

mbaros
  • 825
  • 8
  • 31
  • These lines about set the bitrate looks good. AudioConverterSetProperty – rotoava Jan 14 '17 at 06:51
  • But i think the more important is the config about "input" and "output" audio format and property. In my code, I exactly encode 2048 bytes pcm data at once.This my aac encoder codes http://test86400.b0.upaiyun.com/aacencode.zip, maybe helpfull. – rotoava Jan 14 '17 at 06:58
  • @rotoava, thanks for the comment. I am still trying to figure out the correct way. If any news, I will comment here. – mbaros Jan 17 '17 at 17:19

0 Answers0