View in English

  • Apple 开发者
    • 入门汇总

    探索“入门汇总”

    • 概览
    • 学习
    • Apple Developer Program

    及时了解最新动态

    • 最新动态
    • 开发者你好
    • 平台

    探索“平台”

    • Apple 平台
    • iOS
    • iPadOS
    • macOS
    • Apple tvOS
    • visionOS
    • watchOS
    • App Store

    精选

    • 设计
    • 分发
    • 游戏
    • 配件
    • 网页
    • Home
    • CarPlay 车载
    • 技术

    探索“技术”

    • 概览
    • Xcode
    • Swift
    • SwiftUI

    精选

    • 辅助功能
    • App Intents
    • Apple 智能
    • 游戏
    • 机器学习与 AI
    • 安全性
    • Xcode Cloud
    • 社区

    探索“社区”

    • 概览
    • “与 Apple 会面交流”活动
    • 社区主导的活动
    • 开发者论坛
    • 开源

    精选

    • WWDC
    • Swift Student Challenge
    • 开发者故事
    • App Store 大奖
    • Apple 设计大奖
    • Apple Developer Centers
    • 文档

    探索“文档”

    • 文档库
    • 技术概述
    • 示例代码
    • 《人机界面指南》
    • 视频

    发布说明

    • 精选更新
    • iOS
    • iPadOS
    • macOS
    • watchOS
    • visionOS
    • Apple tvOS
    • Xcode
    • 下载

    探索“下载”

    • 所有下载
    • 操作系统
    • 应用程序
    • 设计资源

    精选

    • Xcode
    • TestFlight
    • 字体
    • SF Symbols
    • Icon Composer
    • 支持

    探索“支持”

    • 概览
    • 帮助指南
    • 开发者论坛
    • “反馈助理”
    • 联系我们

    精选

    • 《开发者账户帮助》
    • 《App 审核指南》
    • 《App Store Connect 帮助》
    • 即将实行的要求
    • 协议和准则
    • 系统状态
  • 快速链接

    • 活动
    • 新闻
    • 论坛
    • 示例代码
    • 视频
 

视频

打开菜单 关闭菜单
  • 专题
  • 所有视频
  • 关于

