ISOMedia.Offsets (ISOMedia v0.1.0)

Copy Markdown View Source

Recomputes stco/co64 chunk-offset tables after boxes have moved, and the faststart/1 rearrangement built on top of it.

Assumes mdat payloads are byte-identical to what was parsed (this is box relocation, not sample editing). Each mdat carries its current basis position via source_offset/source_size, so a chunk offset is remapped by the uniform byte delta of the mdat it points into. After remapping, each mdat's source_offset is updated to its new position, which makes the operation idempotent and lets repeated edit→fix cycles compose.

Summary

Functions

Move moov to immediately after any leading ftyp (and before mdat), then fix chunk offsets. Returns the tree unchanged if it has no moov or no mdat.

Return boxes with every stco/co64 table corrected for the current arrangement. Promotes stcoco64 (latched, never demoted) when an offset reaches the :co64_threshold (default 4294967295), iterating layout to a fixpoint. Raises if an mdat was synthesized or resized, or if a chunk offset maps into no mdat.

Functions

faststart(boxes, opts \\ [])

Move moov to immediately after any leading ftyp (and before mdat), then fix chunk offsets. Returns the tree unchanged if it has no moov or no mdat.

fix_chunk_offsets(boxes, opts \\ [])

Return boxes with every stco/co64 table corrected for the current arrangement. Promotes stcoco64 (latched, never demoted) when an offset reaches the :co64_threshold (default 4294967295), iterating layout to a fixpoint. Raises if an mdat was synthesized or resized, or if a chunk offset maps into no mdat.

Options:

  • :co64_threshold — promote a table to co64 when any offset exceeds this value. Defaults to 2^32 − 1; lower it only in tests to exercise promotion without a multi-gigabyte file.