我正在尝试从 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/