avcodec/nvenc: let preset decide default gop size

Default GOP size is now set by preset and tuning info. This GOP size is only overwriten if -g value is provided.

Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org>
pull/389/head
Ricardo Monteiro 2 years ago committed by Timo Rothenpieler
parent 997d8a7e73
commit 99dfdb45a8
  1. 35
      libavcodec/nvenc.c
  2. 2
      libavcodec/nvenc_av1.c
  3. 2
      libavcodec/nvenc_h264.c
  4. 2
      libavcodec/nvenc_hevc.c

@ -1171,8 +1171,8 @@ static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx)
if (ctx->intra_refresh) { if (ctx->intra_refresh) {
h264->enableIntraRefresh = 1; h264->enableIntraRefresh = 1;
h264->intraRefreshPeriod = avctx->gop_size; h264->intraRefreshPeriod = cc->gopLength;
h264->intraRefreshCnt = avctx->gop_size - 1; h264->intraRefreshCnt = cc->gopLength - 1;
#ifdef NVENC_HAVE_SINGLE_SLICE_INTRA_REFRESH #ifdef NVENC_HAVE_SINGLE_SLICE_INTRA_REFRESH
h264->singleSliceIntraRefresh = ctx->single_slice_intra_refresh; h264->singleSliceIntraRefresh = ctx->single_slice_intra_refresh;
#endif #endif
@ -1192,8 +1192,8 @@ static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx)
if (ctx->intra_refresh) { if (ctx->intra_refresh) {
h264->idrPeriod = NVENC_INFINITE_GOPLENGTH; h264->idrPeriod = NVENC_INFINITE_GOPLENGTH;
} else if (avctx->gop_size >= 0) { } else if (cc->gopLength > 0) {
h264->idrPeriod = avctx->gop_size; h264->idrPeriod = cc->gopLength;
} }
if (IS_CBR(cc->rcParams.rateControlMode)) { if (IS_CBR(cc->rcParams.rateControlMode)) {
@ -1295,8 +1295,8 @@ static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx)
if (ctx->intra_refresh) { if (ctx->intra_refresh) {
hevc->enableIntraRefresh = 1; hevc->enableIntraRefresh = 1;
hevc->intraRefreshPeriod = avctx->gop_size; hevc->intraRefreshPeriod = cc->gopLength;
hevc->intraRefreshCnt = avctx->gop_size - 1; hevc->intraRefreshCnt = cc->gopLength - 1;
#ifdef NVENC_HAVE_SINGLE_SLICE_INTRA_REFRESH #ifdef NVENC_HAVE_SINGLE_SLICE_INTRA_REFRESH
hevc->singleSliceIntraRefresh = ctx->single_slice_intra_refresh; hevc->singleSliceIntraRefresh = ctx->single_slice_intra_refresh;
#endif #endif
@ -1318,8 +1318,8 @@ static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx)
if (ctx->intra_refresh) { if (ctx->intra_refresh) {
hevc->idrPeriod = NVENC_INFINITE_GOPLENGTH; hevc->idrPeriod = NVENC_INFINITE_GOPLENGTH;
} else if (avctx->gop_size >= 0) { } else if (cc->gopLength > 0) {
hevc->idrPeriod = avctx->gop_size; hevc->idrPeriod = cc->gopLength;
} }
if (IS_CBR(cc->rcParams.rateControlMode)) { if (IS_CBR(cc->rcParams.rateControlMode)) {
@ -1413,12 +1413,12 @@ static av_cold int nvenc_setup_av1_config(AVCodecContext *avctx)
if (ctx->intra_refresh) { if (ctx->intra_refresh) {
av1->enableIntraRefresh = 1; av1->enableIntraRefresh = 1;
av1->intraRefreshPeriod = avctx->gop_size; av1->intraRefreshPeriod = cc->gopLength;
av1->intraRefreshCnt = avctx->gop_size - 1; av1->intraRefreshCnt = cc->gopLength - 1;
av1->idrPeriod = NVENC_INFINITE_GOPLENGTH; av1->idrPeriod = NVENC_INFINITE_GOPLENGTH;
} else if (avctx->gop_size >= 0) { } else if (cc->gopLength > 0) {
av1->idrPeriod = avctx->gop_size; av1->idrPeriod = cc->gopLength;
} }
if (IS_CBR(cc->rcParams.rateControlMode)) { if (IS_CBR(cc->rcParams.rateControlMode)) {
@ -1603,17 +1603,18 @@ FF_ENABLE_DEPRECATION_WARNINGS
} }
if (avctx->gop_size > 0) { if (avctx->gop_size > 0) {
if (avctx->max_b_frames >= 0) { // only overwrite preset if a GOP size was selected as input
/* 0 is intra-only, 1 is I/P only, 2 is one B-Frame, 3 two B-frames, and so on. */
ctx->encode_config.frameIntervalP = avctx->max_b_frames + 1;
}
ctx->encode_config.gopLength = avctx->gop_size; ctx->encode_config.gopLength = avctx->gop_size;
} else if (avctx->gop_size == 0) { } else if (avctx->gop_size == 0) {
ctx->encode_config.frameIntervalP = 0; ctx->encode_config.frameIntervalP = 0;
ctx->encode_config.gopLength = 1; ctx->encode_config.gopLength = 1;
} }
if (avctx->max_b_frames >= 0 && ctx->encode_config.gopLength > 1) {
/* 0 is intra-only, 1 is I/P only, 2 is one B-Frame, 3 two B-frames, and so on. */
ctx->encode_config.frameIntervalP = avctx->max_b_frames + 1;
}
/* force to enable intra refresh */ /* force to enable intra refresh */
if(ctx->single_slice_intra_refresh) if(ctx->single_slice_intra_refresh)
ctx->intra_refresh = 1; ctx->intra_refresh = 1;

@ -154,7 +154,7 @@ static const FFCodecDefault defaults[] = {
{ "qdiff", "-1" }, { "qdiff", "-1" },
{ "qblur", "-1" }, { "qblur", "-1" },
{ "qcomp", "-1" }, { "qcomp", "-1" },
{ "g", "250" }, { "g", "-1" },
{ "bf", "-1" }, { "bf", "-1" },
{ "refs", "0" }, { "refs", "0" },
{ NULL }, { NULL },

@ -218,7 +218,7 @@ static const FFCodecDefault defaults[] = {
{ "qdiff", "-1" }, { "qdiff", "-1" },
{ "qblur", "-1" }, { "qblur", "-1" },
{ "qcomp", "-1" }, { "qcomp", "-1" },
{ "g", "250" }, { "g", "-1" },
{ "bf", "-1" }, { "bf", "-1" },
{ "refs", "0" }, { "refs", "0" },
{ NULL }, { NULL },

@ -199,7 +199,7 @@ static const FFCodecDefault defaults[] = {
{ "qdiff", "-1" }, { "qdiff", "-1" },
{ "qblur", "-1" }, { "qblur", "-1" },
{ "qcomp", "-1" }, { "qcomp", "-1" },
{ "g", "250" }, { "g", "-1" },
{ "bf", "-1" }, { "bf", "-1" },
{ "refs", "0" }, { "refs", "0" },
{ NULL }, { NULL },

Loading…
Cancel
Save