同时从两个相机(TelePhoto 和 WideAngle)捕获帧

Capture frames from both cameras (TelePhoto and WideAngle) in the same time

可以从 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)

但是如何从 TelephotoCamera and WideAngleCamera in the same time (using devices with dual cameras.

获取帧

编辑1
尝试将 2 个输入添加到 capture session:

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

NSInvalidArgumentException: Multiple audio/video AVCaptureInputs are not currently supported

Edit2
已尝试启用 isDualCameraDualPhotoDeliveryEnabled flag for capture photo output:

capturePhotoOutput?.isDualCameraDualPhotoDeliveryEnabled = true

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

但是
isDualCameraDualPhotoDeliverySupportediPhone 8 Plus
上给出 false 这可能是我的问题的原因吗?


仍然没有运气。

是的,有可能。
只需选择正确的配置。


捕获设备应该是builtInDualCamera:

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

配置捕获会话后配置捕获照片输出:

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

capturePhotoOutput?.isHighResolutionCaptureEnabled = true

capturePhotoOutput?.isDualCameraDualPhotoDeliveryEnabled = true


拍摄照片前配置照片设置:

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

photoSettings.isDualCameraDualPhotoDeliveryEnabled = true


实施 AVCapturePhotoCaptureDelegate,并覆盖下一个方法:

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

您将收到 2 photoOutput 个回调!