Skip to content

Commit

Permalink
Add edit function to drop active area metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
quietvoid committed Nov 16, 2021
1 parent 15de813 commit 029a1ec
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
7 changes: 6 additions & 1 deletion editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ The editor expects a JSON config like the example below:
// Should be set to true when final video has no letterbox bars
"crop": boolean,

// Optional, specifies whether to drop some or all L5 metadata
// Possible options: "all", "zeroes"
// "zeroes" drops the L5 metadata blocks which have all offsets set to zero.
"drop_l5": string,

// List of presets to add letterbox bars
"presets": [
{
Expand Down Expand Up @@ -63,4 +68,4 @@ The editor expects a JSON config like the example below:
"max_frame_average_light_level": int
}
}
```
```
50 changes: 50 additions & 0 deletions src/dovi/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{collections::HashMap, path::PathBuf};

use anyhow::{bail, ensure, Result};
use dolby_vision::st2094_10::generate::Level6Metadata;
use dolby_vision::st2094_10::ExtMetadataBlock;
use serde::{Deserialize, Serialize};

use super::{encode_rpus, parse_rpu_file, write_rpu_file, DoviRpu};
Expand Down Expand Up @@ -43,6 +44,9 @@ pub struct ActiveArea {
#[serde(default)]
crop: bool,

#[serde(skip_serializing_if = "Option::is_none")]
drop_l5: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
presets: Option<Vec<ActiveAreaOffsets>>,

Expand Down Expand Up @@ -257,6 +261,10 @@ impl ActiveArea {
self.crop(rpus);
}

if let Some(drop_opt) = &self.drop_l5 {
self.drop_specific_l5(drop_opt, rpus)?;
}

if let Some(edits) = &self.edits {
if !edits.is_empty() {
self.do_edits(edits, rpus)?;
Expand Down Expand Up @@ -323,4 +331,46 @@ impl ActiveArea {

Ok(())
}

fn drop_specific_l5(&self, drop_opt: &str, rpus: &mut Vec<Option<DoviRpu>>) -> Result<()> {
let param = drop_opt.to_lowercase();

println!("Dropping L5 metadata with opt '{}'", param);

rpus.iter_mut().filter_map(|e| e.as_mut()).for_each(|rpu| {

if let Some(ref mut vdr_dm_data) = rpu.vdr_dm_data {
let drop_it = if param == "zeroes" {
let level5_block = vdr_dm_data
.st2094_10_metadata
.ext_metadata_blocks
.iter()
.find(|e| matches!(e, ExtMetadataBlock::Level5(_)));

if let Some(ExtMetadataBlock::Level5(m)) = level5_block {
m.active_area_left_offset == 0
&& m.active_area_right_offset == 0
&& m.active_area_top_offset == 0
&& m.active_area_bottom_offset == 0
} else {
false
}
} else {
param == "all"
};

if drop_it {
rpu.modified = true;

vdr_dm_data
.st2094_10_metadata
.ext_metadata_blocks
.retain(|b| b.level() != 5);
vdr_dm_data.st2094_10_metadata.update_extension_block_info();
}
}
});

Ok(())
}
}

0 comments on commit 029a1ec

Please sign in to comment.