An AVAsset​Export​Session object transcodes the contents of an AVAsset source object to create an output of the form described by a specified export preset.


Prior to initializing an instance of AVAsset​Export​Session, you can use all​Export​Presets() to get the complete list of presets available. Use export​Presets(compatible​With:​) 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 (preset​Name), and the output file type (output​File​Type), you can start the export running by invoking export​Asynchronously(completion​Handler:​). 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 export​Asynchronously(completion​Handler:​) 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, preset​Name:​ String)

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

Configuring Output

var output​URL:​ URL?

The URL of the export session’s output.

var supported​File​Types:​ [String]

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

var output​File​Type:​ String?

The type of file to be written by the session.

var file​Length​Limit:​ Int64

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

var time​Range:​ CMTime​Range

The time range to be exported from the source.

var metadata:​ [AVMetadata​Item]?

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

var metadata​Item​Filter:​ AVMetadata​Item​Filter?

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

var audio​Mix:​ AVAudio​Mix?

Indicates whether non-default audio mixing is enabled for export, and supplies the parameters for audio mixing.

var audio​Time​Pitch​Algorithm:​ String

Indicates the processing algorithm used to manage audio pitch for scaled audio edits.

var should​Optimize​For​Network​Use:​ Bool

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

var video​Composition:​ AVVideo​Composition?

Indicates whether video composition is enabled for export, and supplies the instructions for video composition.

var custom​Video​Compositor:​ AVVideo​Compositing?

Indicates the custom video compositor instance used, if any.

var can​Perform​Multiple​Passes​Over​Source​Media​Data:​ Bool

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

var directory​For​Temporary​Files:​ URL?

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

Export Presets

var preset​Name:​ String

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

class func all​Export​Presets()

Returns all available export preset names.

class func export​Presets(compatible​With:​ AVAsset)

Returns the identifiers compatible with a given asset.

func determine​Compatible​File​Types(completion​Handler:​ ([String]) -> Void)

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


func export​Asynchronously(completion​Handler:​ () -> Void)

Starts the asynchronous execution of an export session.

func cancel​Export()

Cancels the execution of an export session.

var error:​ Error?

Describes the error that occurred if the export status is AVAsset​Export​Session​Status​Failed or AVAsset​Export​Session​Status​Cancelled.

var estimated​Output​File​Length:​ Int64

Indicates the estimated size in bytes of the exported file.

var max​Duration:​ CMTime

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

Export Status

var progress:​ Float

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

Accessing the Asset

var asset:​ AVAsset

The asset with which the export session was initialized.



Constants to indicate the status of the session.

Export Preset Names for Device-Appropriate Quick​Time Files

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

Export Preset Names for Quick​Time Files of a Given Size

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

Export Preset Name for i​Tunes 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