Rust API
In Rust, an encoder is nc_encoder::Encoder<B>, the shared engine, driving one
codec's backend B: nc_h264::H264Backend, nc_hevc::HevcBackend,
nc_vvc::VvcBackend, nc_av1::Av1Backend, nc_vp9::Vp9Backend or
nc_av2::Av2Backend. Each codec crate also has its decoder (nc_h264::Decoder, ...).
The crates are not published on crates.io; depend on them by git or path.
# Cargo.toml
[dependencies]
nc-common = { git = "https://github.com/cribbinsb/nanocodec" }
nc-encoder = { git = "https://github.com/cribbinsb/nanocodec" }
nc-h264 = { git = "https://github.com/cribbinsb/nanocodec" }
The encoder
Encoder::new(EncoderConfig): codec, size, frame rate, quantiser, key-frame interval, temporal layers and the parameter overrides (ParamOverrides; empty is the codec's Default).set_rate_control(RateControlConfig::new(bits_per_second))turns on real-time rate control; its fields set the peak, buffer, quantiser bounds and frame dropping.encode_raw(&RawFrame)codes a borrowed I420, YV12 or NV12 frame with any strides (encode_raw_atwith a capture time);encode(&Picture)takes an owned picture. Each returns anEncodedFrame: the access unit or temporal unit, empty when the frame was dropped or held, and its metadata (index, frame type, temporal layer, quantiser, references).- Live control:
request_keyframe,set_intra_refresh,set_resolution,set_frame_rate, and the receiver'sacknowledgeandreport_loss.
This is the only way any of our front ends encodes: the command line, the C API and the browser module all
drive this Encoder.
Minimal encode and decode loop
H.264 at 300 kbps, decoded frame by frame. It is
crates/nc-h264/examples/encode_decode.rs, compiled by the workspace tests; run it with
cargo run --release -p nanocodec-h264 --example encode_decode:
Loading…
The API documentation of every crate: cargo doc --open -p nanocodec-encoder.