CMSampleBufferRef的缓冲区大小 [英] Buffer size of CMSampleBufferRef
问题描述
我正在尝试从AVFoundation回调中获取CMSampleBufferRef的大小
I am trying to get the size of CMSampleBufferRef from AVFoundation call-back
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
If I understand it correctly, I should use this method to get buffer size. But I always got 0 from the return. and It is said that "If there are no sample sizes in this CMSampleBuffer, a size of 0 will be returned." In this case, I wonder if AVFoundation framework does not provide a buffer size information or I mis-understand document.
一个后续问题: 顺便说一句,我想知道在这种情况下是否可以使用
A follow up question: By the way, I wonder in this case if I could use
CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
从pixelBuffer获取sampleBuffer的大小吗?
from pixelBuffer to get the size of sampleBuffer?
推荐答案
如何创建AVCaptureSession?
How do you create your AVCaptureSession?
基本上,CMSampleBuffer可以包含多个信息.
Basically a CMSampleBuffer can contain multiple information.
- 原始图像缓冲区(您可以使用CMSampleBufferGetImageBuffer提取)
- 音频缓冲区(必须使用CMSampleBufferGetBlockBuffer提取)
- CoreVideo编码的图像数据缓冲区(还必须使用CMSampleBufferGetBlockBuffer提取)
因此,您应该首先检查captureoutput
是否是您想要的,如果是并且您希望获得图像,则应将图像获取为CVPixelBufferRef
,然后使用CVPixelBufferGetDataSize
检查图像上的数据大小.
So you should first check if the captureoutput
is what you wanted, and if it is and you expect an image, then you should get the image as CVPixelBufferRef
then check the data size on the image using CVPixelBufferGetDataSize
这篇关于CMSampleBufferRef的缓冲区大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!