Understanding CMTimeRange - how it works

Apple defines a timeRange as:

Represented by two CMTime structs, one that specifies the start time of the range and another that specifies the duration of the range..

Please see my post on what CMTime is here.

The main point you need to understand is that it in NOT an inpoint and an outpoint which is how it looks...


It is a START TIME and a DURATION... I wish i had a dollar for every time this has been a problem for me. I would have $8.

The whole timerange for any media asset (video or audio) is: the very start time of the asset (kCMTimeZero) to the length of the media asset (mediaAsset.duration).

So we want to make a selection in our source (video) media asset.

We want the range to start at CMTime = 1 second and have a duration of CMTime = 3 seconds.

So we create a (non mutable) variable called startTime:CMTime and assign it a value of 1 second (CMTimeMake(600,600)).

And we also need a duration for our range. This is ALSO a CMTime.

Our duration we want to be 3 seconds, so we make a duration variable that is equal to 3 seconds CMTimeMake(1800,600).