| 1 |
# av1-grain |
| 2 |
|
| 3 |
[](https://docs.rs/av1-grain) |
| 4 |
[](https://crates.io/crates/av1-grain) |
| 5 |
[](https://github.com/rust-av/av1-grain/blob/main/LICENSE) |
| 6 |
|
| 7 |
This crate contains helper functions for parsing and generating AV1 film grain data. |
| 8 |
|
| 9 |
This code was originally created for use in rav1e. |
| 10 |
It has been moved to this crate so it can be shared with other |
| 11 |
AV1 crates that need to deal with film grain. |
| 12 |
|
| 13 |
## Examples |
| 14 |
|
| 15 |
The `generate_photon_noise_params` and `write_grain_table` APIs live behind the |
| 16 |
`create` feature. Enable it in your project to produce plain-text photon noise tables |
| 17 |
compatible with `svt-av1`, `aomenc`, and similar encoders: |
| 18 |
|
| 19 |
```rust |
| 20 |
use av1_grain::{ |
| 21 |
generate_photon_noise_params, write_grain_table, NoiseGenArgs, TransferFunction, |
| 22 |
}; |
| 23 |
|
| 24 |
fn main() -> anyhow::Result<()> { |
| 25 |
// This would apply to the entire video--we can use `u64::MAX` as the end timestamp for simplicity. |
| 26 |
let segment = generate_photon_noise_params( |
| 27 |
0, |
| 28 |
u64::MAX, |
| 29 |
NoiseGenArgs { |
| 30 |
// This setting can range from 100-6400 to adjust the noise strength |
| 31 |
iso_setting: 800, |
| 32 |
width: 1920, |
| 33 |
height: 1080, |
| 34 |
transfer_function: TransferFunction::BT1886, |
| 35 |
chroma_grain: true, |
| 36 |
random_seed: None, |
| 37 |
}, |
| 38 |
); |
| 39 |
|
| 40 |
write_grain_table("example.tbl", &[segment])?; |
| 41 |
Ok(()) |
| 42 |
} |
| 43 |
``` |
| 44 |
|
| 45 |
Running this program generates a photon noise table covering the entire video |
| 46 |
(`start_time` 0 to `end_time` `u64::MAX`) and stores it in `example.tbl`. The |
| 47 |
file extension is arbitrary; `.tbl` is a common choice. |