mux/meta: preserve color_space round-trip in m2ts metadata
MetaStream::Video dropped color_space on from_title/to_title, hardcoding BT.709 on the way back. HDR titles (BT.2020) lost their color metadata. Add a color_space field, populate it in from_title, and use it in to_title. For pre-0.30.7 metadata that has no color_space, derive it from the preserved hdr field (all HDR formats are BT.2020, SDR is BT.709). Adds ColorSpace::id() + FromStr for serialization round-trip.
This commit is contained in:
@@ -779,6 +779,22 @@ impl ColorSpace {
|
||||
ColorSpace::Unknown => "",
|
||||
}
|
||||
}
|
||||
|
||||
const ALL_CS: &[(&'static str, ColorSpace)] = &[
|
||||
("bt709", ColorSpace::Bt709),
|
||||
("bt2020", ColorSpace::Bt2020),
|
||||
("unknown", ColorSpace::Unknown),
|
||||
];
|
||||
|
||||
/// Compact identifier for serialization (round-trips via `FromStr`).
|
||||
pub fn id(&self) -> &'static str {
|
||||
for (id, v) in Self::ALL_CS {
|
||||
if v == self {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
"unknown"
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for ColorSpace {
|
||||
@@ -787,6 +803,24 @@ impl std::fmt::Display for ColorSpace {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::str::FromStr for ColorSpace {
|
||||
type Err = ();
|
||||
fn from_str(s: &str) -> std::result::Result<Self, ()> {
|
||||
for (id, v) in ColorSpace::ALL_CS {
|
||||
if *id == s {
|
||||
return Ok(*v);
|
||||
}
|
||||
}
|
||||
// Also accept display names (e.g. "BT.2020").
|
||||
for (_id, v) in ColorSpace::ALL_CS {
|
||||
if ColorSpace::name(v) == s {
|
||||
return Ok(*v);
|
||||
}
|
||||
}
|
||||
Ok(ColorSpace::Unknown)
|
||||
}
|
||||
}
|
||||
|
||||
// ─── FromStr impls — single source of truth via ALL_* arrays ───────────────
|
||||
//
|
||||
// Each enum defines a const array of (str, variant) pairs. Display, FromStr,
|
||||
|
||||
Reference in New Issue
Block a user