Created
October 8, 2021 14:57
-
-
Save anupamchugh/9866d8b401c255a5a337a14c15ca09fb to your computer and use it in GitHub Desktop.
This file contains 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 lazy var previewLayer = AVCaptureVideoPreviewLayer(session: self.captureSession) | |
private let videoDataOutput = AVCaptureVideoDataOutput() | |
private func showCameraFeed() { | |
self.previewLayer.videoGravity = .resizeAspectFill | |
self.view.layer.addSublayer(self.previewLayer) | |
self.previewLayer.frame = self.view.frame | |
} | |
private func setCameraOutput() { | |
self.videoDataOutput.videoSettings = [(kCVPixelBufferPixelFormatTypeKey as NSString) : NSNumber(value: kCVPixelFormatType_32BGRA)] as [String : Any] | |
self.videoDataOutput.alwaysDiscardsLateVideoFrames = true | |
self.videoDataOutput.setSampleBufferDelegate(self, queue: DispatchQueue(label: "camera_frame_processing_queue")) | |
self.captureSession.addOutput(self.videoDataOutput) | |
guard let connection = self.videoDataOutput.connection(with: AVMediaType.video), | |
connection.isVideoOrientationSupported else { return } | |
connection.videoOrientation = .portrait | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment