From patchwork Mon Apr 3 12:52:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 3266 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.44.195 with SMTP id s186csp67345vss; Mon, 3 Apr 2017 05:52:37 -0700 (PDT) X-Received: by 10.28.133.203 with SMTP id h194mr9816818wmd.122.1491223957476; Mon, 03 Apr 2017 05:52:37 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s26si16671732wra.10.2017.04.03.05.52.37; Mon, 03 Apr 2017 05:52:37 -0700 (PDT) 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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 91236680D23; Mon, 3 Apr 2017 15:52:24 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from nef2.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 840D4680CFC for ; Mon, 3 Apr 2017 15:52:18 +0300 (EEST) Received: from phare.normalesup.org (archicubes.ens.fr [129.199.129.80]) by nef2.ens.fr (8.13.6/1.01.28121999) with ESMTP id v33CqJgL096728 for ; Mon, 3 Apr 2017 14:52:19 +0200 (CEST) Received: by phare.normalesup.org (Postfix, from userid 1001) id 9EE1FE0101; Mon, 3 Apr 2017 14:52:19 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Mon, 3 Apr 2017 14:52:15 +0200 Message-Id: <20170403125215.16031-2-george@nsup.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170403125215.16031-1-george@nsup.org> References: <20170403125215.16031-1-george@nsup.org> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef2.ens.fr [129.199.96.32]); Mon, 03 Apr 2017 14:52:19 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH 2/2] ffmpeg: use reordered duration for stream PTS. 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Nicolas George --- ffmpeg.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) Not sure if this is correct, the timestamp handling is awfully complicated. But FATE succeeds and the result is a correct value of next_pts after the last frame with a VFR file. diff --git a/ffmpeg.c b/ffmpeg.c index 02ff073615..f67896d439 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -2356,7 +2356,7 @@ static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output, return err < 0 ? err : ret; } -static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output, int eof, +static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output, int *duration_pts, int eof, int *decode_failed) { AVFrame *decoded_frame; @@ -2447,6 +2447,7 @@ static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output, int eo ist->hwaccel_retrieved_pix_fmt = decoded_frame->format; best_effort_timestamp= av_frame_get_best_effort_timestamp(decoded_frame); + *duration_pts = decoded_frame->pkt_duration; if (ist->framerate.num) best_effort_timestamp = ist->cfr_next_pts++; @@ -2617,6 +2618,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo // while we have more to decode or while the decoder did output something on EOF while (ist->decoding_needed) { int duration_dts = 0; + int duration_pts = 0; int got_output = 0; int decode_failed = 0; @@ -2629,7 +2631,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo &decode_failed); break; case AVMEDIA_TYPE_VIDEO: - ret = decode_video (ist, repeating ? NULL : &avpkt, &got_output, !pkt, + ret = decode_video (ist, repeating ? NULL : &avpkt, &got_output, &duration_pts, !pkt, &decode_failed); if (!repeating || !pkt || got_output) { if (pkt && pkt->duration) { @@ -2648,7 +2650,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo } if (got_output) - ist->next_pts += duration_dts; //FIXME the duration is not correct in some cases + ist->next_pts += av_rescale_q(duration_pts, ist->st->time_base, AV_TIME_BASE_Q); break; case AVMEDIA_TYPE_SUBTITLE: if (repeating)