如何在func Capture中仅处理1/10帧

时间:2018-09-18 07:09:43

标签: ios swift macos

我正在按照以下方法对帧进行某种处理

func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {}

但是我不想在所有帧中都这样做,比如说我想要1/15或1/10,如何实现此目标?swift是否提供了任何预构建逻辑?

1 个答案:

答案 0 :(得分:0)

您可以在类中添加一个计数器,然后在 captureOutput

中增加它
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection){
i += 1
   if (i % 15 == 0) //every 15 frames
   {
   //process your frame
   }
}