You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iPhone 16 Pro中videoZoomFactor在不同相机下缩放效果差异问题

iPhone 16 Pro 相机videoZoomFactor缩放幅度差异问题

在iPhone 16 Pro上测试发现,使用builtInTripleCamera(三摄组合设备)和builtInUltraWideCamera(单超广角镜头)时,设置相同的videoZoomFactor值,缩放幅度存在差异:

  • 当缩放因子设为1时,两者画面完全一致,且打印videoDevice.activeFormat.videoFieldOfView显示视场角相同;
  • 当缩放因子大于1时,builtInUltraWideCamera的实际缩放幅度明显更大。

缩放差异示意图

相机初始化配置代码

var singleLensCamera: AVCaptureDevice.DeviceType = .builtInWideAngleCamera
var currentDeviceCamera: AVCaptureDevice.DeviceType = .builtInWideAngleCamera
var combinedLensCamera: AVCaptureDevice.DeviceType?

let deviceDiscoverySession = AVCaptureDevice.DiscoverySession(
        deviceTypes: [ .builtInWideAngleCamera, .builtInUltraWideCamera, .builtInTelephotoCamera, .builtInTripleCamera, .builtInDualCamera, .builtInDualWideCamera ],
        mediaType: .video,
        position: .back 
    )
let avCaptureDevices = deviceDiscoverySession.devices.map { $0.deviceType }

if avCaptureDevices.contains(.builtInTripleCamera) {
    combinedLensCamera = .builtInTripleCamera
} else if avCaptureDevices.contains(.builtInDualWideCamera) {
    combinedLensCamera = .builtInDualWideCamera
} else if avCaptureDevices.contains(.builtInDualCamera) {
    combinedLensCamera = .builtInDualCamera
}

combinedLensCamera = nil // 注释此行切换为组合相机,取消注释使用单镜头相机

if avCaptureDevices.contains(.builtInUltraWideCamera) {
    singleLensCamera = .builtInUltraWideCamera
} else {
    singleLensCamera = .builtInWideAngleCamera
}

var deviceType: AVCaptureDevice.DeviceType {
    if combinedLensCamera != nil { return combinedLensCamera! }
    else { return singleLensCamera }
}

currentDeviceCamera = deviceType

let defaultVideoDevice = AVCaptureDevice.default(deviceType, for: .video, position: .back)

guard let videoDevice = defaultVideoDevice else {
    print("^^Could not find any video device")
    setupResult = .configurationFailed
    return
}

do {
    videoInput = try AVCaptureDeviceInput(device: videoDevice)
} catch {
    print("^^Could not create video device input: \(error)")
    setupResult = .configurationFailed
    return
}

session.beginConfiguration()

session.sessionPreset = .photo

phoneCameraAOV = videoDevice.activeFormat.videoFieldOfView
print("^^phoneCameraAOV \(phoneCameraAOV)")

// 添加视频输入
guard session.canAddInput(videoInput) else {
    print("^^Could not add video device input to the session")
    setupResult = .configurationFailed
    session.commitConfiguration()
    return
}
session.addInput(videoInput)

// 添加视频数据输出
if session.canAddOutput(videoDataOutput) {
    session.addOutput(videoDataOutput)
    videoDataOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey as String: Int(kCVPixelFormatType_32BGRA)]
    videoDataOutput.setSampleBufferDelegate(self, queue: dataOutputQueue)
} else {
    print("^^Could not add video data output to the session")
    setupResult = .configurationFailed
    session.commitConfiguration()
    return
}

// 添加照片输出
if session.canAddOutput(photoOutput) {
    session.addOutput(photoOutput)
    photoOutput.isHighResolutionCaptureEnabled = true
} else {
    print("^^Could not add photo output to the session")
    setupResult = .configurationFailed
    session.commitConfiguration()
    return
}

session.commitConfiguration()

缩放控制代码

let focalScaleFactor = 2.0

if let combinedLensCamera {
    if let device = AVCaptureDevice.default(combinedLensCamera, for: .video, position: .back) {
        try? device.lockForConfiguration()
        device.videoZoomFactor = focalScaleFactor
        device.unlockForConfiguration()
    }
} else {
    if let device = AVCaptureDevice.default(singleLensCamera, for: .video, position: .back) {
        try? device.lockForConfiguration()
        device.videoZoomFactor = focalScaleFactor
        device.unlockForConfiguration()
    }
}

测试说明:启动应用可查看当前单镜头超广角相机的缩放效果;取消注释CameraViewMetal.swift第214行后重启,可切换为三摄组合设备进行对比测试。


内容的提问来源于stack exchange,提问作者zakray

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 06:57:35