UNPKG

mp4box

Version:

JavaScript version of GPAC's MP4Box tool

43 lines (41 loc) 1.35 kB
BoxParser.createFullBoxCtor("trun", "TrackRunBox", function(stream) { var readBytes = 0; this.sample_count = stream.readUint32(); readBytes+= 4; if (this.size - this.hdr_size > readBytes && (this.flags & BoxParser.TRUN_FLAGS_DATA_OFFSET) ) { this.data_offset = stream.readInt32(); //signed readBytes += 4; } else { this.data_offset = 0; } if (this.size - this.hdr_size > readBytes && (this.flags & BoxParser.TRUN_FLAGS_FIRST_FLAG) ) { this.first_sample_flags = stream.readUint32(); readBytes += 4; } else { this.first_sample_flags = 0; } this.sample_duration = []; this.sample_size = []; this.sample_flags = []; this.sample_composition_time_offset = []; if (this.size - this.hdr_size > readBytes) { for (var i = 0; i < this.sample_count; i++) { if (this.flags & BoxParser.TRUN_FLAGS_DURATION) { this.sample_duration[i] = stream.readUint32(); } if (this.flags & BoxParser.TRUN_FLAGS_SIZE) { this.sample_size[i] = stream.readUint32(); } if (this.flags & BoxParser.TRUN_FLAGS_FLAGS) { this.sample_flags[i] = stream.readUint32(); } if (this.flags & BoxParser.TRUN_FLAGS_CTS_OFFSET) { if (this.version === 0) { this.sample_composition_time_offset[i] = stream.readUint32(); } else { this.sample_composition_time_offset[i] = stream.readInt32(); //signed } } } } });