尝试了解 CMTime 和 CMTimeMake
1) CMTimeMake(1,10)
表示持续时间为 1 秒,时间刻度为 10,即每秒 10 帧。这意味着 10 帧的视频持续时间为 1 秒?
2)
CMTime lastTime=CMTimeMake(1,10);
CMTime frameTime=CMTimeMake(1, 10);
CMTime currentTime=CMTimeAdd(lastTime, frameTime)
= (2, 10) ?
当前时间每秒 10 帧的 2 秒视频?
1) CMTimeMake(1,10)
means duration of 1 second and timescale of 10, or 10 frames per second. This means 1s duration of video with 10 frames?
2)
CMTime lastTime=CMTimeMake(1,10);
CMTime frameTime=CMTimeMake(1, 10);
CMTime currentTime=CMTimeAdd(lastTime, frameTime)
= (2, 10) ?
2 seconds of video and with 10 frames per second of the currentTime?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
1)
CMTimeMake(1,10)
实际上表示值 1 和时间刻度 10。它们是分子和分母,因此是 1/10 秒,而不是 1 秒。2) 结果类似于
CMTimeMake(2, 10)
,即 2/10 秒。1)
CMTimeMake(1,10)
actually means a value of 1 and a timescale of 10. They are a numerator and denominator, so it is 1/10 of a second, not 1 second.2) The result will be like
CMTimeMake(2, 10)
, which is 2/10ths of a second.彼得是对的。
下面的代码使这个概念更加清晰:
1)
上面的代码给出:
{3000/600 = 5.000}
这意味着总持续时间为 5 秒,包含 3000 帧,时间尺度为每秒 600 帧。
2)
这个给出 {10000/600 = 16.667}
这意味着总持续时间为 16.667 秒,其中 10000 帧,时间尺度为每秒 600 帧。
注意 CMTimeMake(int64_t value, int32_t timescale) 之间的区别
和 CMTimeMakeWithSeconds(Float64 Seconds, int32_t PreferredTimeScale)
希望这个解释有帮助。如需进一步说明,请随时在本文中提出更多问题。
Peter is right.
The following code makes the concept more clear:
1)
The above code gives:
{3000/600 = 5.000}
Which means a total duration of 5 seconds, with 3000 frames with a timescale of 600 frames per second.
2)
This one gives {10000/600 = 16.667}
Which means a total duration of 16.667 seconds, with 10000 frames with a timescale of 600 frames per second.
Notice the difference between CMTimeMake(int64_t value, int32_t timescale)
and CMTimeMakeWithSeconds(Float64 seconds, int32_t preferredTimeScale)
Hope this explanation helps. For further clarifications, please don't hesitate to post further questions on this post.
使用
CMTimeMake(A, B)
您可以存储一个有理数,即A / B
秒的精确分数CMTimeMake(1, 4)
->时间间隔 0.25 秒使用
CMTimeMakeWithSeconds(A, B)
,您可以将A
秒 存储为B
步的分辨率CMTimeMakeWithSeconds(0.25, ...)
->时间间隔 0.25 秒您通常会看到
CMTimeMakeWithSeconds(time, NSEC_PER_SEC)
。NSEC_PER_SEC
实际上意味着“最大分辨率”。With
CMTimeMake(A, B)
you store a rational number, an exact fractionA / B
secondsCMTimeMake(1, 4)
-> the time interval 0.25 secondsWith
CMTimeMakeWithSeconds(A, B)
you storeA
seconds to a resolution ofB
stepsCMTimeMakeWithSeconds(0.25, ...)
-> the time interval 0.25 secondsYou commonly see
CMTimeMakeWithSeconds(time, NSEC_PER_SEC)
. TheNSEC_PER_SEC
effectively means "max resolution".1 秒的间隔
如果您只想知道如何设置 1 秒的间隔(像我一样),这就是您的答案:
Interval for 1 Second
If you only want to know how to make an interval for 1 second (like me), this is your answer:
CMTime 结构表示
存储为有理数的时间长度。
CMTime 有一个值和一个时间刻度字段,并表示时间值/时间刻度秒。请参阅查看这个明确的答案
A CMTime struct represents a
length of time that is stored as rational number.
CMTime has a value and a timescale field, and represents the time value/timescale seconds .See See this SO Answer which is clear
Swift CMTime
当你操作时间时很重要以节省准确性。
CMTime
建议您使用两个整数(value 和 timescale)来表示浮点数。与浮点运算相比,附加函数简化了 CMTime 数学计算重要的
CMTime
属性包括:的等份数公式为
下一个示例显示下一项:
- CMTimeCompare,CMTimeAdd... 使用秒创建CMTime
您可以创建
CMTime
使用值 和时间刻度,其中将计算秒(值/时间刻度)。这种方法很清晰,而且您还可以使用秒和preferredTimescale创建CMTime
。在这种情况下,您的值和秒可以不同,并需要重新计算以满足公式(值必须为Int64),这就是它可以四舍五入的原因,结果秒也被重新计算Swift CMTime
When you operate time it is important to save accuracy.
CMTime
propose you to use two integers(value and timescale) to present a float number. Additional functions simplify CMTime mathematics in contrast to float operationsImportant
CMTime
properties are:The formula is
Next example shows next items:
Create CMTime using seconds
You are able to create
CMTime
using value and timescale where seconds will be calculated(value / timescale). This approach is clear but also you are able to createCMTime
using seconds and preferredTimescale. In this case your value and seconds can be different and be recalculated to satisfy formula(value must be Int64) that is why it can be rounded, as a result seconds also is recalculated