AVCaptureSession with multiple previews

后端 未结 5 1069
花落未央
花落未央 2020-11-28 21:48

I have an AVCaptureSession running with an AVCaptureVideoPreviewLayer.

I can see the video so I know it\'s working.

However, I\'d like to have a collection v

5条回答
  •  自闭症患者
    2020-11-28 22:23

    Simply set the contents of the preview layer to another CALayer:

    CGImageRef cgImage = (__bridge CGImage)self.previewLayer.contents; self.duplicateLayer.contents = (__bridge id)cgImage;

    You can do this with the contents of any Metal or OpenGL layer. There was no increase in memory usage or CPU load on my end, either. You're not duplicating anything but a tiny pointer. That's not so with these other "solutions."

    I have a sample project that you can download that displays 20 preview layers at the same time from a single camera feed. Each layer has a different effect applied to our.

    You can watch a video of the app running, as well as download the source code at:

    https://demonicactivity.blogspot.com/2017/05/developer-iphone-video-camera-wall.html?m=1

提交回复
热议问题