定义音频格式宏
#define PROFILE_AAC_LC 2
#define PROFILE_AAC_HE 5
#define PROFILE_AAC_HE_v2 29
#define PROFILE_AAC_LD 23
#define PROFILE_AAC_ELD 39
初始化
HANDLE_AACENCODER _encoder;
AACENC_ERROR rt = aacEncOpen(&_encoder, 0, 0);
if (rt != AACENC_OK) {
NSLog(@"aac enc open error %zd",rt);
return;
}
aacEncoder_SetParam(_encoder, AACENC_AOT, PROFILE_AAC_HE_v2);
aacEncoder_SetParam(_encoder, AACENC_BITRATE, 64 * 1000);
aacEncoder_SetParam(_encoder, AACENC_SAMPLERATE, 44100);
aacEncoder_SetParam(_encoder, AACENC_CHANNELMODE, MODE_2);
编码
size_t length = xx;//pcm len
char *point = xx; //pcm data
AACENC_BufDesc in = {0};
{
INT bid = IN_AUDIO_DATA;
INT elSize = 2;
void *buf[1] = {point};
in.bufs = buf;
in.numBufs = 1;
in.bufferIdentifiers = &bid;
in.bufElSizes = &elSize;
}
AACENC_BufDesc out = {0};
{
INT size = 1024;
INT bid = OUT_BITSTREAM_DATA;
void *buf[1] = {malloc(1024)};
INT elSize = 1;
out.bufs = buf;
out.bufSizes = &size;
out.numBufs = 1;
out.bufferIdentifiers = &bid;
out.bufElSizes = &elSize;
}
AACENC_InArgs inArgs = {0};
inArgs.numInSamples = (INT)length/2;
AACENC_OutArgs outArgs = {0};
AACENC_ERROR rt = aacEncEncode(_encoder, &in, &out, &inArgs, &outArgs);
if (rt != AACENC_OK) {
NSLog(@"aac enc encode error %zd",rt);
}else{
NSLog(@"aac enc encode size %zd %zd",outArgs.numOutBytes, out.bufSizes[0]);
}
if (out.bufs[0]) {
free(out.bufs[0]);
}
参考
vlc的例子 https://fossies.org/linux/vlc/modules/codec/fdkaac.c