PR #26216 opened by Pu Cheng (GeekQAQ)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26216
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26216.patch

setts holds one packet back until the next one arrives, and keeps the
previous input and output packets, the packet counter N and STARTPTS /
STARTDTS for its expressions. Without a flush callback all of this
survives av_bsf_flush(): after a flush and a seek (or a switch to
another stream) the held packet of the previous position is output at
the start of the new one, and N, STARTPTS, STARTDTS and the PREV_*
values continue from the previous stream.

Add a flush callback that drops the held packets and resets the
counter and the start timestamps.

Signed-off-by: Pu Cheng <[email protected]>



>From 2df160120d41e21f314e29dc891ed2c1970a82bb Mon Sep 17 00:00:00 2001
From: Pu Cheng <[email protected]>
Date: Fri, 20 Nov 2026 14:08:21 +0800
Subject: [PATCH] avcodec/bsf/setts: add a flush callback

setts holds one packet back until the next one arrives, and keeps the
previous input and output packets, the packet counter N and STARTPTS /
STARTDTS for its expressions. Without a flush callback all of this
survives av_bsf_flush(): after a flush and a seek (or a switch to
another stream) the held packet of the previous position is output at
the start of the new one, and N, STARTPTS, STARTDTS and the PREV_*
values continue from the previous stream.

Add a flush callback that drops the held packets and resets the
counter and the start timestamps.

Signed-off-by: Pu Cheng <[email protected]>
---
 libavcodec/bsf/setts.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/libavcodec/bsf/setts.c b/libavcodec/bsf/setts.c
index 4106eb950e7..f7da6a43a6a 100644
--- a/libavcodec/bsf/setts.c
+++ b/libavcodec/bsf/setts.c
@@ -268,6 +268,18 @@ static void setts_close(AVBSFContext *bsf)
     s->duration_expr = NULL;
 }
 
+static void setts_flush(AVBSFContext *bsf)
+{
+    SetTSContext *s = bsf->priv_data;
+
+    av_packet_unref(s->prev_inpkt);
+    av_packet_unref(s->prev_outpkt);
+    av_packet_unref(s->cur_pkt);
+    s->frame_number = 0;
+    s->var_values[VAR_STARTPTS] = AV_NOPTS_VALUE;
+    s->var_values[VAR_STARTDTS] = AV_NOPTS_VALUE;
+}
+
 #define OFFSET(x) offsetof(SetTSContext, x)
 #define FLAGS 
(AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_SUBTITLE_PARAM|AV_OPT_FLAG_BSF_PARAM)
 
@@ -294,5 +306,6 @@ const FFBitStreamFilter ff_setts_bsf = {
     .priv_data_size = sizeof(SetTSContext),
     .init           = setts_init,
     .close          = setts_close,
+    .flush          = setts_flush,
     .filter         = setts_filter,
 };
-- 
2.54.1

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to