diff mbox series

[FFmpeg-devel,4/4] avcodec/nvenc: Add constrainedFrame encoding support

Message ID 1630579138-6145-4-git-send-email-lance.lmwang@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/4] avcodec/nvenc: make number of slices per frame configurable
Related show

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Limin Wang Sept. 2, 2021, 10:38 a.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavcodec/nvenc.c      | 12 ++++++++++++
 libavcodec/nvenc.h      |  1 +
 libavcodec/nvenc_h264.c |  2 ++
 libavcodec/nvenc_hevc.c |  2 ++
 libavcodec/version.h    |  2 +-
 5 files changed, 18 insertions(+), 1 deletion(-)

Comments

Timo Rothenpieler Sept. 6, 2021, 12:49 p.m. UTC | #1
Series applied.

While testing, I found that constrained encoding for HEVC was not a 
thing until SDK 10.0, so I added the necessary check and compile time 
guards for that.

Also done some other minor style and logic changes, and renamed the 
options to use "-" instead of "_", so the options match their libx264 
counterpart.
Limin Wang Sept. 7, 2021, 1:26 a.m. UTC | #2
On Mon, Sep 06, 2021 at 02:49:47PM +0200, Timo Rothenpieler wrote:
> Series applied.
> 
> While testing, I found that constrained encoding for HEVC was not a thing
> until SDK 10.0, so I added the necessary check and compile time guards for
> that.
> 
> Also done some other minor style and logic changes, and renamed the options
> to use "-" instead of "_", so the options match their libx264 counterpart.
Thanks, I notice libx264 use "-" style, but it's not consistent with other options
of nvenc. So I use "_" instead. I'm not sure what's style is more preferable.



> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Timo Rothenpieler Sept. 7, 2021, 8:35 a.m. UTC | #3
On 07.09.2021 03:26, lance.lmwang@gmail.com wrote:
> On Mon, Sep 06, 2021 at 02:49:47PM +0200, Timo Rothenpieler wrote:
>> Series applied.
>>
>> While testing, I found that constrained encoding for HEVC was not a thing
>> until SDK 10.0, so I added the necessary check and compile time guards for
>> that.
>>
>> Also done some other minor style and logic changes, and renamed the options
>> to use "-" instead of "_", so the options match their libx264 counterpart.
> Thanks, I notice libx264 use "-" style, but it's not consistent with other options
> of nvenc. So I use "_" instead. I'm not sure what's style is more preferable.
> 

The style of nvenc options is already all over the place, and staying in 
line with libx264 seems a bit more important here.

Maybe at some future major bump the options can be cleaned up a bit.
diff mbox series

Patch

diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index 79f3253..5eeb4fe 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -552,6 +552,12 @@  static int nvenc_check_capabilities(AVCodecContext *avctx)
         return AVERROR(ENOSYS);
     }
 
+    ret = nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_CONSTRAINED_ENCODING);
+    if(ctx->constrained_encoding && ret <= 0) {
+        av_log(avctx, AV_LOG_WARNING, "constrained encoding not supported by the device\n");
+        return AVERROR(ENOSYS);
+    }
+
     ctx->support_dyn_bitrate = nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_DYN_BITRATE_CHANGE);
 
     return 0;
@@ -1108,6 +1114,9 @@  static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx)
 #endif
     }
 
+    if (ctx->constrained_encoding)
+        h264->enableConstrainedEncoding = 1;
+
     h264->disableSPSPPS = (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) ? 1 : 0;
     h264->repeatSPSPPS  = (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) ? 0 : 1;
     h264->outputAUD     = ctx->aud;
@@ -1214,6 +1223,9 @@  static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx)
 #endif
     }
 
+    if (ctx->constrained_encoding)
+        hevc->enableConstrainedEncoding = 1;
+
     hevc->disableSPSPPS = (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) ? 1 : 0;
     hevc->repeatSPSPPS  = (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) ? 0 : 1;
     hevc->outputAUD     = ctx->aud;
diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h
index 1e756a6..950c2ab 100644
--- a/libavcodec/nvenc.h
+++ b/libavcodec/nvenc.h
@@ -233,6 +233,7 @@  typedef struct NvencContext
     int extra_sei;
     int intra_refresh;
     int single_slice_intra_refresh;
+    int constrained_encoding;
 } NvencContext;
 
 int ff_nvenc_encode_init(AVCodecContext *avctx);
diff --git a/libavcodec/nvenc_h264.c b/libavcodec/nvenc_h264.c
index 1a46e70..ab7c67f 100644
--- a/libavcodec/nvenc_h264.c
+++ b/libavcodec/nvenc_h264.c
@@ -192,6 +192,8 @@  static const AVOption options[] = {
                                                             OFFSET(intra_refresh),AV_OPT_TYPE_BOOL,  { .i64 = 0 }, 0, 1, VE },
     { "single_slice_intra_refresh", "Use single slice intra refresh.",
                                                             OFFSET(single_slice_intra_refresh), AV_OPT_TYPE_BOOL,  { .i64 = 0 }, 0, 1, VE },
+    { "constrained_encoding", "enable constrainedFrame encoding where each slice in the constrained picture is independent of other slices.",
+                                                            OFFSET(constrained_encoding), AV_OPT_TYPE_BOOL,  { .i64 = 0 }, 0, 1, VE },
     { NULL }
 };
 
diff --git a/libavcodec/nvenc_hevc.c b/libavcodec/nvenc_hevc.c
index 8c89d6e..180e7a3 100644
--- a/libavcodec/nvenc_hevc.c
+++ b/libavcodec/nvenc_hevc.c
@@ -173,6 +173,8 @@  static const AVOption options[] = {
                                                             OFFSET(intra_refresh),AV_OPT_TYPE_BOOL,  { .i64 = 0 }, 0, 1, VE },
     { "single_slice_intra_refresh", "Use single slice intra refresh.",
                                                             OFFSET(single_slice_intra_refresh), AV_OPT_TYPE_BOOL,  { .i64 = 0 }, 0, 1, VE },
+    { "constrained_encoding", "enable constrainedFrame encoding where each slice in the constrained picture is independent of other slices.",
+                                                            OFFSET(constrained_encoding), AV_OPT_TYPE_BOOL,  { .i64 = 0 }, 0, 1, VE },
     { NULL }
 };
 
diff --git a/libavcodec/version.h b/libavcodec/version.h
index d39329b..10f998e 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@ 
 
 #define LIBAVCODEC_VERSION_MAJOR  59
 #define LIBAVCODEC_VERSION_MINOR   6
-#define LIBAVCODEC_VERSION_MICRO 100
+#define LIBAVCODEC_VERSION_MICRO 101
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
                                                LIBAVCODEC_VERSION_MINOR, \