Process Live Photos on multiple threads
Asked Answered
B

1

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
}
Background answered 4/10, 2019 at 12:38 Comment(0)
H
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.
Hagan answered 4/10, 2019 at 13:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.