[FFmpeg-cvslog] avcodec/nvenc: add support for forcing intra/idr frames

Timo Rothenpieler git at videolan.org
Wed Oct 12 21:54:25 EEST 2016


ffmpeg | branch: master | Timo Rothenpieler <timo at rothenpieler.org> | Wed Oct 12 20:51:43 2016 +0200| [30c558750374b179dc910da6fc354724679d630e] | committer: Timo Rothenpieler

avcodec/nvenc: add support for forcing intra/idr frames

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=30c558750374b179dc910da6fc354724679d630e
---

 libavcodec/nvenc.c      | 8 +++++++-
 libavcodec/nvenc.h      | 1 +
 libavcodec/nvenc_h264.c | 2 ++
 libavcodec/nvenc_hevc.c | 2 ++
 libavcodec/version.h    | 2 +-
 5 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index f6f756f..e6c1c94 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -1737,7 +1737,13 @@ int ff_nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
             pic_params.pictureStruct = NV_ENC_PIC_STRUCT_FRAME;
         }
 
-        pic_params.encodePicFlags = 0;
+        if (ctx->forced_idr >= 0 && frame->pict_type == AV_PICTURE_TYPE_I) {
+            pic_params.encodePicFlags =
+                ctx->forced_idr ? NV_ENC_PIC_FLAG_FORCEIDR : NV_ENC_PIC_FLAG_FORCEINTRA;
+        } else {
+            pic_params.encodePicFlags = 0;
+        }
+
         pic_params.inputTimeStamp = frame->pts;
 
         nvenc_codec_specific_pic_params(avctx, &pic_params);
diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h
index 648d1dc..bad659a 100644
--- a/libavcodec/nvenc.h
+++ b/libavcodec/nvenc.h
@@ -185,6 +185,7 @@ typedef struct NvencContext
     int rc_lookahead;
     int aq;
     int no_scenecut;
+    int forced_idr;
     int b_adapt;
     int temporal_aq;
     int zerolatency;
diff --git a/libavcodec/nvenc_h264.c b/libavcodec/nvenc_h264.c
index 2d7f2d1..6914046b 100644
--- a/libavcodec/nvenc_h264.c
+++ b/libavcodec/nvenc_h264.c
@@ -91,6 +91,8 @@ static const AVOption options[] = {
                                                             OFFSET(async_depth),  AV_OPT_TYPE_INT,   { .i64 = INT_MAX }, 0, INT_MAX, VE },
     { "no-scenecut",  "When lookahead is enabled, set this to 1 to disable adaptive I-frame insertion at scene cuts",
                                                             OFFSET(no_scenecut),  AV_OPT_TYPE_BOOL,  { .i64 = 0 }, 0,  1, VE },
+    { "forced-idr",   "If forcing keyframes, force them as IDR frames.",
+                                                            OFFSET(forced_idr),   AV_OPT_TYPE_BOOL,  { .i64 = -1 }, -1, 1, VE },
     { "b_adapt",      "When lookahead is enabled, set this to 0 to disable adaptive B-frame decision",
                                                             OFFSET(b_adapt),      AV_OPT_TYPE_BOOL,  { .i64 = 1 }, 0,  1, VE },
     { "spatial-aq",   "set to 1 to enable Spatial AQ",      OFFSET(aq),           AV_OPT_TYPE_BOOL,  { .i64 = 0 }, 0,  1, VE },
diff --git a/libavcodec/nvenc_hevc.c b/libavcodec/nvenc_hevc.c
index 4edc741..320f290 100644
--- a/libavcodec/nvenc_hevc.c
+++ b/libavcodec/nvenc_hevc.c
@@ -90,6 +90,8 @@ static const AVOption options[] = {
                                                             OFFSET(async_depth),  AV_OPT_TYPE_INT,   { .i64 = INT_MAX }, 0, INT_MAX, VE },
     { "no-scenecut",  "When lookahead is enabled, set this to 1 to disable adaptive I-frame insertion at scene cuts",
                                                             OFFSET(no_scenecut),  AV_OPT_TYPE_BOOL,  { .i64 = 0 }, 0, 1, VE },
+    { "forced-idr",   "If forcing keyframes, force them as IDR frames.",
+                                                            OFFSET(forced_idr),   AV_OPT_TYPE_BOOL,  { .i64 = -1 }, -1, 1, VE },
     { "spatial_aq",   "set to 1 to enable Spatial AQ",      OFFSET(aq),           AV_OPT_TYPE_BOOL,  { .i64 = 0 }, 0, 1, VE },
     { "zerolatency",  "Set 1 to indicate zero latency operation (no reordering delay)",
                                                             OFFSET(zerolatency),  AV_OPT_TYPE_BOOL,  { .i64 = 0 }, 0, 1, VE },
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 4e34850..9c2bf6d 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 
 #define LIBAVCODEC_VERSION_MAJOR  57
 #define LIBAVCODEC_VERSION_MINOR  61
-#define LIBAVCODEC_VERSION_MICRO 102
+#define LIBAVCODEC_VERSION_MICRO 103
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
                                                LIBAVCODEC_VERSION_MINOR, \



More information about the ffmpeg-cvslog mailing list