Modules
Lossless ISOBMFF (MP4/MOV/M4A/HEIF) box surgery in pure Elixir.
A single generic ISOBMFF box.
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).
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.
Typed view of the elst Edit List Box (inside trak → edts).
Typed view of the ftyp File Type Box.
Typed view of the hdlr Handler Reference Box.
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.
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.
Typed view of the trex Track Extends box (inside moov → mvex).
Typed view of the tfdt Track Fragment Decode Time box.
Typed view of the tfhd Track Fragment Header box.
Typed view of the tkhd Track Header Box. Exposes track_id/duration
(and creation/modification times); trailing fields are preserved in rest.
Typed view of the trun Track Run box (per-sample list).
Read-only extraction of a track's codec + media metadata into %ISOMedia.TrackInfo{}.
Slices the opaque stsd sample entry and mdhd tail directly (avc1 + mp4a); the core
parser/Registry are untouched, so the byte-for-byte round-trip invariant is preserved.
Losslessly concatenate N compatible clips end-to-end.
Generate the DASH MPD (.mpd) for the CMAF segments ISOMedia.split_segments/1 produces:
a single muxed static/VOD rendition using SegmentTemplate + SegmentTimeline. Pure XML
templating over FragmentIndex.fragment_spans/1 + ISOMedia.Manifest (the same
codec/resolution/bandwidth computations HLS uses), via a small zero-dependency XML builder
(element/3 + attr_escape/1 + iso8601_duration/1) — the library keeps no runtime deps,
and the MPD's value surface is small and controlled. write_dash/3 derives the segment
filenames from the $Number$ template so the written files match the manifest.
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).
Track discovery and single-track extraction.
An inert reference to a byte range on disk: %FileSlice{path, offset, length}.
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.
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.
Helper for the version (1 byte) + flags (3 bytes) prefix that many
ISOBMFF boxes (FullBoxes) carry before their payload.
Generate HLS (.m3u8) playlists for the CMAF segments ISOMedia.split_segments/1
produces — a media playlist (segment list) and a multivariant (master) playlist
(codecs/resolution/bandwidth), for a single muxed VOD rendition. Pure string templating
over FragmentIndex.fragment_spans/1 + ISOMedia.Manifest; URIs match write_segments.
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.
Parses an ISOBMFF file without loading it entirely into memory.
Manifest-agnostic computations shared by the HLS and DASH generators: the per-track
codec strings, the video resolution, and the peak per-segment bandwidth. Pure, read-only
functions over a fragmented (fragment/2-shaped) tree — one home for the codec/bandwidth
logic so HLS and DASH only format (DRY).
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.
Recomputes stco/co64 chunk-offset tables after boxes have moved, and the
faststart/1 rearrangement built on top of it.
Decodes an ISOBMFF binary into a list of ISOMedia.Box structs.
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.
Classifies which box types are containers (hold child boxes).
One media sample, decoded from a track's sample tables.
Decodes a track's stbl sample tables into an ordered list of ISOMedia.Sample.
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]).
Serializes ISOMedia.Box trees back into ISOBMFF binary.
Integer timescale rescaling shared across editing operations.
Decoded codec + media metadata for one track. See ISOMedia.track_info/2.
Losslessly trim every track to a time range [start_sec, end_sec).