12

When trying to create a 32 bits RGBA CVPixelBuffer, I constantly get errors.

Most notably error -6680 which means: "The buffer does not support the specified pixel format."

This is the code fragment: (Width and height are specified as 256*256)

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
//                         [NSNumber numberWithBool:YES], kCVPixelBufferCGBitmapContextCompatibilityKey,
//                         [NSNumber numberWithBool:YES], kCVPixelBufferCGImageCompatibilityKey,
//                         [NSNumber numberWithBool:YES], kCVPixelBufferOpenGLCompatibilityKey,
                         nil];
CVPixelBufferRef pxbuffer = NULL;
CVReturn status = CVPixelBufferCreate(kCFAllocatorDefault, WIDTH,
                                      HEIGHT, kCVPixelFormatType_32RGBA, (CFDictionaryRef) options, 
                                      &pxbuffer);
NSParameterAssert(status == kCVReturnSuccess && pxbuffer != NULL);

Can anyone give a hint as to what I'm doing wrong?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Toad
  • 15,593
  • 16
  • 82
  • 128

1 Answers1

11

You'll need to use a different pixel format. Just because there's a constant defined for 32RGBA doesn't mean it's supported. This tech note lists the supported formats (as of when it was written) and the functions you can use to find out what formats are currently supported:

Technical Q&A QA1501 Core Video - Available Pixel Formats

The most similar formats that are supported are 32ARGB and 32BGRA.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
  • It's strange. Because I need this buffer format for the new CVOpenGLESTextureCacheCreateTextureFromImage function. In the RosyWriter apple example they use this very format (although they obtain this buffer from the camera). – Toad Nov 06 '11 at 19:57
  • 1
    RosyWriter doesn't mention `kCVPixelFormatType_32RGBA`. In the call to `CVOpenGLESTextureCacheCreateTextureFromImage`, it uses `GL_RGBA` as the `internalFormat` parameter, but it uses `GL_BGRA` as the `format` parameter, which "Specifies the format of the pixel data." – rob mayoff Nov 06 '11 at 20:18
  • In fact RosyWriter uses `kCVPixelFormatType_32BGRA` (not `...32RGBA`). – rob mayoff Nov 06 '11 at 20:19
  • yes! it's working! Thanks so much! Staring too long at all these parameters can make you parameter blind apparently. – Toad Nov 06 '11 at 20:29
  • @robmayoff Hi, would you plz have a glance at my issue. thx.http://stackoverflow.com/questions/37611593/how-to-create-cvpixelbufferref-with-nv12-data – Grey Jun 08 '16 at 07:39