Skip to main content

ff_encode/
bitrate.rs

1/// Maximum CRF value accepted by H.264/H.265 encoders.
2pub const CRF_MAX: u32 = 51;
3
4/// Bitrate control mode for video encoding.
5///
6/// Passed to [`crate::VideoEncoderBuilder::bitrate_mode`].
7#[derive(Debug, Clone, PartialEq)]
8pub enum BitrateMode {
9    /// Constant bitrate in bits per second.
10    Cbr(u64),
11    /// Variable bitrate: target average bitrate and hard ceiling (both bps).
12    Vbr { target: u64, max: u64 },
13    /// Constant rate factor — quality-based (0–51 for H.264/H.265; lower = better).
14    Crf(u32),
15}
16
17#[cfg(test)]
18mod tests {
19    use super::*;
20
21    #[test]
22    fn cbr_should_store_bitrate() {
23        assert!(matches!(
24            BitrateMode::Cbr(5_000_000),
25            BitrateMode::Cbr(5_000_000)
26        ));
27    }
28
29    #[test]
30    fn vbr_should_store_target_and_max() {
31        let mode = BitrateMode::Vbr {
32            target: 4_000_000,
33            max: 6_000_000,
34        };
35        assert!(matches!(
36            mode,
37            BitrateMode::Vbr {
38                target: 4_000_000,
39                max: 6_000_000
40            }
41        ));
42    }
43
44    #[test]
45    fn crf_should_store_quality_value() {
46        assert!(matches!(BitrateMode::Crf(23), BitrateMode::Crf(23)));
47    }
48}