在应用率大于2倍的情况下从avplayer突然播放 [英] Jerky playback from avplayer on Applying Rate greater than 2x

查看:166
本文介绍了在应用率大于2倍的情况下从avplayer突然播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想调整Avplayer的速率,我可以借助

I want to tweak Avplayer rate , I able to do with help of

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

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

Also disabled audio tracks , it is running good when it is less than 2.0. But when we apply it greater than 2X it results in Choppy or jerky video.

当我在Google上搜索此内容时-我发现此链接暗示了相同的行为

When i googled about this - I found this one link suggesting same behaviour

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

当数据速率或其他处理要求达到 以指定的速率播放超出了AVFoundation的能力 赶上.在这种情况下,AVPlayer会自动降低质量 为了跟上播放速度,采用了一层后备 策略取决于当时的情况.退化的一层 将仅解码和显示视频子流中的I帧,并且 这确实看起来很不稳定.

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.

如果有的话,有谁能帮我,我应该使用哪种方法来实现相同的目标?

Can any one help like if it so , than what approach shall i use to achieve same ?

推荐答案

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

As @Rhythmic suggested these ways can be implemented but these all are kind of hassle . I googled it more and found a way and it is working very fine no jerk or choppy .

只需不设置费率,就可以这样设置费率.首先创建AVPlayer,AVPlayerItem和AVAsset的实例.

Just do not set rate , set Rate like this . First create instance of AVPlayer , AVPlayerItem and 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倍以上的速度.

this code can even support more than 2x or 4x speed easily .

这篇关于在应用率大于2倍的情况下从avplayer突然播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