问题描述
我正在为我的应用程序使用Brad Larson的优秀图书馆。目前我遇到了一个问题。我的应用程序捕获10秒视频,然后允许过滤
申请。在 GPUImageMovie
中应用过滤器
时,我无法暂停播放并应用新的过滤器
这样视频就会连续播放而不从头开始。
I am using Brad Larson's great library GPUImage for my application. Currently I am stuck with an issue. My application captures 10 second videos and after that allows filter
applying. While applying filters
in GPUImageMovie
, I am not able to pause the play and apply new filter
so that video will play continuously without starting from the beginning.
我看到一个开放的github问题。如果有人遇到类似问题并找到解决方案,请发布您的答案。在此先感谢。
I saw an open github issue here. If anyone faced similar issue and found a solution, please post your answers. Thanks in advance.
推荐答案
最后我在经过太多搜索后修复此问题并尝试。我们需要使用AVPlayerItem而不是URL来启动GPUImageMovie。我从获得了这个有价值的线索。
And finally I fixed this after too many searches and try. We need to initiate GPUImageMovie with AVPlayerItem instead of URL. I got this valuable clue from here.
我发布了我目前在我的应用程序中使用的代码,它正在按预期工作。但iPod 6.1中存在性能问题,我正在研究相同的增强功能。
I am posting my code which I am currently using in my application and it is working as expected. But there are performance issues in iPod 6.1 and I am working on enhancements of the same.
设置GPUImageMovie的初始方法,
Initial method to setup 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;
}
当用户点击过滤器按钮时,会调用此方法。
This method is called when user clicks on a filter button.
- (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];
}
生成过滤器后,使用此方法处理视频播放恢复。
After filter generation, video play resume is handled in this method.
- (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];
}
这篇关于应用过滤器时GPUImageMovie暂停的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!