GPUImage Filter链(1)前言

摄像头采集的过程

(CMSampleBufferRef)sampleBuffer 
// 这里的sampleBuffer就是采集到的数据了,但它是Video还是Audio的数据,得根据connection来判断

如果把要从采集的数据中拿到视频数据呢?

CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
int width = CVPixelBufferGetWidth(pixelBuffer);
int height = CVPixelBufferGetHeight(pixelBuffer);

所以,CMSampleBufferRef和CVPixelBufferRef的关系就知道了

再看一篇文章就更清楚了

深入理解 CVPixelBufferRef

在iOS里,我们经常能看到 CVPixelBufferRef 这个类型,在Camera 采集返回的数据里得到一个CMSampleBufferRef,而每个CMSampleBufferRef里则包含一个 CVPixelBufferRef,在视频硬解码的返回数据里也是一个 CVPixelBufferRef。
顾名思义,CVPixelBufferRef 是一种像素图片类型,由于CV开头,所以它是属于 CoreVideo 模块的。

CVPixelBufferRef是可以转换成一个 openGL texture的,方法如下:

CVOpenGLESTextureRef pixelBufferTexture; 

CVOpenGLESTextureCacheCreateTextureFromImage(kCFAllocatorDefault,
                                             _textureCache,
                                             pixelBuffer,
                                             NULL,
                                             GL_TEXTURE_2D,
                                             GL_RGBA,
                                             width,
                                             height,
                                             GL_BGRA,
                                             GL_UNSIGNED_BYTE,
                                             0,
                                             &pixelBufferTexture);

其中,_textureCache 代表一个 Texture缓存,每次生产的Texture都是从缓存获取的,这样可以省掉反复创建Texture的开销,_textureCache要实现创建好,创建方法如下

CVOpenGLESTextureCacheCreate(kCFAllocatorDefault, NULL, _context, NULL, &_textureCache);

你可能感兴趣的:(GPUImage Filter链(1)前言)