Skip to content

Commit

Permalink
Add profile 4 handling, info subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
quietvoid committed May 5, 2021
1 parent 2fd4d87 commit adf622d
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 9 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.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dovi_tool"
version = "0.3.1"
version = "0.3.2"
authors = ["quietvoid"]
edition = "2018"
license = "MIT"
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,12 @@ See examples in `assets` folder.

* `dovi_tool editor -i RPU.bin -j assets/editor_examples/mode.json --rpu-out RPU_mode2.bin`

#### info
Prints the parsed RPU data for a specific frame.

* `dovi_tool info -i RPU.bin -f 0`

 

Build artifacts can be found in the Github Actions.
More features may or may not be added in the future.
2 changes: 2 additions & 0 deletions profiles.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Differentiating between Dolby Vision profiles.
##### Profile 4
Possibly `vdr_bit_depth_minus_8` > 4
##### Profile 5
`vdr_rpu_profile = 0`
`bl_video_full_range_flag = 0`
Expand Down
19 changes: 19 additions & 0 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,23 @@ pub enum Command {
#[structopt(long, help = "Output HEVC file location", parse(from_os_str))]
output: Option<PathBuf>,
},

Info {
#[structopt(
name = "input",
short = "i",
long,
help = "Sets the input RPU file to use",
parse(from_os_str)
)]
input: PathBuf,

#[structopt(
name = "frame",
short = "f",
long,
help = "Frame number to show info for"
)]
frame: Option<usize>,
},
}
1 change: 1 addition & 0 deletions src/dovi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub mod converter;
pub mod demuxer;
pub mod editor;
pub mod rpu_extractor;
pub mod rpu_info;
pub mod rpu_injector;

mod io;
Expand Down
12 changes: 12 additions & 0 deletions src/dovi/rpu/rpu_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ impl DoviRpu {
let reader = &mut dovi_rpu.reader;
dovi_rpu.header = RpuDataHeader::rpu_data_header(reader);

// Preliminary header validation
dovi_rpu.dovi_profile = dovi_rpu.header.get_dovi_profile();

dovi_rpu.header.validate(dovi_rpu.dovi_profile);
Expand Down Expand Up @@ -78,6 +79,8 @@ impl DoviRpu {
assert_eq!(last_byte, 0x80);
}

dovi_rpu.validate();

dovi_rpu
}

Expand Down Expand Up @@ -228,4 +231,13 @@ impl DoviRpu {
panic!("Attempt to convert profile 5: RPU is not profile 5!");
}
}

pub fn validate(&mut self) {
self.dovi_profile = self.header.get_dovi_profile();
self.header.validate(self.dovi_profile);

if let Some(ref mut vdr_dm_data) = self.vdr_dm_data {
vdr_dm_data.validate(self.dovi_profile);
}
}
}
8 changes: 6 additions & 2 deletions src/dovi/rpu/rpu_data_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,13 @@ impl RpuDataHeader {
}
}
1 => {
// 7 or 8
// 4, 7 or 8
if self.el_spatial_resampling_filter_flag && !self.disable_residual_flag {
7
if self.vdr_bit_depth_minus_8 == 4 {
7
} else {
4
}
} else {
8
}
Expand Down
9 changes: 9 additions & 0 deletions src/dovi/rpu/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ pub fn _parse_file(input: PathBuf) -> (Vec<u8>, DoviRpu) {
(original_data, dovi_rpu)
}

#[test]
fn profile4() {
let (original_data, mut dovi_rpu) = _parse_file(PathBuf::from("./assets/profile4.bin"));
assert_eq!(dovi_rpu.dovi_profile, 4);
let parsed_data = dovi_rpu.write_rpu_data();

assert_eq!(&original_data, &parsed_data);
}

#[test]
fn profile5() {
let (original_data, mut dovi_rpu) = _parse_file(PathBuf::from("./assets/profile5.bin"));
Expand Down
9 changes: 5 additions & 4 deletions src/dovi/rpu/vdr_dm_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,16 @@ impl VdrDmData {
}
}

data.validate();

data
}

pub fn validate(&self) {
pub fn validate(&self, profile: u8) {
assert!(self.affected_dm_metadata_id <= 15);
assert!(self.signal_bit_depth >= 8 && self.signal_bit_depth <= 16);
assert_eq!(self.signal_eotf, 65535);

if profile > 4 {
assert_eq!(self.signal_eotf, 65535);
}
}

pub fn write(&self, writer: &mut BitVecWriter) {
Expand Down
29 changes: 29 additions & 0 deletions src/dovi/rpu_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use std::path::PathBuf;

use super::{parse_rpu_file, rpu::DoviRpu};

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

impl RpuInfo {
pub fn info(input: PathBuf, frame: Option<usize>) {
let mut info = RpuInfo {
input,
frame,
rpus: None,
};

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

if let Some(ref rpus) = info.rpus {
if let Some(f) = info.frame {
assert!(f < rpus.len());

println!("{:#?}", rpus[f]);
}
}
}
}
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use commands::Command;
mod dovi;
use dovi::{
converter::Converter, demuxer::Demuxer, editor::Editor, rpu_extractor::RpuExtractor,
rpu_injector::RpuInjector, Format, RpuOptions,
rpu_info::RpuInfo, rpu_injector::RpuInjector, Format, RpuOptions,
};

#[derive(StructOpt, Debug)]
Expand Down Expand Up @@ -75,6 +75,7 @@ fn main() {
rpu_in,
output,
} => RpuInjector::inject_rpu(input, rpu_in, output),
Command::Info { input, frame } => RpuInfo::info(input, frame),
}
}

Expand Down

0 comments on commit adf622d

Please sign in to comment.