2017-11-30 2 views
0

AVFoundation의 AVCaptureVideoDataOutput을 사용하여 녹화중인 비디오에 워터 마크/로고를 추가하려고합니다. 문제가 있습니다. UIImage의 투명한 부분이 검은 색으로 일단 비디오에 쓰여졌습니다. 내가 뭘 잘못하고있는 걸까요?CIContext 렌더링 : toCVPixelBuffer : 경계 : colorSpace : 알파 채널이있는 이미지에 함수가 작동하지 않습니다.

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); 

답변

0

할 수 있습니다 복합 투명성을 보존하고 픽셀 버퍼에 저를 렌더링 이미지. 예 :

CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); 
    CIImage *cameraImage = [[CIImage alloc] initWithCVPixelBuffer:pixelBuffer]; 
    CGColorSpaceRef cSpace = CGColorSpaceCreateDeviceRGB(); 
    cameraImage = [self.logoImage imageByCompositingOverImage:cameraImage]; 
    [self.context render:cameraImage toCVPixelBuffer:pixelBuffer bounds:cameraImage.extent colorSpace:cSpace]; 

    CVPixelBufferUnlockBaseAddress(pixelBuffer, 0); 
    CGColorSpaceRelease(cSpace); 
+0

안녕하세요 beyowulf 답장을 보내 주셔서 감사합니다. 하지만 지금은 다른 문제가 있는데, "AVCaptureVideoDataOutputSampleBufferDelegate - (void) captureOutput : (AVCaptureOutput *) captureOutput didOutputSampleBuffer : (CMSampleBufferRef) sampleBuffer fromConnection :(AVCaptureConnection *) 연결"함수와 그 이후의 캡처에서 모든 CVPixelBufferRef에 투명 로고를 렌더링하고 있습니다. "나는 오디오 문제가있다. 그것은 비디오와 일치하지 않습니다. –

관련 문제