Media Assets, Playback, and Editing

Get and inspect media assets; queue media for playback and customize playback behavior; edit and combine assets; import and export raw media streams.

Overview

The AVFoundation framework provides classes for the inspection, playback, editing, and exporting of audiovisual media assets. Use these classes if you want to:

  • Retrieve media assets for playback, or gather information about an asset.

  • Play audio and video media assets.

  • Combine, edit, and remix audio and video assets from multiple sources.

  • Obtain the media data of an asset, or write media data to a new file of a specified type.

  • Transcode the contents of an asset to create a new representation.

Assets are the building blocks for media players, and they provide a representation of a media resource. Assets come from many different media resources, such as local or remote media files, or from media streamed using HTTP Live Streaming. Use assets to efficiently retrieve and load audiovisual media in a timely manner. Inspect assets to learn about their properties, such as their duration and playback rate.

You use a player to manage the playback and timing of an asset, for example starting and stopping playback, and seeking to a particular time. A player manages the playback of a single media asset at a time. A queue player manages the queuing of media assets played sequentially. To play an asset, you need its counterpart in the player item. A player item manages the timing and presentation state of an asset played by the player. A player item also contains player item tracks that correspond to the tracks in the asset. You direct the output of a player to a specialized Core Animation layer, a player layer, or a synchronized layer.

With AVFoundation you can create new representations of an asset in several ways. Use a composition to combine multiple audio and video assets into a new, composite asset. Use an export session to re-encode an existing asset into a format defined by one of many commonly used presets. If you need more control over the transformation, use an asset reader and asset writer in tandem to convert an asset to a new representation. You use an asset writer to create assets from media such as sample buffers or still images.

Topics

Essentials

Guidelines for Apple TV 4K Development

Follow these guidelines when developing for Apple TV 4K.

Creating a Basic Video Player (iOS and tvOS)

Create a simple video playback app with built-in controls.

Creating a Basic Video Player (macOS)

Create a simple video playback app with built-in controls.

Media Assets

About the Asset Model

Understand how assets are used as the building blocks for media players.

AVAsset

The abstract class used to model timed audiovisual media such as videos and sounds.

AVAssetTrack

An object that provides the track-level inspection interface for an asset’s media tracks.

Asset Manipulation

Retrieve assets for playback or to gather information about an asset.

Asset File Import and Export

Import and export media samples to and from the file system.

Media Playback

Responding to Playback State Changes

Respond to changes in a player's playback state.

Observing the Playback Time

Observe the playback time for an asset in order to update the player's state.

Seeking Through Media

Seek or scrub across a media item to quickly access a specific time point.

Asset Playback

Play audio and video assets modeled by a player item.

Sample Buffer Playback

Play audio and video sample buffers using a custom player.

QuickTime and ISO-Related Media

Create, play, and modify QuickTime and ISO-related media assets.

Creating a Movie Player App with Basic Playback Controls

Play movies using a custom interface that implements simple playback functionality.

Metadata Manipulation

Finding Metadata Values

Retrieve and filter all of the metadata associated with an asset.

JavaScript Object Notation (JSON) Chapter Format for HTTP Live Streaming

Understand the JSON chapter formatting required for HTTP Live Streaming.

AVMetadataItem

A metadata item associated with an audiovisual asset or one of its tracks.

AVMetadataGroup

A collection of metadata items associated with a timeline segment.

AVMetadataItemFilter

An object that filters selected information from a metadata item.

AVMetadataItemValueRequest

An object used to respond to a request to load the value of a metadata item.

AVMutableMetadataItem

A mutable metadata item associated with an audiovisual asset or with one of its tracks.

AVDateRangeMetadataGroup

A collection of metadata items that are valid for use within a specific date range.

AVMutableDateRangeMetadataGroup

A mutable collection of metadata items that are valid for use within a specific range of dates.

AVTimedMetadataGroup

A collection of metadata items that are valid for use during a specific time range.

AVMutableTimedMetadataGroup

A mutable collection of metadata items that are valid for use during a specific time range.

AVMetadataFormat

A value that defines a metadata format.

Media Item Transfer

AVPlayerItemOutput

The abstract class that defines the common interface for moving samples from an asset to a player.

AVPlayerItemOutputPushDelegate

Methods you can implement to respond to changes in the media data sequence.

AVPlayerItemLegibleOutput

An object that can vend media with a legible characteristic as an attributed string.

AVPlayerItemMetadataOutput

An object used to vend collections of metadata items carried in metadata tracks.

AVPlayerItemVideoOutput

An object that coordinates the output of content associated with a Core Video pixel buffer.

AVPlayerItemMediaDataCollector

The abstract base for media data collectors.

HTTP Live Streaming

About the Common Media Application Format with HTTP Live Streaming

Understand the Common Media Application Format as it applies to HTTP Live Streaming

Using AVFoundation to Play and Persist HTTP Live Streams

Play HTTP Live Streams and preserve streams on disk for offline play back.

Sample Buffer Manipulation

AVSampleBufferRequest

An object that describes a sample buffer creation request.

AVSampleCursor

An object that provides information about the current media sample at its current position.

AVSampleBufferGenerator

An object used to create sample buffer opaque objects.

AVQueuedSampleBufferRendering

Methods you can implement to enqueue sample buffers for presentation.

Media Composition and Editing

Media Composition

Combine, edit, and remix audio and video tracks from multiple sources in a single composition.

Text Formatting

AVTextStyleRule

An object that represents text styling rules applied to text in a media item.

Media Selection

Adding Subtitles and Alternative Audio Tracks

Extend your app's appeal to users by adding subtitles and alternative audio tracks in their native language.

AVMediaSelection

An object that represents a complete rendition of media selection options on an asset.

AVMediaSelectionGroup

An object that represents a collection of mutually exclusive options for the presentation of media within an asset.

AVMediaSelectionOption

An object that represents a specific option for the presentation of media within a group of options.

AVMutableMediaSelection

A mutable object that represents a complete rendition of media selection options on an asset.

Content Key Decryption

AVContentKeyRequest

An object that encapsulates information about a content decryption key request issued from a content key session object.

AVContentKeyResponse

An object that encapsulates information about a response to a content decryption key request.

AVContentKeySession

An object used to create and track decryption keys for media data.

AVPersistableContentKeyRequest

An object that encapsulates information about a persistable content decryption key request issued from a content key session.

Supporting Types

Video Settings Dictionaries

Define output image and video formats by using the key and value constants.

Video Settings

Dictionary keys for configuring video compression and compression settings for video assets.

AVFileType

A uniform type identifier for various file formats.

AVMediaType

An identifier for various media types.

AVMediaCharacteristic

The options for specifying media type characteristics.

See Also

Playback and Editing

Configuring iOS and tvOS Audio Playback Behavior

Customize your app’s audio playback capabilities by configuring its audio session and background modes.

AirPlay 2

With AirPlay 2, you can wirelessly send your content from any Apple device to a device enabled with AirPlay.