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

# Summary of changes

Briefly describe what this PR does and why.

Fix #24259

Ignore Filter atrim, with duration set to INT64_MAX is ignoredl, not 0.

<!--
If this PR requires new FATE test samples, attach them to the PR and
list their target paths below (relative to the fate-suite root).

Attached filenames must match the sample's filename:

```fate-samples
# e.g. vorbis/new-sample.ogg
```
-->



>From b14fda46c3102d2a677cf1f4311398a2fe59f537 Mon Sep 17 00:00:00 2001
From: Ariel Yu <[email protected]>
Date: Wed, 16 Sep 2026 16:36:22 +0800
Subject: [PATCH 1/2] Fix default s->duration_tb and s->duration to INT64_MAX
 and change some condition accordingly.

Fix #24529

Signed-off-by: Ariel Yu <[email protected]>
---
 libavfilter/trim.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavfilter/trim.c b/libavfilter/trim.c
index 6d1016ac81..c19b1118d8 100644
--- a/libavfilter/trim.c
+++ b/libavfilter/trim.c
@@ -107,7 +107,7 @@ static int trim_filter_frame(AVFilterLink *inlink, AVFrame 
*frame)
     if (s->first_pts == AV_NOPTS_VALUE && frame->pts != AV_NOPTS_VALUE)
         s->first_pts = frame->pts;
 
