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
kCMTimeZerokCMTimeInvalidkCMTimePositiveInfinitykCMTimeNegativeInfinity
Special CMTime constant testers
CMTIME_IS_INVALIDCMTIME_IS_POSITIVE_INFINITYCMTIME_IS_INDEFINITECMTime 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
kCMTimeRangeZerokCMTimeRangeInvalid
CMTimeRange special constant testers
CMTIMERANGE_IS_VALIDCMTIMERANGE_IS_INVALIDCMTIMERANGE_IS_EMPTYCMTIMERANGE_IS_EMPTY