aboutsummaryrefslogtreecommitdiff
path: root/remuxer/src/codec_param/av1.rs
blob: 349cfc20f7194840cae9b9465df4e20055306d98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
    This file is part of jellything (https://codeberg.org/metamuffin/jellything)
    which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
    Copyright (C) 2026 metamuffin <metamuffin.org>
*/

use crate::codec_param::CodecParam;

pub fn av1_codec_param(cp: &[u8]) -> CodecParam {
    let profile = (cp[1] >> 5) & 0b111;
    let level = cp[1] & 0b11111;
    let tier = (cp[2] >> 7) & 0b1;
    let high_bitdepth = (cp[2] >> 6) & 0b1;
    let twelve_bit = (cp[2] >> 5) & 0b1;
    let _monochrome = (cp[2] >> 4) & 0b1;
    let _css_x = (cp[2] >> 3) & 0b1;
    let _css_y = (cp[2] >> 2) & 0b1;
    let _css_pos = cp[2] & 0b11;

    let tier_char = if tier == 1 { 'H' } else { 'M' };
    let bit_depth = if twelve_bit == 1 {
        12
    } else if high_bitdepth == 1 {
        10
    } else {
        8
    };
    CodecParam {
        string: format!(
            "av01.{profile}.{level:02}{tier_char}.{bit_depth:02}" // .{monochrome}.{css_x}{css_y}{css_pos}
        ),
        bit_depth: Some(bit_depth),
    }
}

#[test]
fn sample1() {
    assert_eq!(av1_codec_param(&[0x81, 0x04, 0x4E]).string, "av01.0.04M.10");
}
#[test]
fn sample2() {
    assert_eq!(av1_codec_param(&[0x81, 0x35, 0xF4]).string, "av01.1.21H.12");
}