我有一个小整数值,我想将其转换为 CMTime。
问题是
CMTime(值:_,时间刻度:_)
或
CMTimeMakeWithSeconds(值:_,时间刻度:_)
将始终返回发言权,以便时间始终等于
0.0 seconds
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
将时间值表示为整数的有理数
分子(value
)和分母(timescale
)。为了表示一个小值
像你的一样,你必须选择更大的时间尺度(取决于
所需的精度)。示例:
let smallValue = 0.0401588716
let frameTime = CMTime(seconds: smallValue, preferredTimescale: 1000000)
print(frameTime.seconds) // 0.040158
在发布问题之前我应该考虑一下。
let smallValue = 0.0401588716
let oneSec = CMTimeMakeWithSeconds(1, timeScale: 1)
let frameTime = CMTimeMultiplyByFloat64(oneSec , smallValue)
print(CMTimeGetSeconds(frameTime)) // 0.040158872