Skip to content

Instantly share code, notes, and snippets.

public func flipCamera() {
sessionQueue.async { [unowned self] in
self.captureSession.beginConfiguration()
guard let currentCaptureInput = self.captureSession.inputs.first as? AVCaptureInput else { return }
self.captureSession.removeInput(currentCaptureInput)
guard let currentCaptureOutput = self.captureSession.outputs.first as? AVCaptureOutput else { return }
self.captureSession.removeOutput(currentCaptureOutput)
self.position = self.position == .front ? .back : .front
self.configureSession()
self.captureSession.commitConfiguration()
@b-r-o
b-r-o / FrameExtractor.swift
Created May 3, 2017 20:40
Update the camera position and configure session
self.position = self.position == .front ? .back : .front
self.configureSession()
@b-r-o
b-r-o / FrameExtractor.swift
Created May 3, 2017 20:37
Remove the output
guard let currentCaptureOutput = self.captureSession.outputs.first as? AVCaptureOutput else { return }
self.captureSession.removeOutput(currentCaptureOutput)
@b-r-o
b-r-o / FrameExtractor.swift
Created May 3, 2017 20:36
Remove the current input device
guard let currentCaptureInput = self.captureSession.inputs.first as? AVCaptureInput else { return }
self.captureSession.removeInput(currentCaptureInput)
@b-r-o
b-r-o / FrameExtractor.swift
Created May 3, 2017 20:33
Work on a background thread, begin and commit configuration
public func flipCamera() {
sessionQueue.async { [unowned self] in
self.captureSession.beginConfiguration()
// We're going to do all the changes here
self.captureSession.commitConfiguration()
}
}
@b-r-o
b-r-o / FrameExtractor.swift
Created May 3, 2017 20:29
Call the flip camera method
public func flipCamera() {
}
@b-r-o
b-r-o / FrameExtractor.swift
Created April 29, 2017 20:23
Start capturing images again
captureSession.startRunning()
captureSession.stopRunning()
@b-r-o
b-r-o / FrameExtractor.swift
Last active December 9, 2019 15:21
TL;DR?
import UIKit
import AVFoundation
protocol FrameExtractorDelegate: class {
func captured(image: UIImage)
}
class FrameExtractor: NSObject, AVCaptureVideoDataOutputSampleBufferDelegate {
private let position = AVCaptureDevicePosition.front
@b-r-o
b-r-o / FrameExtractor.swift
Created January 2, 2017 23:07
Clean permission request mechanism
init() {
checkPermission()
sessionQueue.async { [unowned self] in
self.configureSession()
self.captureSession.startRunning()
}
}
// MARK: AVSession configuration
private func checkPermission() {