我正在使用AVFoundation拍摄照片。但无论如何我改变了sessionPreset,输出仍为videoDevice.activeFormat Optional(<AVCaptureDeviceFormat: 0x608000001eb0> 'vide'/'2vuy' enc dims = 1280x720, pres dims = 1280x720 { 29.97 25.00 24.00 15.00 fps })
我想要的只是将输出更改为高质量。
我的整个代码是
self.avCaptureSession = AVCaptureSession()
let devices = AVCaptureDevice.devices()
self.avCurrentCaptureDevice = devices!.last as? AVCaptureDevice
do {
self.avCaptureInput = try AVCaptureDeviceInput(device: self.avCurrentCaptureDevice)
} catch {
}
do {
try self.avCurrentCaptureDevice?.lockForConfiguration()
} catch {
return
}
self.avCaptureSession?.beginConfiguration()
self.avCaptureSession?.addInput(self.avCaptureInput)
self.avCaptureSession?.sessionPreset = AVCaptureSessionPreset320x240
self.avOutput = AVCaptureVideoDataOutput()
if (self.avCaptureSession?.canAddOutput(self.avOutput) != nil) {
self.avCaptureSession?.addOutput(self.avOutput)
}
self.avOutput?.videoSettings = [(kCVPixelBufferPixelFormatTypeKey as NSString) : NSNumber(value: kCVPixelFormatType_32BGRA as UInt32)]
self.avOutput?.alwaysDiscardsLateVideoFrames = true
let queue: DispatchQueue = DispatchQueue(label: "myqueue", attributes: [])
self.avOutput?.setSampleBufferDelegate(self, queue: queue)
self.avCaptureSession?.commitConfiguration()
print("videoDevice.activeFormat", self.avCurrentCaptureDevice?.activeFormat! as Any)
答案 0 :(得分:0)