[FFmpeg-cvslog] avcodec/nvenc: let preset decide default gop size

Ricardo Monteiro git at videolan.org
Thu Jun 22 20:33:33 EEST 2023


ffmpeg | branch: master | Ricardo Monteiro <rmonteiro at nvidia.com> | Thu Jun 22 12:18:19 2023 +0200| [99dfdb45a89955916651eeaeac77d938e9a4217a] | committer: Timo Rothenpieler

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 at rothenpieler.org>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=99dfdb45a89955916651eeaeac77d938e9a4217a
---

 libavcodec/nvenc.c      | 35 ++++++++++++++++++-----------------
 libavcodec/nvenc_av1.c  |  2 +-
 libavcodec/nvenc_h264.c |  2 +-
 libavcodec/nvenc_hevc.c |  2 +-
 4 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index d56ebc68e2..06579a502b 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -1171,8 +1171,8 @@ static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx)
 
     if (ctx->intra_refresh) {
         h264->enableIntraRefresh = 1;
-        h264->intraRefreshPeriod = avctx->gop_size;
-        h264->intraRefreshCnt = avctx->gop_size - 1;
+        h264->intraRefreshPeriod = cc->gopLength;
+        h264->intraRefreshCnt = cc->gopLength - 1;
 #ifdef NVENC_HAVE_SINGLE_SLICE_INTRA_REFRESH
         h264->singleSliceIntraRefresh = ctx->single_slice_intra_refresh;
 #endif
@@ -1192,8 +1192,8 @@ static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx)
 
     if (ctx->intra_refresh) {
         h264->idrPeriod = NVENC_INFINITE_GOPLENGTH;
-    } else if (avctx->gop_size >= 0) {
-        h264->idrPeriod = avctx->gop_size;
+    } else if (cc->gopLength > 0) {
+        h264->idrPeriod = cc->gopLength;
     }
 
     if (IS_CBR(cc->rcParams.rateControlMode)) {
@@ -1295,8 +1295,8 @@ static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx)
 
     if (ctx->intra_refresh) {
         hevc->enableIntraRefresh = 1;
-        hevc->intraRefreshPeriod = avctx->gop_size;
-        hevc->intraRefreshCnt = avctx->gop_size - 1;
+        hevc->intraRefreshPeriod = cc->gopLength;
+        hevc->intraRefreshCnt = cc->gopLength - 1;
 #ifdef NVENC_HAVE_SINGLE_SLICE_INTRA_REFRESH
         hevc->singleSliceIntraRefresh = ctx->single_slice_intra_refresh;
 #endif
@@ -1318,8 +1318,8 @@ static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx)
 
     if (ctx->intra_refresh) {
         hevc->idrPeriod = NVENC_INFINITE_GOPLENGTH;
-    } else if (avctx->gop_size >= 0) {
-        hevc->idrPeriod = avctx->gop_size;
+    } else if (cc->gopLength > 0) {
+        hevc->idrPeriod = cc->gopLength;
     }
 
     if (IS_CBR(cc->rcParams.rateControlMode)) {
@@ -1413,12 +1413,12 @@ static av_cold int nvenc_setup_av1_config(AVCodecContext *avctx)
 
     if (ctx->intra_refresh) {
         av1->enableIntraRefresh = 1;
-        av1->intraRefreshPeriod = avctx->gop_size;
-        av1->intraRefreshCnt = avctx->gop_size - 1;
+        av1->intraRefreshPeriod = cc->gopLength;
+        av1->intraRefreshCnt = cc->gopLength - 1;
 
         av1->idrPeriod = NVENC_INFINITE_GOPLENGTH;
-    } else if (avctx->gop_size >= 0) {
-        av1->idrPeriod = avctx->gop_size;
+    } else if (cc->gopLength > 0) {
+        av1->idrPeriod = cc->gopLength;
     }
 
     if (IS_CBR(cc->rcParams.rateControlMode)) {
@@ -1603,17 +1603,18 @@ FF_ENABLE_DEPRECATION_WARNINGS
     }
 
     if (avctx->gop_size > 0) {
-        if (avctx->max_b_frames >= 0) {
-            /* 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;
-        }
-
+        // only overwrite preset if a GOP size was selected as input
         ctx->encode_config.gopLength = avctx->gop_size;
     } else if (avctx->gop_size == 0) {
         ctx->encode_config.frameIntervalP = 0;
         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 */
     if(ctx->single_slice_intra_refresh)
         ctx->intra_refresh = 1;
diff --git a/libavcodec/nvenc_av1.c b/libavcodec/nvenc_av1.c
index 2b349c7b61..43643f7bf1 100644
--- a/libavcodec/nvenc_av1.c
+++ b/libavcodec/nvenc_av1.c
@@ -154,7 +154,7 @@ static const FFCodecDefault defaults[] = {
     { "qdiff", "-1" },
     { "qblur", "-1" },
     { "qcomp", "-1" },
-    { "g", "250" },
+    { "g", "-1" },
     { "bf", "-1" },
     { "refs", "0" },
     { NULL },
diff --git a/libavcodec/nvenc_h264.c b/libavcodec/nvenc_h264.c
index 698615855b..a99860998e 100644
--- a/libavcodec/nvenc_h264.c
+++ b/libavcodec/nvenc_h264.c
@@ -218,7 +218,7 @@ static const FFCodecDefault defaults[] = {
     { "qdiff", "-1" },
     { "qblur", "-1" },
     { "qcomp", "-1" },
-    { "g", "250" },
+    { "g", "-1" },
     { "bf", "-1" },
     { "refs", "0" },
     { NULL },
diff --git a/libavcodec/nvenc_hevc.c b/libavcodec/nvenc_hevc.c
index d99077f170..a02f277888 100644
--- a/libavcodec/nvenc_hevc.c
+++ b/libavcodec/nvenc_hevc.c
@@ -199,7 +199,7 @@ static const FFCodecDefault defaults[] = {
     { "qdiff", "-1" },
     { "qblur", "-1" },
     { "qcomp", "-1" },
-    { "g", "250" },
+    { "g", "-1" },
     { "bf", "-1" },
     { "refs", "0" },
     { NULL },



More information about the ffmpeg-cvslog mailing list