VP9 level targeting: add a new AUTO mode

In the new AUTO mode, restrict the minimum alt-ref interval and max column
tiles adaptively based on picture size, while not applying any rate control
constraints.

This mode aims to produce encodings that fit into levels corresponding to
the source picture size, with minimum compression quality lost. However, the
bitstream is not guaranteed to be level compatible, e.g., the average bitrate
may exceed level limit.

BUG=b/64451920

Change-Id: I02080b169cbbef4ab2e08c0df4697ce894aad83c
This commit is contained in:
Hui Su 2017-08-10 15:05:20 -07:00
parent d49a1a5329
commit c3a6943c16
7 changed files with 55 additions and 4 deletions

View File

@ -130,7 +130,7 @@ TEST_P(LevelTest, TestTargetLevelApi) {
if (level == 10 || level == 11 || level == 20 || level == 21 ||
level == 30 || level == 31 || level == 40 || level == 41 ||
level == 50 || level == 51 || level == 52 || level == 60 ||
level == 61 || level == 62 || level == 0 || level == 255)
level == 61 || level == 62 || level == 0 || level == 1 || level == 255)
EXPECT_EQ(VPX_CODEC_OK,
vpx_codec_control(&enc, VP9E_SET_TARGET_LEVEL, level));
else

View File

@ -1209,6 +1209,14 @@ static void set_tile_limits(VP9_COMP *cpi) {
clamp(cpi->oxcf.tile_columns, min_log2_tile_cols, max_log2_tile_cols);
cm->log2_tile_rows = cpi->oxcf.tile_rows;
}
if (cpi->oxcf.target_level == LEVEL_AUTO) {
const uint32_t pic_size = cpi->common.width * cpi->common.height;
const int level_tile_cols = log_tile_cols_from_picsize_level(pic_size);
if (cm->log2_tile_cols > level_tile_cols) {
cm->log2_tile_cols = VPXMAX(level_tile_cols, min_log2_tile_cols);
}
}
}
static void update_frame_size(VP9_COMP *cpi) {

View File

@ -360,6 +360,7 @@ typedef struct IMAGE_STAT {
typedef enum {
LEVEL_UNKNOWN = 0,
LEVEL_AUTO = 1,
LEVEL_1 = 10,
LEVEL_1_1 = 11,
LEVEL_2 = 20,
@ -913,6 +914,18 @@ static INLINE int get_level_index(VP9_LEVEL level) {
return -1;
}
// Return the log2 value of max column tiles corresponding to the level that
// the picture size fits into.
static INLINE int log_tile_cols_from_picsize_level(uint32_t pic_size) {
int i;
for (i = LEVEL_1; i < LEVEL_MAX; ++i) {
if (vp9_level_defs[i].max_luma_picture_size > pic_size) {
return get_msb(vp9_level_defs[i].max_col_tiles);
}
}
return INT_MAX;
}
VP9_LEVEL vp9_get_level(const Vp9LevelSpec *const level_spec);
void vp9_new_framerate(VP9_COMP *cpi, double framerate);

View File

@ -64,6 +64,13 @@ static int get_max_tile_cols(VP9_COMP *cpi) {
vp9_get_tile_n_bits(mi_cols, &min_log2_tile_cols, &max_log2_tile_cols);
log2_tile_cols =
clamp(cpi->oxcf.tile_columns, min_log2_tile_cols, max_log2_tile_cols);
if (cpi->oxcf.target_level == LEVEL_AUTO) {
const uint32_t pic_size = cpi->common.width * cpi->common.height;
const int level_tile_cols = log_tile_cols_from_picsize_level(pic_size);
if (log2_tile_cols > level_tile_cols) {
log2_tile_cols = VPXMAX(level_tile_cols, min_log2_tile_cols);
}
}
return (1 << log2_tile_cols);
}

View File

@ -1851,6 +1851,23 @@ void vp9_rc_set_gf_interval_range(const VP9_COMP *const cpi,
// Clamp min to max
rc->min_gf_interval = VPXMIN(rc->min_gf_interval, rc->max_gf_interval);
if (oxcf->target_level == LEVEL_AUTO) {
const uint32_t pic_size = cpi->common.width * cpi->common.height;
int i;
for (i = LEVEL_1; i < LEVEL_MAX; ++i) {
if (vp9_level_defs[i].max_luma_picture_size > pic_size) {
if (rc->min_gf_interval <=
(int)vp9_level_defs[i].min_altref_distance) {
rc->min_gf_interval =
(int)vp9_level_defs[i].min_altref_distance + 1;
rc->max_gf_interval =
VPXMAX(rc->max_gf_interval, rc->min_gf_interval);
}
break;
}
}
}
}
}

View File

@ -213,7 +213,7 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx,
level != LEVEL_4 && level != LEVEL_4_1 && level != LEVEL_5 &&
level != LEVEL_5_1 && level != LEVEL_5_2 && level != LEVEL_6 &&
level != LEVEL_6_1 && level != LEVEL_6_2 && level != LEVEL_UNKNOWN &&
level != LEVEL_MAX)
level != LEVEL_AUTO && level != LEVEL_MAX)
ERROR("target_level is invalid");
}

View File

@ -468,8 +468,14 @@ static const arg_def_t tune_content = ARG_DEF_ENUM(
static const arg_def_t target_level = ARG_DEF(
NULL, "target-level", 1,
"Target level (255: off (default); 0: only keep level stats; 10: level 1.0;"
" 11: level 1.1; ... 62: level 6.2)");
"Target level\n"
" 255: off (default)\n"
" 0: only keep level stats\n"
" 1: adaptively set alt-ref "
"distance and column tile limit based on picture size, and keep"
" level stats\n"
" 10: level 1.0 11: level 1.1 "
"... 62: level 6.2");
static const arg_def_t row_mt =
ARG_DEF(NULL, "row-mt", 1,