[FFmpeg-cvslog] avcodec/nvenc: added support for rate control lookahead
Oliver Collyer
git at videolan.org
Sun Aug 28 18:12:08 EEST 2016
ffmpeg | branch: master | Oliver Collyer <ovcollyer at mac.com> | Thu Aug 25 16:20:03 2016 +0100| [a81b398e869ed2f7f972f797f8992ad32bfb8ba1] | committer: Timo Rothenpieler
avcodec/nvenc: added support for rate control lookahead
Signed-off-by: Timo Rothenpieler <timo at rothenpieler.org>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a81b398e869ed2f7f972f797f8992ad32bfb8ba1
---
libavcodec/nvenc.c | 11 +++++++++++
libavcodec/nvenc.h | 1 +
libavcodec/nvenc_h264.c | 1 +
libavcodec/nvenc_hevc.c | 1 +
4 files changed, 14 insertions(+)
diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index 5706590..d1c7d93 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -328,6 +328,12 @@ static int nvenc_check_capabilities(AVCodecContext *avctx)
return AVERROR(ENOSYS);
}
+ ret = nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_LOOKAHEAD);
+ if (ctx->rc_lookahead > 0 && ret <= 0) {
+ av_log(avctx, AV_LOG_VERBOSE, "RC lookahead not supported\n");
+ return AVERROR(ENOSYS);
+ }
+
return 0;
}
@@ -687,6 +693,11 @@ static av_cold void nvenc_setup_rate_control(AVCodecContext *avctx)
} else if (ctx->encode_config.rcParams.averageBitRate > 0) {
ctx->encode_config.rcParams.vbvBufferSize = 2 * ctx->encode_config.rcParams.averageBitRate;
}
+
+ if (ctx->rc_lookahead > 0) {
+ ctx->encode_config.rcParams.enableLookahead = 1;
+ ctx->encode_config.rcParams.lookaheadDepth = FFMIN(ctx->rc_lookahead, 32);
+ }
}
static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx)
diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h
index 37d41ea..cd86c47 100644
--- a/libavcodec/nvenc.h
+++ b/libavcodec/nvenc.h
@@ -179,6 +179,7 @@ typedef struct NvencContext
int device;
int flags;
int async_depth;
+ int rc_lookahead;
} NvencContext;
int ff_nvenc_encode_init(AVCodecContext *avctx);
diff --git a/libavcodec/nvenc_h264.c b/libavcodec/nvenc_h264.c
index b576f15..4ef9836 100644
--- a/libavcodec/nvenc_h264.c
+++ b/libavcodec/nvenc_h264.c
@@ -76,6 +76,7 @@ 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 },
{ "cbr", "Use cbr encoding mode", OFFSET(cbr), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
{ "2pass", "Use 2pass encoding mode", OFFSET(twopass), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE },
diff --git a/libavcodec/nvenc_hevc.c b/libavcodec/nvenc_hevc.c
index d9a4bf6..e875772 100644
--- a/libavcodec/nvenc_hevc.c
+++ b/libavcodec/nvenc_hevc.c
@@ -74,6 +74,7 @@ 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 },
{ "cbr", "Use cbr encoding mode", OFFSET(cbr), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
{ "2pass", "Use 2pass encoding mode", OFFSET(twopass), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE },
More information about the ffmpeg-cvslog
mailing list