Skip to main content

set_enabled

Function set_enabled 

Source
pub fn set_enabled(on: bool)
Expand description

Turn accounting on (from the harness) — never on by default.

Examples found in repository?
examples/bit_accountant.rs (line 71)
44fn main() {
45    let path = std::env::args().nth(1).unwrap_or_else(|| "video-tests/clips/foreman_cif.y4m".into());
46    let n: usize = std::env::var("BA_FRAMES").ok().and_then(|v| v.parse().ok()).unwrap_or(24);
47    let qp: u8 = std::env::var("BA_QP").ok().and_then(|v| v.parse().ok()).unwrap_or(27);
48    let (w, h, frames) = read_y4m(&path, n);
49    let name = std::path::Path::new(&path).file_stem().unwrap().to_string_lossy().to_string();
50    for (pname, preset) in [("quality", Preset::Quality)] {
51        let mut cfg = EncoderConfig::new(w, h);
52        cfg.qp = qp;
53        cfg.gop_size = 60;
54        cfg.preset = preset;
55        // The accountant must be runnable in the SAME configuration whose gap is
56        // under investigation, or its split describes a different encoder than the
57        // one being measured. BA_BFRAMES / BA_REFS mirror the all-tools arm.
58        if let Ok(v) = std::env::var("BA_BFRAMES") {
59            if let Ok(b) = v.parse::<u32>() {
60                cfg.bframes = b;
61                cfg.bframes_adaptive = false;
62            }
63        }
64        if let Ok(v) = std::env::var("BA_REFS") {
65            if let Ok(r) = v.parse::<u32>() {
66                cfg.num_ref_frames = r;
67            }
68        }
69        let cfg_bframes = cfg.bframes;
70        rusty_h264_encoder::bitacct::reset();
71        rusty_h264_encoder::bitacct::set_enabled(true);
72        let mut enc = Encoder::new(cfg).unwrap();
73        // B-frames require the lookahead path (`encode_all`); the per-frame
74        // `encode` loop cannot reorder. Use whichever the config demands so the
75        // accountant can profile the B-carrying arm at all.
76        let total: usize = if cfg_bframes > 0 {
77            enc.encode_all(&frames).unwrap().iter().map(|n| n.len()).sum()
78        } else {
79            let mut t = 0usize;
80            for f in &frames {
81                t += enc.encode(f).len();
82            }
83            t
84        };
85        rusty_h264_encoder::bitacct::add_actual_bytes(total);
86        rusty_h264_encoder::bitacct::set_enabled(false);
87        let mbs = (w.div_ceil(16) * h.div_ceil(16) * frames.len()) as u64;
88        rusty_h264_encoder::bitacct::dump(
89            &format!("{name} {pname} qp{qp} x{} ({} bytes)", frames.len(), total),
90            mbs,
91        );
92        if std::env::var_os("RFF_BSTATS").is_some() {
93            rusty_h264_encoder::mb16::bstats::dump();
94        }
95        if std::env::var_os("BA_MVDTAB").is_some() {
96            rusty_h264_encoder::bitacct::dump_mvd_table();
97        }
98    }
99}