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


class AVAssetImageGenerator : NSObject


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)

Creates an image generator for use with a specified asset.

Generating Images

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

Returns an image for the asset at or near a specified time.

typealias AVAssetImageGeneratorCompletionHandler

A block that you use to receive thumbnail images generated from an asset.

enum AVAssetImageGenerator.Result

The statuses indicating the outcome of image generation.

func cancelAllCGImageGeneration()

Cancels all pending image generation requests.

Managing Image-Generation Time Tolerances

var requestedTimeToleranceBefore: CMTime

The maximum amount of time before a requested time you can generate an image.

var requestedTimeToleranceAfter: CMTime

The maximum length of time after a requested time you can generate an image.

Configuring Image-Generation Behavior

var apertureMode: AVAssetImageGenerator.ApertureMode?

Specifies the aperture mode for the generated image.

struct AVAssetImageGenerator.ApertureMode

The aperture modes used when generating images.

var appliesPreferredTrackTransform: Bool

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

var asset: AVAsset

The asset that initialized the image generator.

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.

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