本文介绍了像素格式,CVPixelBufferRefs和glReadPixels的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在使用 glReadPixels 将数据读入 CVPixelBufferRef 。我使用 CVPixelBufferRef 作为 AVAssetWriter 的输入。不幸的是,像素格式似乎不匹配。 我认为 glReadPixels 返回 RGBA 格式的像素数据,而 AVAssetWriter 想要 ARGB 格式的像素数据。将 RGBA 转换为 ARGB 的最佳方法是什么? 这是我到目前为止所尝试的内容: 沿argb =(rgba >> 8)行的位操作(rgba<< 24) 使用 CGImageRef 作为中间步骤 位操作不起作用,因为CVPixelBufferRef似乎不支持下标。 CGImageRef 中间步骤确实有效...但我不希望有50行额外的代码可能会影响性能。解决方案比使用CPU交换组件更好的是编写一个简单的片段着色器,以便在渲染图像时在GPU上有效地执行此操作。 最好的方法是使用iOS5 CoreVideo CVOpenGLESTextureCache完全删除复制阶段,它允许您直接渲染到CVPixelBufferRef,从而消除了对glReadPixels的调用。 / p> ps我很确定AVAssetWriter想要BGRA格式的数据(实际上它可能想要它在yuv中,但这是另一个故事)。 更新:至于链接,doco似乎仍然在NDA之下,但有两个可免费下载的示例代码: GLCameraRipple 和 RosyWriter 头文件本身包含很好的文档,并且mac等价物非常相似(CVOpenGLTextureCache),所以你应该有足够的东西让你开始。 I'm using glReadPixels to read data into a CVPixelBufferRef. I use the CVPixelBufferRef as the input into an AVAssetWriter. Unfortunately the pixel formats seem to be mismatched. I think glReadPixels is returning pixel data in RGBA format while AVAssetWriter wants pixel data in ARGB format. What's the best way to convert RGBA to ARGB?Here's what I've tried so far:bit manipulation along the lines of argb = (rgba >> 8) | (rgba << 24)using a CGImageRef as an intermediate stepThe bit manipulation didn't work because CVPixelBufferRef doesn't seem to support subscripts. The CGImageRef intermediate step does work... but I'd prefer not to have 50 extra lines of code that could potentially be a performance hit. 解决方案 Better than using the CPU to swap the components would be to write a simple fragment shader to efficiently do it on the GPU as you render the image. And the best bestest way is to completely remove the copying stage by using an iOS5 CoreVideo CVOpenGLESTextureCache which allows you to render straight to the CVPixelBufferRef, eliminating the call to glReadPixels.p.s. I'm pretty sure AVAssetWriter wants data in BGRA format (actually it probably wants it in yuv, but that's another story). UPDATE: as for links, the doco seems to still be under NDA, but there are two pieces of freely downloadable example code available:GLCameraRipple and RosyWriterThe header files themselves contain good documentation, and the mac equivalent is very similar (CVOpenGLTextureCache), so you should have plenty to get you started. 这篇关于像素格式,CVPixelBufferRefs和glReadPixels的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-26 14:32