GPUImageMovieWriter setCompletionBlock很久了

时间:2016-08-14 20:20:21

标签: ios objective-c gpuimage

我正在使用" GPUImageMovieWriter"用于视频过滤。但GPUImageMovieWriter的完成时间与原始视频持续时间相同。这是我正在使用的代码下面。

-(void)applyFilterToVideo:(NSInteger)filterNumber{
    @autoreleasepool
    {
        self.showLoading=YES;
        _movieFile = [[GPUImageMovie alloc] initWithURL:originalFileUrl];

        self.videoFilter=[self filter:filterNumber]; // get selected filter
        _movieFile.runBenchmark = YES;
        _movieFile.playAtActualSpeed = YES;
        [_movieFile addTarget:_videoFilter];

        //Setting path for temporary storing the video in document directory
        NSURL *movieURL = [self dataFilePath:@"tempVideo.mp4"]; // url where we want to save our new edited video
        NSLog(@"movieURL = %@", movieURL.absoluteString);

        CGSize size =[self getVideoResolution:originalFileUrl];

        self.movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:size];

        [_videoFilter addTarget:_movieWriter];

        // this let allow gpumoviewriter to handle the audio. if not used the resulted video is without audio.
        _movieWriter.shouldPassthroughAudio = YES;
        _movieFile.audioEncodingTarget = _movieWriter;

        [_movieFile enableSynchronizedEncodingUsingMovieWriter:_movieWriter];

        [self.movieWriter startRecording];
        [_movieFile startProcessing];

         __block BOOL completeRec = NO;
         __unsafe_unretained typeof(self) weakSelf = self;

         //completion block video editing completed and this block is called.
         [self.movieWriter setCompletionBlock:^{

            [weakSelf.videoFilter removeTarget:weakSelf.movieWriter];
            [weakSelf.movieWriter finishRecording];
            [weakSelf.movieFile removeTarget:weakSelf.videoFilter];

            if (!completeRec)
            {
                // playing our new filtered video
                [weakSelf performSelectorOnMainThread:@selector(playTheVideo:) withObject:movieURL waitUntilDone:NO];

                completeRec = YES;
            }
        }];
    }
}





-(void) playTheVideo:(NSURL *)videoURL{
    NSTimeInterval time= videoPlayer.currentPlaybackTime;

    UIView *parentView = imageViewFiltered; // adjust as needed
    CGRect bounds = parentView.bounds; // get bounds of parent view
    CGRect subviewFrame = CGRectInset(bounds, 0, 0); // left and right margin of 0
    videoPlayer.view.frame = subviewFrame;
    videoPlayer.view.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);

    [parentView addSubview:videoPlayer.view];
    videoPlayer.contentURL = videoURL;
    [videoPlayer setCurrentPlaybackTime:time];


    [videoPlayer stop];
    [videoPlayer play];
    self.showLoading=NO;


}

任何人都可以告诉我如何缩短处理时间吗?

0 个答案:

没有答案