我想调整 Avplayer 速率,我可以在以下帮助下完成
[_avplayer play];
[_avplayer setRate:1.5];
还禁用了音轨,低于2.0时运行良好。
但当我们应用它超过 2 倍时,就会导致视频不稳定或不稳定。
当我用谷歌搜索这一点时 - 我发现这个链接暗示了相同的行为
https://developer.apple.com/library/content/qa/qa1772/_index.html
当数据速率或其他处理要求超过 2.0 时,以大于 2.0 的速率播放可能会导致播放不稳定或断断续续。
以指定速率播放超出了 AVFoundation 的能力
赶上。在这些情况下,AVPlayer 会自动降低质量
为了跟上播放的速度,采用了一层后备
策略取决于当时的情况。一级退化
仅解码并显示视频子流中的 I 帧,并且
这确实看起来很不稳定。
任何人都可以提供帮助吗?如果是这样,那么我应该使用什么方法来实现相同的目标?
正如@Rhythmic 所建议的,这些方法可以实现,但这些都有点麻烦。我用谷歌搜索了更多,找到了一种方法,它工作得很好,没有混蛋或不稳定。
只是不设置费率,像这样设置费率。首先创建 AVPlayer 、 AVPlayerItem 和 AVAsset 的实例。
AVMutableComposition *composition = [AVMutableComposition composition];
NSError *error = nil;
[composition insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset.duration)
ofAsset:asset
atTime:kCMTimeZero error:&error];
[composition scaleTimeRange:CMTimeRangeMake(kCMTimeZero, asset.duration)
toDuration:CMTimeMultiplyByFloat64(asset.duration, 1 / rate)];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:composition];
self.avRefPlayer = [AVPlayer playerWithPlayerItem:playerItem];
self.avRefPlayerLayer = [AVPlayerLayer layer];
[self.avRefPlayerLayer setPlayer:self.avRefPlayer];
[self.avRefPlayerLayer setFrame:_refrencedView.bounds];
[self.avRefPlayerLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
该代码甚至可以轻松支持超过 2 倍或 4 倍的速度。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)