# ISOMedia v0.1.0 - Table of Contents

> Lossless ISOBMFF (MP4/MOV/M4A/HEIF) box surgery in pure Elixir: parse any ISO Base Media file into a byte-exact tree of boxes, then navigate, edit, extract, trim, concatenate, fragment, and re-serialize it.

## Pages

- [ISOMedia](readme.md)
- [Changelog](changelog.md)

## Modules

- [ISOMedia](ISOMedia.md): Lossless ISOBMFF (MP4/MOV/M4A/HEIF) box surgery in pure Elixir.
- [ISOMedia.Box](ISOMedia.Box.md): A single generic ISOBMFF box.
- [ISOMedia.BoxPath](ISOMedia.BoxPath.md): Navigate and update a single box by a child-type path. Shared by `Extract`, `Trim`,
and `Concat` (which all walk `trak`/`mdia`/`minf`/`stbl` subtrees).

- [ISOMedia.Boxes.ChunkOffset](ISOMedia.Boxes.ChunkOffset.md): Typed view of the `stco` (32-bit) and `co64` (64-bit) Chunk Offset Boxes.
`kind` is `:stco` or `:co64`; `offsets` is a list of absolute file offsets.

- [ISOMedia.Boxes.EditList](ISOMedia.Boxes.EditList.md): Typed view of the `elst` Edit List Box (inside `trak` → `edts`).
- [ISOMedia.Boxes.FileType](ISOMedia.Boxes.FileType.md): Typed view of the `ftyp` File Type Box.
- [ISOMedia.Boxes.Handler](ISOMedia.Boxes.Handler.md): Typed view of the `hdlr` Handler Reference Box.
- [ISOMedia.Boxes.MediaHeader](ISOMedia.Boxes.MediaHeader.md): Typed view of the `mdhd` Media Header Box. Exposes `timescale`/`duration`
(and creation/modification times); the trailing language + pre_defined fields
are preserved in `rest`.

- [ISOMedia.Boxes.MovieHeader](ISOMedia.Boxes.MovieHeader.md): Typed view of the `mvhd` Movie Header Box. Exposes `timescale`/`duration`
(and creation/modification times); all trailing fields (rate, volume, matrix,
next_track_ID, ...) are preserved verbatim in `rest`.

- [ISOMedia.Boxes.TrackExtends](ISOMedia.Boxes.TrackExtends.md): Typed view of the `trex` Track Extends box (inside `moov` → `mvex`).
- [ISOMedia.Boxes.TrackFragmentDecodeTime](ISOMedia.Boxes.TrackFragmentDecodeTime.md): Typed view of the `tfdt` Track Fragment Decode Time box.
- [ISOMedia.Boxes.TrackFragmentHeader](ISOMedia.Boxes.TrackFragmentHeader.md): Typed view of the `tfhd` Track Fragment Header box.
- [ISOMedia.Boxes.TrackHeader](ISOMedia.Boxes.TrackHeader.md): Typed view of the `tkhd` Track Header Box. Exposes `track_id`/`duration`
(and creation/modification times); trailing fields are preserved in `rest`.

- [ISOMedia.Boxes.TrackRun](ISOMedia.Boxes.TrackRun.md): Typed view of the `trun` Track Run box (per-sample list).
- [ISOMedia.Concat](ISOMedia.Concat.md): Losslessly concatenate N compatible clips end-to-end.
- [ISOMedia.Defragment](ISOMedia.Defragment.md): Repack a fragmented MP4 (`moof`/`traf`/`trun`) into a standard progressive
`[ftyp, moov, mdat]` — a pure metadata edit, no transcoding. Samples come from
`FragmentIndex`; the output is assembled by `ISOMedia.ProgressiveBuild`, so the
`mdat` is a recursive segment list referencing each fragment's bytes (memory-safe).

