how do I take a photo while capturing video with AVCaptureSession?

Asked on 04/09/2025

1 search

To take a photo while capturing video with AVCaptureSession, you can use the AVCapturePhotoOutput in conjunction with your video capture setup. Here's a general approach based on the information from the WWDC sessions:

  1. Set up your AVCaptureSession: Start by creating an AVCaptureSession and configure it with the necessary inputs and outputs for video capture. This typically involves setting up an AVCaptureDevice for the camera and an AVCaptureMovieFileOutput for video recording.

  2. Add AVCapturePhotoOutput: In addition to your video output, add an AVCapturePhotoOutput to your session. This allows you to capture still images while the video is being recorded.

  3. Capture a Photo: When you want to take a photo, use the capturePhoto(with:delegate:) method of AVCapturePhotoOutput. This can be done while the video is being recorded, allowing you to capture high-quality still images without interrupting the video capture.

For more detailed code examples and explanations, you might want to refer to the session Build compelling spatial photo and video experiences (05:21) which discusses setting up an AVCaptureSession and handling inputs and outputs. Additionally, the session Build a great Lock Screen camera capture experience (04:49) provides insights into handling camera capture experiences, which might be useful if you're working with locked devices or specific capture extensions.