Instance Method

requestExportSession(forVideo:options:exportPreset:resultHandler:)

Requests an export session for writing the video asset’s data to a file, to be loaded asynchronously.

Declaration

func requestExportSession(forVideo asset: PHAsset, options: PHVideoRequestOptions?, exportPreset: String, resultHandler: @escaping (AVAssetExportSession?, [AnyHashable : Any]?) -> Void) -> PHImageRequestID

Parameters

asset

The video asset for which an export session is to be created.

options

Options specifying how Photos should handle the request and notify your app of progress or errors. For details, see PHVideoRequestOptions.

exportPreset

The export preset name for exporting the asset. For available presets, see AVAssetExportSession.

resultHandler

A block that Photos calls after loading the asset’s data and preparing the export session.

The block takes the following parameters:

exportSession

An AVAssetExportSession object that you can use for writing the video asset’s data to a file.

info

A dictionary that provides information about the status of the request. See Image Result Info Keys for possible keys and values.

Return Value

A numeric identifier for the request. If you need to cancel the request before it completes, pass this identifier to the cancelImageRequest(_:) method.

Discussion

When you call this method, Photos downloads the video data (if necessary) and creates an export session. It then calls your resultHandler block to provide the requested video.

For additional export options, use the requestAVAsset(forVideo:options:resultHandler:) method and then create AVAssetReader and AVAssetWriter objects to transcode and output the video asset’s data.

See Also

Requesting Video Objects