ISOMedia.FragmentIndex (ISOMedia v0.2.0)

Copy Markdown View Source

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.

Summary

Functions

Per-moof spans for the fragmented tree boxes, in tree order: [%{duration_ts, timescale, bytes}]. For each moof the video traf is preferred (else the first traf); its trun sample durations are summed (via the cascade) for duration_ts, timescale is that track's mdhd timescale, and bytes is the sibling mdat's payload size. Shared by HLS/DASH manifest generation.

True when the tree is fragmented: has a moov/mvex and at least one moof.

Resolve one trun's per-sample fields against merged defaults (%{duration, size, flags}, already tfhd-over-trex). Returns [%{duration, size, composition_offset, sync?}]. sync? negates the sample_is_non_sync_sample bit.

Index the fragmented track track_id into [%ISOMedia.Sample{}].

Functions

fragment_spans(boxes)

@spec fragment_spans([ISOMedia.Box.t()]) :: [
  %{
    duration_ts: non_neg_integer(),
    timescale: pos_integer(),
    bytes: non_neg_integer()
  }
]

Per-moof spans for the fragmented tree boxes, in tree order: [%{duration_ts, timescale, bytes}]. For each moof the video traf is preferred (else the first traf); its trun sample durations are summed (via the cascade) for duration_ts, timescale is that track's mdhd timescale, and bytes is the sibling mdat's payload size. Shared by HLS/DASH manifest generation.

fragmented?(boxes)

True when the tree is fragmented: has a moov/mvex and at least one moof.

resolve_run(trun, defaults)

Resolve one trun's per-sample fields against merged defaults (%{duration, size, flags}, already tfhd-over-trex). Returns [%{duration, size, composition_offset, sync?}]. sync? negates the sample_is_non_sync_sample bit.

samples(boxes, track_id)

Index the fragmented track track_id into [%ISOMedia.Sample{}].