Skip to content

Reading Boxes ​

The readIsoBoxes function reads boxes from a buffer and returns an array of parsed boxes. By default, the function reads only the box header. To parse the content of a box, provide a reader function for that box type.

NOTE

The function parses container boxes automatically, so they do not need a reader function. The CONTAINERS constant lists all known container types.

Using default config ​

If tree shaking is not a concern, use defaultReaderConfig(). It returns a configuration with every available reader:

typescript
import { defaultReaderConfig, readIsoBoxes } from "@svta/cml-iso-bmff";

const buffer = await fetch("https://example.com/bbb.mp4").then((r) =>
	r.arrayBuffer(),
);

const boxes = readIsoBoxes(buffer, defaultReaderConfig());

Using specific readers ​

For optimal bundle size with tree shaking, import only the readers you need:

typescript
import { readFtyp, readIsoBoxes } from "@svta/cml-iso-bmff";

const buffer = await fetch("https://example.com/bbb.mp4").then((r) =>
	r.arrayBuffer(),
);

const boxes = readIsoBoxes(buffer, {
	readers: {
		ftyp: readFtyp,
	},
});

A Streaming Video Technology Alliance project.