I'm focus to create CVPixelBuffer with bytes data (YUV422), this format is my goal but it doesn't work
var yuv422Array = [UInt16](repeating: 0x0000, count: rows*cols)
yuv422Array[0] = 0x0000
let bytesPerRow = cols * 2
CVPixelBufferCreateWithBytes(kCFAllocatorDefault, cols, rows,
kCVPixelFormatType_422YpCbCr16, &baseAddr, bytesPerRow,
nil, nil, nil, &pixelBuffer)
//...
print(pixelBuffer == nil) // false
print(CIImage(cvPixelBuffer: pixelBuffer) == nil) // true ❌ (CIImage is nil) 😥
I'm also trying to create with BGRA data, it doesn't work too.
var rgbArray = [UInt32](repeating: 0xFF204080, count: rows*cols) //DarkBlue
rgbArray[0] = 0xFFFF0000 // Red
rgbArray[1] = 0xFF00FF00 // Green
rgbArray[2] = 0xFF000001 // Black
let bytesPerRow = cols * 4
CVPixelBufferCreateWithBytes(kCFAllocatorDefault, cols, rows,
kCVPixelFormatType_BGRA32, &baseAddr, bytesPerRow, nil, nil, nil,
&pixelBuffer)
//...
print(pixelBuffer == nil) // false
print(CIImage(cvPixelBuffer: pixelBuffer) == nil) // false, (CIImage is NOT nill)
// but the result is not correct.
Is there an alternative way that I can create CVPixelBuffer
User contributions licensed under CC BY-SA 3.0