Skip to content

Commit 886c610

Browse files
authored
Modification of RC (#145)
* modification of RC Signed-off-by: Minsoo Park <[email protected]> * add clipping to RC update Signed-off-by: Minsoo Park <[email protected]> --------- Signed-off-by: Minsoo Park <[email protected]>
1 parent 8f69853 commit 886c610

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

src/oapv_rc.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -182,21 +182,26 @@ void oapve_rc_get_qp(oapve_ctx_t* ctx, oapve_tile_t* tile, int frame_qp, int* qp
182182

183183
void oapve_rc_update_after_pic(oapve_ctx_t* ctx, double cost)
184184
{
185-
int num_pixel = ctx->w * ctx->h;
186-
for (int c = 1; c < ctx->num_comp; c++) {
187-
num_pixel += (ctx->w * ctx->h) >> (ctx->comp_sft[c][0] + ctx->comp_sft[c][1]);
188-
}
185+
if (cost > 0) {
186+
int num_pixel = ctx->w * ctx->h;
187+
for (int c = 1; c < ctx->num_comp; c++) {
188+
num_pixel += (ctx->w * ctx->h) >> (ctx->comp_sft[c][0] + ctx->comp_sft[c][1]);
189+
}
189190

190-
int total_bits = 0;
191-
for (int i = 0; i < ctx->num_tiles; i++) {
192-
total_bits += ctx->fh.tile_size[i] * 8;
193-
}
191+
int total_bits = 0;
192+
for (int i = 0; i < ctx->num_tiles; i++) {
193+
total_bits += ctx->fh.tile_size[i] * 8;
194+
}
194195

195-
double ln_bpp = log(pow(cost / (double)num_pixel, OAPV_RC_BETA));
196-
double diff_lambda = (ctx->rc_param.beta) * (log((double)total_bits) - log(((double)ctx->param->bitrate * 1000 / ((double)ctx->param->fps_num / ctx->param->fps_den))));
196+
double ln_bpp = log(pow(cost / (double)num_pixel, OAPV_RC_BETA));
197+
double diff_lambda = (ctx->rc_param.beta) * (log((double)total_bits) - log(((double)ctx->param->bitrate * 1000 / ((double)ctx->param->fps_num / ctx->param->fps_den))));
197198

198-
diff_lambda = oapv_clip3(-0.125, 0.125, 0.25 * diff_lambda);
199-
ctx->rc_param.alpha = (ctx->rc_param.alpha) * exp(diff_lambda);
200-
ctx->rc_param.beta = (ctx->rc_param.beta) + diff_lambda / ln_bpp;
199+
diff_lambda = oapv_clip3(-0.125, 0.125, 0.25 * diff_lambda);
200+
ctx->rc_param.alpha = (ctx->rc_param.alpha) * exp(diff_lambda);
201+
ctx->rc_param.beta = (ctx->rc_param.beta) + diff_lambda / ln_bpp;
202+
203+
ctx->rc_param.alpha = oapv_clip3(0.05, 500, ctx->rc_param.alpha);
204+
ctx->rc_param.beta = oapv_clip3(0.1, 3, ctx->rc_param.beta);
205+
}
201206
ctx->rc_param.is_updated = 1;
202207
}

0 commit comments

Comments
 (0)