Skip to content

Function: iterateChildBoxes() ​

ts
function iterateChildBoxes<V>(cursor): Generator<readonly [string, IsoBoxReadCursor<V>], void, undefined>;

Defined in: iterateChildBoxes.ts:58

Iterates over the boxes from the position of a cursor to its end, and yields a read cursor for each box.

The function parses no content of a box. For each box, the result has the type of the box and a new cursor for that box. In that cursor, start is the first byte of the box header, pos is the first byte after the header, and end is the first byte after the box. For a uuid box, pos is the first byte of usertype. The cursor has the readers map, the int64 option, and the truncated option of the input.

The function reads pos and end of the input cursor when it is called, and does not move the input cursor. A later move of the input cursor does not change the iteration. Each cursor of the result is independent, so a move of one cursor moves no other. The iteration stops before a truncated box: the data ends inside the box, or the size is below the header size. The end of the last cursor is then the first byte of that box.

Use the function to read some boxes of a list, to read the position of a box, or to read a box that seekIsoBox does not find, such as the second traf box of a moof box. readChildBoxes reads every box of the list. nextIsoBox steps over one box and creates no cursor.

Type Parameters ​

V ​

V extends IsoInt64 = number

Parameters ​

cursor ​

IsoBoxReadCursor<V>

The cursor at the first byte of the first box.

Returns ​

Generator<readonly [string, IsoBoxReadCursor<V>], void, undefined>

An iterator of the type and the cursor of each box.

Throws ​

RangeError from next() if the input cursor has the truncated option 'throw' and the iteration reaches a truncated box. The message has the position of the box and the cause.

Example ​

ts
const traf = seekIsoBox(load('mss_moof_tfdt.mp4'), ['moof', 'traf'])
const sizes: Record<string, number> = {}
let samples = 0

assert.ok(traf)

for (const [type, child] of iterateChildBoxes(traf)) {
	sizes[type] = child.end - child.start // tfhd, tfdt, and trun with the size of each box

	if (type === 'trun') {
		const trun = readTrun(child)

		samples = trun.samples ? trun.samples.length : trun.sampleCount
	}
}

A Streaming Video Technology Alliance project.