ISOMedia.Fragment (ISOMedia v0.1.0)

Copy Markdown View Source

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.

Summary

Functions

Boundary dts values (in the given samples' timescale): greedily take the first sync sample, then each next sync sample whose dts ≥ previous boundary + target_ts.

Repack a progressive tree into a multiplexed fragmented tree. opts[:target_duration] seconds (default 2.0).

Partition samples into one run per boundary: run i is the samples whose dts is in [boundaries[i], boundaries[i+1]) (the last run is open-ended). boundaries must be in the same timescale as the samples, ascending.

Functions

boundaries(samples, target_ts)

@spec boundaries([ISOMedia.Sample.t()], non_neg_integer()) :: [non_neg_integer()]

Boundary dts values (in the given samples' timescale): greedily take the first sync sample, then each next sync sample whose dts ≥ previous boundary + target_ts.

fragment(boxes, opts \\ [])

@spec fragment(
  ISOMedia.tree(),
  keyword()
) :: ISOMedia.tree()

Repack a progressive tree into a multiplexed fragmented tree. opts[:target_duration] seconds (default 2.0).

windows(samples, boundaries)

@spec windows([ISOMedia.Sample.t()], [non_neg_integer()]) :: [[ISOMedia.Sample.t()]]

Partition samples into one run per boundary: run i is the samples whose dts is in [boundaries[i], boundaries[i+1]) (the last run is open-ended). boundaries must be in the same timescale as the samples, ascending.

The first window is open-ended on the low end: it includes every sample before boundaries[1], regardless of whether its dts is less than boundaries[0]. This preserves any leading non-sync samples (frames before the first keyframe) so that fragmenting remains lossless.