//----8.7.3 Sample Size Boxes -----//
//8.7.3.1 Definition
Box Type:‘stsz’, ‘stz2’
Container:Sample Table Box (‘stbl’)
Mandatory:Yes
Quantity:Exactly one variant must be present
/*
This box contains the sample count and a table giving the size in bytes of each sample. This allows the media data itself to be unframed. The total number of samples in the media is always indicated in the sample count.
*/
aligned(8) class SampleSizeBox extends FullBox(‘stsz’, version = 0, 0) {
unsigned int(32) sample_size;
unsigned int(32) sample_count;
if (sample_size==0) {
for (i=1; i <= sample_count; i++) {
unsigned int(32) entry_size;
}
}
}
version is an integer that specifies the version of this box
sample_size is integer specifying the default sample size. If all the samples are the same size, this field contains that size value. If this field is set to 0, then the samples have different sizes, and those sizes are stored in the sample size table. If this field is not 0, it specifies the constant sample size, and no array follows.
sample_count is an integer that gives the number of samples in the track; if sample-size is 0, then it is also the number of entries in the following table.
entry_size is an integer specifying the size of a sample, indexed by its number.
如果sample_size=0,表示sample不是相同的大小,各个sample的大小存储在sample size table——就是紧跟着的内容(只有sample_size=0的时候才会有)。后面的循环读取的数据就是这些各个sample的大小。
//------8.7.4 Sample To Chunk Box------//
//8.7.4.1 Definition
Box Type:‘stsc’
Container:Sample Table Box (‘stbl’)
Mandatory:Yes
Quantity:Exactly one
/*
Samples within the media data are grouped into chunks. Chunks can be of different sizes, and the samples within a chunk can have different sizes. This table can be used to find the chunk that contains a sample, its position, and the associated sample description.
The table is compactly coded. Each entry gives the index of the first chunk of a run of chunks with the same characteristics. By subtracting one entry here from the previous one, you can compute how many chunks are in this run. You can convert this to a sample count by multiplying by the appropriate samples-per-chunk.
*/
aligned(8) class SampleToChunkBox
extends FullBox(‘stsc’, version = 0, 0) {
unsigned int(32) entry_count;
for (i=1; i <= entry_count; i++) {
unsigned int(32) first_chunk;
unsigned int(32) samples_per_chunk;
unsigned int(32) sample_description_index;
}
}
//----8.7.5 Chunk Offset Box---//
//8.7.5.1 Definition
Box Type:‘stco’, ‘co64’
Container:Sample Table Box (‘stbl’)
Mandatory:Yes
Quantity:Exactly one variant must be present
The chunk offset table gives the index of each chunk into the containing file. There are two variants, permitting the use of 32-bit or 64-bit offsets. The latter is useful when managing very large presentations. At most one of these variants will occur in any single instance of a sample table.
Offsets are file offsets, not the offset into any box within the file (e.g. Media Data Box). This permits referring to media data in files without any box structure. It does also mean that care must be taken when constructing a self-contained ISO file with its metadata (Movie Box) at the front, as the size of the Movie Box will affect the
chunk offsets to the media data.
aligned(8) class ChunkOffsetBox
extends FullBox(‘stco’, version = 0, 0) {
unsigned int(32) entry_count;
for (i=1; i <= entry_count; i++) {
unsigned int(32) chunk_offset;
}
}
aligned(8) class ChunkLargeOffsetBox
extends FullBox(‘co64’, version = 0, 0) {
unsigned int(32) entry_count;
for (i=1; i <= entry_count; i++) {
unsigned int(64) chunk_offset;
}
}
version is an integer that specifies the version of this box
entry_count is an integer that gives the number of entries in the following table
chunk_offset is a 32 or 64 bit integer that gives the offset of the start of a chunk into its containing media file.