Skip to content

Commit

Permalink
More human readable codec string
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Oct 8, 2024
1 parent 341bf96 commit b6812a3
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 37 additions & 7 deletions crates/store/re_video/src/demux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<u8>,
Expand All @@ -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 { .. })
}
}

Expand Down
7 changes: 3 additions & 4 deletions crates/store/re_video/src/demux/mp4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))?;
Expand All @@ -27,7 +26,7 @@ impl VideoData {
let coded_width = track.width;

let config = Config {
codec,
stsd,
description,
coded_height,
coded_width,
Expand Down
2 changes: 1 addition & 1 deletion crates/viewer/re_data_ui/src/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 5 additions & 2 deletions crates/viewer/re_renderer/src/video/decoder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")] {
Expand All @@ -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(),
});
}

Expand Down

0 comments on commit b6812a3

Please sign in to comment.