Instance Property

time

The time offset, in seconds, of this frame relative to the start of the Live Photo.

Required.

Declaration

@property(readonly) CMTime time;

Discussion

You can use this value to vary your image processing over time, creating animated effects. For example, the following code sets up an animated filter that fades from sepia tone to original to sepia tone again over the duration of the Live Photo:

// Save properties of the context to avoid capturing it in the block.
NSTimeInterval duration = CMTimeGetSeconds(context.duration);
NSTimeInterval photoTime = CMTimeGetSeconds(context.photoTime);
// Frame processor block uses duration/photoTime/frameTime to animate.
context.frameProcessor = ^CIImage *(id <PHLivePhotoFrame> frame, NSError **error) {
    NSTimeInterval frameTime = CMTimeGetSeconds(frame.time);
    NSTimeInterval intensity;
    if (frameTime < photoTime) {
        // Vary intensity from -1.0 to 0.0 before the photo.
        intensity = -frameTime / photoTime;
    } else {
        // Vary intensity from 0.0 to 1.0 after the photo.
        intensity = (frameTime - photoTime) / (duration - photoTime);
    }
    return [frame.image imageByApplyingFilter:@"CISepiaTone"
                          withInputParameters:@{ kCIInputIntensityKey: @(intensity) }];
};

See Also

Getting Information About the Frame

renderScale

The scale factor of the frame image relative to the Live Photo’s photo content.

Required.

type

The type of image content in this frame.

Required.

PHLivePhotoFrameType

Identifiers for the type of frame image to be processed. Used with the type property.