Mac Developer Library

Developer

AVFoundation Framework Reference AVAssetExportSession Class Reference

Options
Deployment Target:

On This Page
Language:

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. More...

Inheritance


Conforms To


Import Statement


import AVFoundation @import AVFoundation;

Availability


Available in OS X v10.7 and later.
  • outputURL outputURL Property

    The URL of the export session’s output.

    Declaration

    Swift

    @NSCopying var outputURL: NSURL!

    Objective-C

    @property(nonatomic, copy) NSURL *outputURL

    Discussion

    You can observe this property using Key-value observing.

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.7 and later.

    See Also

    outputFileType

  • An array containing the types of files the session can write. (read-only)

    Declaration

    Swift

    var supportedFileTypes: [AnyObject]! { get }

    Objective-C

    @property(nonatomic, readonly) NSArray *supportedFileTypes

    Discussion

    The types of files the session can write are determined by the asset and and export preset with which the session was initialized. If you need to determine the compatible file formats before initiating the export operation, use the determineCompatibleFileTypesWithCompletionHandler: method.

    You can observe this property using Key-value observing.

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.7 and later.

  • The type of file to be written by the session.

    Declaration

    Swift

    var outputFileType: String!

    Objective-C

    @property(nonatomic, copy) NSString *outputFileType

    Discussion

    The value is a UTI string corresponding to the file type to use when writing the asset. For a list of constants specifying UTIs for standard file types, see AV Foundation Constants Reference.

    You can observe this property using Key-value observing.

    Special Considerations

    You must set a value for this property.

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.7 and later.

  • timeRange timeRange Property

    The time range to be exported from the source.

    Declaration

    Swift

    var timeRange: CMTimeRange

    Objective-C

    @property(nonatomic) CMTimeRange timeRange

    Discussion

    The default time range of an export session is kCMTimeZero to kCMTimePositiveInfinity, meaning that (modulo a possible limit on file length) the full duration of the asset will be exported.

    You can observe this property using Key-value observing.

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.7 and later.

  • metadata metadata Property

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

    Declaration

    Swift

    var metadata: [AnyObject]!

    Objective-C

    @property(nonatomic, copy) NSArray *metadata

    Discussion

    The metadata is an array of AVMetadataItem objects.

    If the value of this key is nil, any existing metadata in the exported asset will be translated as accurately as possible into the appropriate metadata key space for the output file and written to the output.

    You can observe this property using Key-value observing.

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.7 and later.

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

    Declaration

    Swift

    var metadataItemFilter: AVMetadataItemFilter!

    Objective-C

    @property(nonatomic, retain) AVMetadataItemFilter *metadataItemFilter

    Discussion

    If the value of this key is nil, no filter will be applied. This is the default.

    The filter will not be applied to metadata set with via the metadata property. To apply the filter to metadata before it is set on the metadata property, see AVMetadataItem.

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.9 and later.

  • audioMix audioMix Property

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

    Declaration

    Swift

    @NSCopying var audioMix: AVAudioMix!

    Objective-C

    @property(nonatomic, copy) AVAudioMix *audioMix

    Discussion

    You can observe this property using Key-value observing.

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.7 and later.

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

    Declaration

    Swift

    var audioTimePitchAlgorithm: String!

    Objective-C

    @property(nonatomic, copy) NSString *audioTimePitchAlgorithm

    Discussion

    An exception (NSInvalidArgumentException) is raised if this property is set to a value other than the constants defined in Time Pitch Algorithm Settings.

    The default value is AVAudioTimePitchAlgorithmSpectral.

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.9 and later.

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

    Declaration

    Swift

    var shouldOptimizeForNetworkUse: Bool

    Objective-C

    @property(nonatomic) BOOL shouldOptimizeForNetworkUse

    Discussion

    You can observe this property using Key-value observing.

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.7 and later.

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

    Declaration

    Swift

    @NSCopying var videoComposition: AVVideoComposition!

    Objective-C

    @property(nonatomic, copy) AVVideoComposition *videoComposition

    Discussion

    You can observe this property using Key-value observing.

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.7 and later.

  • Indicates the custom video compositor instance used, if any. (read-only)

    Declaration

    Swift

    var customVideoCompositor: AVVideoCompositing! { get }

    Objective-C

    @property(nonatomic, readonly) id< AVVideoCompositing > customVideoCompositor

    Discussion

    The custom video compositor instance that is used during image generation is accessible via this property after the value of videoComposition is set to an AVVideoComposition instance that specifies a custom video compositor class. Any additional communication between the application and that instance of the custom video compositor, if any is required for configuration or other purposes, can only occur once that has happened.

    If the value of videoComposition is changed from an AVVideoComposition that specifies a custom video compositor class to another instance of AVVideoComposition that specifies the same custom video compositor class, the instance of the custom video compositor that was previously created will receive the renderContextChanged: message and remain in use for subsequent image generation.

    This property is nil if there is no video compositor, or if the internal video compositor is in use.

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.9 and later.

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

    Declaration

    Swift

    var canPerformMultiplePassesOverSourceMediaData: Bool

    Objective-C

    @property(nonatomic) BOOL canPerformMultiplePassesOverSourceMediaData

    Discussion

    When the value for this property is YEStrue, the export session can produce higher quality results at the expense of longer export times. Setting this property to YEStrue may also require the export session to write temporary data to disk during the export. To control the location of temporary data, use the property directoryForTemporaryFiles.

    The default value is NOfalse. Not all export session configurations can benefit from performing multiple passes over the source media. In these cases, setting this property to YEStrue has no effect.

    This property cannot be set after the export has started.

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.10 and later.

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

    Declaration

    Swift

    @NSCopying var directoryForTemporaryFiles: NSURL!

    Objective-C

    @property(nonatomic, copy) NSURL *directoryForTemporaryFiles

    Discussion

    An asset export session may need to write temporary files, for example when canPerformMultiplePassesOverSourceMediaData is set to YEStrue. This property specifies where in the filesystem those temporary files are created. All temporary files will be deleted when the export is completed, is canceled, or fails.

    When the value of this property is nil, the export session will choose a suitable location when writing temporary files. The default value is nil.

    This property cannot be set after the export has started. The export will fail if the URL points to a location that is not a directory, does not exist, is not on the local file system, or if a file cannot be created in this directory (for example, due to insufficient permissions or sandboxing restrictions).

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.10 and later.

  • Starts the asynchronous execution of an export session.

    Declaration

    Swift

    func exportAsynchronouslyWithCompletionHandler(_ handler: (() -> Void)!)

    Objective-C

    - (void)exportAsynchronouslyWithCompletionHandler:(void (^)(void))handler

    Parameters

    handler

    A block that is invoked when writing is complete or in the event of writing failure.

    Discussion

    This method starts an asynchronous export operation and returns immediately. status signals the terminal state of the export session, and if a failure occurs, error describes the problem.

    If internal preparation for export fails, handler is invoked synchronously. The handler may also be called asynchronously, after the method returns, in the following cases:

    1. If a failure occurs during the export, including failures of loading, re-encoding, or writing media data to the output.

    2. If cancelExport is invoked.

    3. After the export session succeeds, having completely written its output to the outputURL.

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.7 and later.

  • Cancels the execution of an export session.

    Declaration

    Swift

    func cancelExport()

    Objective-C

    - (void)cancelExport

    Discussion

    You can invoke this method when the export is running.

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.7 and later.

  • error error Property

    Describes the error that occurred if the export status is AVAssetExportSessionStatusFailed or AVAssetExportSessionStatusCancelled. (read-only)

    Declaration

    Swift

    var error: NSError! { get }

    Objective-C

    @property(nonatomic, readonly) NSError *error

    Discussion

    If there is no error to report, the value of this property is nil.

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.7 and later.

  • Indicates the estimated size in bytes of the exported file. (read-only)

    Declaration

    Swift

    var estimatedOutputFileLength: Int64 { get }

    Objective-C

    @property(nonatomic, readonly) long long estimatedOutputFileLength

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.9 and later.

  • progress progress Property

    The progress of the export on a scale from 0 to 1. (read-only)

    Declaration

    Swift

    var progress: Float { get }

    Objective-C

    @property(nonatomic, readonly) float progress

    Discussion

    A value of 0 means the export has not yet begun, 1 means the export is complete.

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.7 and later.

  • status status Property

    The status of the export session. (read-only)

    Declaration

    Swift

    var status: AVAssetExportSessionStatus { get }

    Objective-C

    @property(nonatomic, readonly) AVAssetExportSessionStatus status

    Discussion

    For possible values, see AVAssetExportSessionStatus.

    You can observe this property using Key-value observing.

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.7 and later.

  • asset asset Property

    The asset with which the export session was initialized. (read-only)

    Declaration

    Swift

    var asset: AVAsset! { get }

    Objective-C

    @property(nonatomic, retain, readonly) AVAsset *asset

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.8 and later.

  • Constants to indicate the status of the session.

    Declaration

    Swift

    enum AVAssetExportSessionStatus : Int { case Unknown case Waiting case Exporting case Completed case Failed case Cancelled }

    Objective-C

    enum { AVAssetExportSessionStatusUnknown, AVAssetExportSessionStatusWaiting, AVAssetExportSessionStatusExporting, AVAssetExportSessionStatusCompleted, AVAssetExportSessionStatusFailed, AVAssetExportSessionStatusCancelled }; typedef NSInteger AVAssetExportSessionStatus;

    Constants

    • Unknown

      AVAssetExportSessionStatusUnknown

      Indicates that the status is unknown.

      Available in OS X v10.7 and later.

    • Waiting

      AVAssetExportSessionStatusWaiting

      Indicates that the session is waiting to export more data.

      Available in OS X v10.7 and later.

    • Exporting

      AVAssetExportSessionStatusExporting

      Indicates that the export session is in progress.

      Available in OS X v10.7 and later.

    • Completed

      AVAssetExportSessionStatusCompleted

      Indicates that the export session completed successfully.

      Available in OS X v10.7 and later.

    • Failed

      AVAssetExportSessionStatusFailed

      Indicates that the export session failed.

      Available in OS X v10.7 and later.

    • Cancelled

      AVAssetExportSessionStatusCancelled

      Indicates that the export session was cancelled.

      Available in OS X v10.7 and later.

    Import Statement

    import AVFoundation

    Availability

    Available in OS X v10.7 and later.

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

    Declaration

    Swift

    let AVAssetExportPreset640x480: NSString! let AVAssetExportPreset960x540: NSString! let AVAssetExportPreset1280x720: NSString! let AVAssetExportPreset1920x1080: NSString! let AVAssetExportPreset3840x2160: NSString!

    Objective-C

    NSString *const AVAssetExportPreset640x480; NSString *const AVAssetExportPreset960x540; NSString *const AVAssetExportPreset1280x720; NSString *const AVAssetExportPreset1920x1080; NSString *const AVAssetExportPreset3840x2160;

    Constants

    • AVAssetExportPreset640x480

      AVAssetExportPreset640x480

      Specifies output at 640x480 pixels.

      Available in OS X v10.7 and later.

    • AVAssetExportPreset960x540

      AVAssetExportPreset960x540

      Specifies output at 960x540 pixels.

      Available in OS X v10.7 and later.

    • AVAssetExportPreset1280x720

      AVAssetExportPreset1280x720

      Specifies output at 1280x720 pixels.

      Available in OS X v10.7 and later.

    • AVAssetExportPreset1920x1080

      AVAssetExportPreset1920x1080

      Specifies output at 1920x1080 pixels.

      Available in OS X v10.7 and later.

    • AVAssetExportPreset3840x2160

      AVAssetExportPreset3840x2160

      Specifies output at 3840x2160 pixels.

      Available in OS X v10.10 and later.

    Discussion

    The export will not scale the video up from a smaller size. Video is compressed using H.264; audio is compressed using AAC. Some devices cannot support some sizes.

    Import Statement

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

    Declaration

    Swift

    let AVAssetExportPresetAppleM4A: NSString!

    Objective-C

    NSString *const AVAssetExportPresetAppleM4A;

    Constants

    • AVAssetExportPresetAppleM4A

      AVAssetExportPresetAppleM4A

      Specifies an audio-only .m4a file with appropriate iTunes gapless playback data.

      Available in OS X v10.7 and later.

    Import Statement

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

    Declaration

    Swift

    let AVAssetExportPresetAppleM4VCellular: NSString! let AVAssetExportPresetAppleM4ViPod: NSString! let AVAssetExportPresetAppleM4V480pSD: NSString! let AVAssetExportPresetAppleM4VAppleTV: NSString! let AVAssetExportPresetAppleM4VWiFi: NSString! let AVAssetExportPresetAppleM4V720pHD: NSString! let AVAssetExportPresetAppleM4V1080pHD: NSString! let AVAssetExportPresetAppleProRes422LPCM: NSString!

    Objective-C

    NSString *const AVAssetExportPresetAppleM4VCellular; NSString *const AVAssetExportPresetAppleM4ViPod; NSString *const AVAssetExportPresetAppleM4V480pSD; NSString *const AVAssetExportPresetAppleM4VAppleTV; NSString *const AVAssetExportPresetAppleM4VWiFi; NSString *const AVAssetExportPresetAppleM4V720pHD; NSString *const AVAssetExportPresetAppleM4V1080pHD; NSString *const AVAssetExportPresetAppleProRes422LPCM;

    Constants

    • AVAssetExportPresetAppleM4VCellular

      AVAssetExportPresetAppleM4VCellular

      Specifies a format suitable for playing on Apple devices when streamed over a cellular network.

      Available in OS X v10.7 and later.

    • AVAssetExportPresetAppleM4ViPod

      AVAssetExportPresetAppleM4ViPod

      Specifies a format suitable for playing on an iPod.

      Available in OS X v10.7 and later.

    • AVAssetExportPresetAppleM4V480pSD

      AVAssetExportPresetAppleM4V480pSD

      Specifies a 480p Standard Definition format suitable for playing on Apple devices.

      Available in OS X v10.7 and later.

    • AVAssetExportPresetAppleM4VAppleTV

      AVAssetExportPresetAppleM4VAppleTV

      Specifies a format suitable for playing on AppleTV.

      Available in OS X v10.7 and later.

    • AVAssetExportPresetAppleM4VWiFi

      AVAssetExportPresetAppleM4VWiFi

      Specifies a format suitable for playing on Apple devices when streamed over a WiFi network.

      Available in OS X v10.7 and later.

    • AVAssetExportPresetAppleM4V720pHD

      AVAssetExportPresetAppleM4V720pHD

      Specifies a 720p High Definition format suitable for playing on Apple devices.

      Available in OS X v10.7 and later.

    • AVAssetExportPresetAppleM4V1080pHD

      AVAssetExportPresetAppleM4V1080pHD

      Specifies a 1080p High Definition format suitable for playing on Apple devices.

      Available in OS X v10.8 and later.

    • AVAssetExportPresetAppleProRes422LPCM

      AVAssetExportPresetAppleProRes422LPCM

      Specifies a QuickTime movie with Apple ProRes 422 video and LPCM audio.

      Available in OS X v10.7 and later.

    Discussion

    These presets are only available on OS X.

    The file name should have the extension .m4v (or .m4a for exports with audio only sources).

    Import Statement

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

    Declaration

    Swift

    let AVAssetExportPresetPassthrough: NSString!

    Objective-C

    NSString *const AVAssetExportPresetPassthrough;

    Constants

    • AVAssetExportPresetPassthrough

      AVAssetExportPresetPassthrough

      Specifies that all tracks pass through, unless it is not possible.

      Available in OS X v10.7 and later.

    Discussion

    This option does not show up in the allExportPresets and exportPresetsCompatibleWithAsset: methods.

    Import Statement