Skip to main content

Crate vp8_encoder

Crate vp8_encoder 

Source
Expand description

A real-time VP8 video encoder in pure, safe Rust.

It turns I420 pictures into raw VP8 frames (RFC 6386) for live video: camera and screen sharing over WebRTC. No look-ahead and no reordering: one frame in, at most one frame out.

  • Rate control to a target bitrate, changeable at any time with Encoder::set_rates; frames are skipped when the stream runs far over budget.
  • Keyframes on request (Encoder::request_keyframe or the force_keyframe flag), for PLI and FIR.
  • Optional temporal layers (L1T2, L1T3) in the usual WebRTC pattern.
  • Simulcast: run one encoder per layer, each at its own size; scale_i420 makes the smaller pictures.

Every frame’s probability updates apply to that frame only, so a lost or dropped frame never leaves a receiver with the wrong probabilities.

use vp8_encoder::{Encoder, EncoderConfig, Picture};
let mut enc = Encoder::new(EncoderConfig::new(1280, 720, 30, 2_000_000)).unwrap();
let i420 = vec![128u8; 1280 * 720 * 3 / 2];
let picture = Picture::from_i420(&i420, 1280, 720).unwrap();
if let Some(frame) = enc.encode(&picture, false).unwrap() {
    // frame.data is one raw VP8 frame, ready for an RTP packetiser.
    let _ = (frame.keyframe, frame.temporal_id, frame.layer_sync);
}

See PROVENANCE.md for how this crate was written.

Structs§

EncodedFrame
One encoded frame.
Encoder
A real-time VP8 encoder for one stream (one simulcast layer).
EncoderConfig
Encoder settings.
Picture
A borrowed planar YUV 4:2:0 (I420) picture.

Enums§

EncodeError
Why a frame could not be encoded.
TemporalLayers
Temporal layering.

Functions§

scale_i420
Scales src to width x height and appends it to out as packed I420. Downscaling averages the source area under each output pixel; upscaling interpolates bilinearly.