CMSampleBuffer 转 UIImage

2023-01-13  本文已影响0人  小白lf
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
}
上一篇下一篇

猜你喜欢

热点阅读