Skip to content

Commit

Permalink
Fix non conformant NALU bytes when using write_hevc_unspec62_nalu
Browse files Browse the repository at this point in the history
And update MakeMKV `mux` behaviour
Fixes #209
  • Loading branch information
quietvoid committed Feb 11, 2023
1 parent a930002 commit eb8a664
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 10 deletions.
8 changes: 4 additions & 4 deletions 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,6 +1,6 @@
[package]
name = "dovi_tool"
version = "2.0.1"
version = "2.0.2"
authors = ["quietvoid"]
edition = "2021"
rust-version = "1.64.0"
Expand All @@ -18,7 +18,7 @@ members = [

[dependencies]
bitvec_helpers = { version = "3.1.2", default-features = false, features = ["bitstream-io"] }
hevc_parser = { version = "0.6.0", features = ["hevc_io"] }
hevc_parser = { version = "0.6.1", features = ["hevc_io"] }
dolby_vision = { path = "dolby_vision", "features" = ["xml", "serde"] }
madvr_parse = "1.0.1"

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,11 @@ For working with an HEVC source file, there are multiple options that apply to m

**Flags**:
- `--eos-before-el` Write the EOS/EOB NALUs before the EL. Defaults to `false`.
This flag enables the same behaviour as MakeMKV and yusesope's mux script.
This flag enables the same behaviour yusesope's mux script.
Enabling this therefore results in identical output using **`dovi_tool`**.

In recent versions of `MakeMKV`, EOS/EOB NALUs are removed.

- `--no-add-aud` Disable adding AUD NALUs between frames
- `--discard` Discard the EL while muxing. This is equivalent to injecting the RPU, but without extracting first.

Expand Down
Binary file added assets/tests/source_p5_to_p8_001_end_crc32.bin
Binary file not shown.
3 changes: 3 additions & 0 deletions dolby_vision/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 3.1.1
- Fixed RPU writing edge case that resulted in non conformant NALU bytes when using `write_hevc_unspec62_nalu`.

## 3.1.0
- Conversion mode 2 now defaults to remove luma and chroma mapping by default, only for profile 7 FEL.
- Added `ConversionMode::To81MappingPreserved` for old mode 2 behaviour.
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 = "3.1.0"
version = "3.1.1"
authors = ["quietvoid"]
edition = "2021"
rust-version = "1.60.0"
Expand Down
2 changes: 1 addition & 1 deletion dolby_vision/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub fn add_start_code_emulation_prevention_3_byte(data: &mut Vec<u8>) {
let mut i = 0;

while i < count {
if i > 2 && i < count - 2 && data[i - 2] == 0 && data[i - 1] == 0 && data[i] <= 3 {
if i > 2 && data[i - 2] == 0 && data[i - 1] == 0 && data[i] <= 3 {
data.insert(i, 3);
count += 1;
}
Expand Down
34 changes: 33 additions & 1 deletion src/tests/rpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{io::Read, path::PathBuf};
use anyhow::Result;

use dolby_vision::rpu::dovi_rpu::DoviRpu;
use dolby_vision::rpu::extension_metadata::blocks::ExtMetadataBlock;
use dolby_vision::rpu::extension_metadata::blocks::{ExtMetadataBlock, ExtMetadataBlockLevel6};
use dolby_vision::rpu::extension_metadata::{ColorPrimaries, MasteringDisplayPrimaries};
use dolby_vision::rpu::generate::GenerateConfig;
use dolby_vision::rpu::rpu_data_nlq::DoviELType;
Expand Down Expand Up @@ -1087,3 +1087,35 @@ fn fel_to_p81_preserve_mapping() -> Result<()> {

Ok(())
}

#[test]
fn source_p5_to_p8_001_end_crc32() -> Result<()> {
use dolby_vision::rpu::utils::parse_rpu_file;

let mut rpus = parse_rpu_file(PathBuf::from(
"./assets/tests/source_p5_to_p8_001_end_crc32.bin",
))?;
assert_eq!(rpus.len(), 1);

let dovi_rpu = rpus.first_mut().unwrap();
assert_eq!(5, dovi_rpu.dovi_profile);
assert_eq!([130, 214, 190, 85], dovi_rpu.rpu_data_crc32.to_be_bytes());

dovi_rpu.convert_with_mode(ConversionMode::To81)?;
dovi_rpu.set_active_area_offsets(0, 0, 69, 69)?;

let vdr_dm_data = dovi_rpu.vdr_dm_data.as_mut().unwrap();
vdr_dm_data.replace_metadata_level(ExtMetadataBlock::Level6(ExtMetadataBlockLevel6 {
max_display_mastering_luminance: 4000,
min_display_mastering_luminance: 50,
max_content_light_level: 2095,
max_frame_average_light_level: 46,
}))?;

assert_eq!(8, dovi_rpu.dovi_profile);
let data = dovi_rpu.write_hevc_unspec62_nalu()?;

assert_eq!([183, 0, 0, 3, 1, 128], &data[data.len() - 6..]);

Ok(())
}

0 comments on commit eb8a664

Please sign in to comment.