- [ISOMedia.Extract](ISOMedia.Extract.md): Track discovery and single-track extraction.
- [ISOMedia.FileSlice](ISOMedia.FileSlice.md): An inert reference to a byte range on disk: `%FileSlice{path, offset, length}`.
- [ISOMedia.Fragment](ISOMedia.Fragment.md): Repack a progressive MP4 into a single multiplexed fragmented tree
`[ftyp, moov(+mvex), moof, mdat, …]`. Keyframe-aligned (a fragment starts on a sync
sample so it is independently decodable), lossless (sample bytes via a Phase 8
segment-list `mdat`), memory-safe. The inverse of `ISOMedia.Defragment`.

- [ISOMedia.FragmentIndex](ISOMedia.FragmentIndex.md): Indexes fragmented MP4 (`moof`/`traf`/`trun`) into the same `[%ISOMedia.Sample{}]`
the progressive indexer produces. Offsets are resolved tree-locally (a single
`Layout` walk stamps each `moof`'s position), and the cascade `trun → tfhd → trex`
resolves per-sample duration/size/flags. `chunk_index` is a per-`trun` counter.

- [ISOMedia.FullBox](ISOMedia.FullBox.md): Helper for the `version` (1 byte) + `flags` (3 bytes) prefix that many
ISOBMFF boxes (FullBoxes) carry before their payload.

- [ISOMedia.Layout](ISOMedia.Layout.md): Computes absolute byte offsets for a box tree in its current arrangement,
matching exactly how `ISOMedia.Serializer` lays bytes out. Used to find where
boxes land after editing so chunk offsets can be recomputed.

- [ISOMedia.LazyParser](ISOMedia.LazyParser.md): Parses an ISOBMFF file without loading it entirely into memory.
- [ISOMedia.MdatSource](ISOMedia.MdatSource.md): Resolves an absolute file byte range to a payload segment, given the top-level
`mdat` boxes of a parsed tree. Returns a `%FileSlice{}` when the containing `mdat`
is lazy, or a `binary` slice when it is in memory. Shared by `Extract` and `Trim`.

- [ISOMedia.Offsets](ISOMedia.Offsets.md): Recomputes `stco`/`co64` chunk-offset tables after boxes have moved, and the
`faststart/1` rearrangement built on top of it.
- [ISOMedia.Parser](ISOMedia.Parser.md): Decodes an ISOBMFF binary into a list of `ISOMedia.Box` structs.
- [ISOMedia.ProgressiveBuild](ISOMedia.ProgressiveBuild.md): Assemble a progressive `[ftyp, moov, mdat]` tree from one or more inputs' per-track
samples + `mdat` sources. Shared by `Concat` (N inputs) and `Defragment` (one input).
Preserves interleave (runs sorted by original offset for the byte layout) while keeping
logical `{input, chunk}` order for each track's `stco`.

- [ISOMedia.Registry](ISOMedia.Registry.md): Classifies which box types are containers (hold child boxes).
- [ISOMedia.Sample](ISOMedia.Sample.md): One media sample, decoded from a track's sample tables.
- [ISOMedia.SampleTable](ISOMedia.SampleTable.md): Decodes a track's `stbl` sample tables into an ordered list of `ISOMedia.Sample`.
- [ISOMedia.Segment](ISOMedia.Segment.md): Split a fragmented MP4 tree (the output of `ISOMedia.fragment/2`, shape
`[ftyp, moov, (moof, mdat)+]`) into the DASH/CMAF on-disk layout: a media-less init
segment (`[ftyp, moov]`) plus N standalone media segments (`[styp, moof, mdat]`).
- [ISOMedia.Serializer](ISOMedia.Serializer.md): Serializes `ISOMedia.Box` trees back into ISOBMFF binary.
- [ISOMedia.Timescale](ISOMedia.Timescale.md): Integer timescale rescaling shared across editing operations.
- [ISOMedia.Trim](ISOMedia.Trim.md): Losslessly trim every track to a time range `[start_sec, end_sec)`.

