I\'m recording the screen from my iPhone device to my Mac. As a preview layer I am collecting sample buffers directly from a AVCaptureVideoDataOutput, from whic
I found a workaround for this, which keeps the 2vuy format in the pixel buffer, but the bad thing is that you make a copy of the pixel buffer data which affects performance. I'm posting this for future reference, or if anyone else finds it useful. Basically we intercept the pixel buffer and then add attributes while copying the data.
NSDictionary *attributes = @{
@"IOSurfaceCoreAnimationCompatibility": @YES
};
CVPixelBufferRef copy = NULL;
CVPixelBufferCreate(kCFAllocatorDefault,
CVPixelBufferGetWidth(pixelBuffer),
CVPixelBufferGetHeight(pixelBuffer),
CVPixelBufferGetPixelFormatType(pixelBuffer),
(__bridge CFDictionaryRef)attributes,
©);
CVPixelBufferLockBaseAddress(pixelBuffer, kCVPixelBufferLock_ReadOnly);
CVPixelBufferLockBaseAddress(copy, 0);
void *baseAddress = CVPixelBufferGetBaseAddress(pixelBuffer);
void *copyBaseAddress = CVPixelBufferGetBaseAddress(copy);
memcpy(copyBaseAddress, baseAddress, CVPixelBufferGetDataSize(pixelBuffer));
CVPixelBufferUnlockBaseAddress(copy, 0);
CVPixelBufferUnlockBaseAddress(pixelBuffer, kCVPixelBufferLock_ReadOnly);