问题
I have problem with VideoFrameYUV
to CIImage
conversion. I have tried HW accelerated method with:
CVPixelBufferRef pixelBuffer = frame->cv_pixelbuffer_fastupload;
CIImage *ciImage = [CIImage imageWithCVPixelBuffer:pixelBuffer];
but CIImage
is always NULL
.
I have tried SW way:
CVPixelBufferRef pixelBuffer = NULL;
CVReturn resulst = CVPixelBufferCreate(kCFAllocatorDefault,
frame-> width,
frame -> height,
kCVPixelFormatType_420YpCbCr8Planar,
NULL,
&pixelBuffer);
if (kCVReturnSuccess != CVPixelBufferLockBaseAddress(pixelBuffer, 0) || pixelBuffer == NULL) {
return;
}
long yPlaneWidth = CVPixelBufferGetWidthOfPlane(pixelBuffer, 0);
long yPlaneHeight = CVPixelBufferGetHeightOfPlane(pixelBuffer,0);
long uPlaneWidth = CVPixelBufferGetWidthOfPlane(pixelBuffer, 1);
long uPlaneHeight = CVPixelBufferGetHeightOfPlane(pixelBuffer, 1);
long vPlaneWidth = CVPixelBufferGetWidthOfPlane(pixelBuffer, 2);
long vPlaneHeight = CVPixelBufferGetHeightOfPlane(pixelBuffer, 2);
uint8_t* yDestination = CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 0);
memcpy(yDestination, frame->luma, yPlaneWidth * yPlaneHeight);
uint8_t* uDestination = CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 1);
memcpy(uDestination, frame->chromaB, uPlaneWidth * uPlaneHeight);
uint8_t* vDestination = CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 2);
memcpy(vDestination, frame->chromaR, vPlaneWidth * vPlaneHeight);
CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
[self log:[NSString stringWithFormat:@"Frame width: %@", @(frame-> width).stringValue]];
if(pixelBuffer == NULL) {
[self log:@"PixelBuffer is NULL"];
return;
}
if(CVPixelBufferGetPlaneCount(pixelBuffer) == 3) {
[self log:@"y-cr-cb"];
}
if(CVPixelBufferGetPlaneCount(pixelBuffer) == 2) {
[self log:@"y-cr-cb-bi"];
}
CIImage *ciImage = [CIImage imageWithCVPixelBuffer:pixelBuffer];
if(ciImage != NULL) {
[self log:@"CIImage exist"];
} else {
[self log:@"CIImage doesnt exist"];
}
Output is:
Frame width: 1280
y-cr-cb
CIImage doesnt exist
Frame width: 1280
y-cr-cb
CIImage doesnt exist
....
What am I doing wrong? Thanks.
来源:https://stackoverflow.com/questions/63227358/dji-videoframeyuv-to-ciimage-conversion