Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the time scale portion of a CMTime?

I've been looking at the documentation associated with creating CMTimes. 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?

like image 964
Andy Hin Avatar asked Feb 16 '23 12:02

Andy Hin


1 Answers

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.

like image 184
Michael Dautermann Avatar answered Mar 12 '23 22:03

Michael Dautermann