How should I configure AVCaptureMovieFileOutput to work with spatial video recording?

Generated on 3/11/2025

1 search

To configure AVCaptureMovieFileOutput for spatial video recording, you need to follow these steps:

  1. Create an AV Capture Session: Start by creating an AVCaptureSession and setting up a device input from a capture device like a camera.

  2. Select the Appropriate Camera: Use the built-in dual wide camera, as spatial video requires both the wide and ultra-wide cameras to stream simultaneously.

  3. Choose a Supported Video Format: Iterate through the video formats available on the device and select one that supports spatial video. You can check if a format supports spatial video by verifying if isSpatialVideoCaptureSupported is true.

  4. Enable Spatial Video Recording: Once a suitable format is found, set it as the active format on the video device. Ensure to lock and unlock the video device appropriately and handle any errors if no spatial formats are found.

  5. Set Spatial Video Capture Enabled: Check if spatial video capture is supported and, if so, set isSpatialVideoCaptureEnabled to true. Note that this feature is only available on iPhone 15 Pro, and isSpatialVideoCaptureSupported will return false for other devices.

  6. Video Stabilization and Preview: For improved quality, set the preferred video stabilization mode to cinematic extended enhanced. You can also use the AVCaptureVideoPreviewLayer API to get a video preview feed, although it will always show the wide camera due to the monocular display of the iPhone.

For more detailed guidance, you can refer to the session Build compelling spatial photo and video experiences (05:21) from WWDC 2024.