MP4容器系列文章之STSD BOX

以下內容皆翻譯自官方pdf,同時增加了自己的理解

這篇文章講述的是STSD BOX下的SampleEntry的編碼格式

8.16 Sample Description Box

8.16.1 Definition
BoxTypes: ‘stsd’
Container: Sample Table Box (‘stbl’) Mandatory: Yes
Quantity: Exactly one

8.16.2 Syntax(語法)

aligned(8) abstract class SampleEntry (unsigned int(32) format) extends Box(format){
    const unsigned int(8)[6] reserved = 0;    ////首先6個字節的保留位  值都是0
    unsigned int(16) data_reference_index;  ///一個2個字節來描述的 數據索引
}

///如果是一個空的entry,則追加一個字節的空數據
class HintSampleEntry() extends SampleEntry (protocol) { 
    unsigned int(8) data [];
}
// Visual Sequences    視頻entry

class VisualSampleEntry(codingname) extends SampleEntry (codingname){ 
    unsigned int(16) pre_defined = 0;     //2個字節的保留位
    const unsigned int(16) reserved = 0;    //2個字節的保留位
    unsigned int(32)[3] pre_defined = 0;    //3*4個字節的保留位
    unsigned int(16) width;             //2個字節的寬度
    unsigned int(16) height;                //2個字節的高度
    template unsigned int(32) horizresolution = 0x00480000; // 72 dpi    //縱向dpi,4字節
    template unsigned int(32) vertresolution = 0x00480000; // 72 dpi    //橫向dpi 4字節
    const unsigned int(32) reserved = 0;                                //4字節保留位
    template unsigned int(16) frame_count = 1;                      //2字節的frame_count
    string[32] compressorname;                                      //32字節的compressorname
    //這個地方特殊說明,這個地方需要32個8bit位置,0x00 *32
    第一個8bit來表明字符長度,後面31個8bit來表明壓縮的內容,
    例子:
    0x04,                       //  strlen compressorname: 32 bytes         String[32]
                                                    //32個8 bit    第一個8bit表示長度,剩下31個8bit表示內容
        0x67, 0x31, 0x31, 0x31,  // compressorname: 32 bytes    翻譯過來是g111
        0x00, 0x00, 0x00, 0x00,//
        0x00, 0x00, 0x00, 0x00,//
        0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00,


    template unsigned int(16) depth = 0x0018;                       //2字節的色彩深度
    int(16) pre_defined = -1;                                           //2字節的pre_defined
}
   // Audio Sequences   音頻entry

class AudioSampleEntry(codingname) extends SampleEntry (codingname){ 
    const unsigned int(32)[2] reserved = 0;                             //2*4字節保留位
    template unsigned int(16) channelcount = 2;                         //2字節的channelcount
    template unsigned int(16) samplesize = 16;                          //2字節的 samplesize
    unsigned int(16) pre_defined = 0;                                       //2字節的pre_defined
    const unsigned int(16) reserved = 0 ;                                   //2字節保留位
    template unsigned int(32) samplerate = {timescale of media}<<16;    //4字節聲音赫茲
}

8.16.3 Semantics(語義)

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
entry_count是整數,讓在下表條目的數量
SampleEntry is the appropriate sample entry.
data_reference_index is an integer that contains the index of the data reference to use to retrieve
data associated with samples that use this sample description. Data references are stored in Data
Reference Boxes. The index ranges from 1 to the number of data references.
data_reference_index是一個整數包含索引的數據引用使用使用這個示例的檢索數據與樣本描述。數據引用存儲在數據參考。該指數範圍從1到數據引用的數量。

ChannelCount is either 1 (mono) or 2 (stereo)
單聲道
SampleSize is in bits, and takes the default value of 16
SampleRate is the sampling rate expressed as a 16.16 fixed-point number (hi.lo)
resolution fields give the resolution of the image in pixels-per-inch, as a fixed 16.16 number
frame_count indicates how many frames of compressed video are stored in each sample. The default is
1, for one frame per sample; it may be more than 1 for multiple frames per sample
frame_count表明多少幀壓縮視頻存儲在每個樣本。默認是1,每樣一幀;它可能超過1每個樣本的多個幀數

Compressorname is a name, for informative purposes. It is formatted in a fixed 32-byte field, with the
first byte set to the number of bytes to be displayed, followed by that number of bytes of displayable
data, and then padding to complete 32 bytes total (including the size byte). The field may be set to 0.

Compressorname是一個名字,因爲信息的目的。在固定32字節的字段是格式化的,第一個字節設置爲顯示的字節數,其次是可顯示的數據的字節數,然後填充完成32字節總數(包括字節大小)。可能被設置爲0。

depth takes one of the following values
0x0018 – images are in colour with no alpha
width and height are the maximum visual width and height of the stream described by this sample
description, in pixels

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章