diff --git a/.github/scripts/Linux/ffmpeg-patches/0001-NVENC_INFINITE_GOPLENGTH-is-useless-for-UltraGrid-up.patch b/.github/scripts/Linux/ffmpeg-patches/0001-NVENC_INFINITE_GOPLENGTH-is-useless-for-UltraGrid-up.patch new file mode 100644 index 000000000..11cd46aee --- /dev/null +++ b/.github/scripts/Linux/ffmpeg-patches/0001-NVENC_INFINITE_GOPLENGTH-is-useless-for-UltraGrid-up.patch @@ -0,0 +1,53 @@ +From 2bd65325dc20ad1ea3111e8a8b8328224fd9ee0a Mon Sep 17 00:00:00 2001 +From: Martin Pulec +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 + diff --git a/src/video_compress/libavcodec.cpp b/src/video_compress/libavcodec.cpp index 71da2c438..75ba48efd 100644 --- a/src/video_compress/libavcodec.cpp +++ b/src/video_compress/libavcodec.cpp @@ -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(codec_ctx->priv_data, "intra-refresh", 1); }