Skip to content

Commit

Permalink
Photon noise arguments (#764)
Browse files Browse the repository at this point in the history
* Add photon-noise arguments

Width and height, use if you are changing the resolution of the input.

* Update chunk.rs

Readjustment and removed println

* cargo fmt
  • Loading branch information
superyu1337 authored Jun 11, 2023
1 parent 50f50d9 commit ac687ab
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
12 changes: 11 additions & 1 deletion av1an-core/src/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct Chunk {
pub passes: u8,
pub video_params: Vec<String>,
pub encoder: Encoder,
pub noise_size: (Option<u32>, Option<u32>),
// do not break compatibility with output produced by older versions of av1an
/// Optional target quality CQ level
#[serde(rename = "per_shot_target_quality_cq")]
Expand Down Expand Up @@ -57,7 +58,13 @@ impl Chunk {
let grain_table = Path::new(&self.temp).join(format!("iso{iso_setting}-grain.tbl"));
if !grain_table.exists() {
debug!("Generating grain table at ISO {}", iso_setting);
let (width, height) = self.input.resolution()?;
let (mut width, mut height) = self.input.resolution()?;
if self.noise_size.0.is_some() {
width = self.noise_size.0.unwrap();
}
if self.noise_size.1.is_some() {
height = self.noise_size.1.unwrap();
}
let transfer_function = self
.input
.transfer_function_params_adjusted(&self.video_params)?;
Expand Down Expand Up @@ -102,6 +109,7 @@ mod tests {
passes: 1,
video_params: vec![],
encoder: Encoder::x264,
noise_size: (None, None),
};
assert_eq!("00001", ch.name());
}
Expand All @@ -120,6 +128,7 @@ mod tests {
passes: 1,
video_params: vec![],
encoder: Encoder::x264,
noise_size: (None, None),
};
assert_eq!("10000", ch.name());
}
Expand All @@ -139,6 +148,7 @@ mod tests {
passes: 1,
video_params: vec![],
encoder: Encoder::x264,
noise_size: (None, None),
};
assert_eq!("d/encode/00001.ivf", ch.output());
}
Expand Down
3 changes: 3 additions & 0 deletions av1an-core/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,7 @@ impl Av1anContext {
),
passes: self.args.passes,
encoder: self.args.encoder,
noise_size: self.args.photon_noise_size,
tq_cq: None,
};
chunk.apply_photon_noise_args(
Expand Down Expand Up @@ -922,6 +923,7 @@ impl Av1anContext {
),
passes: self.args.passes,
encoder: self.args.encoder,
noise_size: self.args.photon_noise_size,
tq_cq: None,
};
chunk.apply_photon_noise_args(
Expand Down Expand Up @@ -1104,6 +1106,7 @@ impl Av1anContext {
),
passes: self.args.passes,
encoder: self.args.encoder,
noise_size: self.args.photon_noise_size,
tq_cq: None,
};
chunk.apply_photon_noise_args(
Expand Down
1 change: 1 addition & 0 deletions av1an-core/src/scenes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ fn get_test_args() -> Av1anContext {
encoder: Encoder::aom,
extra_splits_len: Some(100),
photon_noise: Some(10),
photon_noise_size: (None, None),
chroma_noise: false,
sc_pix_format: None,
keep: false,
Expand Down
1 change: 1 addition & 0 deletions av1an-core/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub struct EncodeArgs {
pub workers: usize,
pub set_thread_affinity: Option<usize>,
pub photon_noise: Option<u8>,
pub photon_noise_size: (Option<u32>, Option<u32>), // Width and Height
pub chroma_noise: bool,
pub zones: Option<PathBuf>,

Expand Down
9 changes: 9 additions & 0 deletions av1an/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,14 @@ pub struct CliOpts {
#[clap(long, help_heading = "Encoding")]
pub photon_noise: Option<u8>,

/// Manually set the width for the photon noise table.
#[clap(long, help_heading = "Encoding")]
pub photon_noise_width: Option<u32>,

/// Manually set the height for the photon noise table.
#[clap(long, help_heading = "Encoding")]
pub photon_noise_height: Option<u32>,

/// Adds chroma grain synthesis to the grain table generated by `--photon-noise`. (Default: false)
#[clap(long, help_heading = "Encoding", requires = "photon_noise")]
pub chroma_noise: bool,
Expand Down Expand Up @@ -667,6 +675,7 @@ pub fn parse_cli(args: CliOpts) -> anyhow::Result<Vec<EncodeArgs>> {
photon_noise: args
.photon_noise
.and_then(|arg| if arg == 0 { None } else { Some(arg) }),
photon_noise_size: (args.photon_noise_width, args.photon_noise_height),
chroma_noise: args.chroma_noise,
sc_pix_format: args.sc_pix_format,
keep: args.keep,
Expand Down

0 comments on commit ac687ab

Please sign in to comment.