I am trying to simultaneously capture from both the telephoto and wide angle cameras on a iPhoneX. This is how I initialized the device:
let captureDevice = AVCaptureDevice.default(.builtInDualCamera, for: .video, position: .back)
and I requested dual photo delivery for AVPhotoOutput:
let photoSettings = AVCapturePhotoSettings()
photoSettings.isDualCameraDualPhotoDeliveryEnabled = true
capturePhotoOutput.capturePhoto(with: photoSettings, delegate: self)
However, I am running into this error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[AVCapturePhotoOutput setDualCameraDualPhotoDeliveryEnabled:] Dual Camera dual photo delivery is not supported in this configuration'
Are there additional settings I need to enable or disable?
You have to make sure that your capture device, capture session and capture output are properly configured:
Get capture device, using the following settings (which are already correct in your code): AVCaptureDeviceTypeBuiltInDualCamera, AVMediaTypeVideo, AVCaptureDevicePositionBack
Create AVCaptureDeviceInput using the device you just retrieved in 1.
Corresponding code (Objective-C):
// Create capture device discovery session to retrieve devices matching our
// needs
// -------------------------------------------------------------------------------
AVCaptureDeviceDiscoverySession* captureDeviceDiscoverySession = [AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:@[AVCaptureDeviceTypeBuiltInDualCamera]
mediaType:AVMediaTypeVideo
position:AVCaptureDevicePositionBack];
// Loop through the retrieved devices and select correct one
// -------------------------------------------------------------------------------
for(AVCaptureDevice* device in [captureDeviceDiscoverySession devices])
{
if(device.position == AVCaptureDevicePositionBack)
{
self.captureDevice = device;
break;
}
}
// Get camera input
// -------------------------------------------------------------------------------
NSError* error = nil;
AVCaptureDeviceInput* videoDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:self.captureDevice error:&error];
if(!videoDeviceInput)
{
NSLog(@"Could not retrieve camera input, error: %@", error);
return;
}
// Initialize capture session
// -------------------------------------------------------------------------------
self.captureSession = [[AVCaptureSession alloc] init];
self.captureSession.sessionPreset = AVCaptureSessionPresetPhoto;
// Add video device input and photo data output to our capture session
// -------------------------------------------------------------------------------
self.captureOutput = [AVCapturePhotoOutput new];
[self.captureSession beginConfiguration];
if(![self.captureSession canAddOutput:self.captureOutput])
{
NSLog(@"Cannot add photo output!");
return;
}
[self.captureSession addInput:videoDeviceInput];
[self.captureSession addOutput:self.captureOutput];
[self.captureSession commitConfiguration];
// Configure output settings AFTER input & output have been added to the session
// -------------------------------------------------------------------------------
if(self.captureOutput.isDualCameraDualPhotoDeliverySupported)
self.captureOutput.dualCameraDualPhotoDeliveryEnabled = YES;
// Create video preview layer for this session, and add it to our preview UIView
// -------------------------------------------------------------------------------
AVCaptureVideoPreviewLayer* videoPreviewLayer = [AVCaptureVideoPreviewLayer layerWithSession:self.captureSession];
videoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspect;
videoPreviewLayer.frame = self.view.bounds;
[self.view.layer addSublayer:videoPreviewLayer];
// Start capturing session
// -------------------------------------------------------------------------------
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
[self.captureSession startRunning];
});
Code (Objective-C):
AVCapturePhotoSettings* settings = [AVCapturePhotoSettings photoSettingsWithFormat:@{AVVideoCodecKey: AVVideoCodecTypeJPEG}];
settings.dualCameraDualPhotoDeliveryEnabled = YES;
[self.captureOutput capturePhotoWithSettings:settings delegate:self];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With