iOSのAAC-HE-V1をxcodeバージョン8.0(8A218a)でエンコードするにはfdk v2.0.101を使用しますが、チャンネルとしてmonoを設定しても、常にステレオチャンネルのaacデータを取得します。iOSでfdkでAAC-HE-V1をエンコードする際に正しいチャンネルを取得するにはどうすればよいですか?
fdkでAAC-HE-V1をエンコードする際に正しいチャネルを取得するにはどうすればよいですか?
PS:AAC-LCはOKです。 iOS 9.3でiPhone 6でテスト済み
次のコードスニペットです:
初期化部分部分をEnocoding
UINT channels = 1;
HANDLE_AACENCODER encoder_handle;
AACENC_InfoStruct encoder_info;
int HE_AACv1 = 5;
TRANSPORT_TYPE transport_type = TT_MP4_ADTS;
CHANNEL_MODE mode;
switch (channels) {
case 1: mode = MODE_1; break;
case 2: mode = MODE_2; break;
case 3: mode = MODE_1_2; break;
case 4: mode = MODE_1_2_1; break;
case 5: mode = MODE_1_2_2; break;
case 6: mode = MODE_1_2_2_1; break;
}
CheckError(aacEncOpen(&encoder_handle, 0, channels), @"Unable to open encoder : %i");
CheckError(aacEncoder_SetParam(encoder_handle, AACENC_AOT, HE_AACv1), @"Unable to set the AOT : %i");
CheckError(aacEncoder_SetParam(encoder_handle, AACENC_SAMPLERATE, 44100),
@"Unable to set the sample rate : %i");
CheckError(aacEncoder_SetParam(encoder_handle, AACENC_CHANNELMODE, mode),
@"Unable to set the channel mode : %i");
CheckError(aacEncoder_SetParam(encoder_handle, AACENC_CHANNELORDER, 1),
@"Unable to set the wav channel order : %i");
CheckError(aacEncoder_SetParam(encoder_handle, AACENC_BITRATE, 90000),
@"Unable to set the bitrate : %i");
CheckError(aacEncoder_SetParam(encoder_handle, AACENC_TRANSMUX, transport_type),
@"Unable to set the ADTS transmux : %i");
CheckError(aacEncoder_SetParam(encoder_handle, AACENC_AFTERBURNER, 1),
@"Unable to set the afterburner mode : %i");
CheckError(aacEncEncode(encoder_handle, NULL, NULL, NULL, NULL),
@"Unable to initialize the encoder : %i");
CheckError(aacEncInfo(encoder_handle, &encoder_info), @"Unable to get the encoder info : %i");
:
AudioBuffer originBuffer = ...;
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 = originBuffer.mDataByteSize;
void *in_ptr = originBuffer.mData;
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) {
// handle output_data
} else {
free(output_data);
}