Hey guys, I just start to use the API AVPortraitEffectsMatte. I often work around the AVDepthData. But I'm confused with the return value of portrait matte.
I want to capture the photo also get the portrait effect matte in the same time. When I use the fileDataRepresentationWithCustomizer, the matte works fine. I can get matte from photos just toke, and the callback photo.portraitEffectsMatte ISN'T nil. But when I want to capture the photo with pixelformat, and also set the setPortraitEffectsMatteDeliveryEnabled correctly, the photo.portraitEffectsMatte in callback is always nil. Why?
I tested it on my iPhone X with iOS 12. Here is the code I use.
First I enable the depth and portrait matte in AVCapturePhotoOutput.
if (photoOutput.isDepthDataDeliverySupported)
{
[photoOutput setDepthDataDeliveryEnabled:YES];
}
if (@available(iOS 12.0, *))
{
if (photoOutput.isPortraitEffectsMatteDeliverySupported)
{
[photoOutput setPortraitEffectsMatteDeliveryEnabled:YES];
}
}
And I wrote this when I press the capture button.
AVCapturePhotoSettings * photoSettings = [AVCapturePhotoSettings photoSettingsWithFormat:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA], kCVPixelBufferPixelFormatTypeKey, nil]];
if (photoOutput.isDepthDataDeliverySupported)
{
[photoSettings setDepthDataDeliveryEnabled:YES];
photoSettings.embedsDepthDataInPhoto = NO;
}
if (@available(iOS 12.0, *))
{
if (photoOutput.isPortraitEffectsMatteDeliverySupported)
{
[photoSettings setPortraitEffectsMatteDeliveryEnabled:YES];
photoSettings.embedsPortraitEffectsMatteInPhoto = NO;
}
}
[photoOutput capturePhotoWithSettings:photoSettings delegate:self];
Finally get this callback.
- (void)captureOutput:(AVCapturePhotoOutput *)output didFinishProcessingPhoto:(AVCapturePhoto *)photo error:(nullable NSError *)error
{
if (@available(iOS 12.0, *))
{
NSLog(@"%@", photo.portraitEffectsMatte ? @"Matte": @"nil");
}
}
But it's still nil.
How can I get the correct portrait matte with the pixelformat output?
Thank you.