Commit de0ff955 authored by Thomas Daede's avatar Thomas Daede
Browse files

Add --tiles option to automatically assign tiles.

Use a simple algorithm that greedily splits, longer direction first.
parent 6d330d26
......@@ -85,8 +85,15 @@ pub struct EncoderConfig {
pub min_quantizer: u8,
pub bitrate: i32,
pub tune: Tune,
/// log2(tile columns). If tiles is also specified, this acts
/// as a minimum.
pub tile_cols_log2: usize,
/// log2(tile rows). If tiles is also specified, this acts
/// as a minimum.
pub tile_rows_log2: usize,
/// Number of tiles desired. The video is split automatically so that
/// it contains at least this many tiles.
pub tiles: usize,
pub speed_settings: SpeedSettings,
/// `None` for one-pass encode. `Some(1)` or `Some(2)` for two-pass encoding.
pub pass: Option<u8>,
......@@ -137,6 +144,7 @@ impl EncoderConfig {
tune: Tune::default(),
tile_cols_log2: 0,
tile_rows_log2: 0,
tiles: 0,
speed_settings: SpeedSettings::from_preset(speed),
pass: None,
show_psnr: false,
......
......@@ -206,6 +206,14 @@ pub fn parse_cli() -> CliOptions {
.takes_value(true)
.default_value("0")
)
.arg(
Arg::with_name("TILES")
.help("Number of tiles. Tile-cols and tile-rows are overridden\n\
so that the video has at least this many tiles.")
.long("tiles")
.takes_value(true)
.default_value("0")
)
// MASTERING
.arg(
Arg::with_name("PIXEL_RANGE")
......@@ -466,6 +474,8 @@ fn parse_config(matches: &ArgMatches<'_>) -> EncoderConfig {
cfg.tile_cols_log2 = matches.value_of("TILE_COLS_LOG2").unwrap().parse().unwrap();
cfg.tile_rows_log2 = matches.value_of("TILE_ROWS_LOG2").unwrap().parse().unwrap();
cfg.tiles = matches.value_of("TILES").unwrap().parse().unwrap();
if cfg.tile_cols_log2 > 6 || cfg.tile_rows_log2 > 6 {
panic!("Log2 of tile columns and rows may not be greater than 6");
}
......
......@@ -504,7 +504,7 @@ impl<T: Pixel> FrameInvariants<T> {
let w_in_b = 2 * config.width.align_power_of_two_and_shift(3); // MiCols, ((width+7)/8)<<3 >> MI_SIZE_LOG2
let h_in_b = 2 * config.height.align_power_of_two_and_shift(3); // MiRows, ((height+7)/8)<<3 >> MI_SIZE_LOG2
let tiling = TilingInfo::new(
let mut tiling = TilingInfo::new(
sequence.sb_size_log2(),
config.width,
config.height,
......@@ -512,6 +512,31 @@ impl<T: Pixel> FrameInvariants<T> {
config.tile_rows_log2
);
if config.tiles > 0 {
let mut tile_rows_log2 = 0;
let mut tile_cols_log2 = 0;
while (tile_rows_log2 < tiling.max_tile_rows_log2) || (tile_cols_log2 < tiling.max_tile_cols_log2) {
tiling = TilingInfo::new(
sequence.sb_size_log2(),
config.width,
config.height,
tile_cols_log2,
tile_rows_log2
);
if tiling.rows * tiling.cols >= config.tiles { break };
if ((tiling.tile_height_sb >= tiling.tile_width_sb) &&
(tiling.tile_rows_log2 < tiling.max_tile_rows_log2))
|| (tile_cols_log2 >= tiling.max_tile_cols_log2) {
tile_rows_log2 += 1;
} else {
tile_cols_log2 += 1;
}
}
}
Self {
sequence,
width: config.width,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment