PR #26098 opened by Forgejo_Fairy
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26098
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26098.patch

Input `-t` currently compares its cutoff against DTS that already includes 
`-itsoffset`. With a 10 fps all-keyframe input, `-ss 2 -t 3` and offsets −3, 0, 
+1 and +3 produce 60, 30, 20 and 0 packets instead of 30.

Subtract the input timestamp offset for the stream-copy duration comparison, 
using saturating subtraction. Packet timestamps and the existing 
`copyts`/`start_at_zero` baseline are preserved.

Add six sample-free FATE tests covering positive and negative offsets with 
default timestamp handling, `-copyts`, and `-copyts -start_at_zero`. All six 
fail before the change and pass afterward. The existing limited-input-seek 
tests and `fate-source` also pass, and `git diff --check` is clean.

Additional Linux AArch64 validation covered 60 combinations of zero/nonzero 
source start timestamps, seeking, timestamp-copy modes and offsets. Each 
patched case retained 30 packets with payload sizes and checksums matching its 
zero-offset control. Full FATE was not run.

Fixes #26060.


From af9da4898f5199f37420f0e2ed74efea0096803e Mon Sep 17 00:00:00 2001
From: Michael Niedermayer <[email protected]>
Date: Mon, 16 Nov 2026 11:38:35 +0000
Subject: [PATCH] fftools/ffmpeg_demux: exclude itsoffset from streamcopy
 duration

Input -t is a duration, but the streamcopy cutoff compares it with a
DTS that already includes -itsoffset. Positive offsets shorten the
selected media, possibly dropping every packet, while negative offsets
extend it.

Subtract the user-specified offset for this comparison without changing
packet timestamps or the existing copyts/start_at_zero baseline. Use
saturating subtraction so the new arithmetic cannot overflow.

Add six sample-free FATE cases covering positive and negative offsets
with default timestamp handling, copyts, and copyts/start_at_zero.
All six fail before this change and pass with it. The existing limited
input seek tests also pass.

Fixes #26060.

Assisted-by: Fairy
---
 fftools/ffmpeg_demux.c                        |  3 ++-
 tests/fate/ffmpeg.mak                         | 23 +++++++++++++++++++
 .../fate/ffmpeg-streamcopy-itsoffset-negative | 15 ++++++++++++
 ...fmpeg-streamcopy-itsoffset-negative-copyts | 15 ++++++++++++
 ...treamcopy-itsoffset-negative-start_at_zero | 15 ++++++++++++
 .../fate/ffmpeg-streamcopy-itsoffset-positive | 15 ++++++++++++
 ...fmpeg-streamcopy-itsoffset-positive-copyts | 15 ++++++++++++
 ...treamcopy-itsoffset-positive-start_at_zero | 15 ++++++++++++
 8 files changed, 115 insertions(+), 1 deletion(-)
 create mode 100644 tests/ref/fate/ffmpeg-streamcopy-itsoffset-negative
 create mode 100644 tests/ref/fate/ffmpeg-streamcopy-itsoffset-negative-copyts
 create mode 100644 
tests/ref/fate/ffmpeg-streamcopy-itsoffset-negative-start_at_zero
 create mode 100644 tests/ref/fate/ffmpeg-streamcopy-itsoffset-positive
 create mode 100644 tests/ref/fate/ffmpeg-streamcopy-itsoffset-positive-copyts
 create mode 100644 
tests/ref/fate/ffmpeg-streamcopy-itsoffset-positive-start_at_zero

diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 5409dcdc6c0..4cadd0b07d2 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -500,7 +500,8 @@ static int input_packet_process(Demuxer *d, AVPacket *pkt, 
unsigned *send_flags)
             start_time += f->start_time != AV_NOPTS_VALUE ? f->start_time : 0;
             start_time += start_at_zero ? 0 : f->start_time_effective;
         }
-        if (ds->dts >= d->recording_time + start_time)
+        // The duration is independent of the user-specified timestamp offset.
+        if (av_sat_sub64(ds->dts, f->input_ts_offset) >= d->recording_time + 
start_time)
             *send_flags |= DEMUX_SEND_STREAMCOPY_EOF;
     }
 
diff --git a/tests/fate/ffmpeg.mak b/tests/fate/ffmpeg.mak
index b46eff0cf3b..0dd4fa04ec5 100644
--- a/tests/fate/ffmpeg.mak
+++ b/tests/fate/ffmpeg.mak
@@ -466,6 +466,29 @@ fate-ffmpeg-streamcopy-t: CMD = ffmpeg
     -c copy -f null -t 1 -
 FATE_FFMPEG-$(call REMUX, RAWVIDEO, NULL_MUXER) += fate-ffmpeg-streamcopy-t
 
