简体   繁体   中英

AVCaptureVideoDataOutputSampleBufferDelegate with SceneKit and AVDeviceCapture background

I'm trying to grab the CVPixelBuffer while using the camera video feed as a background to SceneKit. Please note I cannot use ARKit for my project as I need the front + back camera and no world tracking overhead. Even attempting the most basic example:

let captureDevice = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back)
self.scnScene.background.contents = captureDevice

results in the following error in iOS 11.2:

[SceneKit] Error: Cannot get pixel buffer (CVPixelBufferRef)

Whenever this error pops up, the AVCaptureVideoDataOutputSampleBufferDelegate stops being called.

Since I was unable to simultaneously use the AVCaptureDevice as a background to SceneKit and grab its CVPixelBuffer , my solution was to render the sample buffer to a MTLTexture then apply that as a background to SceneKit. See here as a starting point:

https://developer.apple.com/documentation/arkit/displaying_an_ar_experience_with_metal

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM