我正在尝试在使用 AVFoundation 的 AVCaptureVideoDataOutput 录制的视频上添加水印/徽标。我遇到的问题是 UIImage 的透明部分在写入视频后是黑色的。我做错了什么?
CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(buffer);
……
……
CIImage *image = [[CIImage alloc] initWithData:logoData];
CVPixelBufferLockBaseAddress( pixelBuffer, 0 );
CIContext *ciContext = [CIContext contextWithOptions:nil];
CGColorSpaceRef cSpace = CGColorSpaceCreateDeviceRGB();
[ciContext render:image toCVPixelBuffer:pixelBuffer bounds:CGRectMake(image.extent.origin.x, image.extent.origin.y - 2, image.extent.size.width, image.extent.size.height) colorSpace:cSpace];
CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
CGColorSpaceRelease(cSpace);