GPUImage:取消GPUImageMovieWriter

时间:2012-09-04 11:42:10

标签: ios gpuimage

运行GPUImageMovieWriterGPUImageMovie后,有没有办法取消/停止startRecordingstartProcessing

3 个答案:

答案 0 :(得分:1)

最近,GPUImageMovie添加了一种允许取消处理视频文件的新方法:

- (void)cancelProcessing;

这将允许您有效取消视频处理,不再处理任何帧。

考虑到你的GPUImageMovieWriter的completionBlock仍然会被调用,所以你应该有一些标志来检查这个块是否被成功完成或取消。

以下是一些示例代码:

- (void)processVideo
{
    _wasCancelled = NO;

    self.imageMovie = [self createImageMovie];
    self.filter = [self createFilter];
    [imageMovie addTarget:filter]
    self.movieWriter = [self createMovieWriter];

    [self.movieWriter startRecording];
    [self.imageMovie startProcessing];

    [self.movieWriter setCompletionBlock:^{
        [self.filter removeTarget:movieWriter];
        [self.movieWriter finishRecording];

        if (!_wasCancelled) {
            // Do stuff with the video
        }
    }];
}

- (void)cancelVideoProcessing
{
    _wasCancelled = YES;
    [self.imageMovie cancelProcessing];
}

答案 1 :(得分:0)

假设self.movi​​eWriter是GPUImageMovieWriter, 你需要在调用startRecording和startProcessing之前设置一个回调:

[self.movieWriter setCompletionBlock:^{
    [self finishFilter];
}];

然后您可以使用以下命令停止图像处理:

[self.movieWriter endProcessing];

回调是:

- (void)finishFilter {
    //remove all targets from your filter chain calling "removeAllTargets"
    //then:
    [self.movieWriter finishRecording];
    self.movieWriter.completionBlock = nil;
    self.movieWriter = nil;
}

答案 2 :(得分:0)

为什么。有一个取消录制选项。

[self.movieWriter cancelRecording];

如果视频以任何方式中断,则不会保存这些视频。