Le 03/05/2018 à 12:21 AM, Timo Rothenpieler a écrit :
Hi
thanks for your feedback.
I was not sure of whether to put the capability check with the others
in nvenc_check_capabilities because if the cap is missing this would
remove the encoder altogether:
ex: ln. 453 : if ((ret = nvenc_check_capabilities(avctx)) < 0)
goto fail3;
I'll move it there then or if you think it's preferrable, I can move
it to ff_nvenc_encode_init and store it.
Which option do you prefer ? I'll resubmit and rebase once the other
patch is committed.
Just add a new field to the struct NvencContext.
done
And there is no need to fail on this check, store its result and go
on, unless it's < 0, which indicates an actual error.
done
There's also no need to check for a changed bitrate outside of the
call to reconfig_encoder, when making the same check inside of it again.
done
I have also removed per your suggestion the bitrate settings rc_min_rate
and rc_max_rate to avctx->bit_rate;
I added a check for CQP rc so that the encoder Reconfigure happens only
if rc is not CQP.
Thanks
From 699b858f47ed9fa29b89816e5a5066abd2712610 Mon Sep 17 00:00:00 2001
From: pkviet <pkv.str...@gmail.com>
Date: Thu, 3 May 2018 02:15:52 +0200
Subject: [PATCH] avcodec/nvenc: Enable dynamic bitrate
The patch enables dynamic bitrate through ReconfigureEncoder method
from nvenc API.
This is useful for live streaming in case of network congestion.
Signed-off-by: pkviet <pkv.str...@gmail.com>
---
libavcodec/nvenc.c | 19 +++++++++++++++++--
libavcodec/nvenc.h | 1 +
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index 3313c376fe..38d755ada8 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -550,6 +550,10 @@ static av_cold int nvenc_setup_device(AVCodecContext
*avctx)
av_log(avctx, AV_LOG_FATAL, "Provided device doesn't support
required NVENC features\n");
return ret;
}
+ ctx->dynamic_bitrate = nvenc_check_cap(avctx,
NV_ENC_CAPS_SUPPORT_DYN_BITRATE_CHANGE);
+ if (!ctx->dynamic_bitrate) {
+ av_log(avctx, AV_LOG_VERBOSE, "Dynamic Encode bitrate change not
supported\n");
+ }
} else {
int i, nb_devices = 0;
@@ -1951,8 +1955,20 @@ static int reconfig_encoder(AVCodecContext *avctx, const
AVFrame *frame)
params.reInitEncodeParams.darHeight = dh;
params.reInitEncodeParams.darWidth = dw;
+ ctx->init_encode_params.darHeight = dh;
+ ctx->init_encode_params.darWidth = dw;
+ needs_reconfig = 1;
+ }
+ if (ctx->dynamic_bitrate > 0 && ctx->rc != NV_ENC_PARAMS_RC_CONSTQP
+ && ctx->encode_config.rcParams.averageBitRate != avctx->bit_rate) {
+ params.version = NV_ENC_RECONFIGURE_PARAMS_VER;
+ params.resetEncoder = 1;
+ params.forceIDR = 1;
+ params.reInitEncodeParams = ctx->init_encode_params;
+ params.reInitEncodeParams.encodeConfig->rcParams.averageBitRate =
avctx->bit_rate;
needs_reconfig = 1;
+ needs_encode_config = 1;
}
if (!needs_encode_config)
@@ -1963,8 +1979,7 @@ static int reconfig_encoder(AVCodecContext *avctx, const
AVFrame *frame)
if (ret != NV_ENC_SUCCESS) {
nvenc_print_error(avctx, ret, "failed to reconfigure nvenc");
} else {
- ctx->init_encode_params.darHeight = dh;
- ctx->init_encode_params.darWidth = dw;
+ av_log(avctx, AV_LOG_INFO, "nvencReconfigureEncoder succeeded\n");
}
}
diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h
index c7506d6a15..fd2350aaa6 100644
--- a/libavcodec/nvenc.h
+++ b/libavcodec/nvenc.h
@@ -184,6 +184,7 @@ typedef struct NvencContext
int weighted_pred;
int coder;
int b_ref_mode;
+ int dynamic_bitrate;
} NvencContext;
int ff_nvenc_encode_init(AVCodecContext *avctx);
--
2.16.2.windows.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel