Cameras and Media Capture

Capture photos and record video and audio; configure built-in cameras and microphones or external capture devices.

Overview

The AVFoundation Capture subsystem provides a common high-level architecture for video, photo, and audio capture services in iOS and macOS. Use this system if you want to:

  • Build a custom camera UI to integrate shooting photos or videos into your app's user experience

  • Give users more direct control over photo and video capture, such as focus, exposure, and stabilization options

  • Produce different results than the system camera UI, such as RAW format photos, depth maps, or videos with custom timed metadata

  • Get live access to pixel or audio data streaming directly from a capture device

The main parts of the capture architecture are sessions, inputs, and outputs: Capture sessions connect one or more inputs to one or more outputs. Inputs are sources of media, including capture devices like the cameras and microphones built into an iOS device or Mac. Outputs acquire media from inputs to produce useful data, such as movie files written to disk or raw pixel buffers available for live processing.

Block diagram of the basic capture session architecture: an AVCaptureSession acquires data from an AVCaptureDevice through AVCaptureDeviceInput, and provides data to one or more AVCaptureOutput objects.

Topics

First Steps

Requesting Authorization for Media Capture

Respect user privacy by seeking permission to capture and store photos, audio, and video.

Setting Up a Capture Session

Configure input devices, output media, preview views, and basic settings before capturing photos or video.

class AVCaptureSession

An object that manages capture activity and coordinates the flow of data from input devices to capture outputs.

Capture Devices

Choosing a Capture Device

Select the front or back camera, or use advanced features like the TrueDepth camera or dual camera.

class AVCaptureDevice

A device that provides input (such as audio or video) for capture sessions and offers controls for hardware-specific capture features.

Photo Capture

Capturing Still and Live Photos

Configure and capture single or multiple still images, Live Photos, and other forms of photography.

class AVCapturePhotoOutput

A capture output for still image, Live Photo, and other photography workflows.

class AVCapturePhoto

A container for image data collected by a photo capture output.

Video Capture

class AVCaptureMovieFileOutput

A capture output that records video and audio to a QuickTime movie file.

class AVCaptureVideoDataOutput

A capture output that records video and provides access to video frames for processing.

Audio Capture

class AVCaptureAudioFileOutput

A capture output that records audio and saves the recorded audio to a file.

class AVCaptureAudioDataOutput

A capture output that records audio and provides access to audio sample buffers as they are recorded.

Metadata Capture

class AVCaptureMetadataInput

A capture input for providing timed metadata to a capture session.

class AVCaptureMetadataOutput

A capture output for processing timed metadata produced by a capture session.

class AVMetadataFaceObject

Face information detected by a metadata capture output.

class AVMetadataMachineReadableCodeObject

Barcode information detected by a metadata capture output.

class AVMetadataObject

The abstract superclass for objects provided by a metadata capture output.

Depth Data Capture

Capturing Photos with Depth

Get a depth map with a photo to create effects like the system camera's Portrait mode (on compatible devices).

class AVCaptureDepthDataOutput

A capture output that records scene depth information on compatible camera devices.

class AVDepthData

A container for per-pixel distance or disparity information captured by compatible camera devices.

Streaming Depth Data from the TrueDepth Camera

Visualize depth data in 2D and 3D from the TrueDepth camera.

Enhancing Live Video by Leveraging TrueDepth Camera Data

Apply your own background to a live capture feed streamed from the front-facing TrueDepth camera.

Synchronized Capture

class AVCaptureDataOutputSynchronizer

An object that coordinates time-matched delivery of data from multiple capture outputs.

class AVCaptureSynchronizedDataCollection

A set of data samples from multiple capture outputs collected at the same time.

class AVCaptureSynchronizedDepthData

A container for scene depth information collected using synchronized capture.

class AVCaptureSynchronizedMetadataObjectData

A container for metadata objects collected using synchronized capture.

class AVCaptureSynchronizedSampleBufferData

A container for video or audio samples collected using synchronized capture.

class AVCaptureSynchronizedData

The abstract superclass for media samples collected using synchronized capture.

Media Capture Preview

class AVCaptureVideoPreviewLayer

A Core Animation layer that can display video as it is being captured.

class AVCaptureAudioPreviewOutput

A capture output that provides preview playback for audio being recorded in a capture session.

Mac Capture Options

class AVCaptureScreenInput

A capture input for recording from a screen in macOS.

class AVCaptureStillImageOutput

A capture output for capturing still photos in macOS.

Session Configuration

class AVCaptureInput

The abstract superclass for objects that provide input data to a capture session.

class AVCaptureOutput

The abstract superclass for objects that output the media recorded in a capture session.

class AVCaptureConnection

A connection between a specific pair of capture input and capture output objects in a capture session.

class AVCaptureDeviceInput

A capture input that provides media from a capture device to a capture session.

class AVCaptureAudioChannel

An object that monitors average and peak power levels for an audio channel in a capture connection.

File Output

class AVCaptureFileOutput

The abstract superclass for capture outputs that can record captured data to a file.

protocol AVCaptureFileOutputDelegate

Methods for monitoring or controlling the output of a media file capture.

protocol AVCaptureFileOutputRecordingDelegate

Methods for responding to events that occur while recording captured media to a file.

Errors

struct AVError

Error codes for the AVError domain.