gpt4 book ai didi

ios - 在应用速率大于 2 倍时从 avplayer 播放生涩

转载 作者:行者123 更新时间:2023-12-01 15:52:48 25 4
gpt4 key购买 nike

我想调整 Avplayer rate ,我可以在

[_avplayer play];
[_avplayer setRate:1.5];

还禁用了音轨,当它小于 2.0 时运行良好。
但是当我们应用它大于 2X 时,它会导致视频断断续续或生涩。

当我用谷歌搜索这个时 - 我发现这个链接暗示了相同的行为

https://developer.apple.com/library/content/qa/qa1772/_index.html

Playing at rates greater than 2.0 can result in jerky or choppy playback when the data rate or other processing requirements of playing at the specified rate exceeds the ability of AVFoundation to keep up. In those cases, AVPlayer automatically degrades the quality of playback in order to keep up, employing a tier of fallback strategies depending on prevailing conditions. One tier of degradation is to decode and display only I-frames within the video substream, and this can indeed appear to be choppy.



如果是这样的话,任何人都可以提供帮助,而不是我应该使用什么方法来实现相同的目标?

最佳答案

正如@Rhythmic 所建议的那样,可以实现这些方法,但这些方法都有些麻烦。我在谷歌上搜索了更多,找到了一种方法,它工作得很好,没有 SCSS 或断断续续。

只是不要设置速率,像这样设置速率。首先创建 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 倍的速度。

关于ios - 在应用速率大于 2 倍时从 avplayer 播放生涩,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40506059/

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