pub struct Muxer { /* private fields */ }Expand description
Muxes one rendition’s fetched groups into standalone CMAF, without a live subscription.
The pull-based Export subscribes to a whole broadcast and interleaves
its tracks; Muxer is the building block for a fetch-on-demand consumer (an HLS/DASH
origin) that retrieves one group at a time via
track::Consumer::fetch_group:
readdecodes a fetched group into mediaFrames, normalizing the codec shape (Annex-B H.264/H.265 becomes length-prefixed, with the config record synthesized from the in-band parameter sets).initbuilds the rendition’s init segment (ftyp+moov).fragmentencodes frames as one moof+mdat whosetfdtcarries their real presentation time, so a fragment built from a mid-stream group stands alone.
For video missing codec configuration or geometry, init returns None until a
group has been read to resolve the missing fields from a keyframe.
Implementations§
Source§impl Muxer
impl Muxer
Sourcepub fn video(config: &VideoConfig) -> Result<Self>
pub fn video(config: &VideoConfig) -> Result<Self>
A muxer for a video rendition described by config.
Sourcepub fn audio(config: &AudioConfig) -> Result<Self>
pub fn audio(config: &AudioConfig) -> Result<Self>
A muxer for an audio rendition described by config.
Sourcepub fn timescale(&self) -> Timescale
pub fn timescale(&self) -> Timescale
The media timescale this muxer’s init segment and fragments are expressed in.
Derived from the catalog: a Cmaf rendition’s own init scale, a cadence-compatible scale
for video (falling back to 90 kHz) and the sample rate for audio, unless
with_timescale overrode it.
Sourcepub fn with_timescale(self, timescale: Timescale) -> Result<Self>
pub fn with_timescale(self, timescale: Timescale) -> Result<Self>
Emit at an explicit timescale instead of the one derived from the catalog.
For a consumer whose downstream timeline is fixed, for example an HLS or DASH origin working in 90 kHz ticks.
Errors for a Cmaf rendition, whose init segment passes through from the catalog at its
own scale: overriding would leave the init and the fragments on different timelines. Also
errors above u32::MAX, which the init segment’s mdhd.timescale field cannot hold.
Sourcepub async fn read(&mut self, group: &mut Consumer) -> Result<Vec<Frame>>
pub async fn read(&mut self, group: &mut Consumer) -> Result<Vec<Frame>>
Decode one fetched group into media frames, in decode order.
Reads the group to its end, so call it only on a finished group (a live group would block until the publisher closes it). Parameter-set frames are absorbed into the codec config record; the group’s first emitted frame is marked a keyframe (a group opens on one by convention).
Sourcepub fn poll_read(
&mut self,
waiter: &Waiter,
group: &mut Consumer,
out: &mut Vec<Frame>,
) -> Poll<Result<Vec<Frame>>>
pub fn poll_read( &mut self, waiter: &Waiter, group: &mut Consumer, out: &mut Vec<Frame>, ) -> Poll<Result<Vec<Frame>>>
read, polled: ready with the group’s frames once it ends. Pass the same
empty out to every poll of one group, which holds the frames decoded so far.
Sourcepub fn picture_size(&mut self, keyframe: &Frame) -> Result<Option<(u32, u32)>>
pub fn picture_size(&mut self, keyframe: &Frame) -> Result<Option<(u32, u32)>>
The picture size keyframe decodes to: from its in-band parameter sets (Annex-B, or
length-prefixed beside an avc3/hev1 record) or its frame header (VP8, VP9, and AV1, whose
frame may override its sequence maximum), else the catalog description, or None for audio
or a codec that declares neither.
Pass a group’s first frame: the picture size of a track may change at any keyframe, which
only the media says, so reading this per group tells which config muxes it. It leaves the
init untouched.
Sourcepub fn init(&self) -> Result<Option<Bytes>>
pub fn init(&self) -> Result<Option<Bytes>>
Build the rendition’s CMAF init segment (ftyp+moov), or None if it isn’t buildable yet.
A Cmaf rendition’s catalog init passes through (with the track id normalized to match
fragment); a Legacy/Loc rendition’s is synthesized from the catalog
config. None means a video rendition whose codec config or geometry hasn’t been resolved
yet: read a group (its keyframe carries those fields) and call again.
Sourcepub fn fragment(
&self,
sequence: u32,
frames: &[Frame],
end: Option<Timestamp>,
) -> Result<Bytes>
pub fn fragment( &self, sequence: u32, frames: &[Frame], end: Option<Timestamp>, ) -> Result<Bytes>
Encode frames as one moof+mdat fragment.
The tfdt base decode time is the first frame’s real presentation timestamp (at the
init segment’s timescale), so the fragment is self-contained regardless of which group
it came from. Frames without a duration get one inferred from the following frame’s
timestamp (falling back to the catalog frame rate / sample rate), so multi-sample
fragments stay decodable. sequence is the moof sequence number, informative only.
frames may span several groups, and a sample is never timed by one in the next group
even so: consecutive sequence numbers say nothing about whether the publisher paused
across the boundary.
end, when the caller knows where the content ends (such as the next segment’s start),
times the last presented sample if neither its codec nor a duration marker does.