It is much more robust solution to always calculate second field (when
deinterlacing) PTS from frame rate, then relating on previous PTS,
because if there are B frames in input and some video frames are
corrupted (dropped) it will calculate wrong PTS for second field and
could hang on encoding in do_video_out.
--
Miroslav Slugeň
>From f8a19eb5fb82fee0cce1e1d7248bec57bdea08ac Mon Sep 17 00:00:00 2001
From: Miroslav Slugen <thunde...@email.cz>
Date: Wed, 8 Feb 2017 23:26:28 +0100
Subject: [PATCH 1/1] cuvid: Always calculate second field pts from frame rate
---
libavcodec/cuvid.c | 13 +------------
1 file changed, 1 insertion(+), 12 deletions(-)
diff --git a/libavcodec/cuvid.c b/libavcodec/cuvid.c
index 9b35476..19c024d 100644
--- a/libavcodec/cuvid.c
+++ b/libavcodec/cuvid.c
@@ -51,7 +51,6 @@ typedef struct CuvidContext
AVFifoBuffer *frame_queue;
int deint_mode;
- int64_t prev_pts;
int internal_error;
int decoder_flushing;
@@ -512,14 +511,7 @@ static int cuvid_output_frame(AVCodecContext *avctx, AVFrame *frame)
frame->pts = parsed_frame.dispinfo.timestamp;
if (parsed_frame.second_field) {
- if (ctx->prev_pts == INT64_MIN) {
- ctx->prev_pts = frame->pts;
- frame->pts += (avctx->pkt_timebase.den * avctx->framerate.den) / (avctx->pkt_timebase.num * avctx->framerate.num);
- } else {
- int pts_diff = (frame->pts - ctx->prev_pts) / 2;
- ctx->prev_pts = frame->pts;
- frame->pts += pts_diff;
- }
+ frame->pts += (avctx->pkt_timebase.den * avctx->framerate.den) / (avctx->pkt_timebase.num * avctx->framerate.num);
}
/* CUVIDs opaque reordering breaks the internal pkt logic.
@@ -853,8 +845,6 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx)
if (ret < 0)
goto error;
- ctx->prev_pts = INT64_MIN;
-
if (!avctx->pkt_timebase.num || !avctx->pkt_timebase.den)
av_log(avctx, AV_LOG_WARNING, "Invalid pkt_timebase, passing timestamps as-is.\n");
@@ -913,7 +903,6 @@ static void cuvid_flush(AVCodecContext *avctx)
if (ret < 0)
goto error;
- ctx->prev_pts = INT64_MIN;
ctx->decoder_flushing = 0;
return;
--
2.1.4
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel