从 willOutputSampleBuffer 或相关的抓取图像?

Grab an image from willOutputSampleBuffer or related?

所以,布拉德·拉尔森很棒。我正在使用他的 GPUImage 库,因为他针对视频输出优化了 CGContextCreateImage,而不是直接渲染到 OpenGL 中。然后他重写了它更神奇,一半的问题已经过时了。另一半有新的回调,Like this question,但对于我来说,我无法让视频帧回调不为零。 (CMSampleBuffer 到 CIImage 函数)

我知道我必须 "tag the next frame" 保存在内存中,感谢他的博客。我也知道我处理它(但 GPUImageVideo 也这样做),然后我从帧缓冲区中抓取。还是不行。

应该从 CGImagePicture 的 processImageUpToFilter 函数自动将其过滤到 CGImage 中的捕获命令似乎是我想要的,我已经看到它被提及,但我不知道如何连接输出到它的 frameBuffer。

或者我应该使用GPUImageRawDataOutput,如何连接?我一直在复制和粘贴、编辑、试验,但不确定这是否只是因为我对 openGL 的了解不足以连接正确的东西,或者?

感谢任何帮助。我不会问,因为这里有很多相关问题,但我使用了它们,但输出结果仍然为 nil。

这是我目前的尝试:

func willOutputSampleBuffer(sampleBuffer: CMSampleBuffer!) {
        gpuImageVideoCamera.useNextFrameForImageCapture()
        //Next line seems like a waste, as this func is called in GPUImageVideoCamera already.
        gpuImageVideoCamera.processVideoSampleBuffer(sampleBuffer);
        if let image = gpuImageVideoCamera.imageFromCurrentFramebuffer()
        {
          //it's nil
        }
}

似乎改用了过滤器,useNextFrame 应该在处理之后才不会变得超级慢。

在 willOutputSampleBuffer 内部,就是它。

    if let image = transformFilter.imageFromCurrentFramebuffer()
   {
        // image not nil now.
   }
   transformFilter.useNextFrameForImageCapture(); //enusre this comes after

这给了我们超过 Google 的 p2p 库的惊人速度。 Brad,谢谢,大家应该支持你的努力。