aboutsummaryrefslogtreecommitdiff
path: root/remuxer/src/codec_param
diff options
context:
space:
mode:
Diffstat (limited to 'remuxer/src/codec_param')
-rw-r--r--remuxer/src/codec_param/vp9.rs39
1 files changed, 35 insertions, 4 deletions
diff --git a/remuxer/src/codec_param/vp9.rs b/remuxer/src/codec_param/vp9.rs
index f310350..9193607 100644
--- a/remuxer/src/codec_param/vp9.rs
+++ b/remuxer/src/codec_param/vp9.rs
@@ -4,8 +4,11 @@
Copyright (C) 2026 metamuffin <metamuffin.org>
*/
+use log::warn;
use winter_matroska::TrackEntry;
+#[derive(Debug, Clone, Copy)]
+#[repr(u8)]
enum VPLevel {
Level1 = 10,
Level1_1 = 11,
@@ -23,10 +26,11 @@ enum VPLevel {
Level6_2 = 62,
}
+#[allow(unused)]
struct VPLevelDef {
level: VPLevel,
max_luma_sample_rate: u64,
- max_luma_picture_size: u32,
+ max_luma_picture_size: u64,
max_avg_bitrate: f64,
max_cpb_size: f64,
min_compression_ratio: f64,
@@ -40,7 +44,7 @@ static LEVELS: &[VPLevelDef] = {
const fn level(
a: VPLevel,
b: u64,
- c: u32,
+ c: u64,
d: f64,
e: f64,
f: f64,
@@ -80,6 +84,33 @@ static LEVELS: &[VPLevelDef] = {
]
};
-pub fn vp9_codec_param(_te: &TrackEntry) -> String {
- "vp09.00.50.08".to_string()
+fn level_by_characteristic(luma_sample_rate: u64, luma_picture_size: u64) -> VPLevel {
+ for lv in LEVELS {
+ if luma_sample_rate < lv.max_luma_sample_rate
+ && luma_picture_size < lv.max_luma_picture_size
+ {
+ return lv.level;
+ }
+ }
+ warn!("VP9 level out of range");
+ return VPLevel::Level6_2;
+}
+
+pub fn vp9_codec_param(te: &TrackEntry) -> String {
+ if let Some(_cp) = &te.codec_private {
+ todo!()
+ }
+ let Some(video) = te.video.as_ref() else {
+ panic!("vp9 without video tag")
+ };
+
+ let luma_picture_size = video.pixel_width * video.pixel_height;
+ let sample_duration = te.default_duration.map_or(1. / 60., |x| 1e9 / x as f64);
+ let luma_sample_rate = ((luma_picture_size as f64) / sample_duration) as u64;
+
+ let profile = 0; // TODO
+ let level = level_by_characteristic(luma_sample_rate, luma_picture_size);
+ let bit_depth = 8; // TODO
+
+ format!("vp09.{:02}.{:02}.{:02}", profile, level as u8, bit_depth)
}