Google Face Detection crashing when converting to

2019-08-04 11:44发布

I am creating a custom camera with filters. When I add the following line it crashes without showing any exception.

//Setting video output

func setupBuffer() {
    videoBuffer = AVCaptureVideoDataOutput()
    videoBuffer?.alwaysDiscardsLateVideoFrames = true
    videoBuffer?.videoSettings = [(kCVPixelBufferPixelFormatTypeKey as NSString): NSNumber(value: kCVPixelFormatType_32RGBA)]
    videoBuffer?.setSampleBufferDelegate(self, queue: DispatchQueue.main)
    captureSession?.addOutput(videoBuffer)
}


public func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, from connection: AVCaptureConnection!) {

    if connection.videoOrientation != .portrait {
        connection.videoOrientation = .portrait
    }
        guard let image = GMVUtility.sampleBufferTo32RGBA(sampleBuffer) else {
            print("No Image                 

1条回答
爷、活的狠高调
2楼-- · 2019-08-04 12:15

1) Create separate queue for buffer.

 fileprivate var videoDataOutputQueue = DispatchQueue(label: "VideoDataOutputQueue")

2) Setup buffer with this

        let videoBuffer = AVCaptureVideoDataOutput()
        videoBuffer?.alwaysDiscardsLateVideoFrames = true
        videoBuffer?.videoSettings = [(kCVPixelBufferPixelFormatTypeKey as NSString): NSNumber(value: kCVPixelFormatType_32BGRA)]
        videoBuffer?.setSampleBufferDelegate(self, queue: videoDataOutputQueue ) //
        captureSession?.addOutput(videoBuffer)
查看更多
登录 后发表回答