OSDN Git Service

nvenc: flush the encoder before closing it, as required by the docs
authorAnton Khirnov <anton@khirnov.net>
Fri, 8 Jan 2016 11:29:38 +0000 (12:29 +0100)
committerAnton Khirnov <anton@khirnov.net>
Tue, 12 Jan 2016 08:23:38 +0000 (09:23 +0100)
Otherwise, closing the encoder can crash.

libavcodec/nvenc.c

index 02cb8b4..c151ad5 100644 (file)
@@ -825,6 +825,14 @@ av_cold int ff_nvenc_encode_close(AVCodecContext *avctx)
     NV_ENCODE_API_FUNCTION_LIST *nv = &ctx->nvel.nvenc_funcs;
     int i;
 
+    /* the encoder has to be flushed before it can be closed */
+    if (ctx->nvenc_ctx) {
+        NV_ENC_PIC_PARAMS params        = { .version        = NV_ENC_PIC_PARAMS_VER,
+                                            .encodePicFlags = NV_ENC_PIC_FLAG_EOS };
+
+        nv->nvEncEncodePicture(ctx->nvenc_ctx, &params);
+    }
+
     av_fifo_free(ctx->timestamps);
     av_fifo_free(ctx->pending);
     av_fifo_free(ctx->ready);