[FFmpeg-cvslog] avcodec/nvenc: Delay frame output to increase encoding speed

Timo Rothenpieler git at videolan.org
Sun Jul 26 01:00:03 CEST 2015


ffmpeg | branch: master | Timo Rothenpieler <timo at rothenpieler.org> | Sat Jul 25 23:20:28 2015 +0200| [9f4bff834c47d2093ae35215c4aafa92c29d9d79] | committer: Timo Rothenpieler

avcodec/nvenc: Delay frame output to increase encoding speed

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9f4bff834c47d2093ae35215c4aafa92c29d9d79
---

 libavcodec/nvenc.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index 6e4d631..633fb51 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -163,6 +163,7 @@ typedef struct NvencContext
     int cbr;
     int twopass;
     int gpu;
+    int buffer_delay;
 } NvencContext;
 
 static const NvencValuePair nvenc_h264_level_pairs[] = {
@@ -692,6 +693,9 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx)
     num_mbs = ((avctx->width + 15) >> 4) * ((avctx->height + 15) >> 4);
     ctx->max_surface_count = (num_mbs >= 8160) ? 32 : 48;
 
+    if (ctx->buffer_delay >= ctx->max_surface_count)
+        ctx->buffer_delay = ctx->max_surface_count - 1;
+
     ctx->init_encode_params.enableEncodeAsync = 0;
     ctx->init_encode_params.enablePTD = 1;
 
@@ -1373,7 +1377,7 @@ static int nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
         }
     }
 
-    if (ctx->output_surface_ready_queue.count) {
+    if (ctx->output_surface_ready_queue.count && (!frame || ctx->output_surface_ready_queue.count + ctx->output_surface_queue.count >= ctx->buffer_delay)) {
         tmpoutsurf = out_surf_queue_dequeue(&ctx->output_surface_ready_queue);
 
         res = process_output_surface(avctx, pkt, tmpoutsurf);
@@ -1410,6 +1414,7 @@ static const AVOption options[] = {
     { "cbr", "Use cbr encoding mode", OFFSET(cbr), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
     { "2pass", "Use 2pass cbr encoding mode (low latency mode only)", 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 }
 };
 



More information about the ffmpeg-cvslog mailing list