From b6812a36596b1f55fea437fb77a43d3999dfa747 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 8 Oct 2024 12:44:08 +0200 Subject: [PATCH] More human readable codec string --- Cargo.lock | 2 +- Cargo.toml | 5 +-- crates/store/re_video/src/demux/mod.rs | 44 ++++++++++++++++--- crates/store/re_video/src/demux/mp4.rs | 7 ++- crates/viewer/re_data_ui/src/blob.rs | 2 +- .../re_renderer/src/video/decoder/mod.rs | 7 ++- 6 files changed, 49 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 515f4766969dc..81cdf237dad73 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5367,7 +5367,7 @@ dependencies = [ [[package]] name = "re_mp4" version = "0.1.0" -source = "git+https://github.com/rerun-io/re_mp4?rev=4705e85f62ddb47c32d9c091d8f0662068211bc8#4705e85f62ddb47c32d9c091d8f0662068211bc8" +source = "git+https://github.com/rerun-io/re_mp4?rev=9783a604eb940885c67995059f426a916d9e994f#9783a604eb940885c67995059f426a916d9e994f" dependencies = [ "byteorder", "bytes", diff --git a/Cargo.toml b/Cargo.toml index dd4eb5e0059c9..01dc883f7e93b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -551,9 +551,8 @@ missing_errors_doc = "allow" # egui_commonmark = { git = "https://github.com/rerun-io/egui_commonmark", rev = "7a9dc755bfa351a3796274cb8ca87129b051c084" } # https://github.com/lampsitter/egui_commonmark/pull/65 -# commit on `rerun-io/mp4` `master` branch: https://github.com/rerun-io/re_mp4/tree/master -# https://github.com/rerun-io/mp4/commit/3236c76f9228cf6ab0b2bfb1b8f9ffcde975ea05 -re_mp4 = { git = "https://github.com/rerun-io/re_mp4", rev = "4705e85f62ddb47c32d9c091d8f0662068211bc8" } +re_mp4 = { git = "https://github.com/rerun-io/re_mp4", rev = "9783a604eb940885c67995059f426a916d9e994f" } # TODO: merge PR +# re_mp4 = { path = "../re_mp4" } # commit on `rerun-io/re_arrow2` `main` branch # https://github.com/rerun-io/re_arrow2/commit/e4717d6debc6d4474ec10db8f629f823f57bad07 diff --git a/crates/store/re_video/src/demux/mod.rs b/crates/store/re_video/src/demux/mod.rs index 350e6b1e1b6b1..77b3b02b3f2e4 100644 --- a/crates/store/re_video/src/demux/mod.rs +++ b/crates/store/re_video/src/demux/mod.rs @@ -90,8 +90,40 @@ impl VideoData { /// The codec used to encode the video. #[inline] - pub fn codec(&self) -> &str { - &self.config.codec + pub fn human_readable_codec_string(&self) -> String { + let mut string = self.config.stsd.contents.codec_string().unwrap_or_default(); + + match &self.config.stsd.contents { + re_mp4::StsdBoxContent::Av01 { .. } => { + string += " (AV1)"; + } + re_mp4::StsdBoxContent::Avc1 { .. } => { + string += " (H.264)"; + } + re_mp4::StsdBoxContent::Hvc1 { .. } => { + string += " (H.265 HVC1)"; + } + re_mp4::StsdBoxContent::Hev1 { .. } => { + string += " (H.265 HEV1)"; + } + re_mp4::StsdBoxContent::Vp08 { .. } => { + string += " (VP8)"; + } + re_mp4::StsdBoxContent::Vp09 { .. } => { + string += " (VP9)"; + } + re_mp4::StsdBoxContent::Mp4a { .. } => { + string += " (AAC)"; + } + re_mp4::StsdBoxContent::Tx3g { .. } => { + string += " (TTXT)"; + } + re_mp4::StsdBoxContent::Unknown(four_cc) => { + string += &format!(" ({four_cc})"); + } + } + + string } /// The number of samples in the video. @@ -185,10 +217,8 @@ pub struct Sample { /// Configuration of a video. #[derive(Debug, Clone)] pub struct Config { - /// String used to identify the codec and some of its configuration. - /// - /// e.g. "av01.0.05M.08" (AV1) - pub codec: String, + /// Contains info about the codec, bit depth, etc. + pub stsd: re_mp4::StsdBox, /// Codec-specific configuration. pub description: Vec, @@ -202,7 +232,7 @@ pub struct Config { impl Config { pub fn is_av1(&self) -> bool { - self.codec.starts_with("av01") + matches!(self.stsd.contents, re_mp4::StsdBoxContent::Av01 { .. }) } } diff --git a/crates/store/re_video/src/demux/mp4.rs b/crates/store/re_video/src/demux/mp4.rs index 14732f1f04693..24659f078cb92 100644 --- a/crates/store/re_video/src/demux/mp4.rs +++ b/crates/store/re_video/src/demux/mp4.rs @@ -16,9 +16,8 @@ impl VideoData { .find(|t| t.kind == Some(re_mp4::TrackKind::Video)) .ok_or_else(|| VideoLoadError::NoVideoTrack)?; - let codec = track - .codec_string(&mp4) - .ok_or_else(|| VideoLoadError::UnsupportedCodec(unknown_codec_fourcc(&mp4, track)))?; + let stsd = track.trak(&mp4).mdia.minf.stbl.stsd.clone(); + let description = track .raw_codec_config(&mp4) .ok_or_else(|| VideoLoadError::UnsupportedCodec(unknown_codec_fourcc(&mp4, track)))?; @@ -27,7 +26,7 @@ impl VideoData { let coded_width = track.width; let config = Config { - codec, + stsd, description, coded_height, coded_width, diff --git a/crates/viewer/re_data_ui/src/blob.rs b/crates/viewer/re_data_ui/src/blob.rs index 53b2770c5fab4..ee1e13a779f6c 100644 --- a/crates/viewer/re_data_ui/src/blob.rs +++ b/crates/viewer/re_data_ui/src/blob.rs @@ -206,7 +206,7 @@ fn show_video_blob_info( .value_text(re_format::format_uint(data.num_samples())), ); ui.list_item_flat_noninteractive( - PropertyContent::new("Codec").value_text(data.codec()), + PropertyContent::new("Codec").value_text(data.human_readable_codec_string()), ); if ui_layout != UiLayout::Tooltip { diff --git a/crates/viewer/re_renderer/src/video/decoder/mod.rs b/crates/viewer/re_renderer/src/video/decoder/mod.rs index 75f7074b0063f..3563cc9c18856 100644 --- a/crates/viewer/re_renderer/src/video/decoder/mod.rs +++ b/crates/viewer/re_renderer/src/video/decoder/mod.rs @@ -110,7 +110,10 @@ impl VideoDecoder { unused )] - let debug_name = format!("{debug_name}, codec: {}", data.config.codec); + let debug_name = format!( + "{debug_name}, codec: {}", + data.human_readable_codec_string() + ); cfg_if::cfg_if! { if #[cfg(target_arch = "wasm32")] { @@ -119,7 +122,7 @@ impl VideoDecoder { } else if #[cfg(feature = "video_av1")] { if !data.config.is_av1() { return Err(DecodingError::UnsupportedCodec { - codec: data.config.codec.clone(), + codec: data.human_readable_codec_string(), }); }