Class

PHLivePhotoEditingContext

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

Declaration

class PHLivePhotoEditingContext : NSObject

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.

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

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

init?(livePhotoEditingInput: PHContentEditingInput)

Creates a Live Photo editing context for the specified editing input.

Preparing an Editing Context for Processing

var frameProcessor: PHLivePhotoFrameProcessingBlock?

A block to be called by Photos for processing each frame of the Live Photo’s visual content.

typealias PHLivePhotoFrameProcessingBlock

The signature for a block Photos calls to process Live Photo frames.

var audioVolume: Float

The audio gain to apply to the processed Live Photo.

Processing an Editing Context’s Live Photo

func saveLivePhoto(to: PHContentEditingOutput, options: [String : Any]?, completionHandler: (Bool, Error?) -> Void)

Processes and saves a full-quality Live Photo as the output of your editing session.

struct PHLivePhotoEditingOption

Keys for the options dictionary used with the methods listed in Processing an Editing Context’s Live Photo.

func cancel()

Aborts any Live Photo processing in progress.

Examining an Editing Context’s Live Photo

var fullSizeImage: CIImage

The unedited still photo content of the Live Photo.

var duration: CMTime

The duration, in seconds, of the Live Photo.

var photoTime: CMTime

The offset, in seconds, from the beginning of the Live Photo’s duration to the time corresponding to its still photo.

var orientation: CGImagePropertyOrientation

The image orientation of the Live Photo.

Errors

let PHLivePhotoEditingErrorDomain: String

The domain value for error objects produced by a Live Photo editing context.

Deprecated
enum PHLivePhotoEditingErrorCode

Error codes for Live Photo editing errors.

Relationships

Inherits From

Conforms To

See Also

Editing an Asset

Editing Asset Content

Make a request to modify and save a photo or video asset.

class PHContentEditingInput

A container that provides information about and access to the image, video, or Live Photo content of an asset to be edited.

class PHContentEditingOutput

A container to which you provide the results of editing the photo, video, or Live Photo content of a Photos asset.

class PHAdjustmentData

A description of the edits made to an asset's photo, video, or Live Photo content, which allows your app to reconstruct or revert the effects of prior editing sessions.

class PHContentEditingInputRequestOptions

A set of options affecting the delivery of image or video data when you request to edit the content of a Photos asset.

protocol PHLivePhotoFrame

A container that provides image content for a single frame of a Live Photo in an editing context.

func canPerform(PHAssetEditOperation) -> Bool

Returns whether the asset supports the specified editing operation.

enum PHAssetEditOperation

Values identifying possible actions an asset can support, used by the canPerform(_:) method.

func cancelContentEditingInputRequest(PHContentEditingInputRequestID)

Cancels a request for editing the asset’s content.

typealias PHContentEditingInputRequestID

An identifier for an asset content editing session.

Editing Request Info Keys

Keys indicating the status of an asset content editing request, used in the completion handler of the requestContentEditingInput(with:completionHandler:) method.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software