У меня проблема с преобразованием VideoFrameYUV
в CIImage
. Я пробовал ускоренный метод HW с:
CVPixelBufferRef pixelBuffer = frame->cv_pixelbuffer_fastupload;
CIImage *ciImage = [CIImage imageWithCVPixelBuffer:pixelBuffer];
, но CIImage
всегда NULL
.
Я пробовал способ SW:
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"];
}
Выход :
Frame width: 1280
y-cr-cb
CIImage doesnt exist
Frame width: 1280
y-cr-cb
CIImage doesnt exist
....
Что я делаю не так? Спасибо.