diff options
Diffstat (limited to 'remuxer/src/codec_param/hevc.rs')
| -rw-r--r-- | remuxer/src/codec_param/hevc.rs | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/remuxer/src/codec_param/hevc.rs b/remuxer/src/codec_param/hevc.rs index 3459258..8bff081 100644 --- a/remuxer/src/codec_param/hevc.rs +++ b/remuxer/src/codec_param/hevc.rs @@ -4,21 +4,33 @@ Copyright (C) 2026 metamuffin <metamuffin.org> */ +use crate::codec_param::CodecParam; use std::fmt::Write; -pub(super) fn hevc_codec_param(cp: &[u8]) -> String { +pub(super) fn hevc_codec_param(cp: &[u8]) -> CodecParam { let general_profile_space = cp[1] >> 6; let general_tier_flag = (cp[1] >> 5) & 0b1; let general_profile_idc = cp[1] & 0b11111; let general_level_idc = cp[12]; let general_profile_compatibility_flag = u32::from_be_bytes([cp[2], cp[3], cp[4], cp[5]]).reverse_bits(); + let general_constraint_indicator_flags = &cp[6..12]; + let _min_spatial_segmentation_idc = u16::from_be_bytes([cp[13], cp[14]]) & 0b111111111111; + let _parallelism_type = cp[15] & 0b11; + let _chroma_format_idc = cp[16] & 0b11; + let bit_depth_luma = (cp[17] & 0b111) + 8; + let _bit_depth_chroma = (cp[18] & 0b111) + 8; + let mut d = String::new(); - let trailing_zeroes = cp[6..12].iter().rev().take_while(|x| **x == 0).count(); + let trailing_zeroes = general_constraint_indicator_flags + .iter() + .rev() + .take_while(|x| **x == 0) + .count(); for &flag in &cp[6..12 - trailing_zeroes] { write!(d, ".{flag:02x}").unwrap(); } - format!( + let string = format!( "hvc1.{}{}.{:x}.{}{}{d}", match general_profile_space { 0 => "", @@ -35,21 +47,39 @@ pub(super) fn hevc_codec_param(cp: &[u8]) -> String { _ => unreachable!(), }, general_level_idc, - ) + ); + CodecParam { + string, + bit_depth: Some(bit_depth_luma), + } } #[test] fn sample1() { let cp = [ - 0x01, 0x02, 0x20, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, + 0x01, 0x02, 0x20, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xF0, 0x00, + 0xFC, 0xFD, 0xFA, 0xFA, 0x00, 0x00, 0x0F, ]; - assert_eq!(hevc_codec_param(&cp), "hvc1.2.4.L63.90") + assert_eq!( + hevc_codec_param(&cp), + CodecParam { + string: "hvc1.2.4.L63.90".to_string(), + bit_depth: Some(10) + } + ) } #[test] fn sample2() { let cp = [ - 0x01, 0x01, 0x60, 0x00, 0x00, 0x00, 0xB0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, + 0x01, 0x01, 0x60, 0x00, 0x00, 0x00, 0xB0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0xF0, 0x00, + 0xFC, 0xFD, 0xF8, 0xF8, 0x00, 0x00, 0x0B, ]; - assert_eq!(hevc_codec_param(&cp), "hvc1.1.6.L120.b0") + assert_eq!( + hevc_codec_param(&cp), + CodecParam { + string: "hvc1.1.6.L120.b0".to_string(), + bit_depth: Some(8) + } + ); } |