更多视频

  • 简介
  • 概要
  • 转写文稿
  • 代码
  • 让你的 iOS App 支持 Center Stage 前置摄像头

    借助 AVCapture API,利用 iPhone 17、iPhone 17 Pro 和 iPhone Air 配备的 Center Stage 前置摄像头,为你的 iOS 相机 App 注入强劲动力。探索这些 API 如何实现缩放和旋转选项,从而更灵活地调整自拍和视频构图,并让拍合照的每个人都能自动入境。通过整合视频通话人物居中功能来自动调整画面构图,让用户在虚拟会议和 FaceTime 通话中稳居前排 C 位。你还将了解如何为实时视频会议实现视频防抖功能。

    章节

    • 0:00 - Introduction
    • 1:07 - Center Stage front camera
    • 2:09 - Center Stage for photos
    • 3:09 - Capture session setup
    • 3:56 - Dynamic aspect ratio
    • 6:47 - Smart framing monitor
    • 9:24 - Sensor orientation compensation
    • 11:53 - Center Stage for video recordings
    • 13:16 - Center Stage for video calls

    资源

    • Supporting Center Stage front camera in your iOS app
    • AVCam: Building a camera app
    • AVFoundation
    • Capture setup
      • 高清视频
      • 标清视频

    相关视频

    WWDC26

    • 实现高分辨率照片拍摄

    WWDC23

    • 在 iPadOS App 中支持外部摄像头

    WWDC21

    • 相机拍摄的新功能
  • 搜索此视频…

    大家好,我是 Tracy!

    我是摄像头软件团队 的一名工程师。

    我很高兴向您介绍如何在 您的 iOS 应用中 支持 Center Stage 前置摄像头。 我喜欢自拍! 无论是独自旅行 还是和一群朋友出行。 找到合适的构图 并不总是那么容易。 如果您和我一样, 可能会用过自拍杆, 或者把手机递给 手臂最长的朋友来拍照。 iPhone 17、iPhone Air 和 iPhone 17 Pro 上的 Center Stage 前置摄像头 解决了这个问题。 它让您在构图时 拥有更大的灵活性。 首先,我将概述 Center Stage 前置摄像头。 然后,我将介绍 支持照片拍摄的 Center Stage API。 最后,我将介绍如何支持 视频录制 和视频通话中的 Center Stage。

    传统上,智能手机前置摄像头 传感器具有 4x3 的宽高比, 这会根据手机方向 限制您的取景范围。 而 Center Stage 前置摄像头 采用了正方形图像传感器。 这种正方形设计 让您可以选择任意宽高比。 您可以拍摄竖屏自拍, 也可以拍摄横屏自拍, 而无需旋转 iPhone。 这样可以更稳固地 单手握持手机。 而且由于摄像头居中放置, 您的眼神接触感觉更加自然。

    这款正方形传感器还配备了 视角达 95 度的镜头, 是所有 iPhone 前置摄像头中最广的。 如此宽广的视角帮助您 更好地拍摄群组自拍、 稳定视频,并在视频通话中 保持居中状态。 了解了 Center Stage 前置摄像头 的功能之后, 我将向您展示如何在应用中 实现完美的照片取景体验。 这里的核心功能是 自动缩放和自动旋转。 通过结合正方形传感器、 宽广的视角, 以及自动面部和视线检测, Center Stage 前置摄像头 智能地调整其方向, 并在窄视图和宽视图之间自动切换。 让我来演示一下它的工作原理。 这里,我正在户外拍摄自拍。 当我的朋友 Karen 加入时, 画面自动缩小。 当更多朋友入镜时, 画面旋转以容纳所有人。 为了在您的应用中实现这一体验, 我将首先回顾 拍摄会话的设置, 然后深入介绍两个 API: 动态宽高比 和智能取景监控器。 最后,我将介绍 传感器方向补偿。 从典型的照片拍摄设置开始。 首先,创建一个 AVCaptureSession。 找到 Center Stage 前置摄像头, 在 API 中表示为 AVCaptureDevice, 设备类型为 .builtInUltraWideCamera。 为该摄像头创建一个 AVCaptureDeviceInput。 为了获得摄像头预览, 添加一个 AVCaptureVideoPreviewLayer 到拍摄会话中。 同时,添加一个 AVCapturePhotoOutput 以接收照片。 在添加输入和输出时, 拍摄会话会隐式地在 具有兼容媒体类型的设备之间 建立 AVCaptureConnections。 设置完成后, 我将介绍动态宽高比, 这是手动和自动取景的 基础构建模块。 从 iOS 26 开始,AVCaptureDevice 包含了 dynamicAspectRatio 属性。 当您设置此属性时, 拍摄设备会从 您选择的宽高比中裁剪 正方形图像传感器, 如前所示, 而无需重新构建拍摄会话 或中断预览。 切换过程流畅且迅速。 这里有一张表格, 列出了支持 动态宽高比的示例格式。 它需要前置 .builtInUltraWideCamera, 如前所述。 它仅支持正方形格式, 分辨率从 1280 到 4032 不等。

    共有五种宽高比可供选择: 3x4、4x3、 9x16、16x9 和 1x1。 请注意,4032 照片格式 仅支持 3x4 和 4x3, 因为这两种宽高比 为照片提供了最高分辨率。 了解了这些格式要求之后, 让我展示如何实现 一个"点击旋转"按钮, 使用动态宽高比 在不同方向之间切换。 首先,选择 Center Stage 前置摄像头, 通过创建 AVCaptureDevice.DiscoverySession。 将 .builtInUltraWideCamera 指定为唯一感兴趣的设备类型, 并将位置设为 .front。 由于您只请求了 一个设备, 可以直接获取 发现会话设备数组中的第一个元素。 找到支持 您所需宽高比的格式。 这里,我以 4x3 为例。 检查每种格式的 supportedDynamicAspectRatios 属性。 这将返回该格式 支持的宽高比数组。 为简单起见, 我选取第一个匹配项。 锁定设备进行配置后, 将您选择的格式 设置为 activeFormat。 接下来,将动态宽高比 设置为 4x3。

    此调用返回 变更生效时 第一帧缓冲区的时间戳。

    有了这段代码, 您的应用现在支持"点击旋转", 只需轻触一下 即可改变方向。 接下来是智能取景监控器 API。 它与动态宽高比协同工作, 随着人物进出画面 自动调整取景。 从 iOS 26 开始, AVCaptureDevice 包含了 AVCaptureSmartFramingMonitor 对象。 该监控器会定期提供 取景建议, 基于自动面部和视线检测。 每个建议包含 一个宽高比和一个缩放系数, 您的应用可以采纳或忽略。 由于该监控器 专为照片拍摄设计, 它仅在使用 4032 照片格式时 提供建议。 现在我将演示 如何在代码中设置监控器。 已从动态宽高比设置中 选取超广角前置摄像头,

    您可以继续 找到一种支持 您所需宽高比 和智能取景功能的格式。 找到格式后, 锁定设备进行配置, 并设置 activeFormat。

    接下来,从摄像头获取 smartFramingMonitor。 默认情况下,监控器 不提供任何建议。 这里,我将 enabledFramings 设置为所有 supportedFramings。 但您也可以将其 限制为支持的取景方式的子集, 例如仅使用 4x3 宽高比 配合窄幅和宽幅缩放系数。 配置好监控器之后, 使用键值观察 监控器的 recommendedFraming 属性。 当监控器推荐新的取景方式时, 通过设置摄像头的 动态宽高比来应用建议, 以及视频缩放系数。 为实现平滑的预览过渡, 请先设置 aspectRatio, 再设置 zoomFactor。 现在,您可以随时启动监控器, 包括在 AVCaptureSession 运行期间。 如果您的界面允许用户 关闭自动取景, 请取消注册键值观察 并调用 stopMonitoring。 您的应用现在已支持 自动缩放和自动旋转, 为群组自拍提供 最佳取景建议。 照片拍摄的最后一个主题是 传感器方向补偿。 自最早的 iPhone 前置摄像头以来, 传感器一直以 横向左置方向安装。 如果您在手机竖向握持时 拍摄自拍, 图像缓冲区会 传输到照片输出, 以传感器的原始方向呈现。 缓冲区携带 EXIF 方向元数据标签, 指示应在播放时 旋转 270 度。 然而,在 iPhone 17、iPhone Air 和 iPhone 17 Pro 上, Center Stage 前置摄像头传感器 以竖向方式安装。 如果您的应用依赖 之前有效的旋转值, 照片可能会出现侧转或倒置的情况。

    为了解决这个问题,AVCapturePhotoOutput 默认情况下会自动应用 传感器方向补偿。 它会对照片进行物理旋转, 并在传输到您的应用之前 更新 EXIF 元数据。 生成的照片处于 横向左置方向, 与之前 iPhone 前置摄像头一致。 您可以继续使用 之前使用的相同旋转值。 请注意,此补偿 仅适用于 HEIC、JPEG, 以及未压缩的处理照片。 它永远不会应用于 Bayer RAW 或 Apple ProRAW 拍摄。 从 iOS 26 开始, 您可以通过 cameraSensorOrientation- CompensationEnabled 属性控制此行为。 如果您使用 AVCapturePhotoOutput, 请在禁用补偿的情况下测试 以获得最佳性能, 并确保照片方向 保持正确。 要了解更多有关使用 AVCaptureRotationCoordinator 处理图像旋转的信息, 请查阅 WWDC 2023 的 "Support external cameras in your iPadOS app"。 现在,来介绍视频中的 Center Stage。 我将介绍视频录制 和视频通话。

    动态宽高比 API 同样非常适合视频录制。 您可以点击旋转以获得更宽的视图。 然而,QuickTime 视频轨道要求 所有样本具有相同的尺寸。 如果在拍摄过程中 更改动态宽高比, 视频录制将需要停止。 这是我之前介绍的 照片拍摄设置。 为了将其修改用于视频录制, 您可以使用 AVCaptureMovieFileOutput 代替 AVCapturePhotoOutput。

    在这种设置下, 宽高比改变时 录制将自动停止。 您也可以结合使用 AVCaptureVideoDataOutput 和 AVAssetWriter 来录制视频。 setDynamicAspectRatio 的完成时间戳 允许您结束当前录制 并以更新后的宽高比 开始新的录制。 视频录制还受益于 电影级稳定模式: cinematicExtended 和 cinematicExtendedEnhanced。 两者在 Center Stage 前置摄像头上 均具备人脸感知功能。 它们优先保持 主体的稳定,而非背景。 接下来,我将介绍 视频通话中的 Center Stage。

    这里,我正在进行 FaceTime 通话。 当朋友在小径上加入我时, 摄像头自动拉宽 以将我们两人都纳入画面。 如果您的视频会议应用 已支持 Center Stage, 使用了 Voice over IP 后台模式 以在手机锁屏时保持通话连接。 用户可以直接从控制中心的 视频效果菜单开启 Center Stage。 如果您的应用未使用 Voice over IP 后台模式, 您仍然可以采用 Center Stage API。 该功能适用于 iPhone 前置摄像头, 从 iPhone 17、 iPhone Air 和 iPhone 17 Pro 开始。 与所有系统范围的视频效果一样, 如人像、Studio Light 和手势, Center Stage 按进程启用。 一旦激活,它将应用于 您应用中所有支持的摄像头。 再次展示照片拍摄设置。 对于视频通话,输出有所不同。 视频会议应用通常使用 视频数据输出 以流的形式接收视频缓冲区。 显示、编码和传输 均在应用层处理。 基于此设置, 以下是启用 Center Stage 的方法。 首先,找到一个支持的格式。 锁定设备后 将其设置为活动格式。 默认情况下,用户通过控制中心 而非您的应用来切换 Center Stage。 在开启之前,设置控制模式: cooperative 或 app。 Cooperative 模式允许用户 也通过应用内的按钮来控制它。 然后,将 isCenterStageEnabled 设置为 true。 这样,Center Stage 就已激活。

    取景现在会自动调整 以保持所有人居中。

    要了解更多关于 Center Stage API 首次为 iPad 添加时的信息, 请查阅 WWDC 2021 的 "What's New in camera capture"。 除 Center Stage 之外, 还有另一种改善视频通话体验的方法。 Center Stage 前置摄像头支持 从 iOS 26 开始的 实时低延迟稳定模式。 默认情况下处于关闭状态。 要开启它,请在 AVCaptureConnection 上将 preferredVideoStabilizationMode 设置为 lowLatency。 这里是同一视频通话 的并排比较, 分别展示低延迟稳定开启和关闭的效果。 左侧视频中,稳定功能已关闭。 走动时有明显的抖动。 右侧视频中,稳定功能已开启。 画面稳定得多。

    至此,您已拥有所需的一切, 可以在您的 iOS 应用中 支持 Center Stage 前置摄像头。 以下是进一步改善 应用取景体验的后续步骤。 首先,在应用中 集成取景控件, 以支持方向切换、 自动缩放和自动旋转的开关, 以及 Center Stage 的激活。

    其次,优化前置摄像头性能。 在传感器方向补偿 关闭的情况下进行测试。 确保您的应用 能够正确处理照片旋转。 还可以考虑支持 1800 万像素照片拍摄, 以获得卓越的分辨率和细节。 有关最佳实践,请查阅 WWDC 2026 的 "Implement high resolution photo capture"。 Center Stage 前置摄像头彻底改变了 我在 iPhone 上拍摄自拍 和进行视频通话的方式。 我期待看到 它如何改变您的应用。

    • 5:29 - Support dynamic aspect ratio

      // Select the Center Stage front camera
      
      import AVFoundation
      
      let deviceDiscoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInUltraWideCamera], mediaType: .video, position: .front)
      
      guard let camera = deviceDiscoverySession.devices.first else {
          print("Failed to find the capture device")
          return
      }
      
      // Find a format that supports the 4x3 aspect ratio
      
      for format in camera.formats {
          if format.supportedDynamicAspectRatios.contains(.ratio4x3) {
              try! camera.lockForConfiguration()
              camera.activeFormat = format
              camera.unlockForConfiguration()
              break
          }
      }
      
      // Set dynamic aspect ratio
      
      try! camera.lockForConfiguration()
      
      let timestamp = try! await camera.setDynamicAspectRatio(.ratio4x3)
      print("Applied dynamic aspect ratio at timestamp: \(timestamp)")
      
      camera.unlockForConfiguration()
    • 7:39 - Support smart framing monitor

      // Find a format that supports smart framing
      
      import AVFoundation
      
      for format in camera.formats {
          if format.isSmartFramingSupported {
              try! camera.lockForConfiguration()
              camera.activeFormat = format
              camera.unlockForConfiguration()
              break
          }
      }
      
      // Configure the smart framing monitor
      
      let monitor = camera.smartFramingMonitor!
      
      try! camera.lockForConfiguration()
      monitor.enabledFramings = monitor.supportedFramings
      camera.unlockForConfiguration()
      
      // Monitor framing recommendations
      
      observation = monitor.observe(\.recommendedFraming, options: [.new,]) { monitor, change in
          if let framing = monitor.recommendedFraming {
      
              Task {
                  try! camera.lockForConfiguration()
                  try! await camera.setDynamicAspectRatio(framing.aspectRatio)
                  camera.videoZoomFactor = CGFloat(framing.zoomFactor)
                  camera.unlockForConfiguration()
              }
      
          }
      }
      
      // Start the smart framing monitor
      
      try! monitor.startMonitoring()
      
      // Stop the smart framing monitor
      
      observation?.invalidate()
      observation = nil
      
      monitor.stopMonitoring()
    • 14:44 - Support Center Stage for video calls

      // Find a format that supports Center Stage
      
      import AVFoundation
      
      for format in camera.formats {
          if format.isCenterStageSupported {
              try! camera.lockForConfiguration()
              camera.activeFormat = format
              camera.unlockForConfiguration()
              break
          }
      }
      
      // Turn on Center Stage
      
      AVCaptureDevice.centerStageControlMode = .cooperative
      AVCaptureDevice.isCenterStageEnabled = true
    • 0:00 - Introduction
    • Center Stage front camera is available on iPhone 17, iPhone Air, and iPhone 17 Pro. Discover how its square sensor and wide field of view give you greater flexibility to perfectly frame selfies, group shots, and video calls.

    • 1:07 - Center Stage front camera
    • Take a closer look at the Center Stage front camera's hardware. Learn how its square image sensor and 95-degree field of view let you shoot in any orientation without rotating your device, keeping your grip secure and eye contact natural.

    • 2:09 - Center Stage for photos
    • Bring a perfect framing experience to your app. Explore how Auto Zoom and Auto Rotate combine the wide field of view with automatic face and gaze detection to smartly adjust framing as people move in and out of your shots.

    • 3:09 - Capture session setup
    • An overview of the AVCaptureSession setup required to use the Center Stage front camera. Configure an AVCaptureSession with the built-in ultra-wide camera. Add a video preview layer, and receive photos via AVCapturePhotoOutput.

    • 3:56 - Dynamic aspect ratio
    • Discover the dynamic aspect ratio API. Learn how to query supported formats and seamlessly switch aspect ratios without interrupting your camera preview or rebuilding the capture session.

    • 6:47 - Smart framing monitor
    • Automate your framing with AVCaptureSmartFramingMonitor. Learn how to configure the monitor to receive periodic recommendations for aspect ratio and zoom factor based on face and gaze detection, keeping your subjects perfectly framed.

    • 9:24 - Sensor orientation compensation
    • Understand how iOS handles the native portrait orientation of the Center Stage front camera sensor. Learn how AVCapturePhotoOutput automatically applies orientation compensation.

    • 11:53 - Center Stage for video recordings
    • Apply dynamic aspect ratio to video recordings using AVCaptureMovieFileOutput or AVAssetWriter. Learn how to manage recording transitions and take advantage of cinematic stabilization modes for exceptionally smooth footage.

    • 13:16 - Center Stage for video calls
    • Enhance your video conferencing app with Center Stage. Learn how to adopt the API in cooperative or app mode to keep everyone centered, and discover how to enable low-latency stabilization for significantly smoother video calls.

