Skip to content

Commit

Permalink
Stabilize the --film-grain-table parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
shssoichiro committed Aug 3, 2022
1 parent cd25677 commit ef98d2a
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 91 deletions.
5 changes: 0 additions & 5 deletions src/api/config/encoder.rs
Expand Up @@ -10,7 +10,6 @@
use itertools::*;

use crate::api::color::*;
#[cfg(feature = "unstable")]
use crate::api::config::GrainTableSegment;
use crate::api::{Rational, SpeedSettings};
use crate::encoder::Tune;
Expand Down Expand Up @@ -85,7 +84,6 @@ pub struct EncoderConfig {
/// Metric to tune the quality for.
pub tune: Tune,
/// Parameters for grain synthesis.
#[cfg(feature = "unstable")]
pub film_grain_params: Option<Vec<GrainTableSegment>>,
/// Number of tiles horizontally. Must be a power of two.
///
Expand Down Expand Up @@ -163,7 +161,6 @@ impl EncoderConfig {
quantizer: 100,
bitrate: 0,
tune: Tune::default(),
#[cfg(feature = "unstable")]
film_grain_params: None,
tile_cols: 0,
tile_rows: 0,
Expand Down Expand Up @@ -237,7 +234,6 @@ impl EncoderConfig {
.unwrap_or(false)
}

#[cfg(feature = "unstable")]
pub(crate) fn get_film_grain_at(
&self, timestamp: u64,
) -> Option<&GrainTableSegment> {
Expand All @@ -248,7 +244,6 @@ impl EncoderConfig {
})
}

#[cfg(feature = "unstable")]
pub(crate) fn get_film_grain_mut_at(
&mut self, timestamp: u64,
) -> Option<&mut GrainTableSegment> {
Expand Down
1 change: 0 additions & 1 deletion src/api/config/mod.rs
Expand Up @@ -18,7 +18,6 @@ use crate::util::Pixel;
mod encoder;
pub use encoder::*;

#[cfg(feature = "unstable")]
pub use av1_grain::*;

mod rate;
Expand Down
2 changes: 0 additions & 2 deletions src/api/test.rs
Expand Up @@ -2077,7 +2077,6 @@ fn log_q_exp_overflow() {
min_quantizer: 64,
bitrate: 1,
tune: Tune::Psychovisual,
#[cfg(feature = "unstable")]
film_grain_params: None,
tile_cols: 0,
tile_rows: 0,
Expand Down Expand Up @@ -2155,7 +2154,6 @@ fn guess_frame_subtypes_assert() {
min_quantizer: 0,
bitrate: 16384,
tune: Tune::Psychovisual,
#[cfg(feature = "unstable")]
film_grain_params: None,
tile_cols: 0,
tile_rows: 0,
Expand Down
37 changes: 16 additions & 21 deletions src/bin/common.rs
Expand Up @@ -174,18 +174,23 @@ pub struct CliOptions {
/// Uses grain synthesis to add photon noise to the resulting encode.
/// Takes a strength value 0-64.
#[cfg(feature = "unstable")]
#[clap(long, value_parser = clap::value_parser!(u8).range(0..=64), default_value_t = 0, help_heading = "ENCODE SETTINGS")]
#[clap(
long,
conflicts_with = "film-grain-table",
value_parser = clap::value_parser!(u8).range(0..=64),
default_value_t = 0,
help_heading = "ENCODE SETTINGS"
)]
pub photon_noise: u8,
/// Uses a film grain table file to apply grain synthesis to the encode.
/// Uses the same table file format as aomenc and svt-av1.
#[cfg(feature = "unstable")]
#[clap(
long,
alias = "photon-noise-table",
value_parser,
conflicts_with = "photon-noise",
help_heading = "ENCODE SETTINGS"
)]
pub photon_noise_table: Option<PathBuf>,
pub film_grain_table: Option<PathBuf>,

/// Pixel range
#[clap(long, value_parser, help_heading = "VIDEO METADATA")]
Expand Down Expand Up @@ -625,23 +630,13 @@ fn parse_config(matches: &CliOptions) -> Result<EncoderConfig, CliError> {
panic!("Tile columns and rows may not be greater than 64");
}

#[cfg(feature = "unstable")]
{
let grain_str = matches.photon_noise;
if grain_str > 0 {
if grain_str > 64 {
panic!("Film grain strength must be between 0-64");
}
// We have to know the video resolution before we can generate a table,
// so we must handle that elsewhere.
} else if let Some(table_file) = matches.photon_noise_table.as_ref() {
let contents = std::fs::read_to_string(table_file)
.expect("Failed to read film grain table file");
let table = parse_grain_table(&contents)
.expect("Failed to parse film grain table");
if !table.is_empty() {
cfg.film_grain_params = Some(table);
}
if let Some(table_file) = matches.film_grain_table.as_ref() {
let contents = std::fs::read_to_string(table_file)
.expect("Failed to read film grain table file");
let table = av1_grain::parse_grain_table(&contents)
.expect("Failed to parse film grain table");
if !table.is_empty() {
cfg.film_grain_params = Some(table);
}
}

Expand Down
7 changes: 0 additions & 7 deletions src/encoder.rs
Expand Up @@ -8,7 +8,6 @@
// PATENTS file, you can obtain it at www.aomedia.org/license/patent.

use crate::activity::*;
#[cfg(feature = "unstable")]
use crate::api::config::GrainTableSegment;
use crate::api::*;
use crate::cdef::*;
Expand Down Expand Up @@ -333,14 +332,11 @@ impl Sequence {
decoder_model_info_present_flag: false,
level,
tier,
#[cfg(feature = "unstable")]
film_grain_params_present: config
.film_grain_params
.as_ref()
.map(|entries| !entries.is_empty())
.unwrap_or(false),
#[cfg(not(feature = "unstable"))]
film_grain_params_present: false,
timing_info_present: config.enable_timing_info,
time_base: config.time_base,
}
Expand Down Expand Up @@ -1003,7 +999,6 @@ impl<T: Pixel> FrameInvariants<T> {
fi.input_frameno = input_frameno;
fi.me_range_scale = (inter_cfg.group_input_len >> fi.pyramid_level) as u8;

#[cfg(feature = "unstable")]
if fi.show_frame || fi.showable_frame {
let cur_frame_time = fi.frame_timestamp();
// Increment the film grain seed for the next frame
Expand Down Expand Up @@ -1201,7 +1196,6 @@ impl<T: Pixel> FrameInvariants<T> {
self.sequence.tiling.sb_size_log2
}

#[cfg(feature = "unstable")]
pub fn film_grain_params(&self) -> Option<&GrainTableSegment> {
if !(self.show_frame || self.showable_frame) {
return None;
Expand All @@ -1210,7 +1204,6 @@ impl<T: Pixel> FrameInvariants<T> {
self.config.get_film_grain_at(cur_frame_time)
}

#[cfg(feature = "unstable")]
pub fn frame_timestamp(&self) -> u64 {
// I don't know why this is the base unit for a timestamp but it is. 1/10000000 of a second.
const TIMESTAMP_BASE_UNIT: u64 = 10_000_000;
Expand Down
2 changes: 0 additions & 2 deletions src/fuzzing.rs
Expand Up @@ -258,7 +258,6 @@ impl Arbitrary for ArbitraryEncoder {
enable_timing_info: Arbitrary::arbitrary(u)?,
switch_frame_interval: u.int_in_range(0..=3)?,
tune: *u.choose(&[Tune::Psnr, Tune::Psychovisual])?,
#[cfg(feature = "unstable")]
film_grain_params: None,
};

Expand Down Expand Up @@ -381,7 +380,6 @@ pub fn fuzz_encode_decode<T: Pixel>(p: DecodeTestParameters<T>) {
p.tile_cols_log2,
p.tile_rows_log2,
p.still_picture,
#[cfg(feature = "unstable")]
None,
);
}
1 change: 0 additions & 1 deletion src/header.rs
Expand Up @@ -812,7 +812,6 @@ impl<W: io::Write> UncompressedHeader for BitWriter<W, BigEndian> {
}
}

#[cfg(feature = "unstable")]
if fi.sequence.film_grain_params_present {
if let Some(grain_params) = fi.film_grain_params() {
// Apply grain
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Expand Up @@ -310,7 +310,6 @@ pub use crate::api::color;

/// Encoder configuration and settings
pub mod config {
#[cfg(feature = "unstable")]
pub use crate::api::config::{
GrainTableSegment, NoiseGenArgs, TransferFunction, NUM_UV_COEFFS,
NUM_UV_POINTS, NUM_Y_COEFFS, NUM_Y_POINTS,
Expand Down

0 comments on commit ef98d2a

Please sign in to comment.