如何获得正确的通道,而编码AAC-HE-V1的fdk在iOS上



我使用fdk v2.0.101在iOS上通过xcode Version 8.0 (8A218a)编码aac - he - v1,但我总是得到立体声通道aac数据,即使我将单声道设置为通道。

如何获得正确的通道,而编码AAC-HE-V1由fdk?

PS: AAC-LC是OK。在iOS 9.3的iPhone 6上测试

下面是代码片段:

初始化部分
    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");

Enocoding部分:

  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);
  }

我认为CHANNEL_MODE是原始音频模式。不是aac模式

iOS不支持AAC-HE-V2。

你不需要使用fdk来转换音频

下面是示例代码。

https://developer.apple.com/library/content/samplecode/iPhoneACFileConvertTest/Introduction/Intro.html

我也需要一些关于fdk-aac ios的帮助。这是链接。希望你能看一下。Ios fdk-aac PCM到aac示例

最新更新