GPUImage:内存警告后过度释放帧缓冲区

时间:2015-03-02 17:22:15

标签: ios objective-c gpuimage

我开发了一个使用GPUImage框架的应用程序。我有一些问题。应用程序从摄像头捕获视频,在每个帧上添加一些附加信息,并将其存储在文件中。视频写入可以被用户或系统中断,并且可以重新启动。在几次开始/停止记录迭代之后,应用程序在断言中收到内存警告和应用程序崩溃:

NSAssert(framebufferReferenceCount > 0, @"Tried to overrelease a framebuffer, did you forget to call -useNextFrameForImageCapture before using -imageFromCurrentFramebuffer?");

以下是我配置GPUImage的方法:

enter image description here

首先,我打开相机并配置预览:

-(void)openCamera:(NSString *)preset
{
    self.camera = [[GPUImageVideoCamera alloc] initWithSessionPreset:preset
                                                      cameraPosition:AVCaptureDevicePositionBack];
    self.camera.outputImageOrientation = self.orientation;
    [self.camera addTarget:self.preview];

    [self.camera startCameraCapture];
}

其次,当用户按下按钮时,我开始录制

-(void)addMovieWriter
{
    self.writingChain = [GPUImageFilter new];

    self.blendFilter = [GPUImageNormalBlendFilter new];
    [self.writingChain addTarget:self.blendFilter];

    self.uiElement = [[GPUImageUIElement alloc] initWithView:_internalView];
    [self.uiElement addTarget:self.blendFilter];

    __weak typeof(self) weakSelf = self;
    [self.writingChain setFrameProcessingCompletionBlock:^(GPUImageOutput *output, CMTime time) {
        [weakSelf.uiElement update];
    }];

    self.writer = [[GPUImageMovieWriter alloc] initWithMovieURL:self.movieURL size:[self writerSize]];
    [self.blendFilter addTarget:self.writer];

    [self.camera addTarget:self.writingChain];
    [self.writer startRecording];
}

第三,这样我就打断了写作:

-(void)removeMovieWriter
{
    [self.camera removeTarget:self.writingChain];
    [self.writingChain removeAllTargets];

    [self.writer finishRecording];

    self.writer = nil;
    self.uiElement = nil;
    self.writingChain = nil;
}

如何避免此问题。也许我错了。感谢您的帮助。

0 个答案:

没有答案