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?
A CVPixelBuffer usually contains pixels in RGBA format where each color channel is 8 bits. That means the pixel values in this image are between 0 and 255.
A Core Video pixel buffer is an image buffer that holds pixels in main memory. Applications generating frames, compressing or decompressing video, or using Core Image can all make use of Core Video pixel buffers.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With