I applied the patch to the current ffmpeg master and made some style adjustments, you can take a look on my github fork:

https://github.com/BtbN/FFmpeg/commit/3b5964c521343b883f92079765148fd630a9370c

I also attached the patch for reference.

Any comments?
From 3b5964c521343b883f92079765148fd630a9370c Mon Sep 17 00:00:00 2001
From: Edward Richards <ericha...@nvidia.com>
Date: Fri, 11 Sep 2015 11:07:10 +0200
Subject: [PATCH] avcodec/nvenc: Optimize nvenc parameters

Add 3 more presets: fast, medium, slow.
Improve min/max QP calculation.
Add more verbose log outputs.
Unify nvenc log messages.

Signed-off-by: Timo Rothenpieler <t...@rothenpieler.org>
---
 libavcodec/nvenc.c | 188 ++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 130 insertions(+), 58 deletions(-)

diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index 3174b01..72f13de 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -334,7 +334,7 @@ static int64_t timestamp_queue_dequeue(NvencDataList* queue)
 do { \
     (f) = (t)LOAD_FUNC(dl_fn->cuda_lib, s); \
     if (!(f)) { \
-        av_log(avctx, AV_LOG_FATAL, "Failed loading %s from CUDA library\n", s); \
+        av_log(avctx, AV_LOG_FATAL, "[nvenc]: Failed loading %s from CUDA library\n", s); \
         goto error; \
     } \
 } while (0)
@@ -354,7 +354,7 @@ static av_cold int nvenc_dyload_cuda(AVCodecContext *avctx)
 #endif
 
     if (!dl_fn->cuda_lib) {
-        av_log(avctx, AV_LOG_FATAL, "Failed loading CUDA library\n");
+        av_log(avctx, AV_LOG_FATAL, "[nvenc]: Failed loading CUDA library\n");
         goto error;
     }
 
@@ -382,7 +382,7 @@ error:
 static av_cold int check_cuda_errors(AVCodecContext *avctx, CUresult err, const char *func)
 {
     if (err != CUDA_SUCCESS) {
-        av_log(avctx, AV_LOG_FATAL, ">> %s - failed with error code 0x%x\n", func, err);
+        av_log(avctx, AV_LOG_FATAL, "[nvenc]: >> %s - failed with error code 0x%x\n", func, err);
         return 0;
     }
     return 1;
@@ -408,7 +408,7 @@ static av_cold int nvenc_check_cuda(AVCodecContext *avctx)
         target_smver = 0x52;
         break;
     default:
-        av_log(avctx, AV_LOG_FATAL, "nvenc: Unknown codec name\n");
+        av_log(avctx, AV_LOG_FATAL, " [nvenc]: Unknown codec name\n");
         goto error;
     }
 
@@ -423,11 +423,11 @@ static av_cold int nvenc_check_cuda(AVCodecContext *avctx)
     check_cuda_errors(dl_fn->cu_device_get_count(&device_count));
 
     if (!device_count) {
-        av_log(avctx, AV_LOG_FATAL, "No CUDA capable devices found\n");
+        av_log(avctx, AV_LOG_FATAL, "[nvenc]: No CUDA capable devices found\n");
         goto error;
     }
 
-    av_log(avctx, AV_LOG_VERBOSE, "%d CUDA capable devices found\n", device_count);
+    av_log(avctx, AV_LOG_VERBOSE, "[nvenc]: %d CUDA capable devices found\n", device_count);
 
     dl_fn->nvenc_device_count = 0;
 
@@ -438,14 +438,14 @@ static av_cold int nvenc_check_cuda(AVCodecContext *avctx)
 
         smver = (smmajor << 4) | smminor;
 
-        av_log(avctx, AV_LOG_VERBOSE, "[ GPU #%d - < %s > has Compute SM %d.%d, NVENC %s ]\n", i, gpu_name, smmajor, smminor, (smver >= target_smver) ? "Available" : "Not Available");
+        av_log(avctx, AV_LOG_VERBOSE, "[nvenc]: [ GPU #%d - < %s > has Compute SM %d.%d, NVENC %s ]\n", i, gpu_name, smmajor, smminor, (smver >= target_smver) ? "Available" : "Not Available");
 
         if (smver >= target_smver)
             dl_fn->nvenc_devices[dl_fn->nvenc_device_count++] = cu_device;
     }
 
     if (!dl_fn->nvenc_device_count) {
-        av_log(avctx, AV_LOG_FATAL, "No NVENC capable devices found\n");
+        av_log(avctx, AV_LOG_FATAL, "[nvenc]: No NVENC capable devices found\n");
         goto error;
     }
 
@@ -483,14 +483,14 @@ static av_cold int nvenc_dyload_nvenc(AVCodecContext *avctx)
 #endif
 
     if (!dl_fn->nvenc_lib) {
-        av_log(avctx, AV_LOG_FATAL, "Failed loading the nvenc library\n");
+        av_log(avctx, AV_LOG_FATAL, "[nvenc]: Failed loading the nvenc library\n");
         goto error;
     }
 
     nvEncodeAPICreateInstance = (PNVENCODEAPICREATEINSTANCE)LOAD_FUNC(dl_fn->nvenc_lib, "NvEncodeAPICreateInstance");
 
     if (!nvEncodeAPICreateInstance) {
-        av_log(avctx, AV_LOG_FATAL, "Failed to load nvenc entrypoint\n");
+        av_log(avctx, AV_LOG_FATAL, "[nvenc]: Failed to load nvenc entrypoint\n");
         goto error;
     }
 
@@ -499,11 +499,11 @@ static av_cold int nvenc_dyload_nvenc(AVCodecContext *avctx)
     nvstatus = nvEncodeAPICreateInstance(&dl_fn->nvenc_funcs);
 
     if (nvstatus != NV_ENC_SUCCESS) {
-        av_log(avctx, AV_LOG_FATAL, "Failed to create nvenc instance\n");
+        av_log(avctx, AV_LOG_FATAL, "[nvenc]: Failed to create nvenc instance\n");
         goto error;
     }
 
-    av_log(avctx, AV_LOG_VERBOSE, "Nvenc initialized successfully\n");
+    av_log(avctx, AV_LOG_VERBOSE, "[nvenc]: Nvenc initialized successfully\n");
 
     return 1;
 
@@ -538,7 +538,7 @@ static av_cold void nvenc_unload_nvenc(AVCodecContext *avctx)
     dl_fn->cu_ctx_pop_current = NULL;
     dl_fn->cu_ctx_destroy = NULL;
 
-    av_log(avctx, AV_LOG_VERBOSE, "Nvenc unloaded\n");
+    av_log(avctx, AV_LOG_VERBOSE, "[nvenc]: Nvenc unloaded\n");
 }
 
 static av_cold int nvenc_encode_init(AVCodecContext *avctx)
@@ -556,6 +556,7 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx)
     int lossless = 0;
     int res = 0;
     int dw, dh;
+    int qp_inter_p;
 
     NvencContext *ctx = avctx->priv_data;
     NvencDynLoadFunctions *dl_fn = &ctx->nvenc_dload_funcs;
@@ -574,7 +575,7 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx)
     encode_session_params.apiVersion = NVENCAPI_VERSION;
 
     if (ctx->gpu >= dl_fn->nvenc_device_count) {
-        av_log(avctx, AV_LOG_FATAL, "Requested GPU %d, but only %d GPUs are available!\n", ctx->gpu, dl_fn->nvenc_device_count);
+        av_log(avctx, AV_LOG_FATAL, "[nvenc]: Requested GPU %d, but only %d GPUs are available!\n", ctx->gpu, dl_fn->nvenc_device_count);
         res = AVERROR(EINVAL);
         goto error;
     }
@@ -583,7 +584,7 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx)
     cu_res = dl_fn->cu_ctx_create(&ctx->cu_context, 4, dl_fn->nvenc_devices[ctx->gpu]); // CU_CTX_SCHED_BLOCKING_SYNC=4, avoid CPU spins
 
     if (cu_res != CUDA_SUCCESS) {
-        av_log(avctx, AV_LOG_FATAL, "Failed creating CUDA context for NVENC: 0x%x\n", (int)cu_res);
+        av_log(avctx, AV_LOG_FATAL, "[nvenc]: Failed creating CUDA context for NVENC: 0x%x\n", (int)cu_res);
         res = AVERROR_EXTERNAL;
         goto error;
     }
@@ -591,7 +592,7 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx)
     cu_res = dl_fn->cu_ctx_pop_current(&cu_context_curr);
 
     if (cu_res != CUDA_SUCCESS) {
-        av_log(avctx, AV_LOG_FATAL, "Failed popping CUDA context: 0x%x\n", (int)cu_res);
+        av_log(avctx, AV_LOG_FATAL, "[nvenc]: Failed popping CUDA context: 0x%x\n", (int)cu_res);
         res = AVERROR_EXTERNAL;
         goto error;
     }
@@ -602,16 +603,25 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx)
     nv_status = p_nvenc->nvEncOpenEncodeSessionEx(&encode_session_params, &ctx->nvencoder);
     if (nv_status != NV_ENC_SUCCESS) {
         ctx->nvencoder = NULL;
-        av_log(avctx, AV_LOG_FATAL, "OpenEncodeSessionEx failed: 0x%x - invalid license key?\n", (int)nv_status);
+        av_log(avctx, AV_LOG_FATAL, "[nvenc]: OpenEncodeSessionEx failed: 0x%x\n", (int)nv_status);
         res = AVERROR_EXTERNAL;
         goto error;
     }
 
     if (ctx->preset) {
-        if (!strcmp(ctx->preset, "hp")) {
-            encoder_preset = NV_ENC_PRESET_HP_GUID;
+        if (!strcmp(ctx->preset, "slow")) {
+            encoder_preset = NV_ENC_PRESET_HQ_GUID;
+            ctx->twopass = 1;
+        } else if (!strcmp(ctx->preset, "medium")) {
+            encoder_preset = NV_ENC_PRESET_HQ_GUID;
+            ctx->twopass = 0;
+        } else if (!strcmp(ctx->preset, "fast")) {
+            encoder_preset = NV_ENC_PRESET_HQ_GUID;
+            ctx->twopass = 0;
         } else if (!strcmp(ctx->preset, "hq")) {
             encoder_preset = NV_ENC_PRESET_HQ_GUID;
+        } else if (!strcmp(ctx->preset, "hp")) {
+            encoder_preset = NV_ENC_PRESET_HP_GUID;
         } else if (!strcmp(ctx->preset, "bd")) {
             encoder_preset = NV_ENC_PRESET_BD_GUID;
         } else if (!strcmp(ctx->preset, "ll")) {
@@ -632,12 +642,16 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx)
         } else if (!strcmp(ctx->preset, "default")) {
             encoder_preset = NV_ENC_PRESET_DEFAULT_GUID;
         } else {
-            av_log(avctx, AV_LOG_FATAL, "Preset \"%s\" is unknown! Supported presets: hp, hq, bd, ll, llhp, llhq, lossless, losslesshp, default\n", ctx->preset);
+            av_log(avctx, AV_LOG_FATAL, "[nvenc]: Preset \"%s\" is unknown! Supported presets: slow, medium, high, hp, hq, bd, ll, llhp, llhq, lossless, losslesshp, default\n", ctx->preset);
             res = AVERROR(EINVAL);
             goto error;
         }
     }
 
+    if (ctx->twopass < 0) {
+        ctx->twopass = isLL;
+    }
+
     switch (avctx->codec->id) {
     case AV_CODEC_ID_H264:
         codec = NV_ENC_CODEC_H264_GUID;
@@ -646,14 +660,14 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx)
         codec = NV_ENC_CODEC_HEVC_GUID;
         break;
     default:
-        av_log(avctx, AV_LOG_ERROR, "nvenc: Unknown codec name\n");
+        av_log(avctx, AV_LOG_ERROR, "[nvenc]: Unknown codec name\n");
         res = AVERROR(EINVAL);
         goto error;
     }
 
     nv_status = p_nvenc->nvEncGetEncodePresetConfig(ctx->nvencoder, codec, encoder_preset, &preset_config);
     if (nv_status != NV_ENC_SUCCESS) {
-        av_log(avctx, AV_LOG_FATAL, "GetEncodePresetConfig failed: 0x%x\n", (int)nv_status);
+        av_log(avctx, AV_LOG_FATAL, "[nvenc]: GetEncodePresetConfig failed: 0x%x\n", (int)nv_status);
         res = AVERROR_EXTERNAL;
         goto error;
     }
@@ -728,6 +742,8 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx)
         switch (avctx->codec->id) {
         case AV_CODEC_ID_H264:
             ctx->encode_config.encodeCodecConfig.h264Config.idrPeriod = avctx->gop_size;
+            ctx->encode_config.encodeCodecConfig.h264Config.hierarchicalPFrames = 1;
+            ctx->encode_config.encodeCodecConfig.h264Config.hierarchicalBFrames = 1;
             break;
         case AV_CODEC_ID_H265:
             ctx->encode_config.encodeCodecConfig.hevcConfig.idrPeriod = avctx->gop_size;
@@ -758,6 +774,13 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx)
     if (avctx->rc_max_rate > 0)
         ctx->encode_config.rcParams.maxBitRate = avctx->rc_max_rate;
 
+    av_log(avctx, AV_LOG_VERBOSE, "[nvenc]: avctx->global_quality %d\n", avctx->global_quality);
+    av_log(avctx, AV_LOG_VERBOSE, "[nvenc]: avctx->qmin %d\n[nvenc]: avctx->qmax %d\n", avctx->qmin, avctx->qmax);
+    av_log(avctx, AV_LOG_VERBOSE, "[nvenc]: avctx->i_quant_factor|offset (I-P Ratio) %lf + %lf\n", avctx->i_quant_factor, avctx->i_quant_offset);
+    av_log(avctx, AV_LOG_VERBOSE, "[nvenc]: avctx->b_quant_factor|offset (I-B Ratio) %lf + %lf\n", avctx->b_quant_factor, avctx->b_quant_offset);
+    av_log(avctx, AV_LOG_VERBOSE, "[nvenc]: avctx->gop_size %d -> ctx->encode_config.gopLength %d\n", avctx->gop_size,ctx->encode_config.gopLength);
+    av_log(avctx, AV_LOG_VERBOSE, "[nvenc]: avctx->max_b_frames %d + 1 -> ctx->encode_config.frameIntervalP %d\n", avctx->max_b_frames,ctx->encode_config.frameIntervalP);
+
     if (lossless) {
         if (avctx->codec->id == AV_CODEC_ID_H264)
             ctx->encode_config.encodeCodecConfig.h264Config.qpPrimeYZeroTransformBypassFlag = 1;
@@ -772,15 +795,13 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx)
     } else if (ctx->cbr) {
         if (!ctx->twopass) {
             ctx->encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_CBR;
-        } else if (ctx->twopass == 1 || isLL) {
+        } else {
             ctx->encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_2_PASS_QUALITY;
 
             if (avctx->codec->id == AV_CODEC_ID_H264) {
                 ctx->encode_config.encodeCodecConfig.h264Config.adaptiveTransformMode = NV_ENC_H264_ADAPTIVE_TRANSFORM_ENABLE;
                 ctx->encode_config.encodeCodecConfig.h264Config.fmoMode = NV_ENC_H264_FMO_DISABLE;
             }
-        } else {
-            ctx->encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_CBR;
         }
     } else if (avctx->global_quality > 0) {
         ctx->encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_CONSTQP;
@@ -791,7 +812,7 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx)
         avctx->qmin = -1;
         avctx->qmax = -1;
     } else if (avctx->qmin >= 0 && avctx->qmax >= 0) {
-        if (ctx->twopass == 1) {
+        if (ctx->twopass) {
             ctx->encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_2_PASS_VBR;
 
             if (avctx->codec->id == AV_CODEC_ID_H264) {
@@ -799,19 +820,70 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx)
                 ctx->encode_config.encodeCodecConfig.h264Config.fmoMode = NV_ENC_H264_FMO_DISABLE;
             }
         } else {
-            ctx->encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_VBR;
+            ctx->encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_VBR_MINQP;
         }
 
         ctx->encode_config.rcParams.enableMinQP = 1;
         ctx->encode_config.rcParams.enableMaxQP = 1;
 
-        ctx->encode_config.rcParams.minQP.qpInterB = avctx->qmin;
-        ctx->encode_config.rcParams.minQP.qpInterP = avctx->qmin;
+        ctx->encode_config.rcParams.minQP.qpInterB = avctx->qmin; // * fabs(avctx->b_quant_factor);
+        ctx->encode_config.rcParams.minQP.qpInterP = avctx->qmin; // * fabs(avctx->i_quant_factor);
         ctx->encode_config.rcParams.minQP.qpIntra = avctx->qmin;
 
-        ctx->encode_config.rcParams.maxQP.qpInterB = avctx->qmax;
-        ctx->encode_config.rcParams.maxQP.qpInterP = avctx->qmax;
+        ctx->encode_config.rcParams.maxQP.qpInterB = avctx->qmax; // / fabs(avctx->b_quant_factor);
+        ctx->encode_config.rcParams.maxQP.qpInterP = avctx->qmax; // / fabs(avctx->i_quant_factor);
         ctx->encode_config.rcParams.maxQP.qpIntra = avctx->qmax;
+
+        av_log(avctx, AV_LOG_VERBOSE, "[nvenc]: minQP.qpIntra %d\n", ctx->encode_config.rcParams.minQP.qpIntra);
+        av_log(avctx, AV_LOG_VERBOSE, "[nvenc]: minQP.qpInterP (I-P Ratio) %d\n", ctx->encode_config.rcParams.minQP.qpInterP);
+        av_log(avctx, AV_LOG_VERBOSE, "[nvenc]: minQP.qpInterB (I-B Ratio) %d\n", ctx->encode_config.rcParams.minQP.qpInterB);
+        av_log(avctx, AV_LOG_VERBOSE, "[nvenc]: maxQP.qpIntra %d\n", ctx->encode_config.rcParams.maxQP.qpIntra);
+        av_log(avctx, AV_LOG_VERBOSE, "[nvenc]: maxQP.qpInterP (I-P Ratio) %d\n", ctx->encode_config.rcParams.maxQP.qpInterP);
+        av_log(avctx, AV_LOG_VERBOSE, "[nvenc]: maxQP.qpInterB (I-B Ratio) %d\n", ctx->encode_config.rcParams.maxQP.qpInterB);
+
+        qp_inter_p = (avctx->qmax + 3 * avctx->qmin) / 4; // biased towards Qmin
+        ctx->encode_config.rcParams.initialRCQP.qpInterP  = qp_inter_p;
+
+        if (avctx->i_quant_factor != 0.0 && avctx->b_quant_factor != 0.0) {
+            ctx->encode_config.rcParams.initialRCQP.qpIntra = qp_inter_p * fabs(avctx->i_quant_factor);
+            ctx->encode_config.rcParams.initialRCQP.qpIntra += qp_inter_p * avctx->i_quant_offset;
+            ctx->encode_config.rcParams.initialRCQP.qpInterB = qp_inter_p * fabs(avctx->b_quant_factor);
+            ctx->encode_config.rcParams.initialRCQP.qpInterB += qp_inter_p * avctx->b_quant_offset;
+        } else {
+            ctx->encode_config.rcParams.initialRCQP.qpIntra = qp_inter_p;
+            ctx->encode_config.rcParams.initialRCQP.qpInterB = qp_inter_p;
+        }
+
+        ctx->encode_config.rcParams.enableInitialRCQP = 1;
+
+        av_log(avctx, AV_LOG_VERBOSE, "[nvenc]: initialRCQP.qpIntra %d\n", ctx->encode_config.rcParams.initialRCQP.qpIntra);
+        av_log(avctx, AV_LOG_VERBOSE, "[nvenc]: initialRCQP.qpInterP (I-P Ratio) %d\n", ctx->encode_config.rcParams.initialRCQP.qpInterP);
+        av_log(avctx, AV_LOG_VERBOSE, "[nvenc]: initialRCQP.qpInterB (I-B Ratio) %d\n", ctx->encode_config.rcParams.initialRCQP.qpInterB);
+    } else {
+        if (!ctx->twopass) {
+            ctx->encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_VBR;
+        } else {
+            ctx->encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_2_PASS_VBR;
+        }
+
+        qp_inter_p = 26; // default to 26
+        ctx->encode_config.rcParams.initialRCQP.qpInterP = qp_inter_p;
+
+        if(avctx->i_quant_factor != 0.0 && avctx->b_quant_factor != 0.0) {
+            ctx->encode_config.rcParams.initialRCQP.qpIntra = qp_inter_p * fabs(avctx->i_quant_factor);
+            ctx->encode_config.rcParams.initialRCQP.qpIntra += qp_inter_p * avctx->i_quant_offset;
+            ctx->encode_config.rcParams.initialRCQP.qpInterB = qp_inter_p * fabs(avctx->b_quant_factor);
+            ctx->encode_config.rcParams.initialRCQP.qpInterB += qp_inter_p * avctx->b_quant_offset;
+        } else {
+            ctx->encode_config.rcParams.initialRCQP.qpIntra = qp_inter_p;
+            ctx->encode_config.rcParams.initialRCQP.qpInterB = qp_inter_p;
+        }
+
+        ctx->encode_config.rcParams.enableInitialRCQP = 1;
+
+        av_log(avctx, AV_LOG_VERBOSE, "[nvenc]: initialRCQP.qpIntra %d\n", ctx->encode_config.rcParams.initialRCQP.qpIntra);
+        av_log(avctx, AV_LOG_VERBOSE, "[nvenc]: initialRCQP.qpInterP (I-P Ratio) %d\n", ctx->encode_config.rcParams.initialRCQP.qpInterP);
+        av_log(avctx, AV_LOG_VERBOSE, "[nvenc]: initialRCQP.qpInterB (I-B Ratio) %d\n", ctx->encode_config.rcParams.initialRCQP.qpInterB);
     }
 
     if (avctx->rc_buffer_size > 0)
@@ -853,7 +925,7 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx)
                 ctx->encode_config.profileGUID = NV_ENC_H264_PROFILE_HIGH_GUID;
                 break;
             default:
-                av_log(avctx, AV_LOG_WARNING, "Unsupported profile requested, falling back to high\n");
+                av_log(avctx, AV_LOG_WARNING, "[nvenc]: Unsupported profile requested, falling back to high\n");
                 ctx->encode_config.profileGUID = NV_ENC_H264_PROFILE_HIGH_GUID;
                 break;
             }
@@ -871,7 +943,7 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx)
                 ctx->encode_config.profileGUID = NV_ENC_H264_PROFILE_HIGH_444_GUID;
                 avctx->profile = FF_PROFILE_H264_HIGH_444_PREDICTIVE;
             } else {
-                av_log(avctx, AV_LOG_FATAL, "Profile \"%s\" is unknown! Supported profiles: high, main, baseline\n", ctx->profile);
+                av_log(avctx, AV_LOG_FATAL, "[nvenc]: Profile \"%s\" is unknown! Supported profiles: high, main, baseline\n", ctx->profile);
                 res = AVERROR(EINVAL);
                 goto error;
             }
@@ -883,7 +955,7 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx)
             res = input_string_to_uint32(avctx, nvenc_h264_level_pairs, ctx->level, &ctx->encode_config.encodeCodecConfig.h264Config.level);
 
             if (res) {
-                av_log(avctx, AV_LOG_FATAL, "Level \"%s\" is unknown! Supported levels: auto, 1, 1b, 1.1, 1.2, 1.3, 2, 2.1, 2.2, 3, 3.1, 3.2, 4, 4.1, 4.2, 5, 5.1\n", ctx->level);
+                av_log(avctx, AV_LOG_FATAL, "[nvenc]: Level \"%s\" is unknown! Supported levels: auto, 1, 1b, 1.1, 1.2, 1.3, 2, 2.1, 2.2, 3, 3.1, 3.2, 4, 4.1, 4.2, 5, 5.1\n", ctx->level);
                 goto error;
             }
         } else {
@@ -903,7 +975,7 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx)
             res = input_string_to_uint32(avctx, nvenc_hevc_level_pairs, ctx->level, &ctx->encode_config.encodeCodecConfig.hevcConfig.level);
 
             if (res) {
-                av_log(avctx, AV_LOG_FATAL, "Level \"%s\" is unknown! Supported levels: auto, 1, 2, 2.1, 3, 3.1, 4, 4.1, 5, 5.1, 5.2, 6, 6.1, 6.2\n", ctx->level);
+                av_log(avctx, AV_LOG_FATAL, "[nvenc]: Level \"%s\" is unknown! Supported levels: auto, 1, 2, 2.1, 3, 3.1, 4, 4.1, 5, 5.1, 5.2, 6, 6.1, 6.2\n", ctx->level);
                 goto error;
             }
         } else {
@@ -916,7 +988,7 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx)
             } else if (!strcmp(ctx->tier, "high")) {
                 ctx->encode_config.encodeCodecConfig.hevcConfig.tier = NV_ENC_TIER_HEVC_HIGH;
             } else {
-                av_log(avctx, AV_LOG_FATAL, "Tier \"%s\" is unknown! Supported tiers: main, high\n", ctx->tier);
+                av_log(avctx, AV_LOG_FATAL, "[nvenc]: Tier \"%s\" is unknown! Supported tiers: main, high\n", ctx->tier);
                 res = AVERROR(EINVAL);
                 goto error;
             }
@@ -928,7 +1000,7 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx)
 
     nv_status = p_nvenc->nvEncInitializeEncoder(ctx->nvencoder, &ctx->init_encode_params);
     if (nv_status != NV_ENC_SUCCESS) {
-        av_log(avctx, AV_LOG_FATAL, "InitializeEncoder failed: 0x%x\n", (int)nv_status);
+        av_log(avctx, AV_LOG_FATAL, "[nvenc]: InitializeEncoder failed: 0x%x\n", (int)nv_status);
         res = AVERROR_EXTERNAL;
         goto error;
     }
@@ -972,14 +1044,14 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx)
             break;
 
         default:
-            av_log(avctx, AV_LOG_FATAL, "Invalid input pixel format\n");
+            av_log(avctx, AV_LOG_FATAL, "[nvenc]: Invalid input pixel format\n");
             res = AVERROR(EINVAL);
             goto error;
         }
 
         nv_status = p_nvenc->nvEncCreateInputBuffer(ctx->nvencoder, &allocSurf);
         if (nv_status != NV_ENC_SUCCESS) {
-            av_log(avctx, AV_LOG_FATAL, "CreateInputBuffer failed\n");
+            av_log(avctx, AV_LOG_FATAL, "[nvenc]: CreateInputBuffer failed\n");
             res = AVERROR_EXTERNAL;
             goto error;
         }
@@ -997,7 +1069,7 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx)
 
         nv_status = p_nvenc->nvEncCreateBitstreamBuffer(ctx->nvencoder, &allocOut);
         if (nv_status != NV_ENC_SUCCESS) {
-            av_log(avctx, AV_LOG_FATAL, "CreateBitstreamBuffer failed\n");
+            av_log(avctx, AV_LOG_FATAL, "[nvenc]: CreateBitstreamBuffer failed\n");
             ctx->output_surfaces[surfaceCount++].output_surface = NULL;
             res = AVERROR_EXTERNAL;
             goto error;
@@ -1020,7 +1092,7 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx)
 
         nv_status = p_nvenc->nvEncGetSequenceParams(ctx->nvencoder, &payload);
         if (nv_status != NV_ENC_SUCCESS) {
-            av_log(avctx, AV_LOG_FATAL, "GetSequenceParams failed\n");
+            av_log(avctx, AV_LOG_FATAL, "[nvenc]: GetSequenceParams failed\n");
             goto error;
         }
 
@@ -1113,7 +1185,7 @@ static int process_output_surface(AVCodecContext *avctx, AVPacket *pkt, NvencOut
       slice_mode_data = ctx->encode_config.encodeCodecConfig.hevcConfig.sliceModeData;
       break;
     default:
-      av_log(avctx, AV_LOG_ERROR, "nvenc: Unknown codec name\n");
+      av_log(avctx, AV_LOG_ERROR, "[nvenc]: Unknown codec name\n");
       res = AVERROR(EINVAL);
       goto error;
     }
@@ -1130,12 +1202,12 @@ static int process_output_surface(AVCodecContext *avctx, AVPacket *pkt, NvencOut
 
     nv_status = p_nvenc->nvEncLockBitstream(ctx->nvencoder, &lock_params);
     if (nv_status != NV_ENC_SUCCESS) {
-        av_log(avctx, AV_LOG_ERROR, "Failed locking bitstream buffer\n");
+        av_log(avctx, AV_LOG_ERROR, "[nvenc]: Failed locking bitstream buffer\n");
         res = AVERROR_EXTERNAL;
         goto error;
     }
 
-    if (res = ff_alloc_packet2(avctx, pkt, lock_params.bitstreamSizeInBytes, 0)) {
+    if (res = ff_alloc_packet2(avctx, pkt, lock_params.bitstreamSizeInBytes,0)) {
         p_nvenc->nvEncUnlockBitstream(ctx->nvencoder, tmpoutsurf->output_surface);
         goto error;
     }
@@ -1144,7 +1216,7 @@ static int process_output_surface(AVCodecContext *avctx, AVPacket *pkt, NvencOut
 
     nv_status = p_nvenc->nvEncUnlockBitstream(ctx->nvencoder, tmpoutsurf->output_surface);
     if (nv_status != NV_ENC_SUCCESS)
-        av_log(avctx, AV_LOG_ERROR, "Failed unlocking bitstream buffer, expect the gates of mordor to open\n");
+        av_log(avctx, AV_LOG_ERROR, "[nvenc]: Failed unlocking bitstream buffer, expect the gates of mordor to open\n");
 
     switch (lock_params.pictureType) {
     case NV_ENC_PIC_TYPE_IDR:
@@ -1164,8 +1236,8 @@ FF_DISABLE_DEPRECATION_WARNINGS
         avctx->coded_frame->pict_type = AV_PICTURE_TYPE_BI;
         break;
     default:
-        av_log(avctx, AV_LOG_ERROR, "Unknown picture type encountered, expect the output to be broken.\n");
-        av_log(avctx, AV_LOG_ERROR, "Please report this error and include as much information on how to reproduce it as possible.\n");
+        av_log(avctx, AV_LOG_ERROR, "[nvenc]: Unknown picture type encountered, expect the output to be broken.\n");
+        av_log(avctx, AV_LOG_ERROR, "         Please report this error and include as much information on how to reproduce it as possible.\n");
         res = AVERROR_EXTERNAL;
         goto error;
 FF_ENABLE_DEPRECATION_WARNINGS
@@ -1233,7 +1305,7 @@ static int nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
 
         nv_status = p_nvenc->nvEncLockInputBuffer(ctx->nvencoder, &lockBufferParams);
         if (nv_status != NV_ENC_SUCCESS) {
-            av_log(avctx, AV_LOG_ERROR, "Failed locking nvenc input buffer\n");
+            av_log(avctx, AV_LOG_ERROR, "[nvenc]: Failed locking nvenc input buffer\n");
             return 0;
         }
 
@@ -1286,13 +1358,13 @@ static int nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
                 frame->data[2], frame->linesize[2],
                 avctx->width, avctx->height);
         } else {
-            av_log(avctx, AV_LOG_FATAL, "Invalid pixel format!\n");
+            av_log(avctx, AV_LOG_FATAL, "[nvenc]: Invalid pixel format!\n");
             return AVERROR(EINVAL);
         }
 
         nv_status = p_nvenc->nvEncUnlockInputBuffer(ctx->nvencoder, inSurf->input_surface);
         if (nv_status != NV_ENC_SUCCESS) {
-            av_log(avctx, AV_LOG_FATAL, "Failed unlocking input buffer!\n");
+            av_log(avctx, AV_LOG_FATAL, "[nvenc]: Failed unlocking input buffer!\n");
             return AVERROR_EXTERNAL;
         }
 
@@ -1302,7 +1374,7 @@ static int nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
 
         if (i == ctx->max_surface_count) {
             inSurf->lockCount = 0;
-            av_log(avctx, AV_LOG_FATAL, "No free output surface found!\n");
+            av_log(avctx, AV_LOG_FATAL, "[nvenc]: No free output surface found!\n");
             return AVERROR_EXTERNAL;
         }
 
@@ -1338,7 +1410,7 @@ static int nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
           pic_params.codecPicParams.hevcPicParams.sliceModeData = ctx->encode_config.encodeCodecConfig.hevcConfig.sliceModeData;
           break;
         default:
-          av_log(avctx, AV_LOG_ERROR, "nvenc: Unknown codec name\n");
+          av_log(avctx, AV_LOG_ERROR, "[nvenc]: Unknown codec name\n");
           return AVERROR(EINVAL);
         }
 
@@ -1362,7 +1434,7 @@ static int nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     }
 
     if (nv_status != NV_ENC_SUCCESS && nv_status != NV_ENC_ERR_NEED_MORE_INPUT) {
-        av_log(avctx, AV_LOG_ERROR, "EncodePicture failed!\n");
+        av_log(avctx, AV_LOG_ERROR, "[nvenc]: EncodePicture failed!\n");
         return AVERROR_EXTERNAL;
     }
 
@@ -1415,12 +1487,12 @@ static const enum AVPixelFormat pix_fmts_nvenc[] = {
 #define OFFSET(x) offsetof(NvencContext, x)
 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 static const AVOption options[] = {
-    { "preset", "Set the encoding preset (one of hq, hp, bd, ll, llhq, llhp, default)", OFFSET(preset), AV_OPT_TYPE_STRING, { .str = "hq" }, 0, 0, VE },
+    { "preset", "Set the encoding preset (one of slow = hq 2pass, medium = hq, fast = hp, hq, hp, bd, ll, llhq, llhp, default)", OFFSET(preset), AV_OPT_TYPE_STRING, { .str = "hq" }, 0, 0, VE },
     { "profile", "Set the encoding profile (high, main or baseline)", OFFSET(profile), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
     { "level", "Set the encoding level restriction (auto, 1.0, 1.0b, 1.1, 1.2, ..., 4.2, 5.0, 5.1)", OFFSET(level), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
     { "tier", "Set the encoding tier (main or high)", OFFSET(tier), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
     { "cbr", "Use cbr encoding mode", OFFSET(cbr), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
-    { "2pass", "Use 2pass cbr encoding mode", OFFSET(twopass), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE },
+    { "2pass", "Use 2pass encoding mode", OFFSET(twopass), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE },
     { "gpu", "Selects which NVENC capable GPU to use. First GPU is 0, second is 1, and so on.", OFFSET(gpu), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
     { "delay", "Delays frame output by the given amount of frames.", OFFSET(buffer_delay), AV_OPT_TYPE_INT, { .i64 = INT_MAX }, 0, INT_MAX, VE },
     { NULL }
@@ -1446,7 +1518,7 @@ static const AVClass nvenc_class = {
 
 AVCodec ff_nvenc_encoder = {
     .name = "nvenc",
-    .long_name = NULL_IF_CONFIG_SMALL("Nvidia NVENC h264 encoder"),
+    .long_name = NULL_IF_CONFIG_SMALL("NVIDIA NVENC h264 encoder"),
     .type = AVMEDIA_TYPE_VIDEO,
     .id = AV_CODEC_ID_H264,
     .priv_data_size = sizeof(NvencContext),
@@ -1471,7 +1543,7 @@ static const AVClass nvenc_h264_class = {
 
 AVCodec ff_nvenc_h264_encoder = {
     .name = "nvenc_h264",
-    .long_name = NULL_IF_CONFIG_SMALL("Nvidia NVENC h264 encoder"),
+    .long_name = NULL_IF_CONFIG_SMALL("NVIDIA NVENC h264 encoder"),
     .type = AVMEDIA_TYPE_VIDEO,
     .id = AV_CODEC_ID_H264,
     .priv_data_size = sizeof(NvencContext),
@@ -1495,7 +1567,7 @@ static const AVClass nvenc_hevc_class = {
 
 AVCodec ff_nvenc_hevc_encoder = {
     .name = "nvenc_hevc",
-    .long_name = NULL_IF_CONFIG_SMALL("Nvidia NVENC hevc encoder"),
+    .long_name = NULL_IF_CONFIG_SMALL("NVIDIA NVENC hevc encoder"),
     .type = AVMEDIA_TYPE_VIDEO,
     .id = AV_CODEC_ID_H265,
     .priv_data_size = sizeof(NvencContext),
-- 
2.5.1

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to