这是编码部分示例代码。
我不了解endcode功能的工作模式。
我不知道如何逐帧拆分pcm原始数据,或者只对所有数据进行一次编码。
我需要一些指南或只是代码...
NSData *data = [NSData dataWithContentsOfURL: [[NSBundle mainBundle] URLForResource: @"sourcePCM" withExtension:@"raw"]];
AACENC_OutArgs out_args = { 0 };
AACENC_ERROR err;
int out_identifier = OUT_BITSTREAM_DATA;
uint8_t *output_data = calloc(encoder_info.maxOutBufBytes, 1);
int read = data.length;
void *in_ptr = data.bytes;
int _sampleBytes = ???;
int in_size = read;
int in_elem_size = _sampleBytes;
int in_identifier = IN_AUDIO_DATA;
AACENC_InArgs in_args = { 0 };
in_args.numInSamples = read / _sampleBytes;
AACENC_BufDesc in_buf = { 0 }, out_buf = { 0 };
in_buf.numBufs = 1;
in_buf.bufs = &in_ptr;
in_buf.bufferIdentifiers = &in_identifier;
in_buf.bufSizes = &in_size;
in_buf.bufElSizes = &in_elem_size;
void *out_ptr;
int out_size, out_elem_size;
out_ptr = output_data;
out_size = encoder_info.maxOutBufBytes;
out_elem_size = _sampleBytes;
out_buf.numBufs = 1;
out_buf.bufs = &out_ptr;
out_buf.bufferIdentifiers = &out_identifier;
out_buf.bufSizes = &out_size;
out_buf.bufElSizes = &out_elem_size;
AACENC_ERROR result = aacEncEncode(encoder_handle, &in_buf, &out_buf, &in_args, &out_args);
if (result != AACENC_OK) {
free(output_data);
NSLog(@"FDK-AAC encode fail %i", result);
return;
}
if (out_args.numOutBytes > 0) {
NSData *tmp = [NSData dataWithBytes:out_buf.bufs length: ???];
NSArray *paths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSLog(@"%@", documentsDirectory);
NSString *fileName = [NSString stringWithFormat:@"%@/tmp.aac",
documentsDirectory];
[tmp writeToFile:fileName atomically:true];
if (out_buf.bufs[0]) {
free(out_buf.bufs[0]);
}
} else {
free(output_data);
}