Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ Reads `my_encode.mkv` and outputs a film grain table file at `grain_file.txt`

Reads `my_encode.mkv`, adds film grain to it based on `grain_file.txt`, and outputs the video to `grainy_encode.mkv`

### `grav1synth generate my_encode.mkv -o grainy_encode.mkv --iso 400 --chroma`
### `grav1synth generate my_encode.mkv -o grainy_encode.mkv --iso 400 --chroma --width 1920 --height 1080`

Reads `my_encode.mkv`, adds photon-noise-based film grain to it based on the strength provided by `--iso` (up to `6400`), and outputs the video to `grainy_encode.mkv`. By default applies grain to only the luma plane. `--chroma` enables grain on chroma planes as well.
Reads `my_encode.mkv`, adds photon-noise-based film grain to it based on the strength provided by `--iso` (up to `6400`), and outputs the video to `grainy_encode.mkv`. By default applies grain to only the luma plane. `--chroma` enables grain on chroma planes as well. `--width` and `--height` specify the width and height of the generated grain table. By default, the width and height are the same as the input video.

### `grav1synth remove my_encode.mkv -o clean_encode.mkv`

Expand Down
14 changes: 11 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ pub fn main() -> Result<()> {
overwrite,
iso,
chroma,
width,
height,
} => {
if input == output {
error!(
Expand Down Expand Up @@ -314,7 +316,7 @@ pub fn main() -> Result<()> {
let video_stream = reader.get_video_stream().unwrap();
// SAFETY: We extract the items we need from the struct within the unsafe block,
// so there's no possibility of use-after-free later.
let (width, height, trc) = unsafe {
let (video_width, video_height, trc) = unsafe {
let params = video_stream.parameters().as_ptr();
(
(*params).width as u32,
Expand All @@ -328,8 +330,8 @@ pub fn main() -> Result<()> {
u64::MAX,
av1_grain::NoiseGenArgs {
iso_setting: u32::from(iso),
width,
height,
width: width.unwrap_or(video_width),
height: height.unwrap_or(video_height),
transfer_function: if trc == AVColorTransferCharacteristic::AVCOL_TRC_SMPTE2084
{
TransferFunction::SMPTE2084
Expand Down Expand Up @@ -876,6 +878,12 @@ pub enum Commands {
/// Whether to apply grain to the chroma planes as well.
#[clap(long)]
chroma: bool,
/// The width of the generated grain table. Defaults to the width of the input AV1 file.
#[clap(long, value_parser = clap::value_parser!(u32).range(1..))]
width: Option<u32>,
/// The height of the generated grain table. Defaults to the height of the input AV1 file.
#[clap(long, value_parser = clap::value_parser!(u32).range(1..))]
height: Option<u32>,
},
/// Removes all film grain from a given AV1 video,
/// and outputs it at a given `output` path.
Expand Down