我有一个小整数值,我想将其转换为 CMTime。
问题是
CMTime(value: _ , timeScale: _)
或
CMTimeMakeWithSeconds(value: _ , timeScale: _)
将始终返回发言权,以便时间始终等于0.0秒
let smallValue = 0.0401588716
let frameTime = CMTime(Int64(smallValue) , timeScale: 1)
//frameTime is 0.0 seconds because of Int64 conversion
let frameTimeInSeconds = CMTimeMakeWithSeconds(smallValue , timeScale: 1)
// frameTimeInSeconds also returns 0.0 seconds.
最佳答案
CMTime
将时间值表示为带有整数的有理数
分子(值
)和分母(时间刻度
)。为了表示一个小值
像你的一样,你必须选择更大的时间尺度(取决于
所需的精度)。示例:
let smallValue = 0.0401588716
let frameTime = CMTime(seconds: smallValue, preferredTimescale: 1000000)
print(frameTime.seconds) // 0.040158
关于ios - 使 CMTime 具有很小的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42410190/