raw data from CVImageBuffer without rendering?

旧城冷巷雨未停 提交于 2019-12-01 04:40:21

问题


I'm getting a CVImageBufferRef from my AVCaptureSession, and I'd like to take that image buffer and upload it over the network. To save space and time, I would like to do this without rendering the image into a CIImage and NSBitmapImage, which is the solution I've seen everywhere (like here: How can I obtain raw data from a CVImageBuffer object).

This is because my impression is that the CVImageBuffer might be compressed, which is awesome for me, and if I render it, I have to uncompress it into a full bitmap and then upload the whole bitmap. I would like to take the compressed data (realizing that a single compressed frame might be unrenderable later by itself) just as it sits within the CVImageBuffer. I think this means I want the CVImageBuffer's base data pointer and its length, but it doesn't appear there's a way to get that within the API. Anybody have any ideas?


回答1:


CVImageBuffer itself is an abstract type. Your image should be an instance of either CVPixelBuffer, CVOpenGLBuffer, or CVOpenGLTexture. The documentation for those types lists the functions you can use for accessing the data.

To tell which type you have use the GetTypeID methods:

CVImageBufferRef image = …;
CFTypeID imageType = CFGetTypeID(image);

if (imageType == CVPixelBufferGetTypeID()) {
  // Pixel Data
}
else if (imageType == CVOpenGLBufferGetTypeID()) {
  // OpenGL pbuffer
}
else if (imageType == CVOpenGLTextureGetTypeID()) {
  // OpenGL Texture
}


来源:https://stackoverflow.com/questions/5626703/raw-data-from-cvimagebuffer-without-rendering

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