+# Input duration must not depend on the timestamp offset, including with 
copyts.
+FATE_STREAMCOPY_ITSOFFSET = fate-ffmpeg-streamcopy-itsoffset-positive \
+                          fate-ffmpeg-streamcopy-itsoffset-negative \
+                          fate-ffmpeg-streamcopy-itsoffset-positive-copyts \
+                          fate-ffmpeg-streamcopy-itsoffset-negative-copyts \
+                          
fate-ffmpeg-streamcopy-itsoffset-positive-start_at_zero \
+                          
fate-ffmpeg-streamcopy-itsoffset-negative-start_at_zero
+
+$(FATE_STREAMCOPY_ITSOFFSET): tests/data/vsynth1.yuv
+$(FATE_STREAMCOPY_ITSOFFSET): CMD = framecrc $(COPYTS) -ss 1 -t 1 -itsoffset 
$(OFFSET) \
+    -f rawvideo -r 10 -s 352x288 -pix_fmt yuv420p -i 
$(TARGET_PATH)/tests/data/vsynth1.yuv -c copy
+fate-ffmpeg-streamcopy-itsoffset-positive \
+fate-ffmpeg-streamcopy-itsoffset-positive-copyts \
+fate-ffmpeg-streamcopy-itsoffset-positive-start_at_zero: OFFSET = 1
+fate-ffmpeg-streamcopy-itsoffset-negative \
+fate-ffmpeg-streamcopy-itsoffset-negative-copyts \
+fate-ffmpeg-streamcopy-itsoffset-negative-start_at_zero: OFFSET = -1
+fate-ffmpeg-streamcopy-itsoffset-positive-copyts \
+fate-ffmpeg-streamcopy-itsoffset-negative-copyts: COPYTS = -copyts
+fate-ffmpeg-streamcopy-itsoffset-positive-start_at_zero \
+fate-ffmpeg-streamcopy-itsoffset-negative-start_at_zero: COPYTS = -copyts 
-start_at_zero
+FATE_FFMPEG-$(call DEMMUX, RAWVIDEO, FRAMECRC, PIPE_PROTOCOL) += 
$(FATE_STREAMCOPY_ITSOFFSET)
+
 fate-ffmpeg-negative-t: tests/data/vsynth1.yuv
 fate-ffmpeg-negative-t: CMP = null
 fate-ffmpeg-negative-t: CMD = ffmpeg                                           
                    \
