Skip to main content

ff_encode/video/codec_options/
av1.rs

1//! AV1 (libaom-av1) per-codec encoding options.
2
3/// AV1 per-codec options (libaom-av1).
4#[derive(Debug, Clone)]
5pub struct Av1Options {
6    /// CPU effort level: `0` = slowest / best quality, `8` = fastest / lowest quality.
7    pub cpu_used: u8,
8    /// Log2 of the number of tile rows (0–6).
9    pub tile_rows: u8,
10    /// Log2 of the number of tile columns (0–6).
11    pub tile_cols: u8,
12    /// Encoding usage mode.
13    pub usage: Av1Usage,
14}
15
16impl Default for Av1Options {
17    fn default() -> Self {
18        Self {
19            cpu_used: 4,
20            tile_rows: 0,
21            tile_cols: 0,
22            usage: Av1Usage::VoD,
23        }
24    }
25}
26
27/// AV1 encoding usage mode.
28#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
29pub enum Av1Usage {
30    /// Video-on-demand: maximise quality at the cost of speed.
31    #[default]
32    VoD,
33    /// Real-time: minimise encoding latency.
34    RealTime,
35}
36
37impl Av1Usage {
38    pub(in crate::video) fn as_str(self) -> &'static str {
39        match self {
40            Self::VoD => "vod",
41            Self::RealTime => "realtime",
42        }
43    }
44}
45
46#[cfg(test)]
47mod tests {
48    use super::*;
49
50    #[test]
51    fn av1_usage_should_return_correct_str() {
52        assert_eq!(Av1Usage::VoD.as_str(), "vod");
53        assert_eq!(Av1Usage::RealTime.as_str(), "realtime");
54    }
55
56    #[test]
57    fn av1_options_default_should_have_vod_usage() {
58        let opts = Av1Options::default();
59        assert_eq!(opts.cpu_used, 4);
60        assert_eq!(opts.tile_rows, 0);
61        assert_eq!(opts.tile_cols, 0);
62        assert_eq!(opts.usage, Av1Usage::VoD);
63    }
64}