Expand description
Fragmented MP4 / CMAF box writers.
Produces ISO/IEC 14496-12 §8.8 movie-fragment boxes (moof / mfhd /
traf / tfhd / tfdt / trun) and the corresponding mvex /
mehd / trex declarations that go inside a CMAF init segment’s
moov. CMAF (ISO/IEC 23000-19) constrains the general 14496-12 model:
exactly one track per fragment (one traf per moof), exactly one
track per init segment, and a small set of mandatory boxes.
This module is the box-level primitive layer. Higher-level callers
(init_segment_video, media_segment_video, etc. in subsequent
commits) compose these into init + media segments. The split lets us
unit-test each box’s byte layout against the spec without having to
drive a full encode + segment pipeline.
Spec citations are given by section number in the relevant box’s doc comment so future readers can cross-check against the standard.
§CMAF brand
Init segments for video tracks declare the cmfc brand (CMAF
constraints, per CMAF §7.3.4). Audio tracks use cmfa. Both brands
coexist in compatible_brands alongside the existing iso6 / mp42
/ av01 brands so non-CMAF-aware tools that consume the same boxes
(e.g. an old ffprobe) can still demux them.
§Sample-flags packing
default_sample_flags (in trex / tfhd) and first_sample_flags
/ per-sample flags (in trun) are packed per ISO/IEC 14496-12
§8.8.3.1. The 32 bits are laid out:
reserved[6] = 0
is_leading[2] = 0
sample_depends_on[2]
sample_is_depended_on[2]
sample_has_redundancy[2]
sample_padding_value[3] = 0
sample_is_non_sync_sample[1]
sample_degradation_priority[16] = 0For AV1 / AAC the meaningful values are sample_depends_on = 1
(this sample depends on others — i.e. P / B / non-IDR) or 2
(independent — i.e. IDR / sync), and sample_is_non_sync_sample = 1
for non-key frames, 0 for keyframes. The helper
SampleFlags::pack handles this; callers shouldn’t compose the
u32 by hand.
Modules§
- brand
- CMAF brand identifiers used in
ftyp.compatible_brands.
Structs§
- Cmaf
Audio Muxer - Stateful CMAF audio segmenter. Same model as the video muxer but simpler — every audio sample is independently decodable, so there’s no first-sample-flags / sync-boundary requirement.
- Cmaf
Sample - Per-sample fields written into
trun. Each entry produces one row of (duration, size, flags) in the fragment’s sample table. - Cmaf
Track Manifest - Output of a finalized track muxer: where the init segment lives,
the ordered list of media segments, and the timescale needed to
convert
duration_ticksto seconds. - Cmaf
Video Muxer - Stateful CMAF video segmenter for one AV1 rendition.
- Cmaf
Video Muxer Options - Optional construction parameters for
CmafVideoMuxer. Defaults match the original 5-argnew()behaviour: write init.mp4, start segment numbering at 1, decode-time at 0. - Moof
Data - Full
moofblob with the innertrun.data_offsetpatched up. - Sample
Flags - Sample flags as packed in
default_sample_flags/first_sample_flags/ per-samplesample_flagsintrun. ISO/IEC 14496-12 §8.8.3.1. - Segment
Info - Per-segment metadata returned by
CmafVideoMuxer::flush_segment/CmafAudioMuxer::flush_segment. These records form the input to the HLS playlist writer (Phase 3) and the segment-alignment validator (Phase 5).
Enums§
- Cmaf
Track Kind - Track type discriminator. CMAF places one track per init / fragment;
this enum is what higher-level orchestration uses to pick which
codec dispatch to take. The init / segment writers themselves don’t
take this enum (they have type-specific entry points), so it stays
#[allow(dead_code)]until the pipeline orchestrator (Phase 4) wires it through.
Functions§
- build_
init_ segment_ audio - Build a CMAF audio init segment.
- build_
init_ segment_ video - Build a CMAF video init segment for an AV1 track.
- build_
mehd mehd— Movie Extends Header (14496-12 §8.8.2).- build_
mfhd mfhd— Movie Fragment Header (14496-12 §8.8.5).- build_
moof_ audio - Build an audio
moof. Same composition as video but without first-sample-flags differentiation intrun(every audio sample is independently decodable). - build_
moof_ video - Build a video
mooffor one CMAF fragment. - build_
mvex mvex— Movie Extends container (14496-12 §8.8.1).- build_
tfdt tfdt— Track Fragment Decode Time (14496-12 §8.8.12).- build_
tfhd tfhd— Track Fragment Header (14496-12 §8.8.7).- build_
trex trex— Track Extends (14496-12 §8.8.3).