5
Meine Methode Ändern didOutputSampleBuffer
erfolgreich aufgerufen wird, bis ich Kameras mit dieser Funktion wechseln:Kamera dropped Frames nach Kamera iOS
func switchCameras() {
captureSession.beginConfiguration()
captureSession.sessionPreset = AVCaptureSessionPresetMedium
var error : NSError? = nil
for input in captureSession.inputs {
captureSession.removeInput(input as! AVCaptureInput)
}
if currentCamera == "back" {
currentCamera = "front"
if captureSession.canAddInput(AVCaptureDeviceInput(device: frontCamera, error: &error)) {
captureSession.addInput(AVCaptureDeviceInput(device: frontCamera, error: &error))
} else {
print(error)
}
} else {
currentCamera = "back"
if captureSession.canAddInput(AVCaptureDeviceInput(device: backCamera, error: &error)) {
captureSession.addInput(AVCaptureDeviceInput(device: backCamera, error: &error))
} else {
}
}
print("chagned")
captureSession.commitConfiguration()
}
Nach dem Einschalten werden die Frames manchmal in diesem Verfahren fallen gelassen, so kann ich ein Bild nicht nehmen . Nach ungefähr 5 Sekunden kommen Frames zurück.
func captureOutput(captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, fromConnection connection: AVCaptureConnection!) {
connection.videoOrientation = AVCaptureVideoOrientation.Portrait
if capture == true {
self.capture = false
var newBuffer = sampleBuffer
self.capturePicture(newBuffer)
}
}
Wenn Sie mehr Code benötigen, lassen Sie es mich wissen.
Sie machen den Beispielpufferdelegaten tatsächlich zu dispatch_get_main_queue() oben. Sie verwenden die von Ihnen erstellte Warteschlange nicht. Wie wurde das behoben? – Gizmodo