__iPhone 7上的availableRawPhotoPixelFormatTypes为空;和iOS11
我正试图用AVFoundation捕获原始文件。但是,我在__iPhone 7上的availableRawPhotoPixelFormatTypes为空;和iOS11,ios,swift,avfoundation,rawimage,Ios,Swift,Avfoundation,Rawimage,我正试图用AVFoundation捕获原始文件。但是,我在\uuu可用的WPhotopixelFormatTypes中得到了空数组 这是我的片段 if self._photoOutput == nil { self._photoOutput = AVCapturePhotoOutput() print(self._photoOutput!.__availableRawPhotoPixelFormatTypes) } 并且输出为空数组[] 这可能是什么原因造成的 以下三个因素将导
\uuu可用的WPhotopixelFormatTypes中得到了空数组
这是我的片段
if self._photoOutput == nil {
self._photoOutput = AVCapturePhotoOutput()
print(self._photoOutput!.__availableRawPhotoPixelFormatTypes)
}
并且输出为空数组[]
这可能是什么原因造成的 以下三个因素将导致
availableRawPhotoPixelFormatTypes
数组为空:
\u photoOutput
添加到AVCaptureSession
之前,您正在阅读availableRawPhotoPixelFormatTypes
属性let session = AVCaptureSession()
let photoOutput = AVCapturePhotoOutput()
private func configureSession() {
// Get camera device.
guard let videoCaptureDevice = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back) else {
print("Unable to get camera device.")
return
}
// Create a capture input.
guard let videoInput = try? AVCaptureDeviceInput(device: videoCaptureDevice) else {
print("Unable to obtain video input for default camera.")
return
}
// Make sure inputs and output can be added to session.
guard session.canAddInput(videoInput) else { return }
guard session.canAddOutput(photoOutput) else { return }
// Configure the session.
session.beginConfiguration()
session.sessionPreset = .photo
session.addInput(videoInput)
// availableRawPhotoPixelFormatTypes is empty.
session.addOutput(photoOutput)
// availableRawPhotoPixelFormatTypes should not be empty.
session.commitConfiguration()
}
private func capturePhoto() {
// Photo settings for RAW capture.
let rawFormatType = kCVPixelFormatType_14Bayer_RGGB
// At this point the array should not be empty (session has been configured).
guard photoOutput.availableRawPhotoPixelFormatTypes.contains(NSNumber(value: rawFormatType).uint32Value) else {
print("No available RAW pixel formats")
return
}
let photoSettings = AVCapturePhotoSettings(rawPixelFormatType: rawFormatType)
photoOutput.capturePhoto(with: photoSettings, delegate: self)
}
// MARK: - AVCapturePhotoCaptureDelegate methods
func photoOutput(_ output: AVCapturePhotoOutput,
didFinishProcessingRawPhoto rawSampleBuffer: CMSampleBuffer?,
previewPhoto previewPhotoSampleBuffer: CMSampleBuffer?,
resolvedSettings: AVCaptureResolvedPhotoSettings,
bracketSettings: AVCaptureBracketedStillImageSettings?,
error: Error?) {
guard error == nil, let rawSampleBuffer = rawSampleBuffer else {
print("Error capturing RAW photo:\(error)")
return
}
// Do something with the rawSampleBuffer.
}
苹果的照片捕获指南:
可用的wphotopixelformatypes属性:
)
iPhone摄像头功能:
对于@Thomas的回答,有一个补充:
如果更改
AVCaptureDevice.activeFormat
,AVCaptureSession.sessionPreset
将自动设置为inputPriority
。在这种情况下,availableRawPhotoPixelFormatTypes
也将是空的。除了解释问题是什么之外,还可以提供一些代码来帮助解决问题。我意识到这可能与我尝试使用前置摄像头有关。我明白了,这是有意义的。我将更新答案以帮助未来的读者。我尝试使用除最大可用性以外的维度设置捕获设备格式。WPhotopixelFormatTypes也将为空。iOS 13.3是的,这个答案是正确的。我的解决方案是设置会话。会话再次按至。photo
将起作用这是Apple文档中的一个大漏洞。我不明白为什么availableRawPhotoPixelFormatTypes一直显示为没有记录。非常感谢。