From: Yogender Gupta <ygu...@nvidia.com> As provided by SDK 7. --- doc/APIchanges | 3 +++ libavcodec/nvenc.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ libavcodec/nvenc.h | 10 ++++++++++ libavcodec/nvenc_h264.c | 10 ++++++++++ libavcodec/nvenc_hevc.c | 8 ++++++++ libavcodec/version.h | 2 +- 6 files changed, 77 insertions(+), 1 deletion(-)
diff --git a/doc/APIchanges b/doc/APIchanges index 5aefa81..b57c420 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -13,6 +13,9 @@ libavutil: 2015-08-28 API changes, most recent first: +2016-xx-xx - xxxxxxx - lavc 59.28.0 - nvenc.c + Use the SDK 7 extended support for HEVC and rate-control improvements. + 2016-xx-xx - xxxxxxx - lavc 59.27.0 - avcodec.h Add the extended pixel format profile for HEVC. diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index d951d9e..6e0e4a6 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -600,6 +600,51 @@ static void nvenc_setup_rate_control(AVCodecContext *avctx) if (rc->averageBitRate > 0) avctx->bit_rate = rc->averageBitRate; + + if (ctx->aq) { + ctx->config.rcParams.enableAQ = 1; + ctx->config.rcParams.aqStrength = ctx->aq_strength; + av_log(avctx, AV_LOG_VERBOSE, "AQ Enabled\n"); + } + + if (ctx->temporal_aq) { + ctx->config.rcParams.enableTemporalAQ = 1; + av_log(avctx, AV_LOG_VERBOSE, "Temporal AQ Enabled\n"); + } + + if (ctx->rc_lookahead) { + int lkd_bound = FFMIN(ctx->nb_surfaces, ctx->async_depth) - + ctx->config.frameIntervalP - 4; + + if (lkd_bound < 0) { + av_log(avctx, AV_LOG_WARNING, + "Lookahead Not Enabled. Increase Buffer Delay (-delay)\n"); + } else { + ctx->config.rcParams.enableLookahead = 1; + ctx->config.rcParams.lookaheadDepth = av_clip(ctx->rc_lookahead, 0, lkd_bound); + ctx->config.rcParams.disableIadapt = ctx->no_scenecut; + ctx->config.rcParams.disableBadapt = !ctx->b_adapt; + av_log(avctx, AV_LOG_VERBOSE, + "Lookahead Enabled: depth %d, Scenecut %s, B-Adapt %s\n", + ctx->config.rcParams.lookaheadDepth, + ctx->config.rcParams.disableIadapt ? "Disabled" : "Enabled", + ctx->config.rcParams.disableBadapt ? "Disabled" : "Enabled"); + } + } + + if (ctx->strict_gop) { + ctx->config.rcParams.strictGOPTarget = 1; + av_log(avctx, AV_LOG_VERBOSE, "Strict GOP Target Enabled\n"); + } + + if (ctx->nonref_p) + ctx->config.rcParams.enableNonRefP = 1; + + if (ctx->zerolatency) + ctx->config.rcParams.zeroReorderDelay = 1; + + if (ctx->quality) + ctx->config.rcParams.targetQuality = ctx->quality; } static int nvenc_setup_h264_config(AVCodecContext *avctx) diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h index fddf433..dfd03b5 100644 --- a/libavcodec/nvenc.h +++ b/libavcodec/nvenc.h @@ -171,6 +171,16 @@ typedef struct NVENCContext { int device; int flags; int async_depth; + int rc_lookahead; + int aq; + int no_scenecut; + int b_adapt; + int temporal_aq; + int zerolatency; + int nonref_p; + int strict_gop; + int aq_strength; + int quality; } NVENCContext; int ff_nvenc_encode_init(AVCodecContext *avctx); diff --git a/libavcodec/nvenc_h264.c b/libavcodec/nvenc_h264.c index d58ee88..59e25b1 100644 --- a/libavcodec/nvenc_h264.c +++ b/libavcodec/nvenc_h264.c @@ -71,12 +71,22 @@ static const AVOption options[] = { { "ll_2pass_quality", "Multi-pass optimized for image quality (only for low-latency presets)", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_PARAMS_RC_2_PASS_QUALITY }, 0, 0, VE, "rc" }, { "ll_2pass_size", "Multi-pass optimized for constant frame size (only for low-latency presets)", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_PARAMS_RC_2_PASS_FRAMESIZE_CAP }, 0, 0, VE, "rc" }, { "vbr_2pass", "Multi-pass variable bitrate mode", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_PARAMS_RC_2_PASS_VBR }, 0, 0, VE, "rc" }, + { "rc-lookahead", "Number of frames to look ahead for rate-control", OFFSET(rc_lookahead), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE }, { "surfaces", "Number of concurrent surfaces", OFFSET(nb_surfaces), AV_OPT_TYPE_INT, { .i64 = 32 }, 0, INT_MAX, VE }, { "device", "Select a specific NVENC device", OFFSET(device), AV_OPT_TYPE_INT, { .i64 = -1 }, -2, INT_MAX, VE, "device" }, { "any", "Pick the first device available", 0, AV_OPT_TYPE_CONST, { .i64 = ANY_DEVICE }, 0, 0, VE, "device" }, { "list", "List the available devices", 0, AV_OPT_TYPE_CONST, { .i64 = LIST_DEVICES }, 0, 0, VE, "device" }, { "async_depth", "Delay frame output by the given amount of frames", OFFSET(async_depth), AV_OPT_TYPE_INT, { .i64 = INT_MAX }, 0, INT_MAX, VE }, { "delay", "Delay frame output by the given amount of frames", 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_INT, { .i64 = 0 }, 0, 1, VE }, + { "b_adapt", "When lookahead is enabled, set this to 0 to disable adaptive B-frame decision", OFFSET(b_adapt), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, VE }, + { "spatial-aq", "set to 1 to enable Spatial AQ", OFFSET(aq), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, + { "temporal-aq", "set to 1 to enable Temporal AQ", OFFSET(temporal_aq), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, + { "zerolatency", "Set 1 to indicate zero latency operation (no reordering delay)", OFFSET(zerolatency), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, + { "nonref_p", "Set this to 1 to enable automatic insertion of non-reference P-frames", OFFSET(nonref_p), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, + { "strict_gop", "Set 1 to minimize GOP-to-GOP rate fluctuations", OFFSET(strict_gop), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, + { "aq-strength", "When Spatial AQ is enabled, this field is used to specify AQ strength. AQ strength scale is from 1 (low) - 15 (aggressive)", OFFSET(aq_strength), AV_OPT_TYPE_INT, { .i64 = 8 }, 1, 15, VE }, + { "cq", "Set target quality level (0 to 51, 0-automatic) for constant quality mode in VBR rate control", OFFSET(quality), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 51, VE }, { NULL } }; diff --git a/libavcodec/nvenc_hevc.c b/libavcodec/nvenc_hevc.c index 7cee3c2..873d287 100644 --- a/libavcodec/nvenc_hevc.c +++ b/libavcodec/nvenc_hevc.c @@ -69,12 +69,20 @@ static const AVOption options[] = { { "ll_2pass_quality", "Multi-pass optimized for image quality (only for low-latency presets)", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_PARAMS_RC_2_PASS_QUALITY }, 0, 0, VE, "rc" }, { "ll_2pass_size", "Multi-pass optimized for constant frame size (only for low-latency presets)", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_PARAMS_RC_2_PASS_FRAMESIZE_CAP }, 0, 0, VE, "rc" }, { "vbr_2pass", "Multi-pass variable bitrate mode", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_PARAMS_RC_2_PASS_VBR }, 0, 0, VE, "rc" }, + { "rc-lookahead", "Number of frames to look ahead for rate-control", OFFSET(rc_lookahead), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE }, { "surfaces", "Number of concurrent surfaces", OFFSET(nb_surfaces), AV_OPT_TYPE_INT, { .i64 = 32 }, 0, INT_MAX, VE }, { "device", "Select a specific NVENC device", OFFSET(device), AV_OPT_TYPE_INT, { .i64 = -1 }, -2, INT_MAX, VE, "device" }, { "any", "Pick the first device available", 0, AV_OPT_TYPE_CONST, { .i64 = ANY_DEVICE }, 0, 0, VE, "device" }, { "list", "List the available devices", 0, AV_OPT_TYPE_CONST, { .i64 = LIST_DEVICES }, 0, 0, VE, "device" }, { "async_depth", "Delay frame output by the given amount of frames", OFFSET(async_depth), AV_OPT_TYPE_INT, { .i64 = INT_MAX }, 0, INT_MAX, VE }, { "delay", "Delay frame output by the given amount of frames", 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_INT, { .i64 = 0 }, 0, 1, VE }, + { "spatial_aq", "set to 1 to enable Spatial AQ", OFFSET(aq), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, + { "zerolatency", "Set 1 to indicate zero latency operation (no reordering delay)", OFFSET(zerolatency), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, + { "nonref_p", "Set this to 1 to enable automatic insertion of non-reference P-frames", OFFSET(nonref_p), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, + { "strict_gop", "Set 1 to minimize GOP-to-GOP rate fluctuations", OFFSET(strict_gop), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, + { "aq-strength", "When Spatial AQ is enabled, this field is used to specify AQ strength. AQ strength scale is from 1 (low) - 15 (aggressive)", OFFSET(aq_strength), AV_OPT_TYPE_INT, { .i64 = 8 }, 1, 15, VE }, + { "cq", "Set target quality level (0 to 51, 0-automatic) for constant quality mode in VBR rate control", OFFSET(quality), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 51, VE }, { NULL } }; diff --git a/libavcodec/version.h b/libavcodec/version.h index 20edb61..64b0ee6 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -28,7 +28,7 @@ #include "libavutil/version.h" #define LIBAVCODEC_VERSION_MAJOR 57 -#define LIBAVCODEC_VERSION_MINOR 27 +#define LIBAVCODEC_VERSION_MINOR 28 #define LIBAVCODEC_VERSION_MICRO 0 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ -- 2.8.3 _______________________________________________ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel