AVPlayer 设置 fps

AVPlayer SET fps

嗨,我是经典播放器

var player = AVPlayer(url: fileUrl)
player.play() 

可以设置播放器的FPS吗?例如,我想以 30fps

播放慢动作视频 (240fps)

我试试

player.play()
player.rate = 0.5

但这只能以 120fps 的速度播放 240fps 的视频。

可以在视频播放期间更改 FPS

let timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: false) {_ in
        player.rate = 0.5
}

效果很好,但不能像上面那样设置 30FPS

谢谢!!

如果我理解正确的话,你只是想放慢内容,所以设置速率是正确的方法(你也可以在内容播放时这样做)。

如果你想从 240 到 30 fps,这意味着你想将速率设置为 30/240,这意味着 1/8。

所以应该这样做:

player.rate = Float(1)/Float(8)

您还应该将 playerItem audioPitchAlgorithm 设置为 lowQualityZeroLatency 以外的值,以允许它低于 0.5 直到 1/32

lowQualityZeroLatency

This algorithm is suitable for brief fast-forward and rewind effects as well as low quality voice. The rate is snapped to {0.5, 0.666667, 0.8, 1.0, 1.25, 1.5, 2.0}.

我测试正确的这个片段达到了速度的1/8。

let playerItem = AVPlayerItem(url: URL(string:"https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_ts/master.m3u8")!)
playerItem.audioTimePitchAlgorithm = .varispeed
let avPlayer = AVPlayer(playerItem: playerItem)

let vc = AVPlayerViewController()
vc.player = avPlayer

avPlayer.rate = 0.125
self.present(vc, animated: true)