Skip to content

Commit ac687ab

Browse files
authored
Photon noise arguments (#764)
* 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
1 parent 50f50d9 commit ac687ab

File tree

5 files changed

+25
-1
lines changed

5 files changed

+25
-1
lines changed

av1an-core/src/chunk.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub struct Chunk {
2222
pub passes: u8,
2323
pub video_params: Vec<String>,
2424
pub encoder: Encoder,
25+
pub noise_size: (Option<u32>, Option<u32>),
2526
// do not break compatibility with output produced by older versions of av1an
2627
/// Optional target quality CQ level
2728
#[serde(rename = "per_shot_target_quality_cq")]
@@ -57,7 +58,13 @@ impl Chunk {
5758
let grain_table = Path::new(&self.temp).join(format!("iso{iso_setting}-grain.tbl"));
5859
if !grain_table.exists() {
5960
debug!("Generating grain table at ISO {}", iso_setting);
60-
let (width, height) = self.input.resolution()?;
61+
let (mut width, mut height) = self.input.resolution()?;
62+
if self.noise_size.0.is_some() {
63+
width = self.noise_size.0.unwrap();
64+
}
65+
if self.noise_size.1.is_some() {
66+
height = self.noise_size.1.unwrap();
67+
}
6168
let transfer_function = self
6269
.input
6370
.transfer_function_params_adjusted(&self.video_params)?;
@@ -102,6 +109,7 @@ mod tests {
102109
passes: 1,
103110
video_params: vec![],
104111
encoder: Encoder::x264,
112+
noise_size: (None, None),
105113
};
106114
assert_eq!("00001", ch.name());
107115
}
@@ -120,6 +128,7 @@ mod tests {
120128
passes: 1,
121129
video_params: vec![],
122130
encoder: Encoder::x264,
131+
noise_size: (None, None),
123132
};
124133
assert_eq!("10000", ch.name());
125134
}
@@ -139,6 +148,7 @@ mod tests {
139148
passes: 1,
140149
video_params: vec![],
141150
encoder: Encoder::x264,
151+
noise_size: (None, None),
142152
};
143153
assert_eq!("d/encode/00001.ivf", ch.output());
144154
}

av1an-core/src/context.rs

+3
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,7 @@ impl Av1anContext {
870870
),
871871
passes: self.args.passes,
872872
encoder: self.args.encoder,
873+
noise_size: self.args.photon_noise_size,
873874
tq_cq: None,
874875
};
875876
chunk.apply_photon_noise_args(
@@ -922,6 +923,7 @@ impl Av1anContext {
922923
),
923924
passes: self.args.passes,
924925
encoder: self.args.encoder,
926+
noise_size: self.args.photon_noise_size,
925927
tq_cq: None,
926928
};
927929
chunk.apply_photon_noise_args(
@@ -1104,6 +1106,7 @@ impl Av1anContext {
11041106
),
11051107
passes: self.args.passes,
11061108
encoder: self.args.encoder,
1109+
noise_size: self.args.photon_noise_size,
11071110
tq_cq: None,
11081111
};
11091112
chunk.apply_photon_noise_args(

av1an-core/src/scenes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ fn get_test_args() -> Av1anContext {
269269
encoder: Encoder::aom,
270270
extra_splits_len: Some(100),
271271
photon_noise: Some(10),
272+
photon_noise_size: (None, None),
272273
chroma_noise: false,
273274
sc_pix_format: None,
274275
keep: false,

av1an-core/src/settings.rs

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ pub struct EncodeArgs {
5555
pub workers: usize,
5656
pub set_thread_affinity: Option<usize>,
5757
pub photon_noise: Option<u8>,
58+
pub photon_noise_size: (Option<u32>, Option<u32>), // Width and Height
5859
pub chroma_noise: bool,
5960
pub zones: Option<PathBuf>,
6061

av1an/src/main.rs

+9
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,14 @@ pub struct CliOpts {
355355
#[clap(long, help_heading = "Encoding")]
356356
pub photon_noise: Option<u8>,
357357

358+
/// Manually set the width for the photon noise table.
359+
#[clap(long, help_heading = "Encoding")]
360+
pub photon_noise_width: Option<u32>,
361+
362+
/// Manually set the height for the photon noise table.
363+
#[clap(long, help_heading = "Encoding")]
364+
pub photon_noise_height: Option<u32>,
365+
358366
/// Adds chroma grain synthesis to the grain table generated by `--photon-noise`. (Default: false)
359367
#[clap(long, help_heading = "Encoding", requires = "photon_noise")]
360368
pub chroma_noise: bool,
@@ -667,6 +675,7 @@ pub fn parse_cli(args: CliOpts) -> anyhow::Result<Vec<EncodeArgs>> {
667675
photon_noise: args
668676
.photon_noise
669677
.and_then(|arg| if arg == 0 { None } else { Some(arg) }),
678+
photon_noise_size: (args.photon_noise_width, args.photon_noise_height),
670679
chroma_noise: args.chroma_noise,
671680
sc_pix_format: args.sc_pix_format,
672681
keep: args.keep,

0 commit comments

Comments
 (0)