当前位置:网站首页>CMTime简单介绍
CMTime简单介绍
2022-07-17 00:09:00 【博BOBO】
通常开发者认为时间的呈现格式应该是浮点数据,我们一般使用NSTimeInterval,实际上它是简单的双精度double类型,只是typedef了一下,但是由于浮点型数据计算很容易导致精度的丢失,在一些要求高精度的应用场景显然不适合,于是苹果在Core Media框架中定义了CMTime数据类型作为时间的格式,类型定义如下:
typedef struct{
CMTimeValue value;
CMTimeScale timescale;
CMTimeFlags flags;
CMTimeEpoch epoch;
} CMTime;显然,CMTime定义是一个C语言的结构体,CMTime是以分数的形式表示时间,value表示分子,timescale表示分母,flags是位掩码,表示时间的指定状态。
CMTime的创建
我们一般使用CMTimeMake函数创建,如下:
CMTime t1 = CMTimeMake(3, 1);
CMTime t2 = CMTimeMake(6, 3);
我们也可以通过CMTimeShow函数打印CMTime的相关信息如:
CMTimeShow(t1);
CMTimeShow(t2);
结果如:
{3/1 = 3.000}
{6/3 = 2.000}CMTime计算
相加
CMTime t3 = CMTimeAdd(t1, t2);
想减
CMTime t4 = CMTimeSubtract(t3, t1);
我们也可以通过CMTimeGetSeconds函数获取时间的秒数。
CMTimeRange
CMTimeRange是一个表示时间范围的一个数据类型,定义如下:
其中start表示时间的起点,duratin表示时间范围的持续时间。
一般使用CMTimeRangeMake和CMTimeRangeFromTimeToTime创建如:
CMTimeRange timeRange1 = CMTimeRangeMake(t1, t2);
CMTimeRange timeRange2 = CMTimeRangeFromTimeToTime(t4, t3);CMTimeRange的交集和并集
有时候我们需要获取两个时间范围的交叉时间范围或者两个时间范围的总和时间范围。
交叉时间范围
CMTimeRange intersectionRange = CMTimeRangeGetIntersection(timeRange2, timeRange1);
总和时间范围
CMTimeRange unionRange = CMTimeRangeGetUnion(timeRange1, timeRange2);
CMTime一般用的不多,但是在时间精度有要求的应用中会用到,比如音频,视频的处理。
边栏推荐
猜你喜欢

The use of libtomcrypt password Library

Why is opensea the absolute monopolist of NFT trading market?

基于开源流批一体数据同步引擎ChunJun数据还原—DDL解析模块的实战分享

06 BTC mining difficulty

CheckPoint and DataNode

Differences between let and const, let, const and VaR

What is the QS module?

Libtomcrypt密码库的使用

Why do you spend 1.16 million to buy an NFT avatar in the library of NFT digital collections? The answer may be found by reviewing the "rise history" of NFT avatars

数字藏品NFT“无聊猿”BAYC的内忧与外患
随机推荐
ipfs 文件持久化操作
CheckPoint and DataNode
Common methods of JS array
nmap和nikto扫描
MapReduce environment preparation
Introduction to software vulnerability analysis (5)
Uniapp development, upload pictures in the app and send them directly to OSS
感通融合系统中保障公平度的时间与功率分配方法
Redis 突然变慢了?
Red sun safety range 3
Recurrence of yii2 deserialization vulnerability
Uni canvas intercepts pictures
软件漏洞分析入门(二)
为什么说 OpenSea 是 NFT 交易市场的绝对垄断者?
Router and keep alive
07_ Basic use of events
Red sun range 2
Today, the code farmer girl made notes about the life cycle and practiced the dynamic clock
一文盘点估值超过1亿美元的NFT项目
IPFs file persistence operation