frameProcessor
frameProcessor
frameProcessor Instance Property of PHLivePhotoEditingContext A block to be called by Photos for processing each frame of the Live Photo’s visual content.
var frameProcessor: PHLivePhotoFrameProcessingBlock? { get set }Discussion
Use this property to define the image processing to be performed on each frame of the Live Photo. Setting this property does not begin processing; instead, after you call one of the methods listed in Processing an Editing Context’s Live Photo, Photos executes your block repeatedly to process each frame of the Live Photo’s video and still photo content.
In your frame processor block, use the image property of the provided PHLivePhotoFrame object to access the image to be processed, and return a CIImage object representing the result of your processing. For example, the following code sets up a processor block to apply a simple sepia-tone filter, then calls the saveLivePhoto(to:options:completionHandler:)) method to begin processing the Live Photo for output.
Swift:
func processLivePhoto(input: PHContentEditingInput) {
guard let context = PHLivePhotoEditingContext(livePhotoEditingInput: input)
else { fatalError("not a Live Photo editing input") }
context.frameProcessor = { frame, _ in
return frame.image.applyingFilter("CISepiaTone", withInputParameters: nil)
}
let output = PHContentEditingOutput(contentEditingInput: input)
context.saveLivePhoto(to: output) { success, error in
if success {
// use output with PHAssetChangeRequest or PHContentEditingController
} else {
print("can't process live photo: \(error)")
}
}
}Objective-C:
- (void)processLivePhoto:(PHContentEditingInput *)input {
PHLivePhotoEditingContext *context = [[PHLivePhotoEditingContext alloc] initWithLivePhotoEditingInput:input];
context.frameProcessor = ^CIImage *(id <PHLivePhotoFrame> frame, NSError **error) {
return [frame.image imageByApplyingFilter:@"CISepiaTone" withInputParameters:nil];
}
PHContentEditingOutput *output = [[PHContentEditingOutput alloc] initWithContentEditingInput: input];
[context saveLivePhotoToOutput:output options:nil completionHandler:^(PHLivePhoto *livePhoto, NSError *error) {
if (success) {
// use output with PHAssetChangeRequest or PHContentEditingController
} else {
NSLog(@"can't process: %@", error);
}
];
}