Reputation: 1485
I am using GPUImage framework in iphone to add some filters in a video file. The filters are being applied successfully. But the issue i am facing is that the setCompletionBlock is getting called two times back to back. Can someone please suggest me whats wrong with this code ?
- (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];
}
Upvotes: 2
Views: 1240
Reputation: 2833
movieFile.runBenchmark = YES;
movieFile.playAtActualSpeed = YES;
[movieFile prepareForImageCapture];
call these methods while applying Filter
Upvotes: 6