作为@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倍以上的速度。
魔法!它是如何工作的?我印象深刻。 –
FWIW,我创建的两个应用程序 - 一个在Objective-C中,另一个在Swift中 - 都表现出这个问题。值得注意的是,这个问题不是媒体文件:例如,Quicktime Player可以非常快速地播放它,而我的应用程序看起来不会超过大约1.5倍。我刚刚在Swift中实现了上面的内容,发现它确实有效。例如,我可以播放9x,没问题。 – Jamborino
这很好。然而,通过调整时间尺度变化并进行正确的搜索,在播放视频的同时改变速度仍然非常困难,没有奇怪的帧跳跃。由于该框架显然能够以高速运行,我还是不明白'rate'属性不支持它... – deadbeef