An object that provides thumbnail or preview images of assets independently of playback.


AVAssetImageGenerator uses the default enabled video track(s) to generate images. Generating a single image in isolation can require the decoding of a large number of video frames with complex interdependencies. If you require a series of images, you can achieve far greater efficiency using the asynchronous method, generateCGImagesAsynchronously(forTimes:completionHandler:), which employs decoding efficiencies similar to those used during playback.

You create an asset generator using init(asset:) or assetImageGeneratorWithAsset:. These methods may succeed even if the asset possesses no visual tracks at the time of initialization. You can test whether an asset has any tracks with the visual characteristic using the AVAsset class’s method tracks(withMediaCharacteristic:).

The actual time of a generated image is within the range [requestedTime-requestedTimeToleranceBefore, requestedTime+requestedTimeToleranceAfter] and may differ from the requested time for efficiency.

Assets that represent mutable compositions or mutable movies may gain visual tracks after initialization of an associated image generator.


Creating an Image Generator

init(asset: AVAsset)

Initializes an image generator for use with a specified asset.

Generating Images

func copyCGImage(at: CMTime, actualTime: UnsafeMutablePointer<CMTime>?) -> CGImage

Returns a CGImage for the asset at or near a specified time.

typealias AVAssetImageGeneratorCompletionHandler

This type specifies the signature for the block invoked when generateCGImagesAsynchronously(forTimes:completionHandler:) has completed.

enum AVAssetImageGenerator.Result

Constants to indicate the outcome of image generation.

func cancelAllCGImageGeneration()

Cancels all pending image generation requests.

Managing Image-Generation Time Tolerances

var requestedTimeToleranceBefore: CMTime

The maximum length of time before a requested time for which an image may be generated.

var requestedTimeToleranceAfter: CMTime

The maximum length of time after a requested time for which an image may be generated.

Image-Generation Behavior

var apertureMode: AVAssetImageGenerator.ApertureMode?

Specifies the aperture mode for the generated image.

var appliesPreferredTrackTransform: Bool

Specifies whether to apply the track matrix (or matrices) when extracting an image from the asset.

var asset: AVAsset

The instance of AVAsset with which the AVAssetImageGenerator was initialized.

var maximumSize: CGSize

Specifies the maximum dimensions for the generated image.

var videoComposition: AVVideoComposition?

The video composition to use when extracting images from assets with multiple video tracks.

var customVideoCompositor: AVVideoCompositing?

Returns the custom video compositor instance used, if any


Inherits From

Conforms To

See Also

File Import

class AVAssetReader

A reader object used to obtain the media data of an asset, either file-based or consisting of an assemblage of media data from multiple sources.

class AVAssetReaderAudioMixOutput

An object that defines an interface for reading audio samples that result from mixing the audio from one or more tracks of an asset.

class AVAssetReaderTrackOutput

An object that defines an interface for reading media data from a single track of an asset reader's asset.

class AVAssetReaderSampleReferenceOutput

An object that defines an interface for reading sample references from a single asset track.

class AVAssetReaderVideoCompositionOutput

An object that reads video frames that have been composited from the frames in one or more tracks of a reader's assets.

class AVAssetReaderOutput

An abstract class that defines an interface for reading a single collection of samples of a common media type from an asset reader object.

class AVAssetReaderOutputMetadataAdaptor

An object that defines an interface for reading metadata.