GPUImageMovie在应用filter时暂停

我使用Brad Larson伟大的图书馆GPUImage为我的应用程序。 目前我陷入了一个问题。 我的应用程序捕捉10秒的video,然后允许filter应用。 在GPUImageMovie应用filters时,我无法暂停播放并应用新的filter以便video将从头开始连续播放。

我在这里看到一个开放的github问题。 如果有人遇到类似的问题,并find解决办法,请张贴您的答案。 提前致谢。

最后,我经过了太多的search,并试着解决了这个问题。 我们需要用AVPlayerItem而不是URL来启动GPUImageMovie。 我从这里得到了这个有价值的线索。

我发布我的代码,我目前正在使用在我的应用程序,并按预期工作。 但在iPod 6.1中存在性能问题,我正在进行相同的改进。

初始方法来设置GPUImageMovie,

 - (void)setupVideo { playerItem = [[AVPlayerItem alloc]initWithURL:self.recordSession.outputUrl]; player = [AVPlayer playerWithPlayerItem:playerItem]; movieFile = [[GPUImageMovie alloc] initWithPlayerItem:playerItem]; movieFile.runBenchmark = YES; movieFile.playAtActualSpeed = YES; [self.view sendSubviewToBack:self.videoView]; [movieFile addTarget:filter]; [filter addTarget:self.videoView]; [movieFile startProcessing]; movieRunning = YES; dispatch_async(dispatch_get_main_queue(), ^{ self.playButton.hidden = YES; }); player.rate = 1.0; } 

当用户点击一个filterbutton时,这个方法被调用。

 - (void)filterClicked:(UIButton *)button { // Set paused time. If player reaches end of the video, set pausedTime to 0. if (CMTIME_COMPARE_INLINE(pausedTime, !=, player.currentItem.asset.duration)) { pausedTime = player.currentTime; } else { pausedTime = CMTimeMake(0, 600.0); } [self.videoView setBackgroundColor:[UIColor clearColor]]; [movieFile cancelProcessing]; switch (button.tag) { case 0: filter = [[GPUImageFilter alloc] init]; break; case 1: filter = [[GPUImageColorInvertFilter alloc] init]; break; case 2: filter = [[GPUImageEmbossFilter alloc] init]; break; case 3: filter = [[GPUImageGrayscaleFilter alloc] init]; break; default: filter = [[GPUImageFilter alloc] init]; break; } [self filterVideo]; } 

filter生成后,使用此方法处理video播放恢复。

 - (void)filterVideo { // AVPlayerItem is initialized with required url playerItem = [[AVPlayerItem alloc]initWithURL:self.outputUrl]; [player replaceCurrentItemWithPlayerItem:playerItem]; //GPUImageMovie is initialized with AVPlayerItem movieFile = [[GPUImageMovie alloc] initWithPlayerItem:playerItem]; movieFile.runBenchmark = YES; movieFile.playAtActualSpeed = YES; // Adding targets for movieFile and filter [movieFile addTarget:filter]; [filter addTarget:self.videoView]; // self.videoView is my GPUImageView [movieFile startProcessing]; movieRunning = YES; dispatch_async(dispatch_get_main_queue(), ^{ self.playButton.hidden = YES; }); // Player rate is set to 0 means player is paused [player setRate:0.0]; // Seeking to the point where video was paused if (CMTIME_COMPARE_INLINE(pausedTime, !=, player.currentItem.asset.duration)) { [player seekToTime:pausedTime]; } [player play]; }