我解决了这个,通过继承GPUImageFilter和GPUImageFilterGroup。 在GPUImageFilter我重载方法
- (void)newFrameReadyAtTime:(CMTime)frameTime atIndex:(NSInteger)textureIndex
<...>
[self renderToTextureWithVertices:imageVertices textureCoordinates:[[self class] textureCoordinatesForRotation:inputRotation]];
_bufferCallback(self);
[self informTargetsAboutNewFrameAtTime:frameTime];
<...>
在GPUImageFilterGroup我重载的方法:从preLast滤波器
- (void)addFilter:(GPUImageOutput<GPUImageInput> *)newFilter
{
NSParameterAssert([newFilter isKindOfClass: [FAEShiftFilterWithBackOutputBuffer class]]);
if ([newFilter isKindOfClass:[FAEShiftFilterWithBackOutputBuffer class]])
{
__weak typeof(self) selfWeak = self;
[(FAEShiftFilterWithBackOutputBuffer*)newFilter setOutputBufferCallback:^(FAEShiftFilterWithBackOutputBuffer *sender) {
__strong typeof(selfWeak) selfStrong = selfWeak;
if (selfStrong)
{
if (!selfStrong.lastFramebuffer)
{
if ([selfStrong isPreLastFilter:sender])
{
selfStrong.lastFramebuffer = [sender framebufferForOutput];
[selfStrong.lastFramebuffer lock];
}
}
}
}];
}
[super addFilter:newFilter];
}
这种方法存储outputFrameBuffer。 和方法:在dealloc中和forceProcessingAtSize和forceProcessingAtSizeRespectingAspectRatio方法
- (void)newFrameReadyAtTime:(CMTime)frameTime atIndex:(NSInteger)textureIndex
{
if (self.filterCount > 1)
{
if (self.lastFramebuffer)
{
GPUImageFilter* lastFilter = (GPUImageFilter*)self.terminalFilter;
[lastFilter setInputFramebuffer:self.lastFramebuffer atIndex:0];
[lastFilter newFrameReadyAtTime:frameTime atIndex:textureIndex];
}
else
{
[super newFrameReadyAtTime:frameTime atIndex:textureIndex];
}
}
else
{
[super newFrameReadyAtTime:frameTime atIndex:textureIndex];
}
}
我也复位保存帧缓冲。
- (void)_clearLastFrameBuffer
{
if (_lastFramebuffer)
{
[_lastFramebuffer unlock];
_lastFramebuffer = nil;
}
}