2 years ago

#56142

test-img

tcurdt

Zoom into AVCaptureVideoPreviewLayer

I am setting up a AVCaptureVideoPreviewLayer which shows the full video input in the preview just fine. Now I want zoom into (the layer). I tried to scale and transform on the CALayer level. This does not seem to work for scaling though.

let layer = AVCaptureVideoPreviewLayer(session: session)
layer.videoGravity = AVLayerVideoGravity.resizeAspectFill
//layer.transform = CATransform3DMakeScale(4.0,4.0,1.0)
//layer.setAffineTransform(CGAffineTransform(scaleX: 4.0, y: 4.0))
//layer.contentsScale = 4;
layer.addSublayer(createOverlay())
view.layer!.addSublayer(layer)

Someone else asked a similar question, unfortunately the accepted answer was for a AVCaptureDevice, but in my case the input is an AVCaptureScreenInput. Here I also tried to change this at the source.

let input = AVCaptureScreenInput(displayID: displayId) {
//input.cropRect = CGRect(x: 0, y: 0, width: 400, height: 200)
//input.scaleFactor = 4.0
session.addInput(input)

So far none of the approaches have worked. What's the way to do this?

macos

avfoundation

core-animation

calayer

0 Answers

Your Answer

Accepted video resources