An object that combines media data from multiple file-based sources to present or process media data from multiple sources.
- iOS 4.0+
- macOS 10.7+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
At its top-level,
AVComposition is a collection of tracks, each presenting media of a specific media type, e.g. audio or video, according to a timeline. Each track is represented by an instance of
AVComposition. Each track is comprised of an array of track segments, represented by instances of
AVComposition. Each segment presents a portion of the media data stored in a source container, specified by URL, a track identifier, and a time mapping. The URL specifies the source container, and the track identifier indicates the track of the source container to be presented. All file-based audiovisual assets are eligible to be combined, regardless of container type.
The time mapping specifies the temporal range of the source track that's to be presented and also specifies the temporal range of its presentation in the composition track. If the durations of the source and destination ranges of the time mapping are the same, the media data for the segment will be presented at its natural rate. Otherwise, the segment will be presented at a rate equal to the ratio
You can access the track segments of a track using the
segments property (an array of
AVComposition objects) of
AVComposition. The collection of tracks with media type information for each, and each with its array of track segments (URL, track identifier, and time mapping), form a complete low-level representation of a composition. This representation can be written out by clients in any convenient form, and subsequently the composition can be reconstituted by instantiating a new
AVMutable objects of the appropriate media type, each with its
segments property set according to the stored array of URL, track identifier, and time mapping.
A higher-level interface for constructing compositions is also presented by
AVMutable, offering insertion, removal, and scaling operations without direct manipulation of the trackSegment arrays of composition tracks. This interface makes use of higher-level constructs such as
AVAsset, allowing the client to make use of the same references to candidate sources that it would have created in order to inspect or preview them prior to inclusion in a composition.