From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <ffmpeg-devel-bounces@ffmpeg.org>
Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100])
	by master.gitmailbox.com (Postfix) with ESMTPS id CEDAA4E5AD
	for <ffmpegdev@gitmailbox.com>; Wed, 12 Mar 2025 18:46:07 +0000 (UTC)
Received: from [127.0.1.1] (localhost [127.0.0.1])
	by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7980368ED93;
	Wed, 12 Mar 2025 20:46:03 +0200 (EET)
Received: from mx0.riseup.net (mx0.riseup.net [198.252.153.6])
 by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B7E1068EC32
 for <ffmpeg-devel@ffmpeg.org>; Wed, 12 Mar 2025 20:45:56 +0200 (EET)
Received: from fews02-sea.riseup.net (fews02-sea-pn.riseup.net [10.0.1.112])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
 (No client certificate requested)
 by mx0.riseup.net (Postfix) with ESMTPS id 4ZCfhy4rn0z9wst;
 Wed, 12 Mar 2025 18:45:54 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak;
 t=1741805154; bh=x9ShKSyuZ4Ctk25LLS0+SCFP49O5yFPPIUiM9fmEAZs=;
 h=From:Date:Subject:To:Cc:From;
 b=FZb4B84T6eVH+vDC9ZBLZ/Os+vtKNNFzv1UT/2qB/JV/EeNWHmpu1agMILhJwmy0R
 HJd8YhIT3anczKM+Y+DyOJwJOl+b3bTsuL/KV7b9gIrxVdTD3A6tSEesgopxi6JY/u
 FDGh6ui0kISyMzf2Si/eutDijsfNeBMGlMeide4E=
X-Riseup-User-ID: C1707BCAAB69E483AD2B60F37AD7A5AF959F579416CA19660154437C6319400D
Received: from [127.0.0.1] (localhost [127.0.0.1])
 by fews02-sea.riseup.net (Postfix) with ESMTPSA id 4ZCfhx5PP7zFw5J;
 Wed, 12 Mar 2025 18:45:53 +0000 (UTC)
From: Arthur Grillo <arthurgrillo@riseup.net>
Date: Wed, 12 Mar 2025 15:45:42 -0300
MIME-Version: 1.0
Message-Id: <20250312-video-only-kf-recover-v1-1-1e0e340da663@riseup.net>
X-B4-Tracking: v=1; b=H4sIAFXW0WcC/x3MTQoCMQxA4asMWRtI4w8dryKzkDbV4NBKCkUpv
 bvF5bd4r0MVU6lwXTqYNK1a8oQ7LBCe9/wQ1DgNTHymo2NsGqVgyfsXXwlNQmli6Lx3F6I18Yl
 gtm+TpJ//97aN8QPmWPwlZwAAAA==
X-Change-ID: 20250312-video-only-kf-recover-18816009f240
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH] avformat/fifo: Check for keyframe video type
 before stop dropping
X-BeenThere: ffmpeg-devel@ffmpeg.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org>
List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe>
List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel>
List-Post: <mailto:ffmpeg-devel@ffmpeg.org>
List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help>
List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe>
Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Cc: lingjiujianke@gmail.com, Arthur Grillo <arthurgrillo@riseup.net>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: ffmpeg-devel-bounces@ffmpeg.org
Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org>
Archived-At: <https://master.gitmailbox.com/ffmpegdev/20250312-video-only-kf-recover-v1-1-1e0e340da663@riseup.net/>
List-Archive: <https://master.gitmailbox.com/ffmpegdev/>
List-Post: <mailto:ffmpegdev@gitmailbox.com>

The current behavior when using restart_with_keyframe is that it will
recover if it also encounters any audio packet, as they are flagged as a
keyframe.

The expectation is that packets are dropped until the next _video_
keyframe.

Fix that by checking the packet stream codec type, only letting it
recover when it is a video one.

Fixes ticket: #11467

Signed-off-by: Arthur Grillo <arthurgrillo@riseup.net>
---
Cc: lingjiujianke@gmail.com
---
 libavformat/fifo.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/libavformat/fifo.c b/libavformat/fifo.c
index 23e4149ad606b201aade77e28057afe8e5fe2b71..1ebfa1f38f3affec2d81b5a2bb9d69190a5aa63f 100644
--- a/libavformat/fifo.c
+++ b/libavformat/fifo.c
@@ -185,14 +185,21 @@ static int fifo_thread_write_packet(FifoThreadContext *ctx, AVPacket *pkt)
     AVRational src_tb, dst_tb;
     int ret, s_idx;
     int64_t orig_pts, orig_dts, orig_duration;
+    enum AVMediaType stream_codec_type = avf->streams[pkt->stream_index]->codecpar->codec_type;
 
     if (fifo->timeshift && pkt->dts != AV_NOPTS_VALUE)
         atomic_fetch_sub_explicit(&fifo->queue_duration, next_duration(avf, pkt, &ctx->last_received_dts), memory_order_relaxed);
 
     if (ctx->drop_until_keyframe) {
         if (pkt->flags & AV_PKT_FLAG_KEY) {
-            ctx->drop_until_keyframe = 0;
-            av_log(avf, AV_LOG_VERBOSE, "Keyframe received, recovering...\n");
+            if (stream_codec_type == AVMEDIA_TYPE_VIDEO) {
+                ctx->drop_until_keyframe = 0;
+                av_log(avf, AV_LOG_VERBOSE, "Video keyframe received, recovering...\n");
+            } else {
+                av_log(avf, AV_LOG_VERBOSE, "Dropping non-video keyframe\n");
+                av_packet_unref(pkt);
+                return 0;
+            }
         } else {
             av_log(avf, AV_LOG_VERBOSE, "Dropping non-keyframe packet\n");
             av_packet_unref(pkt);

---
base-commit: 3165fe5ecf4917d9f7d7f27d4fa3af31bc604515
change-id: 20250312-video-only-kf-recover-18816009f240

Best regards,
-- 
Arthur Grillo <arthurgrillo@riseup.net>

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".