像素格式:kCVPixelFormatType_32BGRA 与 AVVideoCodecJPEG

Giz*_*odo 5 avfoundation ios cmsamplebuffer swift

我正在尝试找出哪种方法可以更好地捕获 JPEG

AVFoundation -> PhotoCaptureDelegate

我可以用:

photoSettings = AVCapturePhotoSettings(format: [ kCVPixelBufferPixelFormatTypeKey as String: Int(kCVPixelFormatType_32BGRA) ])
Run Code Online (Sandbox Code Playgroud)

或者

photoSettings = AVCapturePhotoSettings(format: [AVVideoCodecKey : AVVideoCodecJPEG, AVVideoCompressionPropertiesKey : [AVVideoQualityKey : 1.0]] as [String : Any])
Run Code Online (Sandbox Code Playgroud)

我注意到使用AVVideoCodecJPEG,我可以使用压缩质量;但是,如果我在PhotoCaptureDelegate中的CMSampleBuffer中执行任何 TIFF 转换或其他任务,则无法使用。

然而,如果我想以新的方式保存到 JPEG(猜测最有效的方式,我必须使用AVVideoCodecJPEG来执行以下操作:

func capture(_ captureOutput: AVCapturePhotoOutput, didFinishProcessingPhotoSampleBuffer photoSampleBuffer: CMSampleBuffer?, previewPhotoSampleBuffer: CMSampleBuffer?, resolvedSettings: AVCaptureResolvedPhotoSettings, bracketSettings: AVCaptureBracketedStillImageSettings?, error: Error?) {

    self.jpegPhotoData = AVCapturePhotoOutput.jpegPhotoDataRepresentation(forJPEGSampleBuffer: photoSampleBuffer, previewPhotoSampleBuffer: previewPhotoSampleBuffer)

    }
Run Code Online (Sandbox Code Playgroud)

使用哪个更好?