ios - 音频 CMSampleBuffer 格式

标签 ios avfoundation core-audio audio-streaming audio-recording

使用AVCaptureAudioDataOutput时,CMSampleBuffer中存储的数据是什么?它通过委托(delegate)方法 –captureOutput:didOutputSampleBuffer:fromConnection: 传递 CMSampleBuffers 但是 CMSampleBuffer 里面有什么? PCM 还是压缩?采样率、 channel 数等是多少?这如何用于从设备流式传输音频? 谷歌搜索几个小时对我没有帮助。

提前致谢

最佳答案

看起来您可以通过这种方式获得 ASBD:

sampleBuffer->
  CMSampleBufferGetFormatDescription ->
    CMAudioFormatDescriptionGetStreamBasicDescription

然后 ASBD 将详细说明帧大小、是否压缩、字节顺序等。

为了证明这一点(没有错误检查)并获得采样率:

CMSampleBufferRef cmSampleBuffer = ...;

CMFormatDescriptionRef formatDescription =
  CMSampleBufferGetFormatDescription(cmSampleBuffer);

const AudioStreamBasicDescription* const asbd =
  CMAudioFormatDescriptionGetStreamBasicDescription(formatDescription);

double sampleRate = asbd->mSampleRate;

关于ios - 音频 CMSampleBuffer 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8049999/

相关文章:

ios - 为什么我调用这个方法然后当前VC自动回到rootVC

ios - 错误域=AVFoundationErrorDomain 代码=-11800 "The operation could not be completed"{错误域=NSOSStatusErrorDomain 代码=-16976 "(null)"}

ios - 包装 AVPlayer 行为时处理 AVPlayerLayer

ios - AVAsset Export 设置恒定的帧率

ios - 如何清除或不设置 kLinearPCMFormatFlagIsNonInterleaved

objective-c - 这种特定的音频操作需要什么 iOS 框架

ios - Tensorflow 在 iOS 上运行缓慢

ios - 将 pdf 的内容读取为字符串

iphone - Xcode 本地化让我抓狂!不加载 Storyboard

ios - 从麦克风捕获音频时,我陷入了内存泄漏或音频中的过多静电之间