我在 iphone 中使用 GPUImage 框架在视频文件中添加一些过滤器。过滤器已成功应用。但我面临的问题是 setCompletionBlock 被连续调用两次。有人可以建议我这段代码有什么问题吗?
- (IBAction)applyFilter:(id)sender {
NSString *path = [[NSBundle mainBundle] pathForResource:@"OriginalVideo" ofType:@"mp4"];
NSURL *url = [NSURL fileURLWithPath:path];
GPUImageMovie *movieFile = [[GPUImageMovie alloc] initWithURL:url];
GPUImageSepiaFilter *filter = [[GPUImageSepiaFilter alloc] init];
[movieFile addTarget:filter];
NSString *pathToMovie = [Utilities getPathForFileName:@"finalvideo.mp4"];
if ([[NSFileManager defaultManager] fileExistsAtPath:pathToMovie]) {
[[NSFileManager defaultManager] removeItemAtPath:pathToMovie error:nil];
}
unlink([pathToMovie UTF8String]);
NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie];
GPUImageMovieWriter *movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(480.0, 320.0)];
[filter addTarget:movieWriter];
movieWriter.shouldPassthroughAudio = YES;
movieFile.audioEncodingTarget = movieWriter;
[movieFile enableSynchronizedEncodingUsingMovieWriter:movieWriter];
[movieWriter setCompletionBlock:^{
NSLog(@"finished..............................");
[filter removeTarget:movieWriter];
[movieWriter finishRecording];
}];
[movieWriter startRecording];
[movieFile startProcessing];
}