A mutable object used to create a new composition from existing assets.


class AVMutableComposition : AVComposition


This class provides the ability to add and remove tracks, and you can add, remove, and scale time ranges. You can make an immutable snapshot of a mutable composition for playback or inspection as follows:

AVMutableComposition *myMutableComposition =
    <#a mutable composition you want to inspect or play in its current state#>;
AVComposition *immutableSnapshotOfMyComposition = [myMutableComposition copy];
// Create a player to inspect and play the composition.
AVPlayerItem *playerItemForSnapshottedComposition =
    [[AVPlayerItem alloc] initWithAsset:immutableSnapshotOfMyComposition];


Creating a Mutable Composition

init(urlAssetInitializationOptions: [String : Any]?)

Returns a new, empty, mutable composition.

Managing Time Ranges

func insertEmptyTimeRange(CMTimeRange)

Adds or extends an empty time range within all tracks of the composition.

func insertTimeRange(CMTimeRange, of: AVAsset, at: CMTime)

Inserts all the tracks within a given time range of a specified asset into the receiver.

func removeTimeRange(CMTimeRange)

Removes a specified time range from all tracks of the composition.

func scaleTimeRange(CMTimeRange, toDuration: CMTime)

Changes the duration of all tracks in a given time range.

Managing Tracks

var tracks: [AVMutableCompositionTrack]

An array of mutable composition tracks contained by the composition.

func removeTrack(AVCompositionTrack)

Removes a specified track from the receiver.

func mutableTrack(compatibleWith: AVAssetTrack) -> AVMutableCompositionTrack?

Returns a track in the receiver into which any time range of a given asset track can be inserted.

func track(withTrackID: CMPersistentTrackID) -> AVMutableCompositionTrack?

Provides a composition track associated with the specified track ID.

func tracks(withMediaCharacteristic: AVMediaCharacteristic) -> [AVMutableCompositionTrack]

Provides the composition tracks of the specified media characteristic associated with an asset.

func tracks(withMediaType: AVMediaType) -> [AVMutableCompositionTrack]

Provides the composition tracks of the specified media type associated with an asset.

Configuring Video Size

var naturalSize: CGSize

The encoded or authored size of the visual portion of the asset.


Inherits From

Conforms To

See Also

Media Composition

class AVComposition

An object that combines media data from multiple file-based sources to present or process media data from multiple sources.

class AVCompositionTrack

A track in a composition object, consisting of a media type, a track identifier, and track segments.

class AVCompositionTrackSegment

A segment of a track, consisting of a URL, a track identifier, and a time mapping from the source track to the composition track.

class AVMutableCompositionTrack

A mutable track in a composition object that you use to insert, remove, and scale track segments without affecting their low-level representation.