Skip to content

Commit

Permalink
Editor: remove convert_to_cmv4 option
Browse files Browse the repository at this point in the history
And add `remove_cmv4` setting
  • Loading branch information
quietvoid committed Jun 11, 2022
1 parent 80aa8af commit 53d4b90
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 54 deletions.
10 changes: 5 additions & 5 deletions 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
Expand Up @@ -29,7 +29,7 @@ assert_fs = "1.0.7"
predicates = "2.1.1"

[build-dependencies]
vergen = { version = "7.2.0", default_features = false, features = ["git"] }
vergen = { version = "7.2.1", default_features = false, features = ["git"] }

[[bin]]
name = "dovi_tool"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dovi_tool <SUBCOMMAND> --help


## All options
- `--help`, `--version`, `--crop`, `--drop-hdr10plus`, `--mode`, `--edit-config`
- `--help`, `--version`, `--crop`, `--drop-hdr10plus`, `--mode`, `--edit-config`, `--start-code`
## All subcommands
- Metadata utilities: **`info`**, **`generate`**, **`editor`**, **`export`**
- HEVC parsing & handling: **`convert`**, **`demux`**, **`mux`**, **`extract-rpu`**, **`inject-rpu`**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"convert_to_cmv4": true,
"level9": "DCIP3D65",
"level9": "BT.2020",
"level11": {
"content_type": 1,
"whitepoint": 0,
Expand Down
3 changes: 3 additions & 0 deletions assets/editor_examples/remove_cmv4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"remove_cmv4": true
}
14 changes: 6 additions & 8 deletions docs/editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ The editor expects a JSON config like the example below:
// Mode to convert the RPU (refer to README)
"mode": int,

// Adds CM v4.0 metadata with these defaults:
// L9 with DCI-P3 mastering display primaries
// L11 content type set to Cinema, D65 and Reference Mode
//
// Optional, defaults to false.
"convert_to_cmv4": boolean,
// Removes CM v4.0 from the RPU:
// - L3, L8, L9, L10 and L11 are removed
// - DM v2 metadata is removed, along with L254
"remove_cmv4": boolean,

// Whether to remove polynomial/MMR mapping coefficients from the metadata
"remove_mapping": boolean,
Expand Down Expand Up @@ -92,15 +90,15 @@ The editor expects a JSON config like the example below:

// Level 9 Mastering Display Primaries
// Optional, replaces existing L9.
// Implies converting to CM V4.0.
// The RPU must already be CM v4.0 for this to have any effect
//
// String value, must match enum.
// Default: "DCIP3D65".
"level9": MasteringDisplayPrimaries,

