how to set bitrate correctly for aac encoding OSX

佐手、 提交于 2019-12-18 07:11:43

问题


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

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?

来源:https://stackoverflow.com/questions/41638475/how-to-set-bitrate-correctly-for-aac-encoding-osx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!