pub struct BitrateEstimator { /* private fields */ }Expand description
Estimates output bitrate (bits per second) from encode parameters.
The model is a simplified empirical formula:
bitrate ≈ base_bpp * pixels_per_frame * frame_rate * quality_factor
where quality_factor decreases as QP/CRF increases.
An embedded BitrateRunningAnalyzer accumulates per-frame bitrate
statistics incrementally via Welford’s online algorithm so that callers
can query running mean/variance without storing historical data.
§Example
use oximedia_transcode::bitrate_estimator::BitrateEstimator;
let mut est = BitrateEstimator::new();
let bps = est.estimate_from_crf(23, 1920, 1080, 30.0);
assert!(bps > 0);
// Feed observed per-frame bit counts into the running analyzer
est.record_frame_bits(50_000);
est.record_frame_bits(45_000);
let summary = est.running_summary();
assert!(summary.mean_bps > 0.0);Implementations§
Source§impl BitrateEstimator
impl BitrateEstimator
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a BitrateEstimator with default empirical parameters.
The embedded running analyzer is initialised for 30 fps with a 60-frame
rolling window; call with_params_and_fps
to customise these.
Sourcepub fn with_params(base_bpp: f64, decay: f64) -> Self
pub fn with_params(base_bpp: f64, decay: f64) -> Self
Creates a BitrateEstimator with custom parameters.
base_bpp– bits per pixel at QP = 0.decay– exponential decay constant; higher = steeper quality/bitrate curve.
Sourcepub fn with_params_and_fps(
base_bpp: f64,
decay: f64,
fps: f64,
window_frames: usize,
) -> Self
pub fn with_params_and_fps( base_bpp: f64, decay: f64, fps: f64, window_frames: usize, ) -> Self
Creates a BitrateEstimator with custom model parameters and analyzer config.
fps– Frame rate for the running analyzer (bits/frame → bits/s).window_frames– Rolling-window size for recent-peak detection.
Sourcepub fn record_frame_bits(&mut self, bits_per_frame: u64)
pub fn record_frame_bits(&mut self, bits_per_frame: u64)
Records the observed bit count for one encoded frame into the running analyzer.
Use this to track actual per-frame bitrate statistics incrementally (Welford algorithm) without buffering all historical frame data.
Sourcepub fn running_summary(&self) -> BitrateSummary
pub fn running_summary(&self) -> BitrateSummary
Returns a snapshot of current running bitrate statistics.
The summary reflects all frames recorded via record_frame_bits.
Sourcepub fn reset_running_stats(&mut self)
pub fn reset_running_stats(&mut self)
Resets the running bitrate statistics to their initial state.
Sourcepub fn estimate_from_crf(
&self,
crf: u8,
width: u32,
height: u32,
frame_rate: f64,
) -> u64
pub fn estimate_from_crf( &self, crf: u8, width: u32, height: u32, frame_rate: f64, ) -> u64
Estimates output bitrate in bits/s from a CRF value (0–51 for H.264/H.265).
crf– Constant Rate Factor (0 = lossless, 51 = worst).width– Frame width in pixels.height– Frame height in pixels.frame_rate– Frames per second.
Sourcepub fn estimate_from_qp(
&self,
qp: f64,
width: u32,
height: u32,
frame_rate: f64,
) -> u64
pub fn estimate_from_qp( &self, qp: f64, width: u32, height: u32, frame_rate: f64, ) -> u64
Estimates output bitrate in bits/s from a floating-point QP value.
qp– Quantization parameter.width– Frame width in pixels.height– Frame height in pixels.frame_rate– Frames per second.
Sourcepub fn estimate_from_vmaf(
&self,
vmaf: f64,
width: u32,
height: u32,
frame_rate: f64,
) -> u64
pub fn estimate_from_vmaf( &self, vmaf: f64, width: u32, height: u32, frame_rate: f64, ) -> u64
Estimates bitrate from a target VMAF score (0–100).
Linearly maps VMAF → effective QP, then delegates to estimate_from_qp.
VMAF 100 ≈ QP 0 (lossless), VMAF 0 ≈ QP 51 (worst).
Trait Implementations§
Source§impl Debug for BitrateEstimator
impl Debug for BitrateEstimator
Auto Trait Implementations§
impl Freeze for BitrateEstimator
impl RefUnwindSafe for BitrateEstimator
impl Send for BitrateEstimator
impl Sync for BitrateEstimator
impl Unpin for BitrateEstimator
impl UnsafeUnpin for BitrateEstimator
impl UnwindSafe for BitrateEstimator
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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