Created
October 12, 2020 17:03
-
-
Save noppefoxwolf/77ab570018beee87efc03084b019313b to your computer and use it in GitHub Desktop.
draw to CALayer directory.
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
import UIKit | |
import AVFoundation | |
class ViewController: UIViewController, AVCaptureVideoDataOutputSampleBufferDelegate { | |
lazy var session: AVCaptureSession = .init() | |
lazy var input: AVCaptureDeviceInput = try! AVCaptureDeviceInput(device: device) | |
lazy var device: AVCaptureDevice = AVCaptureDevice.default(for: .video)! | |
lazy var output: AVCaptureVideoDataOutput = .init() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
session.addInput(input) | |
session.addOutput(output) | |
output.setSampleBufferDelegate(self, queue: .main) | |
session.startRunning() | |
} | |
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) { | |
view.layer.contents = sampleBuffer.imageBuffer | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment