5

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?

Community
  • 1
  • 1
jab
  • 4,053
  • 3
  • 33
  • 40

1 Answers1

8

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
}
Todd Yandell
  • 14,656
  • 2
  • 50
  • 37
  • Well, the docs say that CVOpenGLTexture is defined in QuartzCore.framework, but I still got linker errors and couldn't build with either the OpenGLBuffer or OpenGLTexture checking (also tried CoreVideo.framework). Fortunately, I appear to have pixel buffers so it's a moot point. – jab Apr 12 '11 at 19:59
  • In CoreVideo/CVPIxelBuffer I see `public typealias CVPixelBuffer = CVImageBuffer` so I don't understand how `CVImageBuffer` is an abstract type. Edit: well this is 7 years later, so I guess this answer is obsolete....? – xaphod Aug 15 '18 at 21:26