GPUImage icon indicating copy to clipboard operation
GPUImage copied to clipboard

GPUImageMovieWriter never calling its delegate or completionBlock

Open ElKnarzo opened this issue 6 years ago • 5 comments

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.

ElKnarzo avatar Feb 06 '18 08:02 ElKnarzo

I also met the question. Do you have any idea about it?

vivianflygirl avatar Jun 12 '18 12:06 vivianflygirl

me too ..

jianshek avatar Aug 03 '18 07:08 jianshek

Any update about this issue, I have same issue one of my application

Mehul1437 avatar Sep 06 '18 11:09 Mehul1437

maybe you should set completion block before you start processing?

hezhk3 avatar Jan 10 '19 01:01 hezhk3

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()
    }
}

bonyadmitr avatar Sep 15 '21 17:09 bonyadmitr