An object that supprts using Core Image filters to process an individual video frame in a video composition.


class AVAsynchronousCIImageFilteringRequest : NSObject


You use this class when creating a composition for Core Image filtering with the init(asset:applyingCIFiltersWithHandler:) method. In that method call, you provide a block to be called by AVFoundation as it processes each frame of video, and the block’s sole parameter is a AVAsynchronousCIImageFilteringRequest object. Use that object both to the video frame image to be filtered and allows you to return a filtered image to AVFoundation for display or export. Listing 1 shows an example of applying a filter to an asset.

Listing 1

Applying Core Image filters to a video asset

let filter = CIFilter(name: "CIGaussianBlur")!
let composition = AVVideoComposition(asset: asset, applyingCIFiltersWithHandler: { request in
    // Clamp to avoid blurring transparent pixels at the image edges
    let source = request.sourceImage.imageByClampingToExtent()
    filter.setValue(source, forKey: kCIInputImageKey)
    // Vary filter parameters based on video timing
    let seconds = CMTimeGetSeconds(request.compositionTime)
    filter.setValue(seconds * 10.0, forKey: kCIInputRadiusKey)
    // Crop the blurred output to the bounds of the original image
    let output = filter.outputImage!.imageByCroppingToRect(request.sourceImage.extent)
    // Provide the filter output to the composition
    request.finishWithImage(output, context: nil)


Getting the Image to be Filtered

var sourceImage: CIImage

The current video frame image.

Getting Contextual Information for Filtering

var compositionTime: CMTime

The time in the video composition corresponding to the frame being processed.

var renderSize: CGSize

The width and height, in pixels, of the frame being processed.

Returning the Filtered Image

func finish(with: CIImage, context: CIContext?)

Provides the filtered video frame image to AVFoundation for further processing or display.

func finish(with: Error)

Notifies AVFoundation that you cannot fulfill the image filtering request.


Inherits From

See Also

Video Composition

class AVVideoComposition

An object that represents an immutable video composition.

class AVMutableVideoComposition

An object that represents a mutable video composition.

class AVAsynchronousVideoCompositionRequest

An object that contains the information necessary for a video compositor to render an output pixel buffer.

class AVMutableVideoCompositionInstruction

An operation performed by a compositor.

class AVMutableVideoCompositionLayerInstruction

An object used to modify the transform, cropping, and opacity ramps applied to a given track in a mutable composition.

class AVVideoCompositionCoreAnimationTool

An object used to incorporate Core Animation into a video composition.

class AVVideoCompositionInstruction

An operation performed by a compositor.

class AVVideoCompositionLayerInstruction

An object used to modify the transform, cropping, and opacity ramps applied to a given track in a composition.

class AVVideoCompositionRenderContext

An object that defines the context within which custom compositors render new output pixel buffers.