gpt4 book ai didi

ios - AVPlayer 设置 fps

转载 作者:行者123 更新时间:2023-11-28 23:25:51 31 4
gpt4 key购买 nike

嗨,我有一个经典的播放器

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 fps 变为 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)

关于ios - AVPlayer 设置 fps,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58787821/

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