在多线程上处理Live Photos

7

我正在使用.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
}
1个回答

0

恐怕在这种情况下无法并行处理帧。您需要记住:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接