---
title: Using composition offset and composition shift least greatest atoms
framework: quicktime-file-format
role: article
role_heading: Article
path: quicktime-file-format/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

Overview Calculate the offset shift with code similar to the following example: 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: 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.

## See Also

### Describing samples

- [Sample table atom ('stbl')](quicktime-file-format/sample_table_atom.md)
- [Seeking with a QuickTime file](quicktime-file-format/seeking_with_a_quicktime_file.md)
- [Sample description atom ('stsd')](quicktime-file-format/sample_description_atom.md)
- [Time-to-sample atom ('stts')](quicktime-file-format/time-to-sample_atom.md)
- [Creating video tracks at 30 frames per second](quicktime-file-format/creating_video_tracks_at_30_frames_per_second.md)
- [Creating video tracks at 29.97 frames per second](quicktime-file-format/creating_video_tracks_at_2997_frames_per_second.md)
- [Creating sound tracks at 44.1 kHz](quicktime-file-format/creating_sound_tracks_at_441_khz.md)
- [Composition offset atom ('ctts')](quicktime-file-format/composition_offset_atom.md)
- [Composition shift least greatest atom ('cslg')](quicktime-file-format/composition_shift_least_greatest_atom.md)
- [Sync sample atom ('stss')](quicktime-file-format/sync_sample_atom.md)
- [Partial sync sample atom ('stps')](quicktime-file-format/partial_sync_sample_atom.md)
- [Sample-to-chunk atom ('stsc')](quicktime-file-format/sample-to-chunk_atom.md)
- [Referencing two data files with a single track](quicktime-file-format/referencing_two_data_files_with_a_single_track.md)
- [Sample size atom ('stsz')](quicktime-file-format/sample_size_atom.md)
- [Chunk offset atom ('stco')](quicktime-file-format/chunk_offset_atom.md)
