---
title: "CMTimeMapTimeFromRangeToRange(_:fromRange:toRange:)"
framework: Core Media
role: symbol
role_heading: Function
platforms: [iOS 4.0+, iPadOS 4.0+, Mac Catalyst 13.1+, macOS 10.7+, tvOS 9.0+, visionOS 1.0+, watchOS 6.0+]
path: "coremedia/cmtimemaptimefromrangetorange(_:fromrange:torange:)"
---

# CMTimeMapTimeFromRangeToRange(_:fromRange:toRange:)

Translates a time through a mapping from two time ranges.

## Declaration

```swift
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

Return Value A time structure that represents the translated time.

## Discussion

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

- [CMTimeClampToRange(_:range:)](coremedia/cmtimeclamptorange(_:range:).md)
- [CMTimeMapDurationFromRangeToRange(_:fromRange:toRange:)](coremedia/cmtimemapdurationfromrangetorange(_:fromrange:torange:).md)
- [CMTimeRangeCopyAsDictionary(_:allocator:)](coremedia/cmtimerangecopyasdictionary(_:allocator:).md)
- [CMTimeRangeCopyDescription(allocator:range:)](coremedia/cmtimerangecopydescription(allocator:range:).md)
- [CMTimeRangeShow(_:)](coremedia/cmtimerangeshow(_:).md)
