BradLarson / GPUImage

An open source iOS framework for GPU-based image and video processing
http://www.sunsetlakesoftware.com/2012/02/12/introducing-gpuimage-framework
BSD 3-Clause "New" or "Revised" License
20.21k stars 4.61k forks source link

GPUImageMovieWriter never calling its delegate or completionBlock #2555

Open ElKnarzo opened 6 years ago

ElKnarzo commented 6 years ago

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.

vivianflygirl commented 6 years ago

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

jianshek commented 5 years ago

me too ..

Mehul1437 commented 5 years ago

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

hezhk3 commented 5 years ago

maybe you should set completion block before you start processing?

bonyadmitr commented 2 years ago

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