// Level 11 Content type metadata
// Optional, replaces existing L11
// Setting this implies converting to CM v4.0
// The RPU must already be CM v4.0 for this to have any effect
"level11": {
// 1 = Cinema, 2 = Games, 3 = Sports, 4 = User generated content
"content_type": int,
Expand Down
6 changes: 6 additions & 0 deletions dolby_vision/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
## ??

## 1.6.6

- Add `ConversionMode` enum to use with `DoviRpu::convert_with_mode`.
- Added support to generate profile 5 RPUs.
- Added long play mode RPU generation.
- This sets `scene_refresh_flag` to `1` for every frame.
- Deprecated `DoviRpu::convert_to_cmv4` as it can lead to playback issues.

## 1.6.5

Expand Down
2 changes: 1 addition & 1 deletion dolby_vision/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dolby_vision"
version = "1.6.5"
version = "1.6.6"
authors = ["quietvoid"]
edition = "2021"
rust-version = "1.56.0"
Expand Down
16 changes: 16 additions & 0 deletions dolby_vision/src/rpu/dovi_rpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,10 @@ impl DoviRpu {
.collect()
}

#[deprecated(
since = "1.6.6",
note = "Causes issues in playback when L8 metadata is not present. Will be removed"
)]
pub fn convert_to_cmv40(&mut self) -> Result<()> {
if let Some(ref mut vdr_dm_data) = self.vdr_dm_data {
if vdr_dm_data.cmv40_metadata.is_none() {
Expand Down Expand Up @@ -530,4 +534,16 @@ impl DoviRpu {
self.header = Profile84::rpu_data_header();
self.rpu_data_mapping = Some(Profile84::rpu_data_mapping());
}

pub fn remove_cmv40_extension_metadata(&mut self) -> Result<()> {
if let Some(ref mut vdr_dm_data) = self.vdr_dm_data {
if vdr_dm_data.cmv40_metadata.is_some() {
self.modified = true;

vdr_dm_data.cmv40_metadata = None;
}
}

Ok(())
}
}
8 changes: 8 additions & 0 deletions dolby_vision/src/rpu/extension_metadata/primaries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,22 @@ pub struct ColorPrimaries {
#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "serde_feature", derive(Deserialize, Serialize))]
pub enum MasteringDisplayPrimaries {
#[cfg_attr(feature = "serde_feature", serde(alias = "DCI-P3 D65"))]
DCIP3D65 = 0,
#[cfg_attr(feature = "serde_feature", serde(alias = "BT.709"))]
BT709,
#[cfg_attr(feature = "serde_feature", serde(alias = "BT.2020"))]
BT2020,
#[cfg_attr(feature = "serde_feature", serde(alias = "SMPTE-C"))]
SMPTEC,
#[cfg_attr(feature = "serde_feature", serde(alias = "BT.601"))]
BT601,
#[cfg_attr(feature = "serde_feature", serde(alias = "DCI-P3"))]
DCIP3,
ACES,
#[cfg_attr(feature = "serde_feature", serde(alias = "S-Gamut"))]
SGamut,
#[cfg_attr(feature = "serde_feature", serde(alias = "S-Gamut-3.Cine"))]
SGamut3Cine,
}

Expand Down
24 changes: 9 additions & 15 deletions src/dovi/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct EditConfig {
mode: u8,

#[serde(default)]
convert_to_cmv4: bool,
remove_cmv4: bool,

#[serde(default)]
remove_mapping: bool,
Expand Down Expand Up @@ -155,12 +155,7 @@ impl Editor {
impl EditConfig {
pub fn from_path(path: &PathBuf) -> Result<Self> {
let json_file = File::open(path)?;
let mut config: EditConfig = serde_json::from_reader(&json_file)?;

// Override to CM v4.0
if !config.convert_to_cmv4 {
config.convert_to_cmv4 = config.level11.is_some() || config.level9.is_some();
}
let config: EditConfig = serde_json::from_reader(&json_file)?;

Ok(config)
}
Expand All @@ -171,8 +166,8 @@ impl EditConfig {
self.remove_frames(ranges, rpus)?;
}

if self.convert_to_cmv4 {
println!("Converting to CMv4.0...");
if self.remove_cmv4 {
println!("Removing CMv4.0 metadata...");
}

if self.mode > 0 {
Expand Down Expand Up @@ -209,8 +204,8 @@ impl EditConfig {
}

pub fn execute_single_rpu(&self, rpu: &mut DoviRpu) -> Result<()> {
if self.convert_to_cmv4 {
rpu.convert_to_cmv40()?;
if self.remove_cmv4 {
rpu.remove_cmv40_extension_metadata()?;
}

if self.mode > 0 {
Expand Down Expand Up @@ -349,15 +344,15 @@ impl EditConfig {
) -> Result<()> {
let primary_index = *primaries as u8;

rpu.modified = true;

let level9 = ExtMetadataBlockLevel9 {
length: 1,
source_primary_index: primary_index,
..Default::default()
};

if let Some(ref mut vdr_dm_data) = rpu.vdr_dm_data {
rpu.modified = true;

vdr_dm_data.replace_metadata_block(ExtMetadataBlock::Level9(level9))?;
}

Expand All @@ -369,9 +364,8 @@ impl EditConfig {
rpu: &mut DoviRpu,
level11: &ExtMetadataBlockLevel11,
) -> Result<()> {
rpu.modified = true;

if let Some(ref mut vdr_dm_data) = rpu.vdr_dm_data {
rpu.modified = true;
vdr_dm_data.replace_metadata_block(ExtMetadataBlock::Level11(level11.clone()))?;
}

Expand Down
Loading

0 comments on commit 53d4b90

Please sign in to comment.