self.videoOutput = AVCaptureVideoDataOutput() self.videoOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey as AnyHashable : kCVPixelFormatType_32BGRA]
AVCaptureVideoDataOutput setVideoSettings: Nicht unterstützte Pixelformattyp in iOS10
wirft
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[AVCaptureVideoDataOutput setVideoSettings:] Unsupported pixel format type - use -availableVideoCVPixelFormatTypes'
Okay, so dass ich dachte die verfügbaren Pixelformattypen zu überprüfen.
(lldb) po self.videoOutput.availableVideoCVPixelFormatTypes ▿ Optional<Array<Any>> ▿ some : 3 elements - 0 : 875704438 - 1 : 875704422 - 2 : 1111970369
Das ist nicht viel geholfen hat. Glücklicherweise gibt es in this answer eine Kategorie, die die PixelFormat-Namen aus NSNumbers ausgibt.
(lldb) po (self.videoOutput.availableVideoCVPixelFormatTypes[2] as! NSNumber).descriptivePixelFormat() Optional<String> - some : "kCVPixelFormatType_32BGRA"
Hmm, also denke ich, 32BGRA schließlich unterstützt wird? Also habe ich versucht, Werte direkt aus dem Array der verfügbaren Formattypen bekommen:
self.videoOutput.videoSettings = [ kCVPixelBufferPixelFormatTypeKey as AnyHashable : self.videoOutput.availableVideoCVPixelFormatTypes.first!]
und
self.videoOutput.videoSettings = [ kCVPixelBufferPixelFormatTypeKey as AnyHashable : self.videoOutput.availableVideoCVPixelFormatTypes.last!]
und beide warfen die gleiche Ausnahme.
Ich habe kein zweites Gerät auf ATM zu testen. aber ich erinnere mich, dass ich vor einem Jahr denselben Code auf iOS9 und einem anderen Gerät verwendet habe.
IOS 10, XCode 8, iPhone SE