Skip to content

Commit 10c2809

Browse files
committed
Revert "CI Linux FFmpeg: remove NVENC IDR patch"
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
1 parent 41da22a commit 10c2809

File tree

2 files changed

+58
-8
lines changed

2 files changed

+58
-8
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
From 2bd65325dc20ad1ea3111e8a8b8328224fd9ee0a Mon Sep 17 00:00:00 2001
2+
From: Martin Pulec <martin.pulec@cesnet.cz>
3+
Date: Mon, 24 Jul 2023 16:15:29 +0200
4+
Subject: [PATCH] NVENC_INFINITE_GOPLENGTH is useless for UltraGrid (updated)
5+
6+
---
7+
libavcodec/avcodec.h | 3 +++
8+
libavcodec/nvenc.c | 3 ---
9+
2 files changed, 3 insertions(+), 3 deletions(-)
10+
11+
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
12+
index fe41ecc3c9..15bc1f5cec 100644
13+
--- a/libavcodec/avcodec.h
14+
+++ b/libavcodec/avcodec.h
15+
@@ -3270,4 +3270,7 @@ int avcodec_is_open(AVCodecContext *s);
16+
* @}
17+
*/
18+
19+
+// UltraGrid patch
20+
+#define PATCHED_FF_NVENC_NO_INFINITE_GOP 1
21+
+
22+
#endif /* AVCODEC_AVCODEC_H */
23+
diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
24+
index 0b6417674e..70adc26f08 100644
25+
--- a/libavcodec/nvenc.c
26+
+++ 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
35+
@@ -1294,7 +1293,6 @@ static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx)
36+
hevc->enableIntraRefresh = 1;
37+
hevc->intraRefreshPeriod = cc->gopLength;
38+
hevc->intraRefreshCnt = cc->gopLength - 1;
39+
- cc->gopLength = NVENC_INFINITE_GOPLENGTH;
40+
#ifdef NVENC_HAVE_SINGLE_SLICE_INTRA_REFRESH
41+
hevc->singleSliceIntraRefresh = ctx->single_slice_intra_refresh;
42+
#endif
43+
@@ -1409,7 +1407,6 @@ static av_cold int nvenc_setup_av1_config(AVCodecContext *avctx)
44+
av1->enableIntraRefresh = 1;
45+
av1->intraRefreshPeriod = cc->gopLength;
46+
av1->intraRefreshCnt = cc->gopLength - 1;
47+
- cc->gopLength = NVENC_INFINITE_GOPLENGTH;
48+
}
49+
50+
av1->idrPeriod = cc->gopLength;
51+
--
52+
2.41.0
53+

src/video_compress/libavcodec.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,19 +1539,16 @@ static void configure_nvenc(AVCodecContext *codec_ctx, struct setparam_param *pa
15391539
}
15401540

15411541
set_forced_idr(codec_ctx, 1);
1542-
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(60, 22, 100)
1543-
const bool new_ff = true;
1542+
#ifdef PATCHED_FF_NVENC_NO_INFINITE_GOP
1543+
const bool patched_ff = true;
15441544
#else
1545-
const bool new_ff = false;
1545+
const bool patched_ff = false;
15461546
if (param->periodic_intra != 0) {
1547-
LOG(LOG_LEVEL_WARNING) << MOD_NAME
1548-
"Old FFmpeg, " << (param->periodic_intra != 1 ? "not " : "")
1549-
<< "enabling Intra Refresh.\n";
1547+
LOG(LOG_LEVEL_WARNING) << MOD_NAME "FFmpeg not patched, " << (param->periodic_intra != 1 ? "not " : "") << "enabling Intra Refresh.\n";
15501548
}
15511549
#endif
15521550

1553-
if ((new_ff && param->periodic_intra != 0) ||
1554-
param->periodic_intra == 1) {
1551+
if ((patched_ff && param->periodic_intra != 0) || param->periodic_intra == 1) {
15551552
check_av_opt_set<int>(codec_ctx->priv_data, "intra-refresh", 1);
15561553
}
15571554

0 commit comments

Comments
 (0)