Created
July 5, 2018 10:33
-
-
Save onmyway133/ab67d30238fb88a0c8af2752b79062d2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func setupAVSession() { | |
captureSession.beginConfiguration() | |
captureSession.sessionPreset = .high | |
defer { | |
captureSession.commitConfiguration() | |
} | |
// input | |
guard | |
let backCamera = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back), | |
let input = try? AVCaptureDeviceInput(device: backCamera), | |
captureSession.canAddInput(input) | |
else { | |
return | |
} | |
captureSession.addInput(input) | |
// output | |
let output = AVCaptureVideoDataOutput() | |
guard captureSession.canAddOutput(output) else { | |
return | |
} | |
captureSession.addOutput(output) | |
output.setSampleBufferDelegate(self, queue: DispatchQueue(label: "MyQueue")) | |
output.alwaysDiscardsLateVideoFrames = true | |
// connection | |
let connection = output.connection(with: .video) | |
connection?.videoOrientation = .portrait | |
// preview layer | |
cameraLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill | |
view.layer.addSublayer(cameraLayer) | |
view.layer.addSublayer(overlayLayer) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment