Class

AVAssetExportSession

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

Overview

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.

Symbols

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: [String]

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

var outputFileType: String?

The type of file to be written by the session.

var fileLengthLimit: Int64

Indicates 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?

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

var audioTimePitchAlgorithm: String

Indicates the 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?

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

var customVideoCompositor: AVVideoCompositing?

Indicates the custom video compositor instance used, if any.

var canPerformMultiplePassesOverSourceMediaData: Bool

A Boolean value that determines if 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.

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: String?, completionHandler: (Bool) -> Void)

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

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

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

Exporting

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.

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.

Constants

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.

Relationships

Inherits From

Conforms To