mp4reader
Version:
MP4 parser, parsed according to the standard, borrows the implementation of MP4 package
1 lines • 20.1 kB
JavaScript
let fsPromise=require("fs/promises"),mp4Info={ftyp:{},moov:{}};function FindStartCode2(buffer=Buffer.from([])){return!!buffer.length&&(0==buffer[0]&&0==buffer[1]&&1==buffer[2])}function FindStartCode3(buffer=Buffer.from([])){return!!buffer.length&&(0==buffer[0]&&0==buffer[1]&&0==buffer[2]&&1==buffer[3])}async function getFileInfoAsync(filename=""){try{let stat;return await fsPromise.stat(filename)}catch(err){return{}}}async function Mp4FindMoov(filename=""){if(""==filename)return-1;let offset=0;const MAX_BUFFER_LEN=1048576;let buff=Buffer.alloc(1048576);for(let k=0;k<1048576e3;k++){let filehandle=await fsPromise.open(filename),{buffer:buffer,bytesRead:bytesRead}=await filehandle.read(buff,0,1048576,offset);if(filehandle.close(),0==bytesRead)return-1;{let result=buffer.indexOf("moov");if(result>0)return{offset:offset+result-4,size:buff.readUInt32BE(result-4)}}offset+=1048576}}async function Mp4DecodeMoov(filename=""){let moovInfo=await Mp4FindMoov(filename);if(-1==moovInfo)return-1;let{size:size=0,offset:offset=0}=moovInfo;if(""==filename||0===size)return-1;let filehandle=await fsPromise.open(filename,"r"),buff=Buffer.alloc(size),{buffer:moov_buffer,bytesRead:bytesRead}=await filehandle.read(buff,0,size,offset);if(filehandle.close(),0==bytesRead)return-1;let mvhd=parse_mvhd(moov_buffer,offset),udta=parse_udta(moov_buffer,offset),trak=parse_trak(moov_buffer,offset);return{...moovInfo,mvhd:mvhd,udta:udta,trak:trak}}var parse_mvhd=function(moov_buffer=Buffer.from([]),base_offset=0){let offset=moov_buffer.indexOf("mvhd");if(offset<0)return-1;offset-=4;let size=moov_buffer.readUInt32BE(offset),box_type=moov_buffer.slice(offset+4,offset+8).toString(),version=moov_buffer[offset+8],flags=moov_buffer.readUInt32BE(offset+8)<<8>>8,ctime=0,mtime=0,scale=0,duration=0;return 0==version?(ctime=time1904To1970(moov_buffer.readUInt32BE(offset+12)),mtime=time1904To1970(moov_buffer.readUInt32BE(offset+16)),scale=moov_buffer.readUInt32BE(offset+20),duration=moov_buffer.readUInt32BE(offset+24)):1==version&&(ctime=time1904To1970(moov_buffer.readDoubleBE(offset+12)),mtime=time1904To1970(moov_buffer.readDoubleBE(offset+20)),scale=moov_buffer.readUInt32BE(offset+28),duration=moov_buffer.readDoubleBE(offset+32)),{ctime:ctime,mtime:mtime,scale:scale,duration:duration,Start_offset:offset+base_offset,Box_size:size,Box_type:box_type,version:version,flags:flags}},parse_trak=function(moov_buffer=Buffer.from([]),base_offset=0){let trak=[],trak_offset_list=[];for(let i=0;i<moov_buffer.length;){let offset=moov_buffer.indexOf("trak",i);if(offset<0)break;let size=moov_buffer.readUInt32BE(offset-4);trak_offset_list.push(offset),i=offset+size-4}return trak_offset_list.forEach(ele=>{let offset=ele;offset-=4;let size=moov_buffer.readUInt32BE(offset),box_type=moov_buffer.slice(offset+4,offset+8).toString(),tkhd=parse_tkhd(moov_buffer.slice(offset),offset+base_offset),mdia=parse_mdia(moov_buffer.slice(offset),offset+base_offset);trak.push({Start_offset:offset+base_offset,Box_size:size,Box_type:box_type,tkhd:tkhd,mdia:mdia})}),trak};async function Mp4DecodeFtyp(filename=""){if(""==filename)return-1;let offset=0,buff=Buffer.alloc(32),filehandle=await fsPromise.open(filename),{buffer:buffer,bytesRead:bytesRead}=await filehandle.read(buff,0,32,0);if(filehandle.close(),0==bytesRead)return-2;{let box_type=buffer.slice(4,8).toString(),Major_brand=buffer.slice(8,12).toString(),Minor_version=buffer.slice(12,16).readUInt32BE(),Compatible_brands=buffer.slice(16,31).toString();return"ftyp"!==box_type?-3:{Start_offset:0,Box_type:box_type,Major_brand:Major_brand,Minor_version:Minor_version,Compatible_brands:Compatible_brands}}}async function Mp4DecodeAll(filename=""){if(""==filename)return-1;let ftyp=await Mp4DecodeFtyp(filename);if(ftyp<0)return console.error("mp4 wrong format"),-1;Object.assign(mp4Info.ftyp,ftyp);let moov=await Mp4DecodeMoov(filename);return Object.assign(mp4Info.moov,moov),mp4Info}function parse_tkhd(moov_buffer=Buffer.from([]),base_offset=0){let offset=moov_buffer.indexOf("tkhd");if(offset<0)return-1;offset-=4;let size=moov_buffer.readUInt32BE(offset),box_type=moov_buffer.slice(offset+4,offset+8).toString(),version=moov_buffer[offset+8],flags=moov_buffer.readUInt32BE(offset+8)<<8>>8,ctime=0,mtime=0,track_id=0,reserved=0,duration=0,layer=0,alternate_group=0,volume=0,matrix=0,width=0,height=0;return 0==version?(ctime=time1904To1970(moov_buffer.readUInt32BE(offset+12)),mtime=time1904To1970(moov_buffer.readUInt32BE(offset+16)),track_id=moov_buffer.readUInt32BE(offset+20),reserved=moov_buffer.readUInt32BE(offset+24),duration=moov_buffer.readUInt32BE(offset+28),layer=moov_buffer.readUInt16BE(offset+40),alternate_group=moov_buffer.readUInt16BE(offset+42),volume=moov_buffer.readUInt16BE(offset+44),matrix=moov_buffer.slice(offset+46,offset+82),width=moov_buffer.readUInt32BE(offset+82),height=moov_buffer.readUInt32BE(offset+86)):1==version&&(ctime=time1904To1970(moov_buffer.readDoubleBE(offset+12)),mtime=time1904To1970(moov_buffer.readDoubleBE(offset+20)),track_id=moov_buffer.readUInt32BE(offset+28),reserved=moov_buffer.readUInt32BE(offset+32),duration=moov_buffer.readUInt32BE(offset+36),layer=moov_buffer.readUInt16BE(offset+48),alternate_group=moov_buffer.readUInt16BE(offset+50),volume=moov_buffer.readUInt16BE(offset+52),matrix=moov_buffer.slice(offset+54,offset+90),width=moov_buffer.readUInt32BE(offset+90),height=moov_buffer.readUInt32BE(offset+94)),{ctime:ctime,mtime:mtime,track_id:track_id,duration:duration,layer:layer,alternate_group:alternate_group,volume:volume,matrix:matrix,width:width,height:height,Start_offset:offset+base_offset,Box_size:size,Box_type:box_type,version:version,flags:flags}}function parse_mdia(moov_buffer=Buffer.from([]),base_offset=0){let offset=moov_buffer.indexOf("mdia"),size,box_type,mdhd,hdlr,minf;return offset<0?-1:(offset-=4,{Start_offset:offset+base_offset,Box_size:moov_buffer.readUInt32BE(offset),Box_type:moov_buffer.slice(offset+4,offset+8).toString(),mdhd:parse_mdhd(moov_buffer,base_offset),hdlr:parse_hdlr(moov_buffer,base_offset),minf:parse_minf(moov_buffer,base_offset)})}function parse_mdhd(moov_buffer=Buffer.from([]),base_offset=0){let offset=moov_buffer.indexOf("mdhd"),size,box_type;return offset<0?-1:(offset-=4,{Start_offset:offset+base_offset,Box_size:moov_buffer.readUInt32BE(offset),Box_type:moov_buffer.slice(offset+4,offset+8).toString()})}function parse_hdlr(moov_buffer=Buffer.from([]),base_offset=0){let offset=moov_buffer.indexOf("hdlr");if(offset<0)return-1;offset-=4;let size=moov_buffer.readUInt32BE(offset),box_type=moov_buffer.slice(offset+4,offset+8).toString(),version=moov_buffer[offset+8],flags=moov_buffer.readUInt32BE(offset+8)<<8>>8,Handler_type=moov_buffer.slice(offset+16,offset+20).toString(),stringLength=size,Name;for(let i=32;i<=size;i++)if(0==moov_buffer[offset+i]){stringLength=i;break}return{Start_offset:offset+base_offset,Box_size:size,Box_type:box_type,version:version,flags:flags,Handler_type:Handler_type,Name:moov_buffer.slice(offset+32,offset+stringLength).toString()}}function parse_minf(moov_buffer=Buffer.from([]),base_offset=0){let offset=moov_buffer.indexOf("minf");if(offset<0)return-1;offset-=4;let size=moov_buffer.readUInt32BE(offset),box_type=moov_buffer.slice(offset+4,offset+8).toString(),mhd=parse_mhd(moov_buffer,base_offset),box_name="vmhd",dinf,stbl,Obj={Start_offset:offset+base_offset,Box_size:size,Box_type:box_type,dinf:parse_dinf(moov_buffer,base_offset),stbl:parse_stbl(moov_buffer,base_offset)};return-1!==mhd&&"vmhd"==mhd.Box_type?Object.assign(Obj,{vmhd:mhd}):-1!==mhd&&"smhd"==mhd.Box_type&&Object.assign(Obj,{smhd:mhd}),Obj}function parse_mhd(moov_buffer=Buffer.from([]),base_offset=0){let offset=moov_buffer.indexOf("vmhd"),size,box_type;return-1==offset&&(offset=moov_buffer.indexOf("smhd")),offset<0?-1:(offset-=4,{Start_offset:offset+base_offset,Box_size:moov_buffer.readUInt32BE(offset),Box_type:moov_buffer.slice(offset+4,offset+8).toString()})}function parse_dinf(moov_buffer=Buffer.from([]),base_offset=0){let offset=moov_buffer.indexOf("dinf"),size,box_type;return offset<0?-1:(offset-=4,{Start_offset:offset+base_offset,Box_size:moov_buffer.readUInt32BE(offset),Box_type:moov_buffer.slice(offset+4,offset+8).toString(),dref:-1})}function parse_stbl(moov_buffer=Buffer.from([]),base_offset=0){let offset=moov_buffer.indexOf("stbl"),size,box_type,stsd,stts,stss,ctts,stsc,stsz,stco;return offset<0?-1:(offset-=4,{Start_offset:offset+base_offset,Box_size:moov_buffer.readUInt32BE(offset),Box_type:moov_buffer.slice(offset+4,offset+8).toString(),stsd:parse_stsd(moov_buffer,base_offset),stts:parse_stts(moov_buffer,base_offset),stss:parse_stss(moov_buffer,base_offset),ctts:parse_ctts(moov_buffer,base_offset),stsc:parse_stsc(moov_buffer,base_offset),stsz:parse_stsz(moov_buffer,base_offset),stco:parse_stco(moov_buffer,base_offset)})}function parse_stsd(moov_buffer=Buffer.from([]),base_offset=0){let offset=moov_buffer.indexOf("stsd");if(offset<0)return-1;offset-=4;let size=moov_buffer.readUInt32BE(offset),box_type=moov_buffer.slice(offset+4,offset+8).toString(),version=moov_buffer[offset+8],flags=moov_buffer.readUInt32BE(offset+8)<<8>>8,entry_count=moov_buffer.readUInt32BE(offset+12),SampleEntry=moov_buffer.slice(offset+20,offset+24).toString();switch(SampleEntry){case"avc1":let avc1;return{Start_offset:offset+base_offset,Box_size:size,Box_type:box_type,entry_count:entry_count,SampleEntry:SampleEntry,avc1:parse_avc1(moov_buffer,base_offset)};case"mp4a":let mp4a;return{Start_offset:offset+base_offset,Box_size:size,Box_type:box_type,SampleEntry:SampleEntry,mp4a:parse_mp4a(moov_buffer,base_offset)};case"mp4v":let mp4v;return{Start_offset:offset+base_offset,Box_size:size,Box_type:box_type,SampleEntry:SampleEntry,mp4v:parse_mp4v(moov_buffer,base_offset)};case"hev1":let hev1;return{Start_offset:offset+base_offset,Box_size:size,Box_type:box_type,SampleEntry:SampleEntry,hev1:parse_hev1(moov_buffer,base_offset)}}return{Start_offset:offset+base_offset,Box_size:size,Box_type:box_type,SampleEntry:SampleEntry}}function parse_hev1(moov_buffer=Buffer.from([]),base_offset=0){let offset=moov_buffer.indexOf("hev1"),size,box_type;return offset<0?-1:(offset-=4,{Start_offset:offset+base_offset,Box_size:moov_buffer.readUInt32BE(offset),Box_type:moov_buffer.slice(offset+4,offset+8).toString()})}function parse_mp4v(){return-1}function parse_mp4a(moov_buffer=Buffer.from([]),base_offset=0){let offset=moov_buffer.indexOf("mp4a"),size,box_type,version,flags,Channel_count,Sample_size,Sample_rate;return offset<0?-1:(offset-=4,{Start_offset:offset+base_offset,Box_size:moov_buffer.readUInt32BE(offset),Box_type:moov_buffer.slice(offset+4,offset+8).toString(),version:moov_buffer[offset+8],flags:moov_buffer.readUInt32BE(offset+8)<<8>>8,Channel_count:moov_buffer.readUInt16BE(offset+24),Sample_size:moov_buffer.readUInt16BE(offset+26),Sample_rate:moov_buffer.readUInt32BE(offset+30),esds:-1})}function parse_avc1(moov_buffer=Buffer.from([]),base_offset=0){let offset=moov_buffer.indexOf("avc1"),size,box_type,version,flags,width,height,Horiz_resolution,Ver_resolution,Frame_count,avcC;return offset<0?-1:(offset-=4,{Start_offset:offset+base_offset,Box_size:moov_buffer.readUInt32BE(offset),Box_type:moov_buffer.slice(offset+4,offset+8).toString(),version:moov_buffer[offset+8],flags:moov_buffer.readUInt32BE(offset+8)<<8>>8,width:moov_buffer.readUInt16BE(offset+32),height:moov_buffer.readUInt16BE(offset+34),Horiz_resolution:moov_buffer.readUInt32BE(offset+36),Ver_resolution:moov_buffer.readUInt32BE(offset+36),Frame_count:moov_buffer.readUInt16BE(offset+44),avcC:parse_avcC(moov_buffer,base_offset)})}function parse_avcC(moov_buffer=Buffer.from([]),base_offset=0){let offset=moov_buffer.indexOf("avcC");if(offset<0)return-1;offset-=4;let size=moov_buffer.readUInt32BE(offset),box_type=moov_buffer.slice(offset+4,offset+8).toString(),Configuration_version=moov_buffer[offset+8],AVC_profile_indication=moov_buffer[offset+9],AVC_profile_compatibility=moov_buffer[offset+10],AVC_level_indication=moov_buffer[offset+11],NALU_length_size=1+(3&moov_buffer[offset+12]),Num_sequence_parameter_sets=31&moov_buffer[offset+13],SPS=[],point=offset+14;for(let i=0;i<Num_sequence_parameter_sets;i++){let len=moov_buffer.readUint16BE(point),sps_array=moov_buffer.slice(point+2,point+2+len);SPS.push(...sps_array),point=point+len+2}let Num_picture_parameter_sets=moov_buffer[point],PPS=[];for(let i=0;i<Num_picture_parameter_sets;i++){let len=moov_buffer.readUint16BE(point+1),pps_array=Uint8Array.from(moov_buffer.slice(point+3,point+3+len));PPS.push(...pps_array),point=point+len+2}return{Start_offset:offset+base_offset,Box_size:size,Box_type:box_type,Configuration_version:Configuration_version,AVC_profile_indication:AVC_profile_indication,AVC_profile_compatibility:AVC_profile_compatibility,AVC_level_indication:AVC_level_indication,NALU_length_size:NALU_length_size,SPS:SPS,PPS:PPS,Num_sequence_parameter_sets:Num_sequence_parameter_sets,Num_picture_parameter_sets:Num_picture_parameter_sets}}function parse_stts(moov_buffer=Buffer.from([]),base_offset=0){let offset=moov_buffer.indexOf("stts");if(offset<0)return-1;offset-=4;let size=moov_buffer.readUInt32BE(offset),box_type=moov_buffer.slice(offset+4,offset+8).toString(),version=moov_buffer[offset+8],flags=moov_buffer.readUInt32BE(offset+8)<<8>>8,count=moov_buffer.readUInt32BE(offset+12),Time_to_sample=[];for(let i=0;i<count;i++)Time_to_sample.push({No:i+1,Sample_count:moov_buffer.readUInt32BE(offset+16+8*i),Sample_duration:moov_buffer.readUInt32BE(offset+16+4+8*i)});return{Start_offset:offset+base_offset,Box_size:size,Box_type:box_type,version:version,flags:flags,count:count,Time_to_sample:Time_to_sample}}function parse_stss(moov_buffer=Buffer.from([]),base_offset=0){let offset=moov_buffer.indexOf("stss");if(offset<0)return-1;offset-=4;let size=moov_buffer.readUInt32BE(offset),box_type=moov_buffer.slice(offset+4,offset+8).toString(),version=moov_buffer[offset+8],flags=moov_buffer.readUInt32BE(offset+8)<<8>>8,count=moov_buffer.readUInt32BE(offset+12),Sample_list=[];for(let i=0;i<count;i++)Sample_list.push(moov_buffer.readUInt32BE(offset+16+4*i));return{Start_offset:offset+base_offset,Box_size:size,Box_type:box_type,version:version,flags:flags,count:count,Sample_list:Sample_list}}function parse_ctts(moov_buffer=Buffer.from([]),base_offset=0){let offset=moov_buffer.indexOf("ctts");if(offset<0)return-1;offset-=4;let size=moov_buffer.readUInt32BE(offset),box_type=moov_buffer.slice(offset+4,offset+8).toString(),version=moov_buffer[offset+8],flags=moov_buffer.readUInt32BE(offset+8)<<8>>8,count=moov_buffer.readUInt32BE(offset+12),Sample_list=[];for(let i=0;i<count;i++)Sample_list.push({No:i+1,Sample_count:moov_buffer.readUInt32BE(offset+16+8*i),Sample_offset:moov_buffer.readUInt32BE(offset+16+4+8*i)});return{Start_offset:offset+base_offset,Box_size:size,Box_type:box_type,version:version,flags:flags,count:count,Sample_list:Sample_list}}function parse_stsc(moov_buffer=Buffer.from([]),base_offset=0){let offset=moov_buffer.indexOf("stsc");if(offset<0)return-1;offset-=4;let size=moov_buffer.readUInt32BE(offset),box_type=moov_buffer.slice(offset+4,offset+8).toString(),version=moov_buffer[offset+8],flags=moov_buffer.readUInt32BE(offset+8)<<8>>8,count=moov_buffer.readUInt32BE(offset+12),Sample_to_chunk=[];for(let i=0;i<count;i++)Sample_to_chunk.push({No:i+1,First_chunk:moov_buffer.readUInt32BE(offset+16+8*i),Sample_perchunk:moov_buffer.readUInt32BE(offset+16+4+8*i),Sample_description_index:moov_buffer.readUInt32BE(offset+16+8+8*i)});return{Start_offset:offset+base_offset,Box_size:size,Box_type:box_type,version:version,flags:flags,count:count,Sample_to_chunk:Sample_to_chunk}}function parse_stsz(moov_buffer=Buffer.from([]),base_offset=0){let offset=moov_buffer.indexOf("stsz");if(offset<0)return-1;offset-=4;let size=moov_buffer.readUInt32BE(offset),box_type=moov_buffer.slice(offset+4,offset+8).toString(),version=moov_buffer[offset+8],flags=moov_buffer.readUInt32BE(offset+8)<<8>>8,Sample_size=moov_buffer.readUInt32BE(offset+12),Sample_count=moov_buffer.readUInt32BE(offset+16),Sample_size_list=[];if(0==Sample_size)for(let i=0;i<Sample_count;i++)Sample_size_list.push({No:i+1,Sample_size:moov_buffer.readUInt32BE(offset+20+4*i)});return{Start_offset:offset+base_offset,Box_size:size,Box_type:box_type,version:version,flags:flags,Sample_size:Sample_size,Sample_count:Sample_count,Sample_size_list:Sample_size_list}}function parse_stco(moov_buffer=Buffer.from([]),base_offset=0){let offset=moov_buffer.indexOf("stco");if(offset<0)return-1;offset-=4;let size=moov_buffer.readUInt32BE(offset),box_type=moov_buffer.slice(offset+4,offset+8).toString(),version=moov_buffer[offset+8],flags=moov_buffer.readUInt32BE(offset+8)<<8>>8,count=moov_buffer.readUInt32BE(offset+12),Chunk_offset_list=[];for(let i=0;i<count;i++)Chunk_offset_list.push({No:i+1,Chunk_offset:moov_buffer.readUInt32BE(offset+16+4*i)});return{Start_offset:offset+base_offset,Box_size:size,Box_type:box_type,version:version,flags:flags,count:count,Chunk_offset_list:Chunk_offset_list}}function parse_udta(moov_buffer=Buffer.from([]),base_offset=0){return-1}function time1904To1970(UTC=0){return new Date(UTC-20828448e5).toLocaleString()}async function Mp4DecodeByModule(filename="",configOption=["ftyp"]){if("object"!=typeof configOption||""==filename)return-1;let option={ftyp:!1,moov:!1,mvhd:!1,trak:!1,tkhd:!1,mdia:!1,hdlr:!1,minf:!1,stbl:!1,stsd:!1,stts:!1,stss:!1,ctts:!1,stsc:!1,stsz:!1,stco:!1};configOption.forEach(el=>{option.hasOwnProperty(el)&&(option[el]=!0)});let resdata={},moovInfo=await Mp4FindMoov(filename),{size:size=0,offset:offset=0}=moovInfo;if(0===size||-1==moovInfo)return-1;let filehandle=await fsPromise.open(filename,"r"),buff=Buffer.alloc(size),{buffer:moov_buffer,bytesRead:bytesRead}=await filehandle.read(buff,0,size,offset);if(filehandle.close(),0==bytesRead)return-1;for(let key in option)switch(key){case"ftyp":if(option[key]){let ftyp=await Mp4DecodeFtyp(filename);Object.assign(resdata,{ftyp:ftyp})}break;case"moov":if(option[key]){let mvhd=parse_mvhd(moov_buffer,offset),udta=parse_udta(moov_buffer,offset),trak=parse_trak(moov_buffer,offset);Object.assign(resdata,{moov:{...moovInfo,mvhd:mvhd,udta:udta,trak:trak}})}break;case"mvhd":if(option[key]){let mvhd=parse_mvhd(moov_buffer,offset);Object.assign(resdata,{mvhd:mvhd})}break;case"trak":if(option[key]){let trak=parse_trak(moov_buffer,offset);Object.assign(resdata,{trak:trak})}break;case"tkhd":case"mdia":case"hdlr":case"minf":case"stbl":case"stsd":case"stts":case"stss":case"ctts":case"stsc":case"stsz":case"stco":if(option[key]){let trak_offset_list=getTrackList(moov_buffer,offset),base_offset=offset,box_data=[];trak_offset_list.forEach(ele=>{let offsetB=ele;offsetB-=4;let size=moov_buffer.readUInt32BE(offsetB),box_type=moov_buffer.slice(offsetB+4,offsetB+8).toString(),res=parse_exact_box(moov_buffer.slice(offsetB),offsetB+base_offset,key);box_data.push(res)});let obj={};obj[key]=box_data,Object.assign(resdata,obj)}}return resdata}function parse_exact_box(buffer=[],offset=0,key=null){switch(key){case"tkhd":return parse_tkhd(buffer,offset);case"mdia":return parse_mdia(buffer,offset);case"hdlr":return parse_hdlr(buffer,offset);case"minf":return parse_minf(buffer,offset);case"stbl":return parse_stbl(buffer,offset);case"stsd":return parse_stsd(buffer,offset);case"stts":return parse_stts(buffer,offset);case"stss":return parse_stss(buffer,offset);case"ctts":return parse_ctts(buffer,offset);case"stsc":return parse_stsc(buffer,offset);case"stsz":return parse_stsz(buffer,offset);case"stco":return parse_stco(buffer,offset)}}function getTrackList(moov_buffer=Buffer.from([]),base_offset=0){let trak=[],trak_offset_list=[];for(let i=0;i<moov_buffer.length;){let offset=moov_buffer.indexOf("trak",i);if(offset<0)break;let size=moov_buffer.readUInt32BE(offset-4);trak_offset_list.push(offset),i=offset+size-4}return trak_offset_list}module.exports={FindStartCode2:FindStartCode2,FindStartCode3:FindStartCode3,getFileInfoAsync:getFileInfoAsync,Mp4FindMoov:Mp4FindMoov,Mp4DecodeFtyp:Mp4DecodeFtyp,Mp4DecodeAll:Mp4DecodeAll,Mp4DecodeByModule:Mp4DecodeByModule};