How to Instantiate AVCapturePhotoSettings( format: [string:string] )

102 views Asked by At

I tried various ways to attempt to instantiate the class: AVCapturePhotoSettings to capture images in lossless BGRA format as listed below:

let settings = AVCapturePhotoSettings(format: [ kCVPixelBufferPixelFormatTypeKey : "BGRA"] )
    
let settings = AVCapturePhotoSettings(format: [ kCVPixelBufferPixelFormatTypeKey as String : "BGRA"] )
    
let settings = AVCapturePhotoSettings(format: [ String( kCVPixelBufferPixelFormatTypeKey) : "BGRA"] 
    
let settings = AVCapturePhotoSettings(format: [ "kCVPixelBufferPixelFormatTypeKey" : "BGRA"] )

The first attempt gets the compile time error:

Cannot convert value of type 'CFString' to expected dictionary key type 'String'

and so the three additional attempts below the first above were done, but each of these attempts got the run time error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[AVCapturePhotoSettings photoSettingsWithFormat:] Either kCVPixelBufferPixelFormatTypeKey or AVVideoCodecKey must be specified'

What is the correct way to use this initiator for the class: AVCapturePhotoSettings ?

0

There are 0 answers