-
-
Save bibhas/0235669e3f21cf04afa5dd1b3d654de7 to your computer and use it in GitHub Desktop.
Update CVImageBufferRef with pixels in capture format with bgra pixels using libyuv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Function to update image buffer in NV12 format with BGRA pixel buffer | |
// Assumptions: | |
// bgra buffer is 32bpp | |
// bgra buffer width and height equal to imageBuffer | |
// bgra buffer stride is equal to imageBuffer width | |
int UpdateSampleBufferWithBGRAPixels(CVImageBufferRef imageBuffer, void *bgraPixels) { | |
const OSType pixelFormat = CVPixelBufferGetPixelFormatType(imageBuffer); | |
assert(pixelFormat == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange || pixelFormat == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange); | |
const size_t width = CVPixelBufferGetWidth(imageBuffer); | |
const size_t height = CVPixelBufferGetHeight(imageBuffer); | |
CVPixelBufferLockBaseAddress(imageBuffer, NULL); | |
const int retval = ARGBToNV12(bgraPixels, 4 * width, | |
CVPixelBufferGetBaseAddressOfPlane(imageBuffer, 0), CVPixelBufferGetBytesPerRowOfPlane(imageBuffer, 0), | |
CVPixelBufferGetBaseAddressOfPlane(imageBuffer, 1), CVPixelBufferGetBytesPerRowOfPlane(imageBuffer, 1), | |
width, height); | |
CVPixelBufferUnlockBaseAddress(imageBuffer, NULL); | |
return retval; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment