1

It's possible to get frame from TelephotoCamera, WideAngleCamera or automatically using DualCamera:

//auto
let device = AVCaptureDevice.default(.builtInDualCamera, for: .video, position: .back)
//telephoto
let device = AVCaptureDevice.default(.builtInTelephotoCamera, for: .video, position: .back)
//wideAngle
let device = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back)

But how to get frames from TelephotoCamera and WideAngleCamera in the same time (using devices with dual cameras).


Edit1
Tried to add 2 inputs to capture session:

captureSession?.addInput(input)
captureSession?.addInput(input2)

NSInvalidArgumentException: Multiple audio/video AVCaptureInputs are not currently supported

Edit2
Tried to enable isDualCameraDualPhotoDeliveryEnabled flag for capture photo output:

capturePhotoOutput?.isDualCameraDualPhotoDeliveryEnabled = true

NSInvalidArgumentException: Dual Camera dual photo delivery is not supported in this configuration

But
isDualCameraDualPhotoDeliverySupported gives false on iPhone 8 Plus
could it be the reason of my problem?


Still no luck.

Volodymyr Kulyk
  • 6,455
  • 3
  • 36
  • 63

1 Answers1

2

Yes, it's possible.
Just pick the right configuration.


Capture device should be builtInDualCamera:

let captureDevice = AVCaptureDevice.default(.builtInDualCamera, for: .video, position: .back)

Configure capture photo output after configuring capture session:

captureSession = AVCaptureSession()
captureSession?.sessionPreset = AVCaptureSession.Preset.photo
captureSession?.addInput(input)
captureSession?.addOutput(capturePhotoOutput!)

capturePhotoOutput?.isHighResolutionCaptureEnabled = true

capturePhotoOutput?.isDualCameraDualPhotoDeliveryEnabled = true


Configure photo settings before capture the photo:

let photoSettings = AVCapturePhotoSettings()
photoSettings.isAutoStillImageStabilizationEnabled = true
photoSettings.isHighResolutionPhotoEnabled = true
photoSettings.isAutoDualCameraFusionEnabled = false

photoSettings.isDualCameraDualPhotoDeliveryEnabled = true


Implement AVCapturePhotoCaptureDelegate, and override next method:

public func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?)

You will receive 2 photoOutput callbacks!

Volodymyr Kulyk
  • 6,455
  • 3
  • 36
  • 63
  • I have an iPhone 7 plus but capturePhotoOutput.isDualCameraDualPhotoDeliverySupported is returning false, and if i ignore this and just set to true, it will crash with Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[AVCapturePhotoOutput setDualCameraDualPhotoDeliveryEnabled:] Dual Camera dual photo delivery is not supported in this configuration'. Any idea is what else need to be configured? i believe 7plus can take dual photos – kawingkelvin Dec 14 '18 at 03:58
  • @kawingkelvin have you checked [this option](https://developer.apple.com/documentation/avfoundation/avcapturephotooutput/2890245-isdualcameradualphotodeliverysup)? – Volodymyr Kulyk Dec 14 '18 at 09:16