在多个线程上处理实时照片

Hen*_*rik 6 core-image swift phlivephoto

我正在使用.frameProcessor处理PHLivePhoto来修改每个帧。帧似乎是按顺序处理的,这很慢。我可以让PHLivePhotoEditingContext.frameProcessor充分利用多个核心吗?

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
}
Run Code Online (Sandbox Code Playgroud)

Fra*_*gel 0

恐怕在这种情况下无法并行化帧处理。你必须记住:

  • 视频帧需要按顺序写入。
  • 并行处理的帧越多,需要的内存就越多。
  • Core Image 正在 GPU 上处理帧,无论如何,GPU 通常一次只能处理一帧。
  • 无论如何,您expensiveOperation并没有真正发生在frameProcessor块中,因为实际渲染是由此范围之外的框架处理的。