设置60fps与闪光灯开启时AVCapturePhotoOutput拍照过曝求助
问题:AVCapturePhotoOutput开启闪光灯+60fps最低帧率导致照片过曝
使用AVCapturePhotoOutput且将flashMode设为.on,同时将AVCaptureDevice的最低帧率设置为60fps时,拍摄的照片会出现严重过曝;相同配置下调至30fps时照片显示正常。尝试过多种AVCapturePhotoSettings配置均未解决问题,怀疑是iOS Bug,寻求解决建议。
复现代码
let settings = AVCapturePhotoSettings() settings.flashMode = flashOn ? .on : .off settings.isAutoVirtualDeviceFusionEnabled = true settings.isAutoRedEyeReductionEnabled = true self.photoOutput.capturePhoto(with: settings, delegate: self)
效果对比
- 60fps下的过曝照片:

- 30fps下的正常照片:

可行解决方向
1. 拍摄前临时切换帧率
在触发拍照操作前,将设备帧率临时切换到30fps区间,拍摄完成后再恢复原60fps设置,绕过高帧率与闪光灯的冲突:
// 拍摄前保存当前帧率配置 var originalMinFrameRate: Double? = nil var originalMaxFrameRate: Double? = nil guard let activeDevice = yourCaptureSession.inputs.compactMap({ $0 as? AVCaptureDeviceInput }).first?.device else { return } do { try activeDevice.lockForConfiguration() originalMinFrameRate = activeDevice.activeVideoMinFrameRate originalMaxFrameRate = activeDevice.activeVideoMaxFrameRate // 切换到30fps固定帧率 activeDevice.activeVideoMinFrameRate = 30 activeDevice.activeVideoMaxFrameRate = 30 activeDevice.unlockForConfiguration() } catch { print("帧率切换失败:\(error.localizedDescription)") } // 执行拍照 self.photoOutput.capturePhoto(with: settings, delegate: self) // 在拍照完成代理中恢复原帧率 func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) { guard let activeDevice = yourCaptureSession.inputs.compactMap({ $0 as? AVCaptureDeviceInput }).first?.device, let minRate = originalMinFrameRate, let maxRate = originalMaxFrameRate else { return } do { try activeDevice.lockForConfiguration() activeDevice.activeVideoMinFrameRate = minRate activeDevice.activeVideoMaxFrameRate = maxRate activeDevice.unlockForConfiguration() } catch { print("帧率恢复失败:\(error.localizedDescription)") } }
2. 禁用虚拟设备融合算法
尝试关闭isAutoVirtualDeviceFusionEnabled,部分iOS设备在高帧率+闪光灯场景下,多摄像头融合算法可能出现测光异常:
settings.isAutoVirtualDeviceFusionEnabled = false
3. 指定照片编码格式
明确设置AVCapturePhotoSettings的编码格式,避免系统自动选择的格式与高帧率模式不兼容:
settings.preferredPhotoCodec = .jpeg // 或.hevc,根据设备支持情况选择
4. 提交Apple Bug反馈
如果以上方法均无效,说明这大概率是iOS系统层面的Bug,建议通过Apple开发者反馈平台提交报告,附上设备型号、iOS版本、完整复现步骤及对比照片,帮助Apple定位修复问题。
内容的提问来源于stack exchange,提问作者Jacob Zyla
相关产品推荐
相关产品推荐

