diff options
author | Timo Rothenpieler <timo@rothenpieler.org> | 2015-07-25 23:20:28 +0200 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2016-05-19 14:17:01 +0200 |
commit | a1e215ea0157360261e856eea2cd468136a68da0 (patch) | |
tree | 45021f4d6965636678f58580bc0ef1d1e2d72cc8 /libavcodec/nvenc.c | |
parent | 9427d92f40d4ab981f0b24e8e1d1cdec1d845ac1 (diff) |
nvenc: Delay frame output to increase encoding speed
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Diffstat (limited to 'libavcodec/nvenc.c')
-rw-r--r-- | libavcodec/nvenc.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 97922453f7..bd704a76ad 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -840,6 +840,8 @@ static int nvenc_setup_surfaces(AVCodecContext *avctx) ctx->nb_surfaces = FFMAX(4 + avctx->max_b_frames, ctx->nb_surfaces); + ctx->async_depth = FFMIN(ctx->async_depth, ctx->nb_surfaces - 1); + ctx->frames = av_mallocz_array(ctx->nb_surfaces, sizeof(*ctx->frames)); if (!ctx->frames) @@ -1301,13 +1303,19 @@ FF_ENABLE_DEPRECATION_WARNINGS static int output_ready(AVCodecContext *avctx, int flush) { NVENCContext *ctx = avctx->priv_data; + int nb_ready, nb_pending; /* when B-frames are enabled, we wait for two initial timestamps to * calculate the first dts */ if (!flush && avctx->max_b_frames > 0 && (ctx->initial_pts[0] == AV_NOPTS_VALUE || ctx->initial_pts[1] == AV_NOPTS_VALUE)) return 0; - return av_fifo_size(ctx->ready) > 0; + + nb_ready = av_fifo_size(ctx->ready) / sizeof(NVENCFrame*); + nb_pending = av_fifo_size(ctx->pending) / sizeof(NVENCFrame*); + if (flush) + return nb_ready > 0; + return (nb_ready > 0) && (nb_ready + nb_pending >= ctx->async_depth); } int ff_nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt, |