Skip to main content

Export

Struct Export 

Source
pub struct Export<S: Stream> { /* private fields */ }
Expand description

Subscribe to a moq broadcast and produce a single fMP4 / CMAF byte stream.

Built from a Source, Export subscribes to the hang catalog, (un)subscribes per-rendition tracks as the catalog changes, decodes both Legacy and CMAF tracks via a per-track source, and re-encodes everything as a merged init segment + moof+mdat fragments, each track in presentation-timestamp order (see poll_next for how far that holds across tracks). This is what an fMP4 player (e.g. ffplay, MSE) expects.

Use poll_next to pull byte chunks: the first call returns the merged init segment (ftyp + multi-track moov), subsequent calls return moof+mdat fragments. By default a fragment is a group, emitted when the group closes. A video keyframe also rolls the fragment within a group; audio follows publisher cuts. with_fragment_duration caps the fragment duration on top of that, for downstream consumers that throttle by fragment rate. Returns None when the broadcast ends.

The init segment declares every enabled rendition in the catalog once each can be described, and fragments cut while it waits are written right after it. Each track holds at most its consumer’s max buffer meanwhile, and the export fails with TrackUndescribed once the init has waited 30 s on the local clock. Annex-B H.264 and H.265 whose catalog codec string and dimensions determine the sample entry are described at the first catalog, as avc3 or hev1 with parameter sets in the samples. From then on the track set is fixed: a rendition that leaves the catalog, as a disabled one (enabled: false) does, is unsubscribed and idles. On its return it is resubscribed after the last group read, under the track it was declared as, when its sample entry is unchanged. That comparison covers the catalog-derived record, so an Annex-B encoder that restarts with a new parameter set can return. A rendition the catalog moves to another track (a new track or broadcast) continues under its declared track the same way, from the new track’s first sync sample past what was read. A new rendition, a changed sample entry, or a return that replays media already written fails the export.

A rendition whose track fails ends alone while another track still reads, and a new rendition of its medium continues it the same way, under its declared track: a publisher that loses a source, such as a microphone, lists a replacement under a new name. A new rendition that joins while a track of its medium still reads waits to continue that one should it fail, and fails the export once no track of its medium could.

poll_next_chunk returns the same bytes as a Chunk, which separates the init segment from a Fragment carrying whether it begins at a sync sample and how long it lasts. A segmenting consumer (e.g. an HLS/LL-HLS packager) needs that to map fragments onto segments and parts; narrow the catalog to a single rendition with Stream::select so the fragments belong to one track.

Implementations§

Source§

impl<S: Stream> Export<S>

Source

pub fn new(source: Source, catalog: S) -> Self

Subscribe to source and produce fMP4 byte chunks, driving track (un)subscription from catalog.

catalog is any Stream of catalog snapshots, typically a catalog::Consumer directly, or narrowed to one rendition set via Stream::select.

Source

pub fn with_delay(self, delay: Delay) -> Self

Set how far behind the live edge each per-track source plays: Delay::min is where it starts, and Delay::max how late a group may fall before it is skipped.

See Consumer for the per-track start and skip behavior. Defaults to zero for both (start at the live edge, skip aggressively).

Source

pub fn with_fragment_duration( self, duration: impl Into<Option<Duration>>, ) -> Self

Cap the fragment (moof+mdat) duration.

By default a fragment is a group: one per GOP for video, and for audio one per group the publisher cut, which is a packet for a live encoder and a segment for an fMP4 import. Setting this caps each fragment to roughly duration of frames, useful for downstream consumers that throttle by fragment rate, or to bound an audio track whose publisher never cuts it. Duration::ZERO emits one fragment per frame. Video with unknown duration waits for the next timestamp or endpoint marker; audio and samples with explicit durations remain immediate. Otherwise the cap applies in addition to the group boundary.

A fragment cut inside a GOP continues the decode timeline where the previous one ended, so B-frame video keeps increasing decode times. Such a fragment cannot see the reordering around it, so unless the catalog declares reorder: 0 (or the codec never reorders), a video sample with unknown duration lasts no longer than the catalog frame rate’s cadence.

Accepts either Duration or Option<Duration> (where None restores the per-group default).

Source

pub fn poll_next(&mut self, waiter: &Waiter) -> Poll<Result<Option<Bytes>>>

Get the next byte chunk.

The first call returns the merged init segment (ftyp + multi-track moov); each subsequent call returns one moof+mdat fragment. Returns None when the catalog and every track have ended.

A track’s own fragments always ascend in timestamp. Across tracks the order is only approximate: a fragment leaves when its group closes or a frame rolls it, so a video GOP follows the audio fragments that overlap it, and two video renditions rolling on keyframes that do not coincide interleave by up to a GOP. Holding fragments back to sort them would cost the length of the longest GOP in added latency, which a live export should not pay for an ordering no fMP4 consumer needs: a demuxer indexes by track and reads tfdt. Narrow the catalog to a single rendition with Stream::select where the order matters.

Source

pub async fn next(&mut self) -> Result<Option<Bytes>>

Get the next byte chunk.

The first call returns the merged init segment (ftyp + multi-track moov); each subsequent call returns one moof+mdat fragment. Returns None when the catalog and every track have ended.

A track’s own fragments always ascend in timestamp. Across tracks the order is only approximate: a fragment leaves when its group closes or a frame rolls it, so a video GOP follows the audio fragments that overlap it, and two video renditions rolling on keyframes that do not coincide interleave by up to a GOP. Holding fragments back to sort them would cost the length of the longest GOP in added latency, which a live export should not pay for an ordering no fMP4 consumer needs: a demuxer indexes by track and reads tfdt. Narrow the catalog to a single rendition with Stream::select where the order matters.

Awaits poll_next.

Source

pub fn poll_next_chunk( &mut self, waiter: &Waiter, ) -> Poll<Result<Option<Chunk>>>

Like poll_next but gets a Chunk, which tells the init segment apart from a Fragment and carries that fragment’s segmenting metadata.

Source

pub async fn next_chunk(&mut self) -> Result<Option<Chunk>>

Like poll_next but gets a Chunk, which tells the init segment apart from a Fragment and carries that fragment’s segmenting metadata.

Awaits poll_next_chunk.

Auto Trait Implementations§

§

impl<S> !RefUnwindSafe for Export<S>

§

impl<S> !UnwindSafe for Export<S>

§

impl<S> Freeze for Export<S>
where S: Freeze,

§

impl<S> Send for Export<S>

§

impl<S> Sync for Export<S>
where S: Sync,

§

impl<S> Unpin for Export<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for Export<S>
where S: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more