func screenshotOfVideoStream(sampleBuffer: CMSampleBuffer?) -> UIImage? {
guard let sampleBuffer = sampleBuffer else { return nil }
guard let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return nil }
let ciImage = CIImage(cvPixelBuffer: imageBuffer)
let temporaryContext = CIContext(options: nil)
guard let cgImage = temporaryContext.createCGImage(ciImage, from: ciImage.extent) else { return nil }
let image = UIImage(cgImage: cgImage, scale: UIScreen.main.scale, orientation: .right)
return image
}
网友评论