【发布时间】:2014-09-09 17:13:19
【问题描述】:
我正在尝试在使用 AVFoundation 的 AVCaptureVideoDataOutput 录制的视频上添加水印/徽标。 我的类设置为 sampleBufferDelegate 并接收 CMSamplebufferRefs。我已经对 CMSampleBufferRefs CVPixelBuffer 应用了一些效果,并将其传递回 AVAssetWriter。
左上角的徽标是使用透明 PNG 交付的。 我遇到的问题是 UIImage 的透明部分在写入视频后是黑色的。 任何人都知道我做错了什么或可能忘记了什么?
下面的代码sn-ps:
//somewhere in the init of the class;
_eaglContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
_ciContext = [CIContext contextWithEAGLContext:_eaglContext
options: @{ kCIContextWorkingColorSpace : [NSNull null] }];
//samplebufferdelegate method:
- (void) captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection {
CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CVPixelBufferLockBaseAddress(pixelBuffer, 0);
....
UIImage *logoImage = [UIImage imageNamed:@"logo.png"];
CIImage *renderImage = [[CIImage alloc] initWithCGImage:logoImage.CGImage];
CGColorSpaceRef cSpace = CGColorSpaceCreateDeviceRGB();
[_ciContext render:renderImage
toCVPixelBuffer:pixelBuffer
bounds: [renderImage extent]
colorSpace:cSpace];
CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
CGColorSpaceRelease(cSpace);
....
}
看起来 CIContext 没有绘制 CIImages alpha。 有什么想法吗?
【问题讨论】:
标签: ios avfoundation core-image cmsamplebufferref