Function: readIsoBoxSize()
function readIsoBoxSize(
view,
at,
end,
ignoreUserType?
): number;Defined in: readIsoBoxSize.ts:22
Returns the size of the box at a position of a DataView, with no allocation.
The function reads the box header by the rules of ISO/IEC 14496-12, clause 4.2. A box with size 0 extends to end. A box with size 1 has its size in the 8 bytes of largesize. The header of a box with largesize has 16 bytes. The header of any other box has 8 bytes. The header of a uuid box has 16 more bytes for usertype.
Use the function in a loop over sibling boxes that has no read cursor. nextIsoBox does the same step with a read cursor.
Parameters
view
The data.
at
number
The position of the first byte of the box. The position must be an integer of 0 or more.
end
number
The position after the last byte that the box can use. The position must not pass the end of view.
ignoreUserType?
boolean
If true, the header of a uuid box does not include usertype. The function then returns the size of a uuid box with fewer than 16 bytes after its header. The default is false.
Returns
number
The size of the box in bytes. The result is 0 at end and for a truncated box. In a truncated box, the data ends inside the box, or the size is below the header size.
Example
const view = new DataView(load('mss_moof_tfdt.mp4'))
const sizes: number[] = []
let at = 0
let size = readIsoBoxSize(view, at, view.byteLength)
while (size) {
sizes.push(size) // the moof box, then the mdat box
at += size
size = readIsoBoxSize(view, at, view.byteLength)
}