An object that transcodes the contents of an asset source object to create an output of the form described by a specified export preset.


Prior to initializing an instance of AVAssetExportSession, you can use allExportPresets() to get the complete list of presets available. Use exportPresets(compatibleWith:) to get a list of presets that are compatible with a specific asset.

After you have initialized an export session with the asset that contains the source media, the export preset name (presetName), and the output file type (outputFileType), you can start the export running by invoking exportAsynchronously(completionHandler:). Because the export is performed asynchronously, this method returns immediately—you can use progress to check on the progress. Depending on the capabilities of the device, some exports may be queued when multiple exports are attempted. When this happens, the status of a queued export will indicate that it's waiting (waiting).

The completion handler you supply to exportAsynchronously(completionHandler:) is called whether the export fails, completes, or is cancelled. Upon completion, the status property indicates whether the export has completed successfully. If it has failed, the value of the error property supplies additional information about the reason for the failure.


Initializing a Session

init?(asset: AVAsset, presetName: String)

Initializes an asset export session with a specified asset and preset.

Configuring Output

var outputURL: URL?

The URL of the export session’s output.

var supportedFileTypes: [AVFileType]

An array containing the types of files the session can write.

var outputFileType: AVFileType?

The type of file to be written by the session.

var fileLengthLimit: Int64

The file length that the output of the session should not exceed.

var timeRange: CMTimeRange

The time range to be exported from the source.

var metadata: [AVMetadataItem]?

The metadata to be written to the output file by the export session.

var metadataItemFilter: AVMetadataItemFilter?

Specifies a filter object to be used during export to determine which metadata items should be transferred from the source asset.

var audioMix: AVAudioMix?

The parameters for audio mixing and an indication whether nondefault audio mixing is enabled for export.

var audioTimePitchAlgorithm: AVAudioTimePitchAlgorithm

A processing algorithm used to manage audio pitch for scaled audio edits.

var shouldOptimizeForNetworkUse: Bool

A Boolean value that indicates whether the movie should be optimized for network use.

var videoComposition: AVVideoComposition?

The instructions for video composition, and indicates whether video composition is enabled for export.

var customVideoCompositor: AVVideoCompositing?

The custom video compositor instance used, if any.

var canPerformMultiplePassesOverSourceMediaData: Bool

A Boolean value that indicates whether the export session can perform multiple passes over the source media to achieve better results.

var directoryForTemporaryFiles: URL?

Specifies a directory that is suitable for containing temporary files generated during the export process.

Configuring Export Presets

var presetName: String

The name of the preset with which the session was initialized.

class func allExportPresets()

Returns all available export preset names.

class func exportPresets(compatibleWith: AVAsset)

Returns the identifiers compatible with a given asset.

class func determineCompatibility(ofExportPreset: String, with: AVAsset, outputFileType: AVFileType?, completionHandler: (Bool) -> Void)

Reports the compatibility of an export present, asset, and output file type to the specified block.

func determineCompatibleFileTypes(completionHandler: ([AVFileType]) -> Void)

Reports the compatible file types for the current export session to the specified block.

Exporting Media

func exportAsynchronously(completionHandler: () -> Void)

Starts the asynchronous execution of an export session.

func cancelExport()

Cancels the execution of an export session.

var error: Error?

Describes the error that occurred if the export status is AVAssetExportSessionStatusFailed or AVAssetExportSessionStatusCancelled.

var estimatedOutputFileLength: Int64

Indicates the estimated size in bytes of the exported file.

var maxDuration: CMTime

Provides an estimate of the maximum duration of the exported media.

Getting Export Status

var progress: Float

The progress of the export on a scale from 0 to 1.

var status: AVAssetExportSessionStatus

The status of the export session.

Accessing the Asset

var asset: AVAsset

The asset with which the export session was initialized.


enum AVAssetExportSessionStatus

Constants to indicate the status of the session.

Export Preset Names for Device-Appropriate QuickTime Files

You use these export options to produce QuickTime .mov files with video size appropriate to the current device.

Export Preset Names for QuickTime Files of a Given Size

You use these export options to produce QuickTime .mov files with a specified video size.

Export Preset Name for iTunes Audio

You use this export option to produce an audio-only .m4a file with appropriate iTunes gapless playback data.

Export Preset Names for Apple Devices

You use these export options to produce files that can be played on the specific Apple devices.

Export Preset Name for Pass-Through

You use this export option to let all tracks pass through.


Inherits From

Conforms To

See Also

File Export

class AVAssetWriter

An object used to write media data to a new file of a specified audiovisual container type.

class AVAssetWriterInput

A writer used to append media samples to a single track of the output file of an AVAssetWriter object.

class AVOutputSettingsAssistant

An object that specifies a set of parameters for configuring objects that use output settings dictionaries.

class AVAssetWriterInputGroup

A group of tracks in a mutually exclusive relationship.

class AVAssetWriterInputMetadataAdaptor

An object that defines an interface for writing metadata packaged as timed metadata groups into a single asset writer input.

class AVAssetWriterInputPassDescription

An object that defines an interface for querying about the requirements of the current pass; for example, the time ranges of media data to append.

class AVAssetWriterInputPixelBufferAdaptor

A buffer used to append video samples packaged as pixel buffers to a single asset writer input.