-    if (s->end_frame != INT64_MAX || s->end_pts != AV_NOPTS_VALUE || 
s->duration_tb) {
+    if (s->end_frame != INT64_MAX || s->end_pts != AV_NOPTS_VALUE || 
s->duration != INT64_MAX) {
         drop = 1;
 
         if (s->end_frame != INT64_MAX && s->nb_frames < s->end_frame)
@@ -115,7 +115,7 @@ static int trim_filter_frame(AVFilterLink *inlink, AVFrame 
*frame)
         if (s->end_pts != AV_NOPTS_VALUE && frame->pts != AV_NOPTS_VALUE &&
             frame->pts < s->end_pts)
             drop = 0;
-        if (s->duration_tb && frame->pts != AV_NOPTS_VALUE &&
+        if (s->duration_tb != INT64_MAX && frame->pts != AV_NOPTS_VALUE &&
             frame->pts - s->first_pts < s->duration_tb)
             drop = 0;
 
@@ -184,7 +184,7 @@ static int atrim_filter_frame(AVFilterLink *inlink, AVFrame 
*frame)
         s->first_pts = pts + start_sample;
 
     /* check if at least a part of the frame is before the end time */
-    if (s->end_sample == INT64_MAX && s->end_pts == AV_NOPTS_VALUE && 
!s->duration_tb) {
+    if (s->end_sample == INT64_MAX && s->end_pts == AV_NOPTS_VALUE && 
s->duration_tb == INT64_MAX) {
         end_sample = frame->nb_samples;
     } else {
         drop       = 1;
@@ -202,7 +202,7 @@ static int atrim_filter_frame(AVFilterLink *inlink, AVFrame 
*frame)
             end_sample = FFMAX(end_sample, s->end_pts - pts);
         }
 
-        if (s->duration_tb && pts - s->first_pts < s->duration_tb) {
+        if (s->duration_tb != INT64_MAX && pts - s->first_pts < 
s->duration_tb) {
             drop       = 0;
             end_sample = FFMAX(end_sample, s->first_pts + s->duration_tb - 
pts);
         }
@@ -273,7 +273,7 @@ static int config_input(AVFilterLink *inlink)
         if (s->end_pts == AV_NOPTS_VALUE || end_pts > s->end_pts)
             s->end_pts = end_pts;
     }
-    if (s->duration)
+    if (s->duration != INT64_MAX)
         s->duration_tb = av_rescale_q(s->duration, AV_TIME_BASE_Q, tb);
 
     return 0;
@@ -321,8 +321,8 @@ static int activate(AVFilterContext *ctx)
        " passed",                                                        
OFFSET(start_pts),   AV_OPT_TYPE_INT64,  { .i64 = AV_NOPTS_VALUE }, INT64_MIN, 
INT64_MAX, FLAGS }, \
     { "end_pts",     "Timestamp of the first frame that should be "            
                                                                                
             \
         "dropped again",                                                 
OFFSET(end_pts),     AV_OPT_TYPE_INT64,  { .i64 = AV_NOPTS_VALUE }, INT64_MIN, 
INT64_MAX, FLAGS }, \
-    { "duration",    "Maximum duration of the output",                   
OFFSET(duration),    AV_OPT_TYPE_DURATION, { .i64 = 0 },                    0, 
INT64_MAX, FLAGS }, \
-    { "durationi",   "Maximum duration of the output",                   
OFFSET(duration),    AV_OPT_TYPE_DURATION, { .i64 = 0 },                    0, 
INT64_MAX, FLAGS },
+    { "duration",    "Maximum duration of the output",                   
OFFSET(duration),    AV_OPT_TYPE_DURATION, { .i64 = INT64_MAX },                
    0, INT64_MAX, FLAGS }, \
+    { "durationi",   "Maximum duration of the output",                   
OFFSET(duration),    AV_OPT_TYPE_DURATION, { .i64 = INT64_MAX },                
    0, INT64_MAX, FLAGS },
 
 
 #if CONFIG_TRIM_FILTER
-- 
2.52.0


>From ddbd334fe4e9245bb8591c31e1019989cd4f9479 Mon Sep 17 00:00:00 2001
From: Ariel Yu <[email protected]>
Date: Wed, 16 Sep 2026 17:46:27 +0800
Subject: [PATCH 2/2] Add test for duration 0 for video and audio.

Signed-off-by: Ariel Yu <[email protected]>
---
 tests/fate/filter-audio.mak               | 2 ++
 tests/fate/filter-video.mak               | 2 ++
 tests/ref/fate/filter-atrim-duration-zero | 5 +++++
 tests/ref/fate/filter-trim-duration-zero  | 5 +++++
 4 files changed, 14 insertions(+)
 create mode 100644 tests/ref/fate/filter-atrim-duration-zero
 create mode 100644 tests/ref/fate/filter-trim-duration-zero

diff --git a/tests/fate/filter-audio.mak b/tests/fate/filter-audio.mak
index b5c27daf1c..5f475e306a 100644
--- a/tests/fate/filter-audio.mak
+++ b/tests/fate/filter-audio.mak
@@ -281,6 +281,8 @@ fate-filter-aselect: CMD = framecrc -i $(SRC) -af 
"aselect=gte(t\,1)*lt(t\,2)"
 
 FATE_ATRIM += fate-filter-atrim-duration
 fate-filter-atrim-duration: CMD = framecrc -i $(SRC) -af 
atrim=start=0.1:duration=0.01
+FATE_ATRIM += fate-filter-atrim-duration-zero
+fate-filter-atrim-duration-zero: CMD = framecrc -i $(SRC) -af atrim=duration=0
 FATE_ATRIM += fate-filter-atrim-mixed
 fate-filter-atrim-mixed: CMD = framecrc -i $(SRC) -af 
atrim=start=0.05:start_sample=1025:end=0.1:end_sample=4411
 
diff --git a/tests/fate/filter-video.mak b/tests/fate/filter-video.mak
index b0284c9813..3c51dcf658 100644
--- a/tests/fate/filter-video.mak
+++ b/tests/fate/filter-video.mak
@@ -401,6 +401,8 @@ fate-filter-transpose: CMD = framecrc -c:v pgmyuv -i $(SRC) 
-vf transpose
 
 FATE_TRIM += fate-filter-trim-duration
 fate-filter-trim-duration: CMD = framecrc -i $(SRC) -vf 
trim=start=0.4:duration=0.05
+FATE_TRIM += fate-filter-trim-duration-zero
+fate-filter-trim-duration-zero: CMD = framecrc -i $(SRC) -vf 
trim=start=0.4:duration=0
 
 FATE_TRIM += fate-filter-trim-frame
 fate-filter-trim-frame: CMD = framecrc -i $(SRC) -vf 
trim=start_frame=3:end_frame=10
diff --git a/tests/ref/fate/filter-atrim-duration-zero 
b/tests/ref/fate/filter-atrim-duration-zero
new file mode 100644
index 0000000000..5f9594d035
--- /dev/null
+++ b/tests/ref/fate/filter-atrim-duration-zero
@@ -0,0 +1,5 @@
+#tb 0: 1/44100
+#media_type 0: audio
+#codec_id 0: pcm_s16le
+#sample_rate 0: 44100
+#channel_layout_name 0: stereo
diff --git a/tests/ref/fate/filter-trim-duration-zero 
b/tests/ref/fate/filter-trim-duration-zero
new file mode 100644
index 0000000000..a3b02f7d07
--- /dev/null
+++ b/tests/ref/fate/filter-trim-duration-zero
@@ -0,0 +1,5 @@
+#tb 0: 1/25
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 352x432
+#sar 0: 0/1
-- 
2.52.0

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

Reply via email to