Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ffmpeg CoreAudio:如何检索原始数据的实际采样率?_Ffmpeg_Core Audio - Fatal编程技术网

Ffmpeg CoreAudio:如何检索原始数据的实际采样率?

Ffmpeg CoreAudio:如何检索原始数据的实际采样率?,ffmpeg,core-audio,Ffmpeg,Core Audio,当尝试在mp4容器中播放AAC-HE内容时,在mp4容器中发现的报告采样率似乎是实际采样率的一半 例如,它显示为24kHz而不是48kHz 使用FFmpeg AAC解码器,只需使用 avcodec_decode_audio4 查看将适当更新的AvcodeContext::sample_速率。因此,很容易调整输出 使用CoreAudio解码器,我将使用AudioConverterRef设置输入和输出AudioStreamBasicDescription 并调用AudioConverterFill

当尝试在mp4容器中播放AAC-HE内容时,在mp4容器中发现的报告采样率似乎是实际采样率的一半

例如,它显示为24kHz而不是48kHz

使用FFmpeg AAC解码器,只需使用

avcodec_decode_audio4
查看将适当更新的AvcodeContext::sample_速率。因此,很容易调整输出

使用CoreAudio解码器,我将使用AudioConverterRef设置输入和输出AudioStreamBasicDescription 并调用AudioConverterFillComplexBuffer

由于转换器执行所有必需的内部转换,包括重新采样,因此一切正常。但它在将内容重新采样到24kHz后播放内容,因为输入AudioStreamBasicDescription中包含了24kHz

有没有一种方法可以像FFmpeg一样,通过解码器而不是解复用器检索实际采样率

希望尽可能避免丢失音频质量,而不是混音数据

谢谢你找到了这个:

解释如何检索更高质量的流

生成的代码如下所示:

AudioStreamBasicDescription inputFormat;
AudioFormatListItem* formatListPtr = NULL;
UInt32 propertySize;
OSStatus rv = noErr;

rv = AudioFileStreamGetPropertyInfo(mStream,
                                    kAudioFileStreamProperty_FormatList,
                                    &propertySize,
                                    NULL);
if (rv == noErr) {
  // allocate memory for the format list items
  formatListPtr = static_cast<AudioFormatListItem*>(malloc(propertySize));
  if (!formatListPtr) {
    LOG("Error %d constructing AudioConverter", rv);
    mCallback->Error();
    return;
  }

  // get the list of Audio Format List Item's
  rv = AudioFileStreamGetProperty(mStream,
                                  kAudioFileStreamProperty_FormatList,
                                  &propertySize,
                                  formatListPtr);
  if (rv == noErr) {
    UInt32 itemIndex;
    UInt32 indexSize = sizeof(itemIndex);

    // get the index number of the first playable format -- this index number will be for
    // the highest quality layer the platform is capable of playing
    rv = AudioFormatGetProperty(kAudioFormatProperty_FirstPlayableFormatFromList,
                                propertySize,
                                formatListPtr,
                                &indexSize,
                                &itemIndex);
    if (rv != noErr) {
      free(formatListPtr);
      LOG("Error %d retrieving best format for AudioConverter", rv);
      return;
    }
    // copy the format item at index we want returned
    inputFormat =  formatListPtr[itemIndex].mASBD;
  }
  free(formatListPtr);
} else {
  // Fill in the input format description from the stream.
  nsresult rv = AppleUtils::GetProperty(mStream,
                                        kAudioFileStreamProperty_DataFormat,
                                        &inputFormat);
  if (NS_FAILED(rv)) {
    LOG("Error %d retrieving default format for AudioConverter", rv);
    return;
  }
}

// Fill in the output format manually.
PodZero(&mOutputFormat);
mOutputFormat.mFormatID = kAudioFormatLinearPCM;
mOutputFormat.mSampleRate = inputFormat.mSampleRate;
mOutputFormat.mChannelsPerFrame = inputFormat.mChannelsPerFrame;