__availableRawPhotoPixelFormatTypes在iPhone 7+和iOS11上为空



我正在尝试用AVFoundation捕获RAW文件。然而,我在__availableRawPhotoPixelFormatTypes中得到了空数组

这是我的片段

if self._photoOutput == nil {
self._photoOutput = AVCapturePhotoOutput()
print(self._photoOutput!.__availableRawPhotoPixelFormatTypes)
}

输出为空数组[]

是什么原因造成的?

以下三件事将导致availableRawPhotoPixelFormatTypes数组为空:

  1. 在使用视频源将_photoOutput添加到AVCaptureSession之前,您正在读取availableRawPhotoPixelFormatTypes属性。

  2. 您正在使用双摄像头输入。如果是,则无法捕获RAW图像。

  3. 您正在使用前置摄像头。如果是,则无法捕获RAW图像。

这是一个优秀的苹果指南中的一些修改过的示例代码(请参阅下面的链接)。为了简洁、简单和更好的概述,我从几个地方复制了它,并对其进行了轻微更新:

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.
}

苹果的照片捕获指南:https://developer.apple.com/library/content/documentation/AudioVideo/Conceptual/PhotoCaptureGuide/index.html

availableRawPhotoPixelFormatTypes属性:https://developer.apple.com/documentation/avfoundation/avcapturephotooutput/1778628-availablerawphotopixelformattype)

iPhone摄像头功能:https://developer.apple.com/library/content/documentation/DeviceInformation/Reference/iOSDeviceCompatibility/Cameras/Cameras.html

@Thomas回答的一个补充:

如果更改AVCaptureDevice.activeFormat,则AVCaptureSession.sessionPreset将自动设置为inputPriority。在这种情况下,availableRawPhotoPixelFormatTypes也将为空。

相关内容

最新更新