ios - CMSampleBufferRef 的缓冲区大小

标签 ios video avfoundation

我正在尝试从 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 的大小?

最佳答案

如果您的 CMSampleBuffer预期包含图像,然后您可以执行以下操作

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

关于ios - CMSampleBufferRef 的缓冲区大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29385893/

相关文章:

ios - 使用谷歌地图时出现错误,错误是 - libc++abi.dylib : terminating with uncaught exception of type NSException

HTML5 视频在 FireFox 浏览器中显示 "No Video With Supported format and MIME type Found"

html - 链接到其他页面进行播放的视频缩略图

Swift - 从 avaudioPCMbuffer 到数组

ios - iOS从视频中删除特定声音

ios - 表达式类型不明确,没有更多上下文(枚举)

ios - 在 UITableView 中设置复选标记

ios - UIWebView 中 PDF 周围的黑色边框,如何使用 Swift 删除

JavaScript - 读取视频文件的元数据

swift - requestAccessForMediaType 不请求许可