Message ID | 20230309185735.93571-1-jeebjp@gmail.com |
---|---|
State | Accepted |
Commit | fba9d9609fe00c8c4d04b76f9ecdd274aad318dd |
Headers | show |
Series | [FFmpeg-devel] avcodec/libsvtav1: use larger of bit rate and max rate for buffer size | expand |
Context | Check | Description |
---|---|---|
yinshiyou/make_loongarch64 | success | Make finished |
yinshiyou/make_fate_loongarch64 | success | Make fate finished |
andriy/make_x86 | success | Make finished |
andriy/make_fate_x86 | success | Make fate finished |
On Thu, Mar 9, 2023 at 8:57 PM Jan Ekström <jeebjp@gmail.com> wrote: > > Generally if maxrate is set, the calculation should be maxrate over > bufsize. This additionally enables CRF + maxrate & bufsize usage. > > In order to keep negative values from enabling zero to be treated > as larger and causing a division by zero, check that one of the > variables is larger than zero. > --- > libavcodec/libsvtav1.c | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) The idea and patch was OK'd by Christopher from SVT-AV1 and James noted that it seemed OK on IRC. Thus will be pulling this in in the evening unless there are concerns raised. Jan
On Mon, Mar 13, 2023 at 11:57 AM Jan Ekström <jeebjp@gmail.com> wrote: > > On Thu, Mar 9, 2023 at 8:57 PM Jan Ekström <jeebjp@gmail.com> wrote: > > > > Generally if maxrate is set, the calculation should be maxrate over > > bufsize. This additionally enables CRF + maxrate & bufsize usage. > > > > In order to keep negative values from enabling zero to be treated > > as larger and causing a division by zero, check that one of the > > variables is larger than zero. > > --- > > libavcodec/libsvtav1.c | 9 ++++++--- > > 1 file changed, 6 insertions(+), 3 deletions(-) > > The idea and patch was OK'd by Christopher from SVT-AV1 and James > noted that it seemed OK on IRC. > > Thus will be pulling this in in the evening unless there are concerns raised. Applied as fba9d9609fe00c8c4d04b76f9ecdd274aad318dd . Jan
diff --git a/libavcodec/libsvtav1.c b/libavcodec/libsvtav1.c index 56e1e22b51..9174e2753c 100644 --- a/libavcodec/libsvtav1.c +++ b/libavcodec/libsvtav1.c @@ -184,8 +184,10 @@ static int config_enc_params(EbSvtAv1EncConfiguration *param, param->min_qp_allowed = avctx->qmin; } param->max_bit_rate = avctx->rc_max_rate; - if (avctx->bit_rate && avctx->rc_buffer_size) - param->maximum_buffer_size_ms = avctx->rc_buffer_size * 1000LL / avctx->bit_rate; + if ((avctx->bit_rate > 0 || avctx->rc_max_rate > 0) && avctx->rc_buffer_size) + param->maximum_buffer_size_ms = + avctx->rc_buffer_size * 1000LL / + FFMAX(avctx->bit_rate, avctx->rc_max_rate); if (svt_enc->crf > 0) { param->qp = svt_enc->crf; @@ -302,7 +304,8 @@ static int config_enc_params(EbSvtAv1EncConfiguration *param, avctx->bit_rate = param->rate_control_mode > 0 ? param->target_bit_rate : 0; avctx->rc_max_rate = param->max_bit_rate; - avctx->rc_buffer_size = param->maximum_buffer_size_ms * avctx->bit_rate / 1000LL; + avctx->rc_buffer_size = param->maximum_buffer_size_ms * + FFMAX(avctx->bit_rate, avctx->rc_max_rate) / 1000LL; if (avctx->bit_rate || avctx->rc_max_rate || avctx->rc_buffer_size) { AVCPBProperties *cpb_props = ff_add_cpb_side_data(avctx);