Contents

PHLivePhotoEditingContext

An editing session for modifying the photo, video, and audio content of a Live Photo.

Declaration

class PHLivePhotoEditingContext

Mentioned in

Overview

A Live Photo is a picture, captured by a supported iOS device, that includes motion and sound from the moments just before and after it was taken. Editing the content of a Live Photo works much like editing other asset types:

  1. In an app using the Photos framework, fetch a PHAsset object that represents the Live Photo to edit, and use that object’s requestContentEditingInput(with:completionHandler:) method to retrieve a PHContentEditingInput object.

In a photo editing extension that runs within the Photos app, your extension’s main view controller (which adopts the PHContentEditingController protocol) receives a PHContentEditingInput object when the user chooses to edit a Live Photo with your extension. 2. Create a Live Photo editing context with the init(livePhotoEditingInput:) initializer.

You can create a Live Photo editing context only from PHContentEditingInput object that represents a Live Photo. Use the livePhoto property of the editing input to verify that it has live Photo content. 3. Use the frameProcessor property to define a block to be used in processing the Live Photo’s visual content. Photos will call this block repeatedly to process each frame of the Live Photo’s video and still photo content. 4. Create a PHContentEditingOutput object to store the results of your edit, then call the saveLivePhoto(to:options:completionHandler:) to process the Live Photo and save it to your editing output object. This method applies your frameProcessor to each frame.

  1. To allow a user to continue working with the edit later (for example, to adjust the parameters of a filter), create a PHAdjustmentData object describing your changes, and store it in the adjustmentData property of your editing output.

  2. In an app using the Photos framework, use a photo library change block to commit the edit. (For details, see PHPhotoLibrary.) In the block, create a PHAssetChangeRequest object and set its contentEditingOutput property to the editing output that you created.

In a photo editing extension, provide the PHContentEditingOutput object that you created in your main view controller’s finishContentEditing(completionHandler:) method.

When you use either of the methods listed in Processing an Editing Context’s Live Photo, Photos calls your frameProcessor block repeatedly to process each frame of the Live Photo’s video and still photo content. In that block, a PHLivePhotoFrame object provides the Live Photo’s existing content as a CIImage object. You use Core Image to modify the image, then provide the result of your edits by returning a CIImage object representing the result of processing the input image.

Topics

Creating a Live Photo Editing Context

Preparing an Editing Context for Processing

Processing an Editing Context’s Live Photo

Examining an Editing Context’s Live Photo

Errors

See Also

Editing an Asset