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.
The function parses container boxes automatically, so they do not need a reader function. The CONTAINERS constant lists all known container types.
If tree shaking is not a concern, use defaultReaderConfig(). It returns a configuration with every available reader:
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());
For optimal bundle size with tree shaking, import only the readers you need:
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,
},
});