软编码Flv 到Mp4 容器(七) fmp4 mdia>hdlr box 和 mdia>minf> smhd 和dinf box讲解

来源:互联网 发布:libgcc s.so.1 ubuntu 编辑:程序博客网 时间:2024/06/07 20:56

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容器中的位置


hdlr box

Box Type: ‘hdlr’
Container: Media Box (‘mdia’) or Meta Box (‘meta’)
Mandatory: Yes
Quantity: Exactly one

定义

aligned(8) class HandlerBox extends FullBox(‘hdlr’, version = 0, 0) { unsigned int(32) pre_defined = 0;  //4字节保留位unsigned int(32) handler_type;      //4字节 vide对应视频 soun对应只有音频const unsigned int(32)[3] reserved = 0; //3*4保留位string   name;//name,长度不定以'\0'结尾}
var hdlr = new Uint8Array([            0x00, 0x00, 0x00, 0x00, // version(0) + flags            0x00, 0x00, 0x00, 0x00, // pre_defined            0x76, 0x69, 0x64, 0x65, // handler_type: 'vide' 在media box中,该值为4个字符     “vide”— video track            0x00, 0x00, 0x00, 0x00, // reserved: 3 * 4 bytes            0x00, 0x00, 0x00, 0x00,            0x00, 0x00, 0x00, 0x00, //保留位            0x56, 0x69, 0x64, 0x65,            0x6F, 0x48, 0x61, 0x6E,            0x64, 0x6C, 0x65, 0x72, 0x00 // name: VideoHandler 长度不定     track type name,以‘\0’结尾的字符串        ]);

hdlr是一个full box,所以它没有子box了,它最终的表现是 4字节长度+4字节’hdlr’+hdlr对象,就是一个完整的hdlr box

hdlr内部分2种情况,由handler_type来定义


minf box

Box Type: ‘minf’
Container: Media Box (‘mdia’)
Mandatory: Yes
Quantity:Exactly one

定义

aligned(8) class MediaInformationBox extends Box(‘minf’) { }

minf是一个容器box


smhd or vmhd box

BoxTypes: ‘vmhd’,‘smhd’,’hmhd’,‘nmhd’
Container: Media Information Box (‘minf’)
Mandatory: Yes
Quantity:Exactly one specific media header shall be present

定义

aligned(8) class VideoMediaHeaderBoxextends FullBox(‘vmhd’, version = 0, 1) {template unsigned int(16) graphicsmode = 0; // copy, see below template unsigned int(16)[3] opcolor = {0, 0, 0};}aligned(8) class SoundMediaHeaderBox   extends FullBox(‘smhd’, version = 0, 0) {   template int(16) balance = 0;   const unsigned int(16)  reserved = 0;}

vmhd和smhd定义是不同的

var SMHD = new Uint8Array([            0x00, 0x00, 0x00, 0x00, // version(0) + flags   box版本,0或1,一般为0。            0x00, 0x00, 0x00, 0x00 // balance(2) + reserved(2) 立体声平衡,[8.8] 格式值,一般为0,-1.0表示全部左声道,1.0表示全部右声道+2位保留位        ]);        // video media headervar VMHD = new Uint8Array([            0x00, 0x00, 0x00, 0x01, // version(0) + flags            0x00, 0x00, // graphicsmode: 2 bytes 视频合成模式,为0时拷贝原始图像,否则与opcolor进行合成   //理论上是4位啊  暂时保留            0x00, 0x00, 0x00, 0x00, // opcolor: 3 * 2 bytes {red,green,blue}            0x00, 0x00        ]);

smhd or vmhd 统称 xmhd ,xmhd是一个full box,没有更多子box

具体分别是用smhd还是vmhd,需要看这个视频是否是一个单音频,还是有视频,单音频用smhd,视频用vmhd


dinf box

Box Type: ‘dinf’
Container: Media Information Box (‘minf’) or Meta Box (‘meta’)
Mandatory: Yes(requiredwithin‘minf’box)andNo(optionalwithin‘meta’box)
Quantity:Exactly one

定义

aligned(8) class DataInformationBox extends Box(‘dinf’) { }

dinf是一个容器box


dref box

BoxTypes: ‘url‘,‘urn‘,‘dref’
Container: Data Information Box (‘dinf’)
Mandatory: Yes
Quantity:Exactly one

定义

//url定义aligned(8) class DataEntryUrlBox (bit(24) flags) extends FullBox(‘url ’, version = 0, flags) {   string   location;}//urn定义aligned(8) class DataEntryUrnBox (bit(24) flags) extends FullBox(‘urn ’, version = 0, flags) { string name;string location;}//dref定义aligned(8) class DataReferenceBoxextends FullBox(‘dref’, version = 0, 0) { unsigned int(32) entry_count;for (i=1; i • entry_count; i++) {DataEntryBox(entry_version, entry_flags) data_entry; }}
var DREF = new Uint8Array([            0x00, 0x00, 0x00, 0x00, // version(0) + flags            0x00, 0x00, 0x00, 0x01, // entry_count 1个url                //url   box开始            0x00, 0x00, 0x00, 0x0C, // entry_size            0x75, 0x72, 0x6C, 0x20, // type 'url '            0x00, 0x00, 0x00, 0x01 // version(0) + flags 当“url”或“urn”的box flag为1时,字符串均为空。        ]);

dref box是一个full box 但是形态不一样,但是在fmp4中,只需要dref形态

这个地方回头细说

阅读全文
0 0
原创粉丝点击