diff mbox

[FFmpeg-devel] lavc/nvenc: enable nvenc encoder instance reuse (v2)

Message ID 20180607150815.11337-1-pkoshevoy@gmail.com
State Accepted
Commit f7d117b4846477852076d28d09db93cce7a697f8
Headers show

Commit Message

Pavel Koshevoy June 7, 2018, 3:08 p.m. UTC
---
 libavcodec/nvenc.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Comments

Pavel Koshevoy June 13, 2018, 1:45 p.m. UTC | #1
On Thu, Jun 7, 2018 at 9:08 AM Pavel Koshevoy <pkoshevoy@gmail.com> wrote:
>
> ---
>  libavcodec/nvenc.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
> index b4186c0bec..cfa7268a5e 100644
> --- a/libavcodec/nvenc.c
> +++ b/libavcodec/nvenc.c
> @@ -2051,8 +2051,16 @@ int ff_nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame)
>      if ((!ctx->cu_context && !ctx->d3d11_device) || !ctx->nvencoder)
>          return AVERROR(EINVAL);
>
> -    if (ctx->encoder_flushing)
> -        return AVERROR_EOF;
> +    if (ctx->encoder_flushing) {
> +        if (avctx->internal->draining)
> +            return AVERROR_EOF;
> +
> +        ctx->encoder_flushing = 0;
> +        ctx->first_packet_output = 0;
> +        ctx->initial_pts[0] = AV_NOPTS_VALUE;
> +        ctx->initial_pts[1] = AV_NOPTS_VALUE;
> +        av_fifo_reset(ctx->timestamp_list);
> +    }
>
>      if (frame) {
>          in_surf = get_free_frame(ctx);
> --
> 2.16.4
>


Can this be applied?

Thank you,
    Pavel
Timo Rothenpieler June 13, 2018, 3:03 p.m. UTC | #2
>>
>> -    if (ctx->encoder_flushing)
>> -        return AVERROR_EOF;
>> +    if (ctx->encoder_flushing) {
>> +        if (avctx->internal->draining)
>> +            return AVERROR_EOF;
>> +
>> +        ctx->encoder_flushing = 0;
>> +        ctx->first_packet_output = 0;
>> +        ctx->initial_pts[0] = AV_NOPTS_VALUE;
>> +        ctx->initial_pts[1] = AV_NOPTS_VALUE;
>> +        av_fifo_reset(ctx->timestamp_list);
>> +    }
>>
>>       if (frame) {
>>           in_surf = get_free_frame(ctx);
>> --
>> 2.16.4
>>
> 
> 
> Can this be applied?

I'm not opposing it, and will in fact apply it if nobody objects.

Still not sure if the API is intended to be used like that, but I can't 
think of anything it might break to offer this functionality.

A second opinion on this would be nice, otherwise I'll apply it with my 
next set of patches in a few days.
Timo Rothenpieler June 15, 2018, 1:44 p.m. UTC | #3
applied
diff mbox

Patch

diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index b4186c0bec..cfa7268a5e 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -2051,8 +2051,16 @@  int ff_nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame)
     if ((!ctx->cu_context && !ctx->d3d11_device) || !ctx->nvencoder)
         return AVERROR(EINVAL);
 
-    if (ctx->encoder_flushing)
-        return AVERROR_EOF;
+    if (ctx->encoder_flushing) {
+        if (avctx->internal->draining)
+            return AVERROR_EOF;
+
+        ctx->encoder_flushing = 0;
+        ctx->first_packet_output = 0;
+        ctx->initial_pts[0] = AV_NOPTS_VALUE;
+        ctx->initial_pts[1] = AV_NOPTS_VALUE;
+        av_fifo_reset(ctx->timestamp_list);
+    }
 
     if (frame) {
         in_surf = get_free_frame(ctx);