Skip to content

Commit 83289a5

Browse files
committed
vcomp/lavc: nvenc no intra-refresh for HEVC/AV1
Since the pulsation issue, it was not much usable, anyways and this clean-ups the code a bit. Also the behavior will be now more deterministic - it behaved differently with patched FFmpeg (most likely GH Linux builds), othewrise differntly. + enable the header-inserter if user expliclty requesetd intra-refresh refers to GH-114
1 parent d9936aa commit 83289a5

File tree

2 files changed

+32
-74
lines changed

2 files changed

+32
-74
lines changed

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

Lines changed: 0 additions & 53 deletions
This file was deleted.

src/video_compress/libavcodec.cpp

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @author Martin Pulec <[email protected]>
44
*/
55
/*
6-
* Copyright (c) 2013-2024 CESNET, z. s. p. o.
6+
* Copyright (c) 2013-2025 CESNET
77
* All rights reserved.
88
*
99
* Redistribution and use in source and binary forms, with or without
@@ -1792,19 +1792,38 @@ static void configure_nvenc(AVCodecContext *codec_ctx, struct setparam_param *pa
17921792
}
17931793
}
17941794

1795-
set_forced_idr(codec_ctx, 1);
1796-
#ifdef PATCHED_FF_NVENC_NO_INFINITE_GOP
1797-
const bool patched_ff = true;
1798-
#else
1799-
const bool patched_ff = false;
1800-
if (param->periodic_intra != 0) {
1801-
LOG(LOG_LEVEL_WARNING) << MOD_NAME "FFmpeg not patched, " << (param->periodic_intra != 1 ? "not " : "") << "enabling Intra Refresh.\n";
1795+
check_av_opt_set(codec_ctx->priv_data, "forced-idr", 1);
1796+
1797+
const bool h264 = codec_ctx->codec_id == AV_CODEC_ID_H264;
1798+
const bool hevc = codec_ctx->codec_id == AV_CODEC_ID_HEVC;
1799+
if (!h264) {
1800+
if (param->periodic_intra == 1) {
1801+
if (hevc) {
1802+
MSG(WARNING,
1803+
"Requeseted intra-refresh for NVENC "
1804+
"HEVC but there may occur artifacts!\n");
1805+
} else {
1806+
MSG(WARNING,
1807+
"Requeseted intra-refresh for NVENC "
1808+
"AV1 but it won't most likely work with UG "
1809+
"because of NVENC_INFINITE_GOPLENGTH!\n");
1810+
}
1811+
}
1812+
if (param->periodic_intra == -1) {
1813+
MSG(WARNING,
1814+
"Intra-refresh won't be enabled for NVENC "
1815+
"HEVC/AV1, bitrate variance will be higher!\n");
1816+
}
18021817
}
1803-
#endif
1804-
1805-
if ((patched_ff && param->periodic_intra != 0) || param->periodic_intra == 1) {
1806-
incomp_feature_warn(INCOMP_INTRA_REFRESH, param->periodic_intra);
1807-
check_av_opt_set<int>(codec_ctx->priv_data, "intra-refresh", 1);
1818+
if ((h264 && param->periodic_intra != 0) ||
1819+
param->periodic_intra == 1) {
1820+
if (param->header_inserter_req == -1) {
1821+
MSG(INFO,
1822+
"Auto-enabling header inserter for %s when "
1823+
"intra-refresh used.\n", codec_ctx->codec->name);
1824+
param->header_inserter_req = 1;
1825+
}
1826+
param->periodic_intra = 1;
18081827
}
18091828

18101829
check_av_opt_set<const char *>(codec_ctx->priv_data, "rc", DEFAULT_NVENC_RC);
@@ -1817,14 +1836,6 @@ static void configure_nvenc(AVCodecContext *codec_ctx, struct setparam_param *pa
18171836
double lavc_rc_buffer_size_factor = DEFAULT_NVENC_RC_BUF_SIZE_FACTOR;
18181837
if (const char *val = get_commandline_param("lavc-rc-buffer-size-factor")) {
18191838
lavc_rc_buffer_size_factor = stof(val);
1820-
} else {
1821-
LOG(LOG_LEVEL_WARNING)
1822-
<< MOD_NAME
1823-
"To reduce NVENC pulsation, you can try \"--param "
1824-
"lavc-rc-buffer-size-factor=0\""
1825-
" or a small number. 0 or higher value (than default "
1826-
<< DEFAULT_NVENC_RC_BUF_SIZE_FACTOR
1827-
<< ") may cause frame drops on receiver.\n";
18281839
}
18291840
codec_ctx->rc_buffer_size =
18301841
(int) ((double) codec_ctx->rc_max_rate / param->desc.fps *

0 commit comments

Comments
 (0)