pub struct RateControl { /* private fields */ }Expand description
Tracks the rate law and picks a quantizer per frame.
Implementations§
Source§impl RateControl
impl RateControl
Sourcepub fn new(bits_per_second: u64, fps: u32, total: Option<u32>) -> Self
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.
Sourcepub fn clamp_qp(self, min: i32, max: i32) -> Self
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.
Sourcepub fn observe(&mut self, qp: i32, bytes: usize)
pub fn observe(&mut self, qp: i32, bytes: usize)
Record what a frame actually cost at the quantizer it was coded with.
Sourcepub fn seed(&mut self, qp: i32, bytes: usize)
pub fn seed(&mut self, qp: i32, bytes: usize)
Seed the law from a probe encode without counting it against the budget.
Sourcepub fn probe_again(&self) -> Option<i32>
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.
Sourcepub fn seed_pair(&mut self, qp: i32, bytes: usize)
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.
Sourcepub fn outcome(&self) -> Option<Reach>
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.
Sourcepub fn group_size(&self, memory_limit: usize) -> usize
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§
Auto Trait Implementations§
impl Forget for RateControl
impl Freeze for RateControl
impl Move for RateControl
impl RefUnwindSafe for RateControl
impl Send for RateControl
impl Sync for RateControl
impl Unpin for RateControl
impl UnsafeUnpin for RateControl
impl UnwindSafe for RateControl
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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