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 index 11cd46aee..523477660 100644 --- 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 @@ -24,14 +24,6 @@ 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; diff --git a/src/video_compress/libavcodec.cpp b/src/video_compress/libavcodec.cpp index a49e08cbe..8844c6f10 100644 --- a/src/video_compress/libavcodec.cpp +++ b/src/video_compress/libavcodec.cpp @@ -1997,16 +1997,30 @@ static void configure_nvenc(AVCodecContext *codec_ctx, struct setparam_param *pa } check_av_opt_set(codec_ctx->priv_data, "forced-idr", 1); + + const bool h264 = codec_ctx->codec_id == AV_CODEC_ID_H264; #ifdef PATCHED_FF_NVENC_NO_INFINITE_GOP const bool patched_ff = true; #else const bool patched_ff = false; - if (param->periodic_intra != 0) { + if (!h264 && param->periodic_intra != 0) { LOG(LOG_LEVEL_WARNING) << MOD_NAME "FFmpeg not patched, " << (param->periodic_intra != 1 ? "not " : "") << "enabling Intra Refresh.\n"; } #endif + if (h264 && param->periodic_intra != 0) { + if (param->header_inserter_req == -1) { + MSG(INFO, + "Auto-enabling header inserter for H.264 when " + "intra-refresh used.\n"); + param->header_inserter_req = 1; + } + param->periodic_intra = 1; + } + if (!h264 && patched_ff && param->periodic_intra != 0) { + param->periodic_intra = 1; + } - if ((patched_ff && param->periodic_intra != 0) || param->periodic_intra == 1) { + if (param->periodic_intra == 1) { incomp_feature_warn(INCOMP_INTRA_REFRESH, param->periodic_intra); check_av_opt_set(codec_ctx->priv_data, "intra-refresh", 1); } @@ -2021,10 +2035,10 @@ static void configure_nvenc(AVCodecContext *codec_ctx, struct setparam_param *pa double lavc_rc_buffer_size_factor = DEFAULT_NVENC_RC_BUF_SIZE_FACTOR; if (const char *val = get_commandline_param("lavc-rc-buffer-size-factor")) { lavc_rc_buffer_size_factor = stof(val); - } else { + } else if (!h264) { LOG(LOG_LEVEL_WARNING) << MOD_NAME - "To reduce NVENC pulsation, you can try \"--param " + "To reduce NVENC HEVC/AV1 pulsation, you can try \"--param " "lavc-rc-buffer-size-factor=0\"" " or a small number. 0 or higher value (than default " << DEFAULT_NVENC_RC_BUF_SIZE_FACTOR