I've been looking at the documentation associated with creating CMTime
s. All the functions (CMTimeMake()
, CMTimeMakeWithSeconds()
, etc.) take a second parameter called preferredTimeSale
.
Can someone explain to me what this is, and why it is specified in this way?
According to the opening paragraphs of Apple's CMTime documentation:
A CMTime is represented as a rational number, with a numerator (an int64_t value), and a denominator (an int32_t timescale). Conceptually, the timescale specifies the fraction of a second each unit in the numerator occupies. Thus if the timescale is 4, each unit represents a quarter of a second; if the timescale is 10, each unit represents a tenth of a second, and so on. In addition to a simple time value, a CMTime can represent non-numeric values: +infinity, -infinity, and indefinite. Using a flag CMTime indicates whether the time been rounded at some point.
So, if the timescale is 4, each single unit of time measurement is one quarter second.
If your timescale is 1, then each single unit of time measurement is one second (but that could be quite a slow animation for your user).
Many video formats use a timescale of 600:
You frequently use a timescale of 600, since this is a common multiple of several commonly-used frame-rates: 24 frames per second (fps) for film, 30 fps for NTSC (used for TV in North America and Japan), and 25 fps for PAL (used for TV in Europe). Using a timescale of 600, you can exactly represent any number of frames in these systems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With