Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
472 views
in Technique[技术] by (71.8m points)

c++ - how to set bitrate correctly for aac encoding OSX

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...