7

I am processing a PHLivePhoto using .frameProcessor to modify each frame. The frames appear to be processed in sequence, which is slow. Can I get PHLivePhotoEditingContext.frameProcessor to take advantage of more than one core?

func processLivePhoto(input: PHContentEditingInput) {
    guard let context = PHLivePhotoEditingContext(livePhotoEditingInput: input)
        else { fatalError("not a Live Photo editing input") }
    context.frameProcessor = { frame, _ in
        let renderedFrame = expensiveOperation(using: frame.image)
        return renderedFrame
    }
    // ...logic for saving
}
Henrik
  • 3,908
  • 27
  • 48

1 Answers1

0

I'm afraid there's no way to parallelize the frame processing in this case. You have to keep in mind:

  • Video frames need to be written in order.
  • The more frames you would process in parallel, the more memory you would need.
  • Core Image is processing the frames on the GPU, which can usually only process one frame at a time anyways.
  • Your expensiveOperation is not really happening in the frameProcessor block anyways, since the actual rendering is handled by the framework outside this scope.
Frank Rupprecht
  • 9,191
  • 31
  • 56