GPUImage
GPUImage copied to clipboard
GPUImageMovieWriter never calling its delegate or completionBlock
I try to apply a filter to a previously recorded video and save it again. However, neither the completionBlock nor the delegate are called. Re-encoding will hang after a certain time and no error will be returned.
I have looked at the example and there is the same problem. In the example I have disabled [movieWriter startRecording];
and the delegate was executed, but the video with the filter is not saved.
I think there is an error or something similar while running "startRecording" of the "GPUImageMovieWriter". Does anyone have any idea how this problem can be solved?
My code:
-(void)applyFilterToVideoAtURL:(NSURL*)url withSize:(CGSize)size completion:(void(^)(void))completion {
movieFile = [[GPUImageMovie alloc] initWithURL:url];
movieFile.runBenchmark = YES;
movieFile.playAtActualSpeed = NO;
filter = [[GPUImagePixellateFilter alloc] init];
[movieFile addTarget:filter];
NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/filtered_video.m4v"];
unlink([pathToMovie UTF8String]);
NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie];
movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:size];
[filter addTarget:movieWriter];
movieWriter.shouldPassthroughAudio = YES;
movieFile.audioEncodingTarget = movieWriter;
[movieFile enableSynchronizedEncodingUsingMovieWriter:movieWriter];
[movieWriter startRecording];
[movieFile startProcessing];
[movieWriter setCompletionBlock:^{
[filter removeTarget:movieWriter];
[movieWriter finishRecording];
dispatch_async(dispatch_get_main_queue(), ^{
if(completion) {
completion();
}
});
}];
}
PS: I work with iOS 11.
I also met the question. Do you have any idea about it?
me too ..
Any update about this issue, I have same issue one of my application
maybe you should set completion block before you start processing?
i have added timer to monitor finish state:
Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { [weak self] timer in
if movieFile.videoEncodingIsFinished, movieFile.audioEncodingIsFinished {
timer.invalidate()
}
}