【问题标题】:Process Live Photos on multiple threads在多个线程上处理实时照片
【发布时间】:2020-02-02 19:17:17
【问题描述】:

我正在使用 .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
}

【问题讨论】:

    标签: swift core-image phlivephoto


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2017-11-06
      • 1970-01-01
      • 1970-01-01
      • 2012-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多