Skip to content

Commit

Permalink
Add info summary
Browse files Browse the repository at this point in the history
  • Loading branch information
quietvoid committed Jun 11, 2022
1 parent 53d4b90 commit 85f55af
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "dovi_tool"
version = "1.5.3"
version = "1.5.4"
authors = ["quietvoid"]
edition = "2021"
rust-version = "1.56.0"
rust-version = "1.58.0"
license = "MIT"
build = "build.rs"

Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The **`dolby_vision`** crate is also hosted in this repo, see [README](dolby_vis
## **Building**
### **Toolchain**

The minimum Rust version to build **`dovi_tool`** is 1.56.0.
The minimum Rust version to build **`dovi_tool`** is 1.58.0.

### **Release binary**
To build release binary in `target/release/dovi_tool` run:
Expand Down Expand Up @@ -43,8 +43,11 @@ dovi_tool <SUBCOMMAND> --help
**`dovi_tool`** provides an important set of tools for analyzing, editing and generating Dolby Vision metadata.
## **Commands**
* ### **info**
Prints the parsed RPU data as JSON for a specific frame.
Frame indices start at 0.
Prints the parsed RPU information.
To get the summary, use `--summary` or `-s`.

Using `--frame`: prints the RPU data as JSON for a specific frame.
- Frame indices start at 0.

**Example to get metadata for frame 124**:
```console
Expand Down
3 changes: 3 additions & 0 deletions src/commands/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ pub struct InfoArgs {
help = "Frame number to show info for"
)]
pub frame: Option<usize>,

#[clap(name = "summary", long, short = 's', help = "Show the RPU summary")]
pub summary: bool,
}
93 changes: 73 additions & 20 deletions src/dovi/rpu_info.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::fmt::Write as FmtWrite;
use std::io::{stdout, Write};
use std::path::PathBuf;

Expand All @@ -11,7 +12,6 @@ use crate::commands::InfoArgs;

pub struct RpuInfo {
input: PathBuf,
frame: Option<usize>,
rpus: Option<Vec<DoviRpu>>,
}

Expand All @@ -21,39 +21,92 @@ impl RpuInfo {
input,
input_pos,
frame,
summary,
} = args;

if frame.is_none() {
if !summary && frame.is_none() {
bail!("No frame number to look up");
}

let input = input_from_either("info", input, input_pos)?;

let mut info = RpuInfo {
input,
frame,
rpus: None,
};
let mut info = RpuInfo { input, rpus: None };

println!("Parsing RPU file...");
stdout().flush().ok();

info.rpus = parse_rpu_file(&info.input)?;

if let Some(ref rpus) = info.rpus {
let f = info.frame.unwrap();
ensure!(
f < rpus.len(),
format!(
"info: invalid frame number (out of range).\nNumber of valid RPUs parsed: {}",
rpus.len()
)
);

let rpu = &rpus[f];

if let Ok(rpu_serialized) = serde_json::to_string_pretty(&rpu) {
println!("{}", rpu_serialized);
if let Some(f) = frame {
ensure!(
f < rpus.len(),
format!(
"info: invalid frame number (out of range).\nNumber of valid RPUs parsed: {}",
rpus.len()
)
);

let rpu = &rpus[f];

if let Ok(rpu_serialized) = serde_json::to_string_pretty(&rpu) {
println!("{}", rpu_serialized);
}
}

if summary {
let count = rpus.len();

let dmv1_count = rpus
.iter()
.filter(|rpu| {
rpu.vdr_dm_data
.as_ref()
.and_then(|vdr| vdr.cmv29_metadata.as_ref())
.is_some()
})
.count();
let dmv2_count = rpus
.iter()
.filter(|rpu| {
rpu.vdr_dm_data
.as_ref()
.and_then(|vdr| vdr.cmv40_metadata.as_ref())
.is_some()
})
.count();

let (needs_count, dm_version) = if dmv2_count == dmv1_count {
(false, "2 (CM v4.x)")
} else if dmv2_count == 0 {
(false, "1 (CM v2.9)")
} else {
(true, "1 + 2 (CM 2.9 and 4.x)")
};

let scene_count = rpus
.iter()
.filter(|rpu| {
rpu.vdr_dm_data
.as_ref()
.and_then(|vdr| (vdr.scene_refresh_flag == 1).then(|| 1))
.is_some()
})
.count();

let mut summary_str =
format!("Summary:\n Frmaes: {count}\n DM version: {dm_version}");

if needs_count {
write!(
summary_str,
"\n v2.9 count: {dmv1_count}\n v4.x count: {dmv2_count}"
)?;
}

write!(summary_str, "\n Scene/shot count: {scene_count}")?;

println!("\n{}", summary_str)
}
}

Expand Down

0 comments on commit 85f55af

Please sign in to comment.