使CMTime值很小 [英] Make CMTime with a very small value

查看:102
本文介绍了使CMTime值很小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小整数值,我想将其转换为CMTime.

I have a small integer value and I want to convert it into CMTime.

问题是

CMTime(值:_,timeScale:_)

CMTime(value: _ , timeScale: _)

CMTimeMakeWithSeconds(值:_,timeScale:_)

CMTimeMakeWithSeconds(value: _ , timeScale: _)

将始终返回下限,因此时间始终等于0.0 seconds

will always return the floor so that time always equals 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将时间值表示为带有整数的 rational 数字 分子(value)和分母(timescale).为了代表一个很小的价值 像您一样,您必须选择更大的时间范围(具体取决于 所需的精度).示例:

CMTime represents a time value as a rational number with integer numerator (the value) and denominator (the timescale) . In order to represent a small value like yours, you have to choose a larger timescale (depending on the desired accuracy). Example:

let smallValue = 0.0401588716
let frameTime = CMTime(seconds: smallValue, preferredTimescale: 1000000) 

print(frameTime.seconds) // 0.040158

这篇关于使CMTime值很小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