同时从两个摄像头(TelePhoto和WideAngle)捕获帧

时间:2018-02-13 14:29:27

标签: ios swift avcapturedevice

可以使用TelephotoCameraWideAngleCameraautomaticallyDualCamera获取相框:

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

但如何同时从TelephotoCameraWideAngleCamera获取帧数(使用dual camera s的设备)。

EDIT1
试图向capture session添加2个输入:

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

NSInvalidArgumentException: Multiple audio/video AVCaptureInputs are not currently supported

EDIT2
尝试为isDualCameraDualPhotoDeliveryEnabled启用capture photo output标记:

capturePhotoOutput?.isDualCameraDualPhotoDeliveryEnabled = true

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


isDualCameraDualPhotoDeliverySupportedfalse上提供iPhone 8 Plus 这可能是我问题的原因吗?

仍然没有运气。

1 个答案:

答案 0 :(得分:2)

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

捕获设备应为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回调!