Seeking with a QuickTime file
Seek with a QuickTime file using child atoms.
Overview
Seeking with a QuickTime file is accomplished primarily by using the child atoms contained in the sample table atom. If an edit list is present, it must also be consulted. If you want to seek a given track to a time T, where T is in the time scale of the movie header atom, you could perform the following operations:
If the track contains an edit list, determine which edit contains the time
Tby iterating over the edits. The start time of the edit in the movie time scale must then be subtracted from the timeTto generateT', the duration into the edit in the movie time scale.T'is next converted to the time scale of the track’s media to generateT''. Finally, the time in the media scale to use is calculated by adding the media start time of the edit toT''.The time-to-sample atom for a track indicates what times are associated with which sample for that track. Use this atom to find the first sample prior to the given time.
The sample that was located in step 1 may not be a random access point. Locating the nearest random access point requires consulting two atoms. The sync sample table indicates which samples are in fact random access points. Using this table, you can locate which is the first sync sample prior to the specified time. The absence of the sync sample table indicates that all samples are synchronization points, and makes this problem easy. The shadow sync atom gives the opportunity for a content author to provide samples that are not delivered in the normal course of delivery, but which can be inserted to provide additional random access points. This improves random access without impacting bit rate during normal delivery. This atom maps samples that are not random access points to alternate samples which are. Also consult this table, if present, to find the first shadow sync sample prior to the sample in question. Having consulted the sync sample table and the shadow sync table, you probably wish to seek to whichever resultant sample is closest to, but prior to, the sample found in step 1.
At this point you know the sample that will be used for random access. Use the sample-to-chunk table to determine in which chunk this sample is located.
Knowing which chunk contained the sample in question, use the chunk offset atom to figure out where that chunk begins.
Starting from this offset, you can use the information contained in the sample-to-chunk atom and the sample size atom to figure out where within this chunk the sample in question is located. This is the desired information.
See Also
Describing samples
Sample table atom ('stbl')Sample description atom ('stsd')Time-to-sample atom ('stts')Creating video tracks at 30 frames per secondCreating video tracks at 29.97 frames per secondCreating sound tracks at 44.1 kHzComposition offset atom ('ctts')Composition shift least greatest atom ('cslg')Using composition offset and composition shift least greatest atomsSync sample atom ('stss')Partial sync sample atom ('stps')Sample-to-chunk atom ('stsc')Referencing two data files with a single trackSample size atom ('stsz')Chunk offset atom ('stco')