CMTime: How Time Is Represented in AVFoundation
CMTime
How is CMTime structured?
CMTime is a C structure that represents time using
- Numerator (int64_t)
- Denominator (int32_t)
Example
// time1 and time2 both represent 100 seconds, but using different timescales.
CMTime time1 = CMTimeMake(200, 2); // 200 half-seconds
CMTime time2 = CMTimeMake(400, 4); // 400 quarter-seconds
Special CMTime constants
kCMTimeZero
kCMTimeInvalid
kCMTimePositiveInfinity
kCMTimeNegativeInfinity
Special CMTime constant testers
CMTIME_IS_INVALID
CMTIME_IS_POSITIVE_INFINITY
CMTIME_IS_INDEFINITE
CMTime myTime = CMTimeMake(200, 2); if (CMTIME_IS_INVALID(myTime)) { NSLog(@“Error”); }
CMTimeRange
How is CMTimeRange structured?
- Start time (CMTime)
- Duration (CMTime)
Example
CMTime time1 = CMTimeMake(200, 2);
CMTime time2 = CMTimeMake(400, 4);
CMTimeRange range = CMTimeRangeMake(time1, time2)
Testing for inclusion
CMTimeRangeContainsTimeRange(range, CMTimeRangeGetEnd(range));
// This is false
CMTimeRange special constants
kCMTimeRangeZero
kCMTimeRangeInvalid
CMTimeRange special constant testers
CMTIMERANGE_IS_VALID
CMTIMERANGE_IS_INVALID
CMTIMERANGE_IS_EMPTY
CMTIMERANGE_IS_EMPTY