Buffer size of CMSampleBufferRef

南楼画角 提交于 2019-12-11 11:59:24

问题


I am trying to get the size of CMSampleBufferRef from AVFoundation call-back

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

According to documentation https://developer.apple.com/library/mac/documentation/CoreMedia/Reference/CMSampleBuffer/index.html#//apple_ref/c/func/CMSampleBufferGetSampleSize

size_t CMSampleBufferGetTotalSampleSize ( CMSampleBufferRef sbuf );

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);

from pixelBuffer to get the size of sampleBuffer?


回答1:


How do you create your AVCaptureSession?

Basically a CMSampleBuffer can contain multiple information.

  • Raw image buffer (which you can extract using CMSampleBufferGetImageBuffer)
  • Audio buffer (which you have to extract using CMSampleBufferGetBlockBuffer)
  • CoreVideo encoded image data buffer (also have to extract using CMSampleBufferGetBlockBuffer)

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



来源:https://stackoverflow.com/questions/29385893/buffer-size-of-cmsamplebufferref

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!