Function: seekIsoBox()
Call Signature
function seekIsoBox<V>(data, path): IsoBoxReadCursor<V> | null;Defined in: seekIsoBox.ts:77
Finds a box by its path and returns a read cursor for that box. The function decodes no other 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. If a box of a type has no box at the rest of the path, the function searches the next box of that type. So the result is the first cursor that seekIsoBoxes returns for the same input, if seekIsoBoxes does not throw. In the 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 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.
The search ends at the first box at the path, so the function does not read the boxes after that box. With the truncated option 'throw', a truncated box after the result gives no error. To check every box of each list in the path, use seekIsoBoxes.
Type Parameters
V
V extends IsoInt64 = number
Parameters
data
The data, or a read cursor. The search starts at the position of a cursor, and the function does not move that cursor. The result keeps the readers map, the int64 option, and the truncated option of a cursor.
path
readonly string[]
The type of each box, from the outer box to the box to find. With an empty path, the result is a 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> | null
A new read cursor for the first box at the path. The result is null for a missing box. By default, the result is also null for a truncated box.
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.
Examples
const segment = await readFile(new URL('./fixtures/mss_moof_tfdt.mp4', import.meta.url))
const cursor = seekIsoBox(segment, ['moof', 'traf', 'tfdt'])
const time = cursor ? readTfdt(cursor).baseMediaDecodeTime : nullconst stsd = seekIsoBox(load('test_frag.mp4'), ['moov', 'trak', 'mdia', 'minf', 'stbl', 'stsd'])
if (stsd) {
stsd.pos += 8 // version, flags, and entry_count
}
const avc1 = stsd && seekIsoBox(stsd, ['avc1'])Call Signature
function seekIsoBox<V>(
data,
path,
config?
): IsoBoxReadCursor<V> | null;Defined in: seekIsoBox.ts:91
Finds a box by its path and returns a read cursor for that box. The function decodes no other box.
Type Parameters
V
V extends IsoInt64 = number
Parameters
data
The data.
path
readonly string[]
The type of each box, from the outer box to the box to find.
config?
The readers map, the int64 option, and the truncated option of the result.
Returns
IsoBoxReadCursor<V> | null
A new read cursor for the first box at the path, or null for a missing box. By default, the result is also null for a truncated box.