Skip to content

Instantly share code, notes, and snippets.

@azamsharp
Created May 10, 2018 19:44
Show Gist options
  • Save azamsharp/a3d264ffc8dbc1298689966712f77162 to your computer and use it in GitHub Desktop.
Save azamsharp/a3d264ffc8dbc1298689966712f77162 to your computer and use it in GitHub Desktop.
private func startLiveVideo() {
session.sessionPreset = AVCaptureSession.Preset.photo
let captureDevice = AVCaptureDevice.default(for: AVMediaType.video)
let deviceInput = try! AVCaptureDeviceInput(device: captureDevice!)
let deviceOutput = AVCaptureVideoDataOutput()
deviceOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey as String: Int(kCVPixelFormatType_32BGRA)]
deviceOutput.setSampleBufferDelegate(self, queue: DispatchQueue.global(qos: DispatchQoS.QoSClass.default))
session.addInput(deviceInput)
session.addOutput(deviceOutput)
let imageLayer = AVCaptureVideoPreviewLayer(session: session)
imageLayer.frame = CGRect(x: 0, y: 0, width: self.imageView.frame.size.width + 100, height: self.imageView.frame.size.height)
imageLayer.videoGravity = .resizeAspectFill
imageView.layer.addSublayer(imageLayer)
session.startRunning()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment