summaryrefslogtreecommitdiff
path: root/libavcodec/nvenc.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2016-05-11 15:38:35 +0200
committerAnton Khirnov <anton@khirnov.net>2016-05-19 14:08:55 +0200
commit9427d92f40d4ab981f0b24e8e1d1cdec1d845ac1 (patch)
tree7907f072adfa223d057e2cdadb4b532c602cf9e5 /libavcodec/nvenc.c
parent795329dd4c5d100bb7c633b1a5d3145090a7a420 (diff)
nvenc: add support for lossless encoding
Based on a patch by Philip Langdale <philipl@overt.org>
Diffstat (limited to 'libavcodec/nvenc.c')
-rw-r--r--libavcodec/nvenc.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index 943cfbefba..97922453f7 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -494,6 +494,14 @@ static void set_vbr(AVCodecContext *avctx, NV_ENC_RC_PARAMS *rc)
}
}
+static void set_lossless(AVCodecContext *avctx, NV_ENC_RC_PARAMS *rc)
+{
+ rc->rateControlMode = NV_ENC_PARAMS_RC_CONSTQP;
+ rc->constQP.qpInterB = 0;
+ rc->constQP.qpInterP = 0;
+ rc->constQP.qpIntra = 0;
+}
+
static void nvenc_override_rate_control(AVCodecContext *avctx,
NV_ENC_RC_PARAMS *rc)
{
@@ -554,6 +562,8 @@ static void nvenc_setup_rate_control(AVCodecContext *avctx)
if (ctx->rc > 0) {
nvenc_override_rate_control(avctx, rc);
+ } else if (ctx->flags & NVENC_LOSSLESS) {
+ set_lossless(avctx, rc);
} else if (avctx->global_quality > 0) {
set_constqp(avctx, rc);
} else if (avctx->qmin >= 0 && avctx->qmax >= 0) {
@@ -591,6 +601,9 @@ static int nvenc_setup_h264_config(AVCodecContext *avctx)
h264->maxNumRefFrames = avctx->refs;
h264->idrPeriod = cc->gopLength;
+ if (ctx->flags & NVENC_LOSSLESS)
+ h264->qpPrimeYZeroTransformBypassFlag = 1;
+
if (ctx->profile)
avctx->profile = ctx->profile;