繁体   English   中英

__availableRawPhotoPixelFormatTypes 在 iPhone 7+ 和 iOS11 上为空

[英]__availableRawPhotoPixelFormatTypes is empty on iPhone 7+ and iOS11

我正在尝试使用 AVFoundation 捕获 RAW 文件。 但是我在__availableRawPhotoPixelFormatTypes得到了空数组

这是我的片段

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

并且输出是空数组[]

什么可能导致这种情况?

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

  1. 在将_photoOutput添加到带有视频源的AVCaptureSession之前,您正在阅读availableRawPhotoPixelFormatTypes属性。

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

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

这是来自优秀 Apple 指南的一些修改后的示例代码(请参阅下面的链接)。 为了简洁、简单和更好的概述,我从几个地方复制并稍微更新了它:

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

Apple 的照片拍摄指南: 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.activeFormatAVCaptureSession.sessionPreset将自动设置为inputPriority 在这种情况下, availableRawPhotoPixelFormatTypes也将为空。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM