Skip to content

Commit abd7ae9

Browse files
committed
vcomp/lavc: h264_nvenc: fix pulsation w intra-refr
Avoid pulsation with inra-refresh by repeating the missing SPS/PPS with header inseter. Unfortunately this is doesn't work well with HEVC because it seems that the NVIDIA encoder keeps the reference almost forever in specific cases, eg. `testcard:patt=text`. However, it _may_ work under some circumstances.
1 parent 976e9ef commit abd7ae9

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

.github/scripts/Linux/ffmpeg-patches/0001-NVENC_INFINITE_GOPLENGTH-is-useless-for-UltraGrid-up.patch

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@ diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
2424
index 0b6417674e..70adc26f08 100644
2525
--- a/libavcodec/nvenc.c
2626
+++ b/libavcodec/nvenc.c
27-
@@ -1173,7 +1173,6 @@ static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx)
28-
h264->enableIntraRefresh = 1;
29-
h264->intraRefreshPeriod = cc->gopLength;
30-
h264->intraRefreshCnt = cc->gopLength - 1;
31-
- cc->gopLength = NVENC_INFINITE_GOPLENGTH;
32-
#ifdef NVENC_HAVE_SINGLE_SLICE_INTRA_REFRESH
33-
h264->singleSliceIntraRefresh = ctx->single_slice_intra_refresh;
34-
#endif
3527
@@ -1294,7 +1293,6 @@ static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx)
3628
hevc->enableIntraRefresh = 1;
3729
hevc->intraRefreshPeriod = cc->gopLength;

src/video_compress/libavcodec.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,16 +1997,30 @@ static void configure_nvenc(AVCodecContext *codec_ctx, struct setparam_param *pa
19971997
}
19981998

19991999
check_av_opt_set(codec_ctx->priv_data, "forced-idr", 1);
2000+
2001+
const bool h264 = codec_ctx->codec_id == AV_CODEC_ID_H264;
20002002
#ifdef PATCHED_FF_NVENC_NO_INFINITE_GOP
20012003
const bool patched_ff = true;
20022004
#else
20032005
const bool patched_ff = false;
2004-
if (param->periodic_intra != 0) {
2006+
if (!h264 && param->periodic_intra != 0) {
20052007
LOG(LOG_LEVEL_WARNING) << MOD_NAME "FFmpeg not patched, " << (param->periodic_intra != 1 ? "not " : "") << "enabling Intra Refresh.\n";
20062008
}
20072009
#endif
2010+
if (h264 && param->periodic_intra != 0) {
2011+
if (param->header_inserter_req == -1) {
2012+
MSG(INFO,
2013+
"Auto-enabling header inserter for H.264 when "
2014+
"intra-refresh used.\n");
2015+
param->header_inserter_req = 1;
2016+
}
2017+
param->periodic_intra = 1;
2018+
}
2019+
if (!h264 && patched_ff && param->periodic_intra != 0) {
2020+
param->periodic_intra = 1;
2021+
}
20082022

2009-
if ((patched_ff && param->periodic_intra != 0) || param->periodic_intra == 1) {
2023+
if (param->periodic_intra == 1) {
20102024
incomp_feature_warn(INCOMP_INTRA_REFRESH, param->periodic_intra);
20112025
check_av_opt_set<int>(codec_ctx->priv_data, "intra-refresh", 1);
20122026
}
@@ -2021,10 +2035,10 @@ static void configure_nvenc(AVCodecContext *codec_ctx, struct setparam_param *pa
20212035
double lavc_rc_buffer_size_factor = DEFAULT_NVENC_RC_BUF_SIZE_FACTOR;
20222036
if (const char *val = get_commandline_param("lavc-rc-buffer-size-factor")) {
20232037
lavc_rc_buffer_size_factor = stof(val);
2024-
} else {
2038+
} else if (!h264) {
20252039
LOG(LOG_LEVEL_WARNING)
20262040
<< MOD_NAME
2027-
"To reduce NVENC pulsation, you can try \"--param "
2041+
"To reduce NVENC HEVC/AV1 pulsation, you can try \"--param "
20282042
"lavc-rc-buffer-size-factor=0\""
20292043
" or a small number. 0 or higher value (than default "
20302044
<< DEFAULT_NVENC_RC_BUF_SIZE_FACTOR

0 commit comments

Comments
 (0)