Skip to content

Commit

Permalink
Merge branch 'improve_rdo_2022'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jovasa committed Jan 4, 2023
2 parents a400504 + f2529a7 commit e9b5005
Show file tree
Hide file tree
Showing 24 changed files with 237 additions and 171 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,22 @@ Compression tools:
--(no-)signhide : Sign hiding [disabled]
--(no-)smp : Symmetric motion partition [disabled]
--(no-)amp : Asymmetric motion partition [disabled]
--rd <integer> : Intra mode search complexity [0]
--rd <integer> : Mode search complexity [0]
- 0: Skip intra if inter is good enough.
- 1: Rough intra mode search with SATD.
- 2: Refine intra mode search with SSE.
- 3: Try all intra modes and enable intra
chroma mode search.
- 2: Refine mode search with SSE.
- 3: More SSE candidates for inter and
chroma mode search for 4x4 intra.
- 4: Even more SSE candidates for both.
- 5: Try all intra modes.
--(no-)mv-rdo : Rate-distortion optimized motion vector costs
[disabled]
--(no-)zero-coeff-rdo : If a CU is set inter, check if forcing zero
residual improves the RD cost. [enabled]
--(no-)full-intra-search : Try all intra modes during rough search.
[disabled]
--(no-)intra-chroma-search : Test non-derived intra chroma modes.
[disabled]
--(no-)transform-skip : Try transform skip [disabled]
--me <string> : Integer motion estimation algorithm [hexbs]
- hexbs: Hexagon Based Search
Expand All @@ -227,6 +231,7 @@ Compression tools:
- 2: + 1/2-pixel diagonal
- 3: + 1/4-pixel horizontal and vertical
- 4: + 1/4-pixel diagonal
--(no-)fast-bipred : Only perform fast bipred search. [enabled]
--pu-depth-inter <int>-<int> : Inter prediction units sizes [0-3]
- 0, 1, 2, 3: from 64x64 to 8x8
- Accepts a list of values separated by ','
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ AC_CONFIG_SRCDIR([src/encmain.c])
#
# Here is a somewhat sane guide to lib versioning: http://apr.apache.org/versioning.html
ver_major=7
ver_minor=1
ver_minor=2
ver_release=0

