像素格式:kCVPixelFormatType_32BGRA与AVVideoCodecJPEG

时间:2017-04-02 21:25:09

标签: ios swift avfoundation cmsamplebuffer

我试图找出哪种方法能更好地捕捉JPEG

AVFoundatation - >的 PhotoCaptureDelegate

我可以使用:

photoSettings = AVCapturePhotoSettings(format: [ kCVPixelBufferPixelFormatTypeKey as String: Int(kCVPixelFormatType_32BGRA) ])

photoSettings = AVCapturePhotoSettings(format: [AVVideoCodecKey : AVVideoCodecJPEG, AVVideoCompressionPropertiesKey : [AVVideoQualityKey : 1.0]] as [String : Any])

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

是的,如果我想以新的方式保存到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)

    }

哪个更好用?

0 个答案:

没有答案