Displaying a processed image from AVCaptureVideoDataOutput in a swiftUI view?

What is the recommended way of showing a processed image from AVCaptureVideoDataOutput in a swiftUI view?

Currently my chain is AVCaptureVideoDataOutput(SampleBuffer) -> CIImage -> CIFilters -> createCGImage from processed CIImage -> Create swiftUI 'Image' from CGIImage, that is in a view

Is there a better way to go from AVCaptureVideoDataOutput to a swiftUI view, with image processing?

Answered by Engineer in 891413022

To get the best performance, you want to render the CIImage using a SwiftUI view via Metal.

There is a presentation from WWDC 22 that describes how to do this https://developer.apple.com/fr/videos/play/wwdc2022/10114/

There is also an associated sample code project: https://developer.apple.com/documentation/CoreImage/generating-an-animation-with-a-core-image-render-destination

Accepted Answer

To get the best performance, you want to render the CIImage using a SwiftUI view via Metal.

There is a presentation from WWDC 22 that describes how to do this https://developer.apple.com/fr/videos/play/wwdc2022/10114/

There is also an associated sample code project: https://developer.apple.com/documentation/CoreImage/generating-an-animation-with-a-core-image-render-destination

Thank you

Displaying a processed image from AVCaptureVideoDataOutput in a swiftUI view?
 
 
Q