<!--
{
  "documentType" : "article",
  "framework" : "QuickTime File Format",
  "identifier" : "/documentation/QuickTime-File-Format/Using_composition_offset_and_composition_shift_least_greatest_atoms",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Using composition offset and composition shift least greatest atoms"
}
-->

# Using composition offset and composition shift least greatest atoms

Calculate the offset shift when you store an out of order video stream’s sample table.

## Overview

Calculate the offset shift with code similar to the following example:

```c
leastDisplayOffset = min { display offsets of all samples }
greatestDisplayOffset = max { display offsets of all samples }
if( leastDisplayOffset < 0 )
  compositionOffsetToDisplayOffsetShift = leastDisplayOffset;
else
  compositionOffsetToDisplayOffsetShift = 0;
```

These values are stored in a composition shift least greatest atom within the sample table atom.

Then write a composition offset table atom that stores the display offsets, adjusting each offset by subtracting compositionOffsetToDisplayOffsetShift:

```c
compositionOffset[n] = displayOffset[n] - compositionOffsetToDisplayOffsetShift;
```

> Note: If a composition shift least greatest atom is not present, assume `compositionOffsetToDisplayOffsetShift = 0`. The sample tables will need to be scanned to find the least and greatest offsets, as well as the presentation start and end times, to determine the decode time offset required for presentation.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)