diff --git a/tests/ref/fate/ffmpeg-streamcopy-itsoffset-negative 
b/tests/ref/fate/ffmpeg-streamcopy-itsoffset-negative
new file mode 100644
index 00000000000..f95b5441e9a
--- /dev/null
+++ b/tests/ref/fate/ffmpeg-streamcopy-itsoffset-negative
@@ -0,0 +1,15 @@
+#tb 0: 1/10
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 352x288
+#sar 0: 0/1
+0,        -10,        -10,        1,   152064, 0x02344760
+0,         -9,         -9,        1,   152064, 0x30f5fcd5
+0,         -8,         -8,        1,   152064, 0xc711ad61
+0,         -7,         -7,        1,   152064, 0x24eca223
+0,         -6,         -6,        1,   152064, 0x52a48ddd
+0,         -5,         -5,        1,   152064, 0xa91c0f05
+0,         -4,         -4,        1,   152064, 0x8e364e18
+0,         -3,         -3,        1,   152064, 0xb15d38c8
+0,         -2,         -2,        1,   152064, 0xf25f6acc
+0,         -1,         -1,        1,   152064, 0xf34ddbff
diff --git a/tests/ref/fate/ffmpeg-streamcopy-itsoffset-negative-copyts 
b/tests/ref/fate/ffmpeg-streamcopy-itsoffset-negative-copyts
new file mode 100644
index 00000000000..c6a2a550677
--- /dev/null
+++ b/tests/ref/fate/ffmpeg-streamcopy-itsoffset-negative-copyts
@@ -0,0 +1,15 @@
+#tb 0: 1/10
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 352x288
+#sar 0: 0/1
+0,          0,          0,        1,   152064, 0x02344760
+0,          1,          1,        1,   152064, 0x30f5fcd5
+0,          2,          2,        1,   152064, 0xc711ad61
+0,          3,          3,        1,   152064, 0x24eca223
+0,          4,          4,        1,   152064, 0x52a48ddd
+0,          5,          5,        1,   152064, 0xa91c0f05
+0,          6,          6,        1,   152064, 0x8e364e18
+0,          7,          7,        1,   152064, 0xb15d38c8
+0,          8,          8,        1,   152064, 0xf25f6acc
+0,          9,          9,        1,   152064, 0xf34ddbff
diff --git a/tests/ref/fate/ffmpeg-streamcopy-itsoffset-negative-start_at_zero 
b/tests/ref/fate/ffmpeg-streamcopy-itsoffset-negative-start_at_zero
new file mode 100644
index 00000000000..c6a2a550677
--- /dev/null
+++ b/tests/ref/fate/ffmpeg-streamcopy-itsoffset-negative-start_at_zero
@@ -0,0 +1,15 @@
+#tb 0: 1/10
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 352x288
+#sar 0: 0/1
+0,          0,          0,        1,   152064, 0x02344760
+0,          1,          1,        1,   152064, 0x30f5fcd5
+0,          2,          2,        1,   152064, 0xc711ad61
+0,          3,          3,        1,   152064, 0x24eca223
+0,          4,          4,        1,   152064, 0x52a48ddd
+0,          5,          5,        1,   152064, 0xa91c0f05
+0,          6,          6,        1,   152064, 0x8e364e18
+0,          7,          7,        1,   152064, 0xb15d38c8
+0,          8,          8,        1,   152064, 0xf25f6acc
+0,          9,          9,        1,   152064, 0xf34ddbff
diff --git a/tests/ref/fate/ffmpeg-streamcopy-itsoffset-positive 
b/tests/ref/fate/ffmpeg-streamcopy-itsoffset-positive
new file mode 100644
index 00000000000..682949762c5
--- /dev/null
+++ b/tests/ref/fate/ffmpeg-streamcopy-itsoffset-positive
@@ -0,0 +1,15 @@
+#tb 0: 1/10
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 352x288
+#sar 0: 0/1
+0,         10,         10,        1,   152064, 0x02344760
+0,         11,         11,        1,   152064, 0x30f5fcd5
+0,         12,         12,        1,   152064, 0xc711ad61
+0,         13,         13,        1,   152064, 0x24eca223
+0,         14,         14,        1,   152064, 0x52a48ddd
+0,         15,         15,        1,   152064, 0xa91c0f05
+0,         16,         16,        1,   152064, 0x8e364e18
+0,         17,         17,        1,   152064, 0xb15d38c8
+0,         18,         18,        1,   152064, 0xf25f6acc
+0,         19,         19,        1,   152064, 0xf34ddbff
diff --git a/tests/ref/fate/ffmpeg-streamcopy-itsoffset-positive-copyts 
b/tests/ref/fate/ffmpeg-streamcopy-itsoffset-positive-copyts
new file mode 100644
index 00000000000..9f0a8ac2898
--- /dev/null
+++ b/tests/ref/fate/ffmpeg-streamcopy-itsoffset-positive-copyts
@@ -0,0 +1,15 @@
+#tb 0: 1/10
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 352x288
+#sar 0: 0/1
+0,         20,         20,        1,   152064, 0x02344760
+0,         21,         21,        1,   152064, 0x30f5fcd5
+0,         22,         22,        1,   152064, 0xc711ad61
+0,         23,         23,        1,   152064, 0x24eca223
+0,         24,         24,        1,   152064, 0x52a48ddd
+0,         25,         25,        1,   152064, 0xa91c0f05
+0,         26,         26,        1,   152064, 0x8e364e18
+0,         27,         27,        1,   152064, 0xb15d38c8
+0,         28,         28,        1,   152064, 0xf25f6acc
+0,         29,         29,        1,   152064, 0xf34ddbff
diff --git a/tests/ref/fate/ffmpeg-streamcopy-itsoffset-positive-start_at_zero 
b/tests/ref/fate/ffmpeg-streamcopy-itsoffset-positive-start_at_zero
new file mode 100644
index 00000000000..9f0a8ac2898
--- /dev/null
+++ b/tests/ref/fate/ffmpeg-streamcopy-itsoffset-positive-start_at_zero
@@ -0,0 +1,15 @@
+#tb 0: 1/10
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 352x288
+#sar 0: 0/1
+0,         20,         20,        1,   152064, 0x02344760
+0,         21,         21,        1,   152064, 0x30f5fcd5
+0,         22,         22,        1,   152064, 0xc711ad61
+0,         23,         23,        1,   152064, 0x24eca223
+0,         24,         24,        1,   152064, 0x52a48ddd
+0,         25,         25,        1,   152064, 0xa91c0f05
+0,         26,         26,        1,   152064, 0x8e364e18
+0,         27,         27,        1,   152064, 0xb15d38c8
+0,         28,         28,        1,   152064, 0xf25f6acc
+0,         29,         29,        1,   152064, 0xf34ddbff
-- 
2.54.0

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

Reply via email to