aboutsummaryrefslogtreecommitdiff
path: root/remuxer/src/codec_param/mod.rs
blob: 4613c88ed099dc9bc6ed143587016c91ad24eee0 (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
44
45
46
47
48
49
/*
    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::{av1::av1_codec_param, hevc::hevc_codec_param, vp9::vp9_codec_param};
use winter_matroska::TrackEntry;

mod av1;
mod hevc;
mod vp9;

#[derive(Debug, PartialEq, Eq)]
struct CodecParam {
    bit_depth: Option<u8>,
    string: String,
}

pub fn codec_param(te: &TrackEntry) -> String {
    let empty_cp = vec![];
    let cp = te.codec_private.as_ref().unwrap_or(&empty_cp);
    match te.codec_id.as_str() {
        "A_AAC" => "mp4a.40.2".to_string(),
        "A_FLAC" => "flac".to_string(),
        "A_OPUS" => "opus".to_string(),
        "A_VORBIS" => "vorbis".to_string(),

        "V_AV1" => av1_codec_param(cp).string,
        "V_MPEG4/ISO/AVC" => format!("avc1.{:02x}{:02x}{:02x}", cp[1], cp[2], cp[3]),
        "V_MPEGH/ISO/HEVC" => hevc_codec_param(cp).string,
        "V_VP9" => vp9_codec_param(te),

        "D_WEBVTT/SUBTITLES" => "webvtt".to_string(),
        "S_TEXT/ASS" => "ass".to_string(),

        x => todo!("{x:?}"),
    }
}

pub fn codec_param_bit_depth(te: &TrackEntry) -> Option<u8> {
    let empty_cp = vec![];
    let cp = te.codec_private.as_ref().unwrap_or(&empty_cp);
    match te.codec_id.as_str() {
        "V_AV1" => av1_codec_param(cp).bit_depth,
        "V_MPEGH/ISO/HEVC" => hevc_codec_param(cp).bit_depth,
        _ => None,
    }
}