Developer Footer

  • 视频
  • WWDC26
  • 让你的 iOS App 支持 Center Stage 前置摄像头
  • 打开菜单 关闭菜单
    • iOS
    • iPadOS
    • macOS
    • Apple tvOS
    • visionOS
    • watchOS
    打开菜单 关闭菜单
    • Swift
    • SwiftUI
    • Swift Playground
    • TestFlight
    • Xcode
    • Xcode Cloud
    • SF Symbols
    打开菜单 关闭菜单
    • 辅助功能
    • 配件
    • Apple 智能
    • App 扩展
    • App Store
    • 音频与视频 (英文)
    • 增强现实
    • 设计
    • 分发
    • 教育
    • 字体 (英文)
    • 游戏
    • 健康与健身
    • App 内购买项目
    • 本地化
    • 地图与位置
    • 机器学习与 AI
    • 开源资源 (英文)
    • 安全性
    • Safari 浏览器与网页 (英文)
    打开菜单 关闭菜单
    • 完整文档 (英文)
    • 部分主题文档 (简体中文)
    • 教程
    • 下载
    • 论坛 (英文)
    • 视频
    打开菜单 关闭菜单
    • 支持文档
    • 联系我们
    • 错误报告
    • 系统状态 (英文)
    打开菜单 关闭菜单
    • Apple 开发者
    • App Store Connect
    • 证书、标识符和描述文件 (英文)
    • 反馈助理
    打开菜单 关闭菜单
    • Apple Developer Program
    • Apple Developer Enterprise Program
    • App Store Small Business Program
    • MFi Program (英文)
    • Mini Apps Partner Program
    • News Partner Program (英文)
    • Video Partner Program (英文)
    • 安全赏金计划 (英文)
    • Security Research Device Program (英文)
    打开菜单 关闭菜单
    • 与 Apple 会面交流
    • Apple Developer Center
    • App Store 大奖 (英文)
    • Apple 设计大奖
    • Apple Developer Academies (英文)
    • WWDC
    阅读最近新闻。
    获取 Apple Developer App。
    版权所有 © 2026 Apple Inc. 保留所有权利。
    使用条款 隐私政策 协议和准则