avcodec/nvenc: don't enqueue timestamps until a frame was accepted
authorAndrey Turkin <andrey.turkin@gmail.com>
Sun, 29 May 2016 12:51:36 +0000 (15:51 +0300)
committerTimo Rothenpieler <timo@rothenpieler.org>
Tue, 31 May 2016 14:50:45 +0000 (16:50 +0200)
Otherwise timestamps/pending FIFOs would go out of sync if nvEncodePicture ever fails.

Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org>
libavcodec/nvenc.c

index a31c6e8..e8b57e4 100644 (file)
@@ -1602,8 +1602,6 @@ int ff_nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
         pic_params.inputDuration = 0;
 
         nvenc_codec_specific_pic_params(avctx, &pic_params);
-
-        timestamp_queue_enqueue(ctx->timestamp_list, frame->pts);
     } else {
         pic_params.encodePicFlags = NV_ENC_PIC_FLAG_EOS;
     }
@@ -1613,8 +1611,10 @@ int ff_nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
         nv_status != NV_ENC_ERR_NEED_MORE_INPUT)
         return nvenc_print_error(avctx, nv_status, "EncodePicture failed!");
 
-    if (frame)
+    if (frame) {
         av_fifo_generic_write(ctx->output_surface_queue, &inSurf, sizeof(inSurf), NULL);
+        timestamp_queue_enqueue(ctx->timestamp_list, frame->pts);
+    }
 
     /* all the pending buffers are now ready for output */
     if (nv_status == NV_ENC_SUCCESS) {