【问题标题】:Buffer size of CMSampleBufferRefCMSampleBufferRef 的缓冲区大小
【发布时间】:2015-06-05 19:27:42
【问题描述】:

我正在尝试从 AVFoundation 回调中获取 CMSampleBufferRef 的大小

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection

根据文档https://developer.apple.com/library/mac/documentation/CoreMedia/Reference/CMSampleBuffer/index.html#//apple_ref/c/func/CMSampleBufferGetSampleSize

size_t CMSampleBufferGetTotalSampleSize ( CMSampleBufferRef sbuf );

如果我理解正确,我应该使用这种方法来获取缓冲区大小。但 我总是从回报中得到 0。并且据说“如果此CMSampleBuffer中没有样本大小,则将返回0的大小。”在这种情况下,我想知道是 AVFoundation 框架没有提供缓冲区大小信息还是我误解了文档。

一个后续问题: 顺便说一句,我想知道在这种情况下我是否可以使用

CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);

从pixelBuffer中获取sampleBuffer的大小?

【问题讨论】:

  • 您找到解决方案了吗?

标签: ios video avfoundation


【解决方案1】:

如果您的 CMSampleBuffer 预计包含图像,那么您可以执行以下操作

- (CGSize)sampleBufferSize:(CMSampleBufferRef)sampleBuffer {
          CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
          size_t imageWidth = CVPixelBufferGetWidth(imageBuffer);
          size_t imageHeight = CVPixelBufferGetHeight(imageBuffer);
          return CGSizeMake(imageWidth, imageHeight);
}

【讨论】:

    【解决方案2】:

    如何创建 AVCaptureSession?

    基本上一个 CMSampleBuffer 可以包含多个信息。

    • 原始图像缓冲区(可以使用 CMSampleBufferGetImageBuffer 提取)
    • 音频缓冲区(必须使用 CMSampleBufferGetBlockBuffer 提取)
    • CoreVideo 编码图像数据缓冲区(也必须使用 CMSampleBufferGetBlockBuffer 提取)

    所以您应该首先检查captureoutput 是否是您想要的,如果是并且您期望图像,那么您应该将图像作为CVPixelBufferRef 获取,然后使用CVPixelBufferGetDataSize 检查图像上的数据大小

    【讨论】:

      猜你喜欢
      • 2020-09-05
      • 2014-06-10
      • 2013-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-11
      相关资源
      最近更新 更多