Function: isContainer()
function isContainer<T>(box): box is [Extract<T, { boxes: unknown } | { type: keyof IsoBoxContainerMap }>] extends [never] ? T & (MetaBox<IsoInt64> | AudioSampleEntry<"mp4a", IsoInt64> | AudioSampleEntry<"enca", IsoInt64> | AudioSampleEntry<"ac-3", IsoInt64> | AudioSampleEntry<"ac-4", IsoInt64> | AudioSampleEntry<"ec-3", IsoInt64> | AudioSampleEntry<"fLaC", IsoInt64> | AudioSampleEntry<"Opus", IsoInt64> | VisualSampleEntry<"av01", IsoInt64> | VisualSampleEntry<"avc1", IsoInt64> | VisualSampleEntry<"avc2", IsoInt64> | VisualSampleEntry<"avc3", IsoInt64> | VisualSampleEntry<"avc4", IsoInt64> | DataInformationBox<IsoInt64> | DataReferenceBox<IsoInt64> | EditBox<IsoInt64> | VisualSampleEntry<"dav1", IsoInt64> | VisualSampleEntry<"dva1", IsoInt64> | VisualSampleEntry<"dvav", IsoInt64> | VisualSampleEntry<"dvh1", IsoInt64> | VisualSampleEntry<"dvhe", IsoInt64> | VisualSampleEntry<"encv", IsoInt64> | GroupsListBox<IsoInt64> | VisualSampleEntry<"hev1", IsoInt64> | VisualSampleEntry<"hvc1", IsoInt64> | LoudnessBox<IsoInt64> | MediaBox<IsoInt64> | AdditionalMetadataContainerBox<IsoInt64> | MovieFragmentRandomAccessBox<IsoInt64> | MediaInformationBox<IsoInt64> | MovieFragmentBox<IsoInt64> | MovieBox<IsoInt64> | MovieExtendsBox<IsoInt64> | PreselectionGroupBox<IsoInt64> | RestrictedSchemeInfoBox<IsoInt64> | SchemeInformationBox<IsoInt64> | ProtectionSchemeInfoBox<IsoInt64> | SampleTableBox<IsoInt64> | SubTrackDefinition<IsoInt64> | SubTrack<IsoInt64> | SampleDescriptionBox<IsoInt64> | TrackFragmentBox<IsoInt64> | TrackBox<IsoInt64> | TrackReferenceBox<IsoInt64> | TrackGroupBox<IsoInt64> | UserDataBox<IsoInt64> | VisualSampleEntry<"vp09", IsoInt64> | WebVttCueBox<IsoInt64>) : Extract<T, { boxes: unknown } | { type: keyof IsoBoxContainerMap }>;Defined in: utils/isContainer.ts:28
Check if a box is a container
The function returns true for a box with a boxes field and for a box with a type in CONTAINERS. The function returns false for a raw box.
In TypeScript, a true result narrows the box to the box types in the type of the box that have a boxes field. These types are the container types, meta, stsd, dref, prsl, and the sample entries. The result also keeps a box type with a type in CONTAINERS and no boxes field, such as the result of a custom moov reader. A 64-bit integer field of a child has the type of the int64 option. If the type of the box includes no type with a boxes field, the box narrows to every box type with a boxes field.
Type Parameters
T
T extends object
Parameters
box
T
The box to check
Returns
box is [Extract<T, { boxes: unknown } | { type: keyof IsoBoxContainerMap }>] extends [never] ? T & (MetaBox<IsoInt64> | AudioSampleEntry<"mp4a", IsoInt64> | AudioSampleEntry<"enca", IsoInt64> | AudioSampleEntry<"ac-3", IsoInt64> | AudioSampleEntry<"ac-4", IsoInt64> | AudioSampleEntry<"ec-3", IsoInt64> | AudioSampleEntry<"fLaC", IsoInt64> | AudioSampleEntry<"Opus", IsoInt64> | VisualSampleEntry<"av01", IsoInt64> | VisualSampleEntry<"avc1", IsoInt64> | VisualSampleEntry<"avc2", IsoInt64> | VisualSampleEntry<"avc3", IsoInt64> | VisualSampleEntry<"avc4", IsoInt64> | DataInformationBox<IsoInt64> | DataReferenceBox<IsoInt64> | EditBox<IsoInt64> | VisualSampleEntry<"dav1", IsoInt64> | VisualSampleEntry<"dva1", IsoInt64> | VisualSampleEntry<"dvav", IsoInt64> | VisualSampleEntry<"dvh1", IsoInt64> | VisualSampleEntry<"dvhe", IsoInt64> | VisualSampleEntry<"encv", IsoInt64> | GroupsListBox<IsoInt64> | VisualSampleEntry<"hev1", IsoInt64> | VisualSampleEntry<"hvc1", IsoInt64> | LoudnessBox<IsoInt64> | MediaBox<IsoInt64> | AdditionalMetadataContainerBox<IsoInt64> | MovieFragmentRandomAccessBox<IsoInt64> | MediaInformationBox<IsoInt64> | MovieFragmentBox<IsoInt64> | MovieBox<IsoInt64> | MovieExtendsBox<IsoInt64> | PreselectionGroupBox<IsoInt64> | RestrictedSchemeInfoBox<IsoInt64> | SchemeInformationBox<IsoInt64> | ProtectionSchemeInfoBox<IsoInt64> | SampleTableBox<IsoInt64> | SubTrackDefinition<IsoInt64> | SubTrack<IsoInt64> | SampleDescriptionBox<IsoInt64> | TrackFragmentBox<IsoInt64> | TrackBox<IsoInt64> | TrackReferenceBox<IsoInt64> | TrackGroupBox<IsoInt64> | UserDataBox<IsoInt64> | VisualSampleEntry<"vp09", IsoInt64> | WebVttCueBox<IsoInt64>) : Extract<T, { boxes: unknown } | { type: keyof IsoBoxContainerMap }>
true if the box is a container, false otherwise
Example
// A moof box that holds an mfhd box with the sequence number 7.
const bytes = new Uint8Array([
0,
0,
0,
24,
0x6d,
0x6f,
0x6f,
0x66, // moof
0,
0,
0,
16,
0x6d,
0x66,
0x68,
0x64,
0,
0,
0,
0,
0,
0,
0,
7, // mfhd
])
const sequenceNumbers: number[] = []
for (const box of readIsoBoxes(bytes, createDefaultReaderConfig())) {
if (isContainer(box)) {
for (const child of box.boxes) {
if (isIsoBoxType('mfhd', child)) {
sequenceNumbers.push(child.sequenceNumber)
}
}
}
}