Skip to content

Commit

Permalink
Only estimate tiles when explicitly instructed
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyingWombat committed Feb 16, 2024
1 parent 16f533d commit 1ceb499
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion av1an-core/src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ impl Encoder {
"--scenecut", "0",
],
Encoder::x265 => into_vec![
"-p", "slow",
"--preset", "slow",
"--crf", "25",
"-D", "10",
"--level-idc", "5.0",
Expand Down
2 changes: 1 addition & 1 deletion av1an-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ pub enum ChunkOrdering {
#[must_use]
pub fn determine_workers(args: &EncodeArgs) -> u64 {
let res = args.input.resolution().unwrap();
let tiles = args.input.calculate_tiles();
let tiles = args.tiles;
let megapixels = (res.0 * res.1) as f64 / 1e6;
// encoder memory and chunk_method memory usage scales with resolution (megapixels),
// approximately linearly. Expressed as GB/Megapixel
Expand Down
10 changes: 8 additions & 2 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 passes: u8,
pub video_params: Vec<String>,
pub tiles: (u32, u32), // tile (cols, rows) count; log2 will be applied later for specific encoders
pub encoder: Encoder,
pub workers: usize,
pub set_thread_affinity: Option<usize>,
Expand All @@ -74,6 +75,7 @@ pub struct EncodeArgs {
pub resume: bool,
pub keep: bool,
pub force: bool,
pub tile_auto: bool,

pub concat: ConcatMethod,
pub target_quality: Option<TargetQuality>,
Expand Down Expand Up @@ -171,13 +173,17 @@ properly into a mkv file. Specify mkvmerge as the concatenation method by settin
);
}

if self.tile_auto {
self.tiles = self.input.calculate_tiles();
}

if !self.force {
if self.video_params.is_empty() {
self.video_params = self.encoder.get_default_arguments(self.input.calculate_tiles());
self.video_params = self.encoder.get_default_arguments(self.tiles);
} else {
// merge video_params with defaults, overriding defaults
// TODO: consider using hashmap to store program arguments instead of string vector
let default_video_params = self.encoder.get_default_arguments(self.input.calculate_tiles());
let default_video_params = self.encoder.get_default_arguments(self.tiles);
let mut skip = false;
let mut _default_params: Vec<String> = Vec::new();
for param in default_video_params {
Expand Down
8 changes: 8 additions & 0 deletions av1an/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,12 @@ pub struct CliOpts {
#[clap(short, long, value_parser = value_parser!(u8).range(1..=2), help_heading = "Encoding")]
pub passes: Option<u8>,

/// Estimate tile count from source
///
/// Worker estimation will consider tile count accordingly.
#[clap(long, help_heading = "Encoding")]
pub tile_auto: bool,

/// Audio encoding parameters (ffmpeg syntax)
///
/// If not specified, "-c:a copy" is used.
Expand Down Expand Up @@ -752,6 +758,8 @@ pub fn parse_cli(args: CliOpts) -> anyhow::Result<Vec<EncodeArgs>> {
Verbosity::Normal
},
workers: args.workers,
tiles: (1, 1), // default value; will be adjusted if tile_auto set
tile_auto: args.tile_auto,
set_thread_affinity: args.set_thread_affinity,
zones: args.zones.clone(),
scaler: {
Expand Down
3 changes: 3 additions & 0 deletions site/src/Cli/encoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
[possible values: 1, 2]
--tile-auto
Estimate tile count based on resolution, and set encoder parameters, if applicable.
-a, --audio-params <AUDIO_PARAMS>
Audio encoding parameters (ffmpeg syntax)
Expand Down

0 comments on commit 1ceb499

Please sign in to comment.