From patchwork Fri Oct 4 09:02:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Gaullier X-Patchwork-Id: 52027 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:938f:0:b0:48e:c0f8:d0de with SMTP id z15csp265749vqg; Fri, 4 Oct 2024 02:03:07 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWdl4z3ekbY5C1ux5CHuL1hkeebFcKdKBaDWhuBZE59vLj0VDbx66dKKApARtJqNbqMaIyuMPlEfadpHz9pFZ2c@gmail.com X-Google-Smtp-Source: AGHT+IG2s0DBLyhAj8fDTtpMUrgMz01bfP3eMXGSgRsp+arJb5D/9qfIs4St6d9zhqBz/PPlQu1y X-Received: by 2002:a05:651c:b14:b0:2f7:544a:28af with SMTP id 38308e7fff4ca-2faf3c159eemr9650691fa.14.1728032587262; Fri, 04 Oct 2024 02:03:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728032587; cv=none; d=google.com; s=arc-20240605; b=gLvd9xbQTlMGGzX2DI0/+XB9GK+4SnN2IoJsyuHDiRc/zQEtiEHs0UfSng7+OhEZ0h nZvaxkTSawST8osbuX4jN/JybsiDe8HuG0p0vc0mXZC9PwChxlDGGMtF/SR7Pm9WhK04 BpkoSuEVqslFq2N5nnI4dICvM+nLnmXLhAR+s/KjieUIYZZOR0WXt94M4BfznMxh1JIo qd6WeX2O4Nufz7ZfC+wGGE4tVOcmjO/l8q1WM7uKZrJfbCf64AAdVnHqdC3p1XljikM4 tOofADY+m2pBQaNe1u1KxNuK6tibxy3L+m9NWCCK65hoM87D7mgmuLv64zjDTuMLwvpX N/Jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=B23jOPbKxLKhJUMoIwcTIUIgD8HgHAqG64zrwUtRAFE=; fh=zgMS+X4RExv2k7fU8QdWClnqVJdqO/9UbUuBS5xxJDs=; b=VaCckCcGzQOIy+uJoqfksa8sUOAPmrYeDo6HWf668XI09W1LaDAF0ogZNF0NF1wThm VoBPcPSXxAAH7Gl7R/FGZcIQMqwvnR6PYdO1U8iM5cqE8uMosy8U4nRQYbsjKx+woSiQ Sf7Us7a6JBt/GMHqLU8ZAcdMUgiztwaX6ZIHdB85MzJi+0Gac1mWUZBo2soZhR8K9PZC cKYg4UE5hjxuiVV71xQI7YKGL4Jv1l7xNekR1497HZHL04jaCHHiy0g94ZxN56kUl55A r0zt/Hh3BGDrvkrBFH0ljgsc8BGppqvrVfZ0ef6+wM9Maf4mN4RWoRGFvIGD7dbR/8x1 fBlw==; dara=google.com ARC-Authentication-Results: i=1; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cji.paris Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 38308e7fff4ca-2faecc6c656si10163861fa.446.2024.10.04.02.03.06; Fri, 04 Oct 2024 02:03:07 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cji.paris Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0844268D84A; Fri, 4 Oct 2024 12:03:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from srv-infra-1.infra.inf.glb.tvvideoms.com (www.inf.tvvideoms.com [213.205.126.156]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8CC4D68D84A for ; Fri, 4 Oct 2024 12:02:56 +0300 (EEST) Received: from cji.paris (unknown [172.16.3.159]) by srv-infra-1.infra.inf.glb.tvvideoms.com (Postfix) with ESMTP id 6EFAA20759; Fri, 4 Oct 2024 09:02:55 +0000 (UTC) From: Nicolas Gaullier To: ffmpeg-devel@ffmpeg.org Date: Fri, 4 Oct 2024 11:02:49 +0200 Message-Id: <20241004090249.129029-2-nicolas.gaullier@cji.paris> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20241004090249.129029-1-nicolas.gaullier@cji.paris> References: <20241004090249.129029-1-nicolas.gaullier@cji.paris> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/1] avfilter/framesync: fix forward EOF pts X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Cc: Nicolas Gaullier Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: pcgqRMWLhG/G Note1: when the EOF pts is not accurate enough, the last frame can be dropped by vf_fps with default rounding. Note2: vf_scale use framesync since e82a3997cdd6c0894869b33ba42430ac3, so this is a very commonplace scenario. For example: ./ffprobe -f lavfi testsrc=d=1,scale,fps -of flat \ -count_frames -show_entries stream=nb_read_frames Before: streams.stream.0.nb_read_frames="24" After: streams.stream.0.nb_read_frames="25" --- libavfilter/framesync.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/libavfilter/framesync.c b/libavfilter/framesync.c index 8e06e0e700..0d5779f830 100644 --- a/libavfilter/framesync.c +++ b/libavfilter/framesync.c @@ -103,14 +103,14 @@ int ff_framesync_init(FFFrameSync *fs, AVFilterContext *parent, unsigned nb_in) return 0; } -static void framesync_eof(FFFrameSync *fs) +static void framesync_eof(FFFrameSync *fs, int64_t pts) { fs->eof = 1; fs->frame_ready = 0; - ff_outlink_set_status(fs->parent->outputs[0], AVERROR_EOF, AV_NOPTS_VALUE); + ff_outlink_set_status(fs->parent->outputs[0], AVERROR_EOF, pts); } -static void framesync_sync_level_update(FFFrameSync *fs) +static void framesync_sync_level_update(FFFrameSync *fs, int64_t eof_pts) { unsigned i, level = 0; @@ -131,7 +131,7 @@ static void framesync_sync_level_update(FFFrameSync *fs) if (level) fs->sync_level = level; else - framesync_eof(fs); + framesync_eof(fs, eof_pts); } int ff_framesync_configure(FFFrameSync *fs) @@ -179,7 +179,7 @@ int ff_framesync_configure(FFFrameSync *fs) for (i = 0; i < fs->nb_in; i++) fs->in[i].pts = fs->in[i].pts_next = AV_NOPTS_VALUE; fs->sync_level = UINT_MAX; - framesync_sync_level_update(fs); + framesync_sync_level_update(fs, AV_NOPTS_VALUE); return 0; } @@ -200,7 +200,7 @@ static int framesync_advance(FFFrameSync *fs) if (fs->in[i].have_next && fs->in[i].pts_next < pts) pts = fs->in[i].pts_next; if (pts == INT64_MAX) { - framesync_eof(fs); + framesync_eof(fs, AV_NOPTS_VALUE); break; } for (i = 0; i < fs->nb_in; i++) { @@ -222,7 +222,7 @@ static int framesync_advance(FFFrameSync *fs) fs->frame_ready = 1; if (fs->in[i].state == STATE_EOF && fs->in[i].after == EXT_STOP) - framesync_eof(fs); + framesync_eof(fs, AV_NOPTS_VALUE); } } if (fs->frame_ready) @@ -255,15 +255,14 @@ static void framesync_inject_frame(FFFrameSync *fs, unsigned in, AVFrame *frame) fs->in[in].have_next = 1; } -static void framesync_inject_status(FFFrameSync *fs, unsigned in, int status, int64_t pts) +static void framesync_inject_status(FFFrameSync *fs, unsigned in, int status, int64_t eof_pts) { av_assert0(!fs->in[in].have_next); - pts = fs->in[in].state != STATE_RUN || fs->in[in].after == EXT_INFINITY - ? INT64_MAX : framesync_pts_extrapolate(fs, in, fs->in[in].pts); fs->in[in].sync = 0; - framesync_sync_level_update(fs); + framesync_sync_level_update(fs, status == AVERROR_EOF ? eof_pts : AV_NOPTS_VALUE); fs->in[in].frame_next = NULL; - fs->in[in].pts_next = pts; + fs->in[in].pts_next = fs->in[in].state != STATE_RUN || fs->in[in].after == EXT_INFINITY + ? INT64_MAX : framesync_pts_extrapolate(fs, in, fs->in[in].pts); fs->in[in].have_next = 1; }