Skip to content

Function: readIsoBoxes() ​

ts
function readIsoBoxes<V>(raw, config?): ParsedIsoBox<V>[];

Defined in: readIsoBoxes.ts:38

Reads ISO boxes from a data source.

The int64 option of the configuration selects the type of every 64-bit integer field. With readInt64AsBigInt, the built-in readers return those fields as a bigint.

A box with a reader in the configuration is a box object. A box with no reader and a type in CONTAINERS has its child boxes in boxes. Any other box with no reader is a raw box: { type, bytes, headerSize }.

The result type does not follow the readers map. Every box has the type ParsedIsoBox, and type has the four-character code. Use isIsoBoxType to narrow a box to a box type. A test such as box.type === 'tfdt' also matches a raw box, and does not narrow.

The function stops before a box if the data ends inside the header or the body of that box. The function also stops before a box with a size below the size of its header. By default, the function then returns the boxes before that box and does not throw for that box.

Type Parameters ​

V ​

V extends IsoInt64 = number

Parameters ​

raw ​

IsoBoxData

The raw ISO data

config? ​

IsoBoxReadConfig<V>

The readers map, the int64 option, and the truncated option.

Returns ​

ParsedIsoBox<V>[]

The parsed boxes

Throws ​

RangeError if a reader throws a RangeError, such as for a box that is too short for its fields.

Throws ​

RangeError if a box is deeper than 128 levels.

Throws ​

RangeError if the truncated option is 'throw' and the data has a truncated box. The message has the position of the box and the cause.

Example ​

ts
// Sample 'ftyp' box (20 bytes)
const bytes = new Uint8Array([
	0x00, 0x00, 0x00, 0x14, 0x66, 0x74, 0x79, 0x70, 0x69, 0x73, 0x6f, 0x6d, 0x00, 0x00, 0x00,
	0x01, 0x69, 0x73, 0x6f, 0x6d,
])
const boxes = readIsoBoxes(bytes.buffer, { readers: { ftyp: readFtyp, stsd: readStsd } })

assert.strictEqual(boxes.length, 1)

const box = boxes[0]
assert.ok(isIsoBoxType('ftyp', box))
assert.strictEqual(box.majorBrand, 'isom')
assert.strictEqual(box.minorVersion, 1)
assert.deepStrictEqual(box.compatibleBrands, ['isom'])

A Streaming Video Technology Alliance project.