gpt4 book ai didi

ios - GPUImageMovie 在应用滤镜时暂停

转载 作者:可可西里 更新时间:2023-11-01 05:08:46 24 4
gpt4 key购买 nike

我正在使用 Brad Larson 的优秀图书馆 GPUImage为我的申请。目前我遇到了一个问题。我的应用程序捕获 10 秒的视频,然后允许应用 filter。在 GPUImageMovie 中应用 filters 时,我无法暂停播放并应用新的 filter 以便视频不从头开始连续播放.

我看到一个开放的 github 问题 here .如果有人遇到类似问题并找到解决方案,请发布您的答案。提前致谢。

最佳答案

经过多次搜索和尝试,我终于解决了这个问题。我们需要使用 AVPlayerItem 而不是 URL 来启动 GPUImageMovie。我从 here 得到了这个有值(value)的线索.

我正在发布我目前在我的应用程序中使用的代码,它按预期工作。但是在 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;
}

当用户点击过滤器按钮时调用此方法。

- (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];

}

过滤器生成后,视频播放恢复在此方法中处理。

- (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];
}

关于ios - GPUImageMovie 在应用滤镜时暂停,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23799836/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com