nvenc: Generate bufferingPeriod/pictureTiming SEI
authorTimo Rothenpieler <timo@rothenpieler.org>
Wed, 11 May 2016 08:34:31 +0000 (10:34 +0200)
committerAnton Khirnov <anton@khirnov.net>
Thu, 19 May 2016 12:17:03 +0000 (14:17 +0200)
For some unknown reason enabling these causes proper CBR padding,
so as there are no known downsides just always enable them in CBR mode.

Signed-off-by: Anton Khirnov <anton@khirnov.net>
libavcodec/nvenc.c

index bd704a7..283a71c 100644 (file)
@@ -57,6 +57,9 @@
 
 #define NVENC_CAP 0x30
 #define BITSTREAM_BUFFER_SIZE 1024 * 1024
 
 #define NVENC_CAP 0x30
 #define BITSTREAM_BUFFER_SIZE 1024 * 1024
+#define IS_CBR(rc) (rc == NV_ENC_PARAMS_RC_CBR ||               \
+                    rc == NV_ENC_PARAMS_RC_2_PASS_QUALITY ||    \
+                    rc == NV_ENC_PARAMS_RC_2_PASS_FRAMESIZE_CAP)
 
 #define LOAD_LIBRARY(l, path)                   \
     do {                                        \
 
 #define LOAD_LIBRARY(l, path)                   \
     do {                                        \
@@ -604,6 +607,11 @@ static int nvenc_setup_h264_config(AVCodecContext *avctx)
     if (ctx->flags & NVENC_LOSSLESS)
         h264->qpPrimeYZeroTransformBypassFlag = 1;
 
     if (ctx->flags & NVENC_LOSSLESS)
         h264->qpPrimeYZeroTransformBypassFlag = 1;
 
+    if (IS_CBR(cc->rcParams.rateControlMode)) {
+        h264->outputBufferingPeriodSEI = 1;
+        h264->outputPictureTimingSEI   = 1;
+    }
+
     if (ctx->profile)
         avctx->profile = ctx->profile;
 
     if (ctx->profile)
         avctx->profile = ctx->profile;
 
@@ -648,6 +656,11 @@ static int nvenc_setup_hevc_config(AVCodecContext *avctx)
     hevc->maxNumRefFramesInDPB = avctx->refs;
     hevc->idrPeriod            = cc->gopLength;
 
     hevc->maxNumRefFramesInDPB = avctx->refs;
     hevc->idrPeriod            = cc->gopLength;
 
+    if (IS_CBR(cc->rcParams.rateControlMode)) {
+        hevc->outputBufferingPeriodSEI = 1;
+        hevc->outputPictureTimingSEI   = 1;
+    }
+
     /* No other profile is supported in the current SDK version 5 */
     cc->profileGUID = NV_ENC_HEVC_PROFILE_MAIN_GUID;
     avctx->profile  = FF_PROFILE_HEVC_MAIN;
     /* No other profile is supported in the current SDK version 5 */
     cc->profileGUID = NV_ENC_HEVC_PROFILE_MAIN_GUID;
     avctx->profile  = FF_PROFILE_HEVC_MAIN;