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]).
Lossless and memory-safe — each segment's mdat stays a source-referencing segment
list, so write_segments/3 streams each segment file disk→disk. The split is
structure-preserving: a muxed input yields muxed segments. For single-track segments,
compose extract_track |> fragment |> split per track.
Summary
Functions
Split a fragmented tree into %{init: [ftyp, moov], segments: [[styp, moof, mdat], …]}.
Raises ArgumentError unless the input is [ftyp, moov, (moof, mdat)+].
Split boxes and write the init + media segments into dir (created if absent):
init.mp4 and seg-1.m4s, seg-2.m4s, …. opts[:init_name] overrides the init filename;
opts[:segment_pattern] is a fn index -> filename end (default fn i -> "seg-#{i}.m4s" end).
Returns {:ok, paths} (init first, then segments in order) or the first write/2
{:error, reason}. Each segment streams disk→disk; the file handle is closed per segment.
Functions
@spec split(ISOMedia.tree()) :: %{init: ISOMedia.tree(), segments: [ISOMedia.tree()]}
Split a fragmented tree into %{init: [ftyp, moov], segments: [[styp, moof, mdat], …]}.
Raises ArgumentError unless the input is [ftyp, moov, (moof, mdat)+].
@spec write_segments(Path.t(), ISOMedia.tree(), keyword()) :: {:ok, [Path.t()]} | {:error, term()}
Split boxes and write the init + media segments into dir (created if absent):
init.mp4 and seg-1.m4s, seg-2.m4s, …. opts[:init_name] overrides the init filename;
opts[:segment_pattern] is a fn index -> filename end (default fn i -> "seg-#{i}.m4s" end).
Returns {:ok, paths} (init first, then segments in order) or the first write/2
{:error, reason}. Each segment streams disk→disk; the file handle is closed per segment.