美文网首页
CMSampleBufferRef转换为UIImage

CMSampleBufferRef转换为UIImage

作者: Leoeoo | 来源:发表于2019-11-27 20:19 被阅读0次
    - (UIImage *)imageFromSampleBuffer:(CMSampleBufferRef)sampleBuffer {
        
        CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
        CIImage *ciImage = [CIImage imageWithCVPixelBuffer:imageBuffer];
        CIContext *temporaryContext = [CIContext contextWithOptions:nil];
        CGImageRef videoImage = [temporaryContext createCGImage:ciImage fromRect:CGRectMake(0, 0, CVPixelBufferGetWidth(imageBuffer), CVPixelBufferGetHeight(imageBuffer))];
        
        UIImage *image = [[UIImage alloc] initWithCGImage:videoImage];
        CGImageRelease(videoImage);
        
        return image;
    }
    

    参考文章:https://www.jianshu.com/p/4b4d44c6be1d

    https://zhuanlan.zhihu.com/p/24762605

    相关文章

      网友评论

          本文标题:CMSampleBufferRef转换为UIImage

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