# Prevents configure from adding a lot of defines to the CFLAGS
Expand Down
19 changes: 14 additions & 5 deletions doc/kvazaar.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH KVAZAAR "1" "June 2022" "kvazaar v2.1.0" "User Commands"
.TH KVAZAAR "1" "September 2022" "kvazaar v2.1.0" "User Commands"
.SH NAME
kvazaar \- open source HEVC encoder
.SH SYNOPSIS
Expand Down Expand Up @@ -252,12 +252,14 @@ Symmetric motion partition [disabled]
Asymmetric motion partition [disabled]
.TP
\fB\-\-rd <integer>
Intra mode search complexity [0]
Mode search complexity [0]
\- 0: Skip intra if inter is good enough.
\- 1: Rough intra mode search with SATD.
\- 2: Refine intra mode search with SSE.
\- 3: Try all intra modes and enable intra
chroma mode search.
\- 2: Refine mode search with SSE.
\- 3: More SSE candidates for inter and
chroma mode search for 4x4 intra.
\- 4: Even more SSE candidates for both.
\- 5: Try all intra modes.
.TP
\fB\-\-(no\-)mv\-rdo
Rate\-distortion optimized motion vector costs
Expand All @@ -271,6 +273,10 @@ residual improves the RD cost. [enabled]
Try all intra modes during rough search.
[disabled]
.TP
\fB\-\-(no\-)intra\-chroma\-search
Test non\-derived intra chroma modes.
[disabled]
.TP
\fB\-\-(no\-)transform\-skip
Try transform skip [disabled]
.TP
Expand All @@ -294,6 +300,9 @@ Fractional pixel motion estimation level [4]
\- 3: + 1/4\-pixel horizontal and vertical
\- 4: + 1/4\-pixel diagonal
.TP
\fB\-\-(no\-)fast\-bipred
Only perform fast bipred search. [enabled]
.TP
\fB\-\-pu\-depth\-inter <int>\-<int>
Inter prediction units sizes [0\-3]
\- 0, 1, 2, 3: from 64x64 to 8x8
Expand Down
9 changes: 8 additions & 1 deletion src/cabac.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,19 @@ void kvz_cabac_encode_bins_ep(cabac_data_t * const data, uint32_t bin_values, in
* \param symbol Value of coeff_abs_level_minus3.
* \param r_param Reference to Rice parameter.
*/
void kvz_cabac_write_coeff_remain(cabac_data_t * const cabac, const uint32_t symbol, const uint32_t r_param)
int kvz_cabac_write_coeff_remain(cabac_data_t* const cabac, const uint32_t symbol, const uint32_t r_param)
{
int32_t code_number = symbol;
uint32_t length;

int bits = 0;

if (code_number < (3 << r_param)) {
length = code_number >> r_param;
CABAC_BINS_EP(cabac, (1 << (length + 1)) - 2 , length + 1, "coeff_abs_level_remaining");
bits += length + 1;
CABAC_BINS_EP(cabac, (code_number % (1 << r_param)), r_param, "coeff_abs_level_remaining");
bits += r_param;
} else {
length = r_param;
code_number = code_number - (3 << r_param);
Expand All @@ -289,8 +293,11 @@ void kvz_cabac_write_coeff_remain(cabac_data_t * const cabac, const uint32_t sym
++length;
}
CABAC_BINS_EP(cabac, (1 << (3 + length + 1 - r_param)) - 2, 3 + length + 1 - r_param, "coeff_abs_level_remaining");
bits += 3 + length + 1 - r_param;
CABAC_BINS_EP(cabac, code_number, length, "coeff_abs_level_remaining");
bits += length;
}
return bits;
}

void kvz_cabac_write_coeff_remain_encry(struct encoder_state_t * const state, cabac_data_t * const cabac,const uint32_t symbol, const uint32_t r_param, int32_t base_level)
Expand Down
4 changes: 2 additions & 2 deletions src/cabac.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ void kvz_cabac_encode_bins_ep(cabac_data_t *data, uint32_t bin_values, int num_b
void kvz_cabac_encode_bin_trm(cabac_data_t *data, uint8_t bin_value);
void kvz_cabac_write(cabac_data_t *data);
void kvz_cabac_finish(cabac_data_t *data);
void kvz_cabac_write_coeff_remain(cabac_data_t *cabac, uint32_t symbol,
uint32_t r_param);
int kvz_cabac_write_coeff_remain(cabac_data_t* cabac, uint32_t symbol,
uint32_t r_param);
void kvz_cabac_write_coeff_remain_encry(struct encoder_state_t * const state, cabac_data_t * const cabac, const uint32_t symbol,
const uint32_t r_param, int32_t base_level);
uint32_t kvz_cabac_write_ep_ex_golomb(struct encoder_state_t * const state, cabac_data_t *data,
Expand Down
16 changes: 12 additions & 4 deletions src/cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ int kvz_config_init(kvz_config *cfg)

cfg->combine_intra_cus = 1;
cfg->force_inter = 0;
cfg->intra_chroma_search = 0;
cfg->fast_bipred = 1;
return 1;
}

Expand Down Expand Up @@ -703,7 +705,7 @@ int kvz_config_parse(kvz_config *cfg, const char *name, const char *value)
},
{
"veryslow",
"rd", "2",
"rd", "3",
"pu-depth-intra", "1-4",
"pu-depth-inter", "0-3",
"me", "tz",
Expand Down Expand Up @@ -731,7 +733,7 @@ int kvz_config_parse(kvz_config *cfg, const char *name, const char *value)
},
{
"placebo",
"rd", "2",
"rd", "3",
"pu-depth-intra", "1-4",
"pu-depth-inter", "0-3",
"me", "tz",
Expand Down Expand Up @@ -1399,6 +1401,12 @@ int kvz_config_parse(kvz_config *cfg, const char *name, const char *value)
else if OPT("force-inter") {
cfg->force_inter = atobool(value);
}
else if OPT("intra-chroma-search") {
cfg->intra_chroma_search = atobool(value);
}
else if OPT("fast-bipred") {
cfg->fast_bipred = atobool(value);
}
else {
return 0;
}
Expand Down Expand Up @@ -1590,8 +1598,8 @@ int kvz_config_validate(const kvz_config *const cfg)
error = 1;
}

if (cfg->rdo < 0 || cfg->rdo > 3) {
fprintf(stderr, "Input error: --rd parameter out of range [0..3]\n");
if (cfg->rdo < 0 || cfg->rdo > 6) {
fprintf(stderr, "Input error: --rd parameter out of range [0..5]\n");
error = 1;
}

Expand Down
17 changes: 13 additions & 4 deletions src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ static const struct option long_options[] = {
{ "no-combine-intra-cus", no_argument, NULL, 0 },
{ "force-inter", no_argument, NULL, 0 },
{ "no-force-inter", no_argument, NULL, 0 },
{ "intra-chroma-search", no_argument, NULL, 0 },
{ "no-intra-chroma-search", no_argument, NULL, 0 },
{ "fast-bipred", no_argument, NULL, 0 },
{ "no-fast-bipred", no_argument, NULL, 0 },
{0, 0, 0, 0}
};

Expand Down Expand Up @@ -550,18 +554,22 @@ void print_help(void)
" --(no-)signhide : Sign hiding [disabled]\n"
" --(no-)smp : Symmetric motion partition [disabled]\n"
" --(no-)amp : Asymmetric motion partition [disabled]\n"
" --rd <integer> : Intra mode search complexity [0]\n"
" --rd <integer> : Mode search complexity [0]\n"
" - 0: Skip intra if inter is good enough.\n"
" - 1: Rough intra mode search with SATD.\n"
" - 2: Refine intra mode search with SSE.\n"
" - 3: Try all intra modes and enable intra\n"
" chroma mode search.\n"
" - 2: Refine mode search with SSE.\n"
" - 3: More SSE candidates for inter and\n"
" chroma mode search for 4x4 intra.\n"
" - 4: Even more SSE candidates for both.\n"
" - 5: Try all intra modes.\n"
" --(no-)mv-rdo : Rate-distortion optimized motion vector costs\n"
" [disabled]\n"
" --(no-)zero-coeff-rdo : If a CU is set inter, check if forcing zero\n"
" residual improves the RD cost. [enabled]\n"
" --(no-)full-intra-search : Try all intra modes during rough search.\n"
" [disabled]\n"
" --(no-)intra-chroma-search : Test non-derived intra chroma modes.\n"
" [disabled]\n"
" --(no-)transform-skip : Try transform skip [disabled]\n"
" --me <string> : Integer motion estimation algorithm [hexbs]\n"
" - hexbs: Hexagon Based Search\n"
Expand All @@ -577,6 +585,7 @@ void print_help(void)
" - 2: + 1/2-pixel diagonal\n"
" - 3: + 1/4-pixel horizontal and vertical\n"
" - 4: + 1/4-pixel diagonal\n"
" --(no-)fast-bipred : Only perform fast bipred search. [enabled]\n"
" --pu-depth-inter <int>-<int> : Inter prediction units sizes [0-3]\n"
" - 0, 1, 2, 3: from 64x64 to 8x8\n"
" - Accepts a list of values separated by ','\n"
Expand Down
32 changes: 16 additions & 16 deletions src/encode_coding_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@
void kvz_encode_last_significant_xy(cabac_data_t * const cabac,
uint8_t lastpos_x, uint8_t lastpos_y,
uint8_t width, uint8_t height,
uint8_t type, uint8_t scan)
uint8_t type, uint8_t scan, double* bits_out)
{
const int index = kvz_math_floor_log2(width) - 2;
uint8_t ctx_offset = type ? 0 : (index * 3 + (index + 1) / 4);
uint8_t shift = type ? index : (index + 3) / 4;
double bits = 0;

cabac_ctx_t *base_ctx_x = (type ? cabac->ctx.cu_ctx_last_x_chroma : cabac->ctx.cu_ctx_last_x_luma);
cabac_ctx_t *base_ctx_y = (type ? cabac->ctx.cu_ctx_last_y_chroma : cabac->ctx.cu_ctx_last_y_luma);
Expand All @@ -81,37 +82,36 @@ void kvz_encode_last_significant_xy(cabac_data_t * const cabac,

// x prefix
for (int last_x = 0; last_x < group_idx_x; last_x++) {
cabac->cur_ctx = &base_ctx_x[ctx_offset + (last_x >> shift)];
CABAC_BIN(cabac, 1, "last_sig_coeff_x_prefix");
CABAC_FBITS_UPDATE(cabac, &base_ctx_x[ctx_offset + (last_x >> shift)], 1, bits, "last_sig_coeff_x_prefix");
}
if (group_idx_x < g_group_idx[width - 1]) {
cabac->cur_ctx = &base_ctx_x[ctx_offset + (group_idx_x >> shift)];
CABAC_BIN(cabac, 0, "last_sig_coeff_x_prefix");
CABAC_FBITS_UPDATE(cabac, &base_ctx_x[ctx_offset + (group_idx_x >> shift)], 0, bits, "last_sig_coeff_x_prefix");
}

// y prefix
for (int last_y = 0; last_y < group_idx_y; last_y++) {
cabac->cur_ctx = &base_ctx_y[ctx_offset + (last_y >> shift)];
CABAC_BIN(cabac, 1, "last_sig_coeff_y_prefix");
CABAC_FBITS_UPDATE(cabac, &base_ctx_y[ctx_offset + (last_y >> shift)], 1, bits, "last_sig_coeff_y_prefix");
}
if (group_idx_y < g_group_idx[height - 1]) {
cabac->cur_ctx = &base_ctx_y[ctx_offset + (group_idx_y >> shift)];
CABAC_BIN(cabac, 0, "last_sig_coeff_y_prefix");
CABAC_FBITS_UPDATE(cabac, &base_ctx_y[ctx_offset + (group_idx_y >> shift)], 0, bits, "last_sig_coeff_y_prefix");
}

// last_sig_coeff_x_suffix
if (group_idx_x > 3) {
const int suffix = lastpos_x - g_min_in_group[group_idx_x];
const int bits = (group_idx_x - 2) / 2;
CABAC_BINS_EP(cabac, suffix, bits, "last_sig_coeff_x_suffix");
const int write_bits = (group_idx_x - 2) / 2;
CABAC_BINS_EP(cabac, suffix, write_bits, "last_sig_coeff_x_suffix");
if (cabac->only_count) bits += write_bits;
}

// last_sig_coeff_y_suffix
if (group_idx_y > 3) {
const int suffix = lastpos_y - g_min_in_group[group_idx_y];
const int bits = (group_idx_y - 2) / 2;
CABAC_BINS_EP(cabac, suffix, bits, "last_sig_coeff_y_suffix");
const int write_bits = (group_idx_y - 2) / 2;
CABAC_BINS_EP(cabac, suffix, write_bits, "last_sig_coeff_y_suffix");
if (cabac->only_count) bits += write_bits;
}
if (cabac->only_count && bits_out) *bits_out += bits;
}

static void encode_transform_unit(encoder_state_t * const state,
Expand Down Expand Up @@ -142,7 +142,7 @@ static void encode_transform_unit(encoder_state_t * const state,
width,
0,
scan_idx,
cur_pu->tr_skip);
cur_pu->tr_skip, NULL);
}

if (depth == MAX_DEPTH + 1) {
Expand Down Expand Up @@ -172,11 +172,11 @@ static void encode_transform_unit(encoder_state_t * const state,
const coeff_t *coeff_v = &state->coeff->v[xy_to_zorder(LCU_WIDTH_C, x_local, y_local)];

if (cbf_is_set(cur_pu->cbf, depth, COLOR_U)) {
kvz_encode_coeff_nxn(state, &state->cabac, coeff_u, width_c, 2, scan_idx, 0);
kvz_encode_coeff_nxn(state, &state->cabac, coeff_u, width_c, 2, scan_idx, 0, NULL);
}

if (cbf_is_set(cur_pu->cbf, depth, COLOR_V)) {
kvz_encode_coeff_nxn(state, &state->cabac, coeff_v, width_c, 2, scan_idx, 0);
kvz_encode_coeff_nxn(state, &state->cabac, coeff_v, width_c, 2, scan_idx, 0, NULL);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/encode_coding_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ void kvz_encode_inter_prediction_unit(encoder_state_t* const state,
void kvz_encode_last_significant_xy(cabac_data_t * const cabac,
uint8_t lastpos_x, uint8_t lastpos_y,
uint8_t width, uint8_t height,
uint8_t type, uint8_t scan);
uint8_t type, uint8_t scan, double* bits_out);

#endif // ENCODE_CODING_TREE_H_
Loading

0 comments on commit e9b5005

Please sign in to comment.