Skip to main content

RateControl

Struct RateControl 

Source
pub struct RateControl { /* private fields */ }
Expand description

Tracks the rate law and picks a quantizer per frame.

Implementations§

Source§

impl RateControl

Source

pub fn new(bits_per_second: u64, fps: u32, total: Option<u32>) -> Self

bits_per_second at fps, over total frames if that is known.

Source

pub fn clamp_qp(self, min: i32, max: i32) -> Self

Restrict the quantizer range, for callers who would rather miss the target than let quality out of a band.

Source

pub fn next_qp(&self) -> i32

The quantizer for the next frame.

Source

pub fn observe(&mut self, qp: i32, bytes: usize)

Record what a frame actually cost at the quantizer it was coded with.

Source

pub fn seed(&mut self, qp: i32, bytes: usize)

Seed the law from a probe encode without counting it against the budget.

Source

pub fn probe_again(&self) -> Option<i32>

A second quantizer worth probing before committing, if there is one.

The probe and the answer can be twenty-five quantizer steps apart, and the rate curve bends enough over that distance that the chord between them is a poor guide — the slope is 0.075 per step at one end and 0.32 at the other. A second probe near where the answer is thought to be turns that chord into a local measurement.

It costs one frame encode, against a whole clip coded at the wrong rate.

Source

pub fn seed_pair(&mut self, qp: i32, bytes: usize)

Fold a second probe in: it refines the law but does not count against the budget, because its frame will be coded again for real.

Source

pub fn spent(&self) -> f64

Bytes emitted so far.

Source

pub fn outcome(&self) -> Option<Reach>

Whether the target turned out to be out of reach, and in which direction.

A bitrate can be unreachable both ways. Past qp_max the encoder has nothing coarser to offer, so content too complex cannot be squeezed into the target. Past qp_min it has nothing finer, so content too simple cannot be made to fill it — a flat render at QP 0 is as large as it will ever get, and asking for ten times that gets the same file.

Both are properties of the request rather than faults, and both are worth saying: a file at a fifth of the requested bitrate looks exactly like a bug from outside.

Judged from what was actually coded, not from the model. Extrapolating the rate law from the quantizers in use out to 0 or 51 is exactly where it stops holding — doing that reported a rendered clip as “2.9x too simple” for a target it in fact came within 3% of.

Source

pub fn group_size(&self, memory_limit: usize) -> usize

How many frames to encode before consulting the controller again.

Frames are encoded in parallel batches, and the controller only learns at a batch boundary — so a clip that fits in one batch gets no feedback at all, and lands wherever the first extrapolation put it. That was worth 10-24% on a ten-frame clip.

Eight rounds, and the group size is derived only from the clip length and the memory budget — never from the core count.

The controller learns once per group, so the group size is the accuracy. Sizing it by how many frames happen to fit on the machine’s cores made the same clip encode to a different size on a different machine: one thread gave ninety-six single-frame rounds and fourteen gave twelve, and the two missed the target by 19% and 1% respectively. Which is the wrong kind of surprise.

Trait Implementations§

Source§

impl Debug for RateControl

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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, 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.