Class

AVAssetTrack

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

Declaration

class AVAssetTrack : NSObject

Overview

AVAssetTrack adopts the AVAsynchronousKeyValueLoading protocol. You can use the protocol’s statusOfValue(forKey:error:) method to determine if a track property can be accessed without blocking the calling thread. If a property’s status is a value other than AVKeyValueStatus.loaded, you should use the protocol’s loadValuesAsynchronously(forKeys:completionHandler:) method to asynchronously load the key prior to use. To cancel pending load requests for all keys of AVAssetTrack you must message its owning AVAsset object (for example, [track.asset cancelLoading]).

Topics

Retrieving Track Information

var asset: AVAsset?

The asset of which the track is a part.

var trackID: CMPersistentTrackID

The persistent unique identifier for this track.

var mediaType: AVMediaType

The media type for the track.

func hasMediaCharacteristic(AVMediaCharacteristic) -> Bool

Returns a Boolean value that indicates whether the track references media with the specified media characteristic.

struct AVMediaCharacteristic

The options for specifying media type characteristics.

var formatDescriptions: [Any]

The format descriptions of the media samples referenced by the track.

var isEnabled: Bool

A Boolean value that indicates whether the track is enabled according to the state stored in its container.

var isPlayable: Bool

A Boolean value that indicates whether the track is playable in the current environment.

var isSelfContained: Bool

A Boolean value that indicates whether the track references sample data contained only within its storage container.

var estimatedDataRate: Float

The estimated data rate, in bits per second, of the media data referenced by the track.

var totalSampleDataLength: Int64

The total number of bytes of sample data required by the track.

var isDecodable: Bool

A Boolean value that indicates whether the receiver is decodable in the current environment.

Retrieving Temporal Properties

var timeRange: CMTimeRange

The time range of the track within the overall timeline of the asset.

var naturalTimeScale: CMTimeScale

The natural time scale of the media referenced by this track.

Retrieving Language Properties

var languageCode: String?

The language associated with the track, as an ISO 639-2/T language code.

var extendedLanguageTag: String?

The language tag associated with the track, as a BCP-47 language tag.

Retrieving Visual Characteristics

var naturalSize: CGSize

The natural dimensions of the media data referenced by the track.

var preferredTransform: CGAffineTransform

The transform specified in the track’s storage container as the preferred transformation of the visual media data for display purposes.

Retrieving Audible Characteristics

var preferredVolume: Float

The volume specified in the track’s storage container as the preferred volume of the audible media data.

Retrieving Frame-Based Characteristics

var nominalFrameRate: Float

The frame rate of the track, in frames per second.

var minFrameDuration: CMTime

The minimum duration of the track’s frames.

var requiresFrameReordering: Bool

A Boolean value that indicates whether samples in the track may have different values for their presentation and decode timestamps.

Finding Track Segments

var segments: [AVAssetTrackSegment]

The time mappings from the track’s media samples to its timeline.

func segment(forTrackTime: CMTime) -> AVAssetTrackSegment?

Returns the track segment that corresponds with, or is closest to, the specified track time.

func samplePresentationTime(forTrackTime: CMTime) -> CMTime

Maps the specified track time through the appropriate time mapping and returns the resulting sample presentation time.

Managing Metadata

var metadata: [AVMetadataItem]

An array of metadata items for all metadata identifiers for which a value is available.

var commonMetadata: [AVMetadataItem]

An array of metadata item objects for each common metadata key for which a value is available.

var availableMetadataFormats: [AVMetadataFormat]

An array containing the metadata formats available for the track.

func metadata(forFormat: AVMetadataFormat) -> [AVMetadataItem]

Creates an array of metadata objects, one for each metadata item in the container of the specified format.

struct AVMetadataFormat

A value that defines a metadata format.

Working with Associated Tracks

var availableTrackAssociationTypes: [AVAssetTrack.AssociationType]

An array of association types used to associate the track with other tracks.

func associatedTracks(ofType: AVAssetTrack.AssociationType) -> [AVAssetTrack]

Creates an array containing other tracks associated with the track that uses the specified association type.

struct AVAssetTrack.AssociationType

Constants for identifying how other tracks are associated with a track.

Creating Sample Cursors

var canProvideSampleCursors: Bool

A Boolean value that indicates whether the asset track can provide instances of sample cursors to traverse its media samples and discover information.

func makeSampleCursor(presentationTimeStamp: CMTime) -> AVSampleCursor?

Creates an instance of a sample cursor and positions it at or near the specified presentation timestamp.

func makeSampleCursorAtFirstSampleInDecodeOrder() -> AVSampleCursor?

Creates an instance of a sample cursor and positions it at the receiver's first media sample in decode order.

func makeSampleCursorAtLastSampleInDecodeOrder() -> AVSampleCursor?

Creates an instance of a sample cursor and positions it at the receiver's last media sample in decode order.

See Also

Media Assets

About the Asset Model

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

class AVAsset

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

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.