美文网首页
CMSampleBuffer 转 UIImage

CMSampleBuffer 转 UIImage

作者: 小白lf | 来源:发表于2023-01-13 18:06 被阅读0次
    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
    }
    

    相关文章

      网友评论

          本文标题:CMSampleBuffer 转 UIImage

          本文链接:https://www.haomeiwen.com/subject/cgswcdtx.html