我解決了這個,通過繼承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;
}
}