軟編碼Flv 到Mp4 容器(十) fmp4 mvex box 講解

https://github.com/332065255/flv2fmp4

代碼庫


軟編碼Flv 到Mp4 容器(一)
軟編碼Flv 到Mp4 容器(二) flv tag拆解
軟編碼Flv 到Mp4 容器(三) flv metadata tag解析
軟編碼Flv 到Mp4 容器(四) fmp4 總覽和基礎講解
軟編碼Flv 到Mp4 容器(五) fmp4 ftyp box 和moov>mvhd box詳解
軟編碼Flv 到Mp4 容器(六) fmp4 moov>trak>tkhd box 和 moov>trak>mdia>mdhd box講解
軟編碼Flv 到Mp4 容器(七) fmp4 mdia>hdlr box 和 mdia>minf> smhd 和dinf box講解
軟編碼Flv 到Mp4 容器(八) fmp4 mdia>stbl>stsd box 講解
軟編碼Flv 到Mp4 容器(九) fmp4 stts stsc stsz stco box 講解
軟編碼Flv 到Mp4 容器(十) fmp4 mvex box 講解
軟編碼Flv 到Mp4 容器(十一) fmp4 moof box詳解
軟編碼Flv 到Mp4 容器(十二) fmp4 mdat box詳解
軟編碼Flv 到Mp4 容器(十三) fmp4 生成ftyp和moov所必要的 flv數據


 - ftyp
 - moov
     - mvhd
     - trak
         - tkhd
         - mdia
             - mdhd
             - hdlr
             - minf
                 - smhd
                 - dinf
                     - dref
                         - url
                 - stbl
                     -  stsd
                         - mp4a(avc1)
                             - esds(avcC)
                     - stts
                     - stsc
                     - stsz
                     - stco


     - mvex
        -trex
 - moof
    - mfhd
    - traf
        -tfhd
        -tfdt
        -sdtp
        -trun
 - mdat

首先對應標題的box在 fmp4容器中的位置

mvex box

Box Type: ‘mvex’
Container: Movie Box (‘moov’)
Mandatory: No
Quantity: Zero or one

定義

aligned(8) class MovieExtendsBox extends Box(‘mvex’){ }

這是一個容器box


trex box

Box Type: ‘trex’
Container: Movie Extends Box (‘mvex’)
Mandatory: Yes
Quantity: Exactly one per track in the Movie Box

定義

aligned(8) class TrackExtendsBox extends FullBox(‘trex’, 0, 0){ 
    unsigned int(32) track_ID;
    unsigned int(32) default_sample_description_index;
    unsigned int(32) default_sample_duration;
    unsigned int(32)  default_sample_size;
    unsigned int(32)  default_sample_flags
}

實現

static trex(meta) {
        let trackId = meta.id;
        let data = new Uint8Array([
            0x00, 0x00, 0x00, 0x00, // version(0) + flags
            (trackId >>> 24) & 0xFF, // track_ID
            (trackId >>> 16) & 0xFF,
            (trackId >>> 8) & 0xFF,
            (trackId) & 0xFF,
            0x00, 0x00, 0x00, 0x01, // default_sample_description_index
            0x00, 0x00, 0x00, 0x00, // default_sample_duration
            0x00, 0x00, 0x00, 0x00, // default_sample_size
            0x00, 0x01, 0x00, 0x01 // default_sample_flags
        ]);
        return MP4.box(MP4.types.trex, data);
    }

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