Class

AVMutableMovie

A mutable object that represents the audiovisual containers that conform to a QuickTime- or ISO-based media file format.

Declaration

class AVMutableMovie : AVMovie

Overview

A mutable subclass of AVMovie, AVMutableMovie, provides methods that support the familiar movie editing model; for instance, you can use AVMutableMovie to copy media data from one track and paste that data into another track. You can also use AVMutableMovie to establish track references from one track to another (for example, to set one track as a chapter track of another track). If you want to perform editing operations on individual tracks, you can use the associated classes AVMovieTrack and AVMutableMovieTrack.

You only use AVMovie and AVMutableMovie when operating on format-specific features of a QuickTime or ISO base media file. You generally do not need to use these classes just to open and play QuickTime movie files or ISO base media files. Instead, you use AVURLAsset and AVPlayerItem.

When performing media insertions, AVMutableMovie interleaves the media data from the tracks in the source asset in order to create movie files that are optimized for playback. However, performing a series of media insertions may result in a movie file that is not optimally interleaved. You can create a well-interleaved, self-contained, fast-start movie file from an instance of AVMutableMovie by passing that instance to an AVAssetExportSession object using the export preset AVAssetExportPresetPassthrough and setting the shouldOptimizeForNetworkUse property to YES.

Topics

Creating a Mutable Movie

init(url: URL, options: [String : Any]?, error: ())

Creates a mutable movie object from a movie header stored in a QuickTime movie file of ISO base media file.

init(data: Data, options: [String : Any]?, error: ())

Creates a mutable movie object from a movie stored in an NSData object.

init(settingsFrom: AVMovie?, options: [String : Any]?)

Creates a mutable movie object without tracks.

Modifying Tracks

func addMutableTracksCopyingSettings(from: [AVAssetTrack], options: [String : Any]?) -> [AVMutableMovieTrack]

Adds one or more empty tracks to the target movie and copies the track settings from the source tracks.

func removeTrack(AVMovieTrack)

Removes the specified track from the target movie.

var tracks: [AVMutableMovieTrack]

An array of tracks in a mutable movie.

func track(withTrackID: CMPersistentTrackID) -> AVMutableMovieTrack?

A mutable movie track representing the track with the specified track identifier.

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

An array of mutable movie tracks that match the specified media characteristic.

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

An array of mutable movie tracks that match the specified media type.

func mutableTrack(compatibleWith: AVAssetTrack) -> AVMutableMovieTrack?

Provides a reference to a track from a mutable movie into which any time range can be inserted.

Modifying Time Ranges

func insertEmptyTimeRange(CMTimeRange)

Adds an empty time range to a movie.

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

Inserts all of the tracks in a specified time range of an asset into a movie.

func removeTimeRange(CMTimeRange)

Removes the specified time range from a movie.

func scale(CMTimeRange, toDuration: CMTime)

Changes the duration of a time range in a movie.

Configuring Movie Properties

var defaultMediaDataStorage: AVMediaDataStorage?

The default storage container for the media data added to a movie.

var metadata: [AVMetadataItem]

An array of metadata stored by the movie.

var interleavingPeriod: CMTime

A time period indicating the duration for interleaving runs of samples for each track.

var isModified: Bool

A Boolean value that indicates whether the movie has been modified.

var preferredRate: Float

The natural rate the movie is to be played.

var preferredTransform: CGAffineTransform

The transform performed on the visual media data of the movie for display purposes.

var preferredVolume: Float

The preferred volume for the audible medata data of the movie.

var timescale: CMTimeScale

The time scale for movies that contain the moov atom.

Relationships

Inherits From

Conforms To

See Also

Movie Editing

class AVMutableMovieTrack

A mutable track that conforms to a QuickTime- or ISO-based media file format.