0

我正在尝试修改所拍照片的曝光时间。

在循环内:

for (customDuration, customISO) in zip(exposureDurations, exposureISOs) { // exposureDurations and exposureISOs are just arrays of exposures
    // code here
}

我将 AVCapture 设备的曝光设置为我的自定义值:

captureDevice = AVCaptureDevice.default(AVCaptureDevice.DeviceType.builtInWideAngleCamera,
                                                       for: AVMediaType.video,
                                                       position: .back) {
captureSession = AVCaptureSession()
capturePhotoOutput = AVCapturePhotoOutput()

do { try captureDevice.lockForConfiguration() }
catch { print("capturebracket: cannot lock camera for configuration."); return }

// set the correct exposure
captureDevice.setExposureModeCustom(duration: customDuration, iso: customISO, completionHandler: { (_) -> Void in exposureModeSet = true })

// unlock the capture device (sets changes)
captureDevice.unlockForConfiguration()

// wait for changes to propagate
while !exposureModeSet {}

// get the correct photo settings
let settings = AVCapturePhotoSettings(format: [AVVideoCodecKey : AVVideoCodecType.jpeg, AVVideoCompressionPropertiesKey : [AVVideoQualityKey : jpegQuality]])

然后我打印该值以确保它已正确设置:

print("duration: \(captureDevice.exposureDuration)") // prints customExposure

print("device duration: \(( captureSession.inputs[0] as? AVCaptureDeviceInput)!.device.exposureDuration)") // prints customExposure

print("device duration: \((capturePhotoOutput.connections[0].inputPorts[0].input as? AVCaptureDeviceInput)!.device.exposureDuration)") // prints customExposure

photoSettings.isAutoStillImageStabilizationEnabled = false

然后我拍照:

capturePhotoOutput.capturePhoto(with: photoSettings, delegate: self)

不知何故,当我以不同的曝光循环浏览上述代码时,照片最终会得到错误的曝光。具体来说,第一次运行正常。第二个有时会在第一次曝光时拍照,有时会在第二次曝光时拍照。第三个有时会在第二次曝光时拍照,有时会在第三次曝光时拍照,依此类推。

有趣的是,当我在拍照前插入一个长的,比如说 1-3 秒的暂停时,所有的曝光都设置正确......所以看起来 AVCaptureDevice 的更改需要时间来传播,并且 photoOutput在正确设置曝光之前冲过去拍摄照片。

有没有人有任何想法?似乎在文档中找不到任何关于它的内容。

4

0 回答 0