Created
March 23, 2017 03:36
-
-
Save jkmathew/fbfe8c2d015adb448c330687320ada91 to your computer and use it in GitHub Desktop.
Startin av capture layer from a view controller
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
func startSession() { | |
//Capture Session | |
let session = AVCaptureSession() | |
session.sessionPreset = AVCaptureSessionPresetPhoto | |
//Add device | |
let device = | |
AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo) | |
//Input | |
do { | |
let input = try AVCaptureDeviceInput.init(device: device) | |
session.addInput(input) | |
//Output | |
let output = AVCaptureVideoDataOutput() | |
session.addOutput(output) | |
output.videoSettings = | |
[kCVPixelBufferPixelFormatTypeKey as AnyHashable : kCVPixelFormatType_32BGRA]; | |
//Preview Layer | |
let previewLayer = AVCaptureVideoPreviewLayer.init(session: session) | |
previewLayer?.frame = view.bounds; | |
previewLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill; | |
view.layer.addSublayer(previewLayer!) | |
//Start capture session | |
session.startRunning(); | |
} | |
catch let error { | |
print(error) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment