【发布时间】:2015-01-13 23:08:43
【问题描述】:
我正在使用AVComposition 编写一些视频处理代码。仅提供必要的背景细节,我从我无法控制的苹果 API 收到CVPixelBuffer。此 CVPixel 缓冲区包含先前渲染的视频帧,因为它们显然是由我无法控制的 Apple API 回收的。所以我的目标是将 CVPixelBufferRef 中的所有像素设置为 [0, 0, 0, 0] (在 RGBA 颜色空间中)。我可以通过这个函数在 CPU 上做到这一点:
- (void)processPixelBuffer: (CVImageBufferRef)pixelBuffer
{
CVPixelBufferLockBaseAddress( pixelBuffer, 0 );
int bufferWidth = CVPixelBufferGetWidth(pixelBuffer);
int bufferHeight = CVPixelBufferGetHeight(pixelBuffer);
unsigned char *pixel = (unsigned char *)CVPixelBufferGetBaseAddress(pixelBuffer);
for( int row = 0; row < bufferHeight; row++ ) {
for( int column = 0; column < bufferWidth; column++ ) {
pixel[0] = 0;
pixel[1] = 0;
pixel[2] = 0;
pixel[3] = 0;
pixel += 4;
}
}
CVPixelBufferUnlockBaseAddress( pixelBuffer, 0 );
}
有什么方法可以让我使用 GPU 完成同样的事情吗?此外,是否可以通过 CoreImage 做到这一点?因为我不知道 openGL,而且设置起来似乎很复杂。
【问题讨论】:
标签: ios avfoundation core-video core-media