Skip to main content

Module encode

Module encode 

Source
Expand description

Encode captured video and publish it as a moq video track.

The output codec is selected via Codec (H.264 or H.265); see its docs for which backends cover each on this platform.

Entry points, high to low level:

  • publish_capture captures and publishes a webcam (turnkey), returning a Publication that reports its state and the Driver that runs it. Requires the capture feature.
  • Producer encodes raw Frames you supply and publishes them (bring your own frames), following the uplink’s bandwidth grant between frames. The counterpart of moq_audio::encode::Producer; the capture driver runs on it.
  • Encoder encodes raw frames into Encoded access units without publishing them. Sink is an Encoder that owns the thread it runs on, for an encoder outliving a single thread’s stack (a shared object, an FFI handle, a task that migrates between workers).
  • Publisher publishes frames you already encoded, with no rate control.

Both Producer and Publisher advertise their catalog rendition as soon as the track exists, resolved from the encoder itself via Config::probe, so a subscriber can discover a track nothing has encoded yet. That’s what lets an on-demand capture wait for its first viewer at all.

Options / Capture (with capture) / Backend / Config configure them. Config::preset picks a Preset, how the encoder trades latency for compression at the configured bitrate. The decode/consume counterpart (mirror of moq-audio’s consumer) lives in the sibling decode module.

The shared moq_mux::rate policy maps a congestion-control bandwidth estimate onto the encoder’s bitrate, which Producer drives for you.

Structs§

Applied
The latency and compression controls a backend actually applied at open.
Capture
Capture and encode settings for publish_capture.
Config
Encoder configuration. width / height / framerate are the encoded output; external Vulkan frames are scaled by the backend on their GPU.
Driver
The task that captures, encodes, and publishes one video track.
Encoded
One encoded video frame: a whole access unit in the codec’s wire framing (Annex-B with in-band parameter sets), plus the presentation time of the raw Frame it came from.
Encoder
Video encoder. Build one with Encoder::new, submit raw Frames via encode, receive the resulting Encoded access units until it returns None, and publish them through a Publisher built for the same Codec.
Finished
A video track whose Producer or Publisher finished it: every frame is published, and it can still be watched or aborted, but not written to.
Options
Encode and publication policy for Producer.
Producer
Encode raw Frames and publish them as a moq video track (avc3 / hev1 by codec).
Publication
A handle that observes a capture publication.
Publisher
Publishes already-encoded video frames as a moq track (avc3 / hev1 depending on the codec), for a caller that runs its own encoder.
Rendition
A smaller rendition a Capture scales from its frames, published as video/<name>.
Rung
A rendition’s place in a simulcast ladder, from Producer::rung, which the next rendition up takes as its Options::lower.
Sink
An Encoder confined to one thread, driven from anywhere.
State
A snapshot of a capture publication’s lifecycle.

Enums§

Backend
Which encoder implementation to use. #[non_exhaustive] so new selection strategies can be added without breaking external matches.
Codec
Output video codec. #[non_exhaustive] so new codecs can be added without breaking external matches.
Preset
How an encoder trades latency for compression at the configured bitrate.
Status
The capture publication’s current lifecycle state.

Constants§

NAMES
Every encoder backend this crate has a name for, on any platform.

Functions§

publish_capture
Capture a webcam and publish it as a video track, plus one per Capture::renditions.