Skip to content

Commit

Permalink
Revert "CI Linux FFmpeg: remove NVENC IDR patch"
Browse files Browse the repository at this point in the history
This reverts commit e457ab8 but the
patch is updated to match current FFmpeg.

The FFmpeg commit that seemed to do the same (7eeef72c6) is not working
correctly because it assigns idrPeriod cc->gopLength, which was set to
NVENC_INFINITE_GOPLENGTH above in case of intra-refresh.

refer to GH-330
  • Loading branch information
MartinPulec committed Aug 21, 2023
1 parent 181b79f commit eb6ac4b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
From 2bd65325dc20ad1ea3111e8a8b8328224fd9ee0a Mon Sep 17 00:00:00 2001
From: Martin Pulec <[email protected]>
Date: Mon, 24 Jul 2023 16:15:29 +0200
Subject: [PATCH] NVENC_INFINITE_GOPLENGTH is useless for UltraGrid (updated)

---
libavcodec/avcodec.h | 3 +++
libavcodec/nvenc.c | 3 ---
2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index fe41ecc3c9..15bc1f5cec 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3270,4 +3270,7 @@ int avcodec_is_open(AVCodecContext *s);
* @}
*/

+// UltraGrid patch
+#define PATCHED_FF_NVENC_NO_INFINITE_GOP 1
+
#endif /* AVCODEC_AVCODEC_H */
diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index 0b6417674e..70adc26f08 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -1173,7 +1173,6 @@ static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx)
h264->enableIntraRefresh = 1;
h264->intraRefreshPeriod = cc->gopLength;
h264->intraRefreshCnt = cc->gopLength - 1;
- cc->gopLength = NVENC_INFINITE_GOPLENGTH;
#ifdef NVENC_HAVE_SINGLE_SLICE_INTRA_REFRESH
h264->singleSliceIntraRefresh = ctx->single_slice_intra_refresh;
#endif
@@ -1294,7 +1293,6 @@ static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx)
hevc->enableIntraRefresh = 1;
hevc->intraRefreshPeriod = cc->gopLength;
hevc->intraRefreshCnt = cc->gopLength - 1;
- cc->gopLength = NVENC_INFINITE_GOPLENGTH;
#ifdef NVENC_HAVE_SINGLE_SLICE_INTRA_REFRESH
hevc->singleSliceIntraRefresh = ctx->single_slice_intra_refresh;
#endif
@@ -1409,7 +1407,6 @@ static av_cold int nvenc_setup_av1_config(AVCodecContext *avctx)
av1->enableIntraRefresh = 1;
av1->intraRefreshPeriod = cc->gopLength;
av1->intraRefreshCnt = cc->gopLength - 1;
- cc->gopLength = NVENC_INFINITE_GOPLENGTH;
}

av1->idrPeriod = cc->gopLength;
--
2.41.0

13 changes: 5 additions & 8 deletions src/video_compress/libavcodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1870,19 +1870,16 @@ static void configure_nvenc(AVCodecContext *codec_ctx, struct setparam_param *pa
}

set_forced_idr(codec_ctx, 1);
#if LIBAVCODEC_VERSION_INT > AV_VERSION_INT(60, 22, 100)
const bool new_ff = true;
#ifdef PATCHED_FF_NVENC_NO_INFINITE_GOP
const bool patched_ff = true;
#else
const bool new_ff = false;
const bool patched_ff = false;
if (param->periodic_intra != 0) {
LOG(LOG_LEVEL_WARNING) << MOD_NAME
"Old FFmpeg, " << (param->periodic_intra != 1 ? "not " : "")
<< "enabling Intra Refresh.\n";
LOG(LOG_LEVEL_WARNING) << MOD_NAME "FFmpeg not patched, " << (param->periodic_intra != 1 ? "not " : "") << "enabling Intra Refresh.\n";
}
#endif

if ((new_ff && param->periodic_intra != 0) ||
param->periodic_intra == 1) {
if ((patched_ff && param->periodic_intra != 0) || param->periodic_intra == 1) {
check_av_opt_set<int>(codec_ctx->priv_data, "intra-refresh", 1);
}

Expand Down

0 comments on commit eb6ac4b

Please sign in to comment.