From patchwork Wed Feb 8 22:31:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Miroslav_Sluge=C5=88?= X-Patchwork-Id: 2453 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp34186vsb; Wed, 8 Feb 2017 14:32:07 -0800 (PST) X-Received: by 10.223.150.118 with SMTP id c51mr19870060wra.190.1486593127722; Wed, 08 Feb 2017 14:32:07 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 19si3932345wmb.47.2017.02.08.14.32.07; Wed, 08 Feb 2017 14:32:07 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@email.cz; dkim=neutral (body hash did not verify) header.i=@email.cz; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=email.cz Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EFEA9680900; Thu, 9 Feb 2017 00:31:59 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mxf2.seznam.cz (mxf2.seznam.cz [77.75.76.123]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3128E6800D2 for ; Thu, 9 Feb 2017 00:31:54 +0200 (EET) Received: from email.seznam.cz by email-smtpc4b.ng.seznam.cz (email-smtpc4b.ng.seznam.cz [10.23.13.105]) id 5df575d169226dcd5d675cdc; Wed, 08 Feb 2017 23:31:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=email.cz; s=beta; t=1486593116; bh=t6Ybty8jk/3mo6VETj3iMHb48hN4zdxQePTZ+YwodPw=; h=DKIM-Signature:Received:From:Subject:To:Message-ID:Date: User-Agent:MIME-Version:Content-Type; b=hA9sfTUjcu9syIUwHVhgkHGwIGwI01qICnyGnOgKfQ9TQdp6V/sBfhQj+agTWIRXK cTMrYj65W+XOL69XqA4Bx7E+XDh4wA2D2jVoq+UcpajMbLyJdUs/QieTv0two5xFv0 ZTnsKqECoOMHcaS/OokjD7c4ziJYS++LHqOWrqxs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=email.cz; s=beta; t=1486593116; bh=t6Ybty8jk/3mo6VETj3iMHb48hN4zdxQePTZ+YwodPw=; h=Received:From:Subject:To:Message-ID:Date:User-Agent:MIME-Version: Content-Type; b=Ihr5lHH+orxGnIVzSMtHpE1xLSLfWs1TmIR2uaa2cGmgJwWQjQdAM6w0sqrC9LS9f bzlPeAQcR/5vzbuTZ+L5TfFzOytoChSIee2Skp4S33qtMgJ52zMauIeEvWIESLLGrF RVUcHBudIhG46bEkAeovXXLEDYqzpsGc0/ZA4HRs= Received: from [192.168.0.6] (ip-94-113-140-7.net.upcbroadband.cz [94.113.140.7]) by email-relay21.ng.seznam.cz (Seznam SMTPD 1.3.56) with ESMTP; Wed, 08 Feb 2017 23:31:55 +0100 (CET) From: =?UTF-8?Q?Miroslav_Sluge=c5=88?= To: ffmpeg-devel@ffmpeg.org Message-ID: <589B9C5A.7000101@email.cz> Date: Wed, 8 Feb 2017 23:31:54 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.0.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] cuvid: Always calculate second field PTS from frame rate X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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. From f8a19eb5fb82fee0cce1e1d7248bec57bdea08ac Mon Sep 17 00:00:00 2001 From: Miroslav Slugen 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