Expand description
Native video capture, encoding, and publishing for Media over QUIC.
Counterpart to moq-audio for video
tracks, and shaped the same way: both split into capture / encode /
decode role modules over a shared root Error, with render as video’s
fourth. Sits on top of moq_mux (and the hang catalog) and adds the
native pieces a desktop/CLI publisher needs.
A raw picture is a Frame wherever it crosses the API: a timestamp and a
Surface holding the pixels. Capture and decode produce them, encode
consumes them and hands back the compressed encode::Encoded, and Size
names a resolution. Group boundaries are the encoder’s business: it places
them per encode::Config::join, and encode::Encoder::cut is there for
the rarer case where a caller needs one at a specific frame.
capturedescribes a frame source and grabs frames per platform: AVFoundation/ScreenCaptureKit on macOS, native V4L2 on Linux, native Media Foundation (camera) and Windows.Graphics.Capture (display/window) on Windows 10 2004+, plus portal/PipeWire on Wayland and X11 capture on Linux. Usecapture::openfor an embeddable raw-frame stream orencode::publish_capturefor turnkey publication. It requires the opt-incapturefeature, which costs the build host nothing on any platform.encodeencodes frames with a native backend and publishes them through the matchingmoq_mux::codecimporter, which handles catalog registration and framing. The codec is chosen viaencode::Codec: H.264 (openh264 / VideoToolbox / Media Foundation / NVENC / VAAPI / V4L2) or H.265 (VideoToolbox / Media Foundation / NVENC). Entry points:encode::publish_capturecaptures a webcam and publishes it (turnkey), returning aPublicationhandle and theDriverthat runs it. The track and catalog are advertised up front (the camera opens at startup so they can be exact), and the camera stays open and encodes whether or not anyone is watching, unlessencode::Capture::on_demandlimits it to while a subscriber is. Requires thecapturefeature.encode::ProducerencodesFrames you supply (from capture, a decoder, or your own pixels viaSurface::rgba) and publishes them, following the connection’s bandwidth grant between frames whenencode::Options::bandwidthcarries the connection’s allocator (the default holds the configured bitrate). While nobody subscribes, a rendition with noencode::Options::lowerignores the grant and encodes at its ceiling, so a later viewer can start on a group cached at that rate.encode::Encoderencodes without publishing, andencode::Publisherpublishes frames you encoded yourself.
decodesubscribes to an H.264, H.265, or AV1 track and decodes it to raw frames with a native backend (VideoToolbox on macOS and iOS, Media Foundation / DXVA on Windows, NVDEC, VAAPI, or an ARM SoC’s V4L2 M2M decoder on Linux, with the opt-inopenh264feature providing software H.264 fallback).decode::Consumeris the mirror ofmoq_audio::decode::Consumer. Andecode::Config::outputpicks native surfaces (the default: an NVDEC frame stays in CUDA memory and feedsencode::Encoder::encodezero-copy, a VAAPI frame is a DMA-BUF the renderer imports) or CPU I420;decode::Config::scale_hintlets a decoder with a hardware scaler emit the output size directly.convertdownloads readback-capableSurfaces to owned, tightly packed RGBA pixels for CPU image and UI toolkits, honoring native color metadata. Vulkan/CUDA surfaces deliberately expose no CPU pixel fallback.renderdraws aFrameon the GPU and hands back awgputexture to present, importing a GPU frame’s surface directly where the platform allows and uploading I420 otherwise. Behind the opt-inrenderfeature, so a codec-only consumer skips the graphics stack.
§API stability
The public API is codec-agnostic: no public type, signature, or error
variant names a backend (openh264 / VideoToolbox / NVENC / NVDEC / VAAPI / V4L2) or a
codec implementation. encode::Encoder takes a Frame,
decode::Read::Frame and capture::Stream carry one (CPU I420 on demand,
GPU-resident when hardware decoded). So swapping
or bumping any backend crate is not a breaking change for consumers. Config
structs are #[non_exhaustive]: build them via default()/new() and set
fields, so new options stay additive.
The one deliberate exception is Surface, the enum behind every frame.
Its variants name platform representations (CVPixelBuffer, Direct3D11,
CUDA, Vulkan/CUDA, AHardwareBuffer) so you can render or re-encode a frame
yourself without a CPU round trip, which means a major bump of one of those
platform crates is a breaking change here. It is #[non_exhaustive] and
every variant has a universal fallback in Surface::into_i420 except the
explicitly GPU-only Surface::Vulkan, so matching stays portable but a
CPU-only consumer can receive Error::Unsupported.
Re-exports§
pub use color::Color;pub use frame::DmaBuf;pub use frame::DmaBufExport;pub use frame::DmaBufPlane;pub use frame::DrmFormat;pub use frame::Frame;pub use frame::I420;pub use frame::Surface;
Modules§
- capture
- Surface capture.
Configis shared; the implementation is per-platform and per-source: - color
Color: which color space a frame’s samples are in.- convert
- CPU conversion of native video surfaces to packed pixels.
- decode
- Subscribe to an H.264, H.265, AV1, VP8, or VP9 track and decode it to raw frames.
- encode
- Encode captured video and publish it as a moq video track.
- frame
Frame: one raw picture, andSurface: its pixels and where they live.- render
- Draw decoded frames on the GPU, handing back a texture you present.
- resize
- Frame resizing options.
Structs§
Enums§
- Device
- The hardware a decoder, encoder, or scaler opens.
- Error
- Errors returned by
moq-video. - Frame
Rate Error - An invalid video frame rate.
- Output
- The representation a decoder, capture, or scaler hands frames back in.
Constants§
- MAX_
FRAMES_ PER_ SECOND - The largest supported video rate, in frames per second.