Skip to content

Function: seekIsoBoxes() ​

Call Signature ​

ts
function seekIsoBoxes<V>(data, path): IsoBoxReadCursor<V>[];

Defined in: seekIsoBoxes.ts:67

Finds every box at a path and returns a read cursor for each box. The function decodes no box.

The function treats the body of each box in the path as a list of boxes. It compares the type of each box with the path. The function searches every box of each type in the path, not only the first one. The result has the boxes in the order of the data. The first cursor of the result is the box that seekIsoBox returns for the same input. In each cursor of the result, 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 search of a list of boxes stops before a truncated box. If that list is the body of a box, the search continues after that box. By default, a truncated box gives a shorter array and no error.

The function knows no box type. A box such as meta or stsd has fields before its child boxes. For such a box, move pos past the fields, then call the function again with that cursor.

Type Parameters ​

V ​

V extends IsoInt64 = number

Parameters ​

data ​

IsoBoxReadCursor<V>

The data, or a read cursor. The search starts at the position of a cursor, and the function does not move that cursor. Each cursor of the result keeps the readers map, the int64 option, and the truncated option of the input cursor.

path ​

readonly string[]

The type of each box, from the outer box to the boxes to find. With an empty path, the result has one cursor at the position of the input. Each character of a type is one byte, so it must be U+00FF or below. The function does not check that rule, and the result is not defined for other characters.

Returns ​

IsoBoxReadCursor<V>[]

A new read cursor for each box at the path. The result is an empty array if the data has no box at the path.

Throws ​

RangeError if a type in the path does not have 4 characters. The message has the type.

Throws ​

RangeError if the cursor has the truncated option 'throw' and the search reaches a truncated box. The message has the position of the box and the cause.

Example ​

ts
const segment = await readFile(new URL('./fixtures/captions_fragmented.mp4', import.meta.url))

const times = seekIsoBoxes(segment, ['moof', 'traf', 'tfdt']).map(
	cursor => readTfdt(cursor).baseMediaDecodeTime,
)

Call Signature ​

ts
function seekIsoBoxes<V>(
   data, 
   path, 
   config?
): IsoBoxReadCursor<V>[];

Defined in: seekIsoBoxes.ts:81

Finds every box at a path and returns a read cursor for each box. The function decodes no box.

Type Parameters ​

V ​

V extends IsoInt64 = number

Parameters ​

data ​

IsoBoxData

The data.

path ​

readonly string[]

The type of each box, from the outer box to the boxes to find.

config? ​

IsoBoxReadConfig<V>

The readers map, the int64 option, and the truncated option of each cursor of the result.

Returns ​

IsoBoxReadCursor<V>[]

A new read cursor for each box at the path. The result is an empty array if the data has no box at the path.

A Streaming Video Technology Alliance project.