Contents

CMTimeMapTimeFromRangeToRange(_:fromRange:toRange:)

Translates a time through a mapping from two time ranges.

Declaration

func CMTimeMapTimeFromRangeToRange(_ t: CMTime, fromRange: CMTimeRange, toRange: CMTimeRange) -> CMTime

Parameters

  • t:

    The time value to translate.

  • fromRange:

    The time range from which the function translates the time range.

  • toRange:

    The time range to which the function maps the time value.

Return Value

A time structure that represents the translated time.

Discussion

The start and end time of fromRange maps to the start and end time of toRange respectively. The function maps other times linearly using the formula:

result = (t-fromRange.start)*(toRange.duration/fromRange.duration)+toRange.start

If either CMTimeRange argument is empty, the function returns an invalid CMTime. If t doesn’t have the same epoch as fromRange.start, the function returns an invalid CMTime. If both fromRange and toRange have duration kCMTimePositiveInfinity, the function offsets t relative to the differences between their starts, but not scaled.

See Also

Utility Functions