Commit 512361b2b7 for ffmpeg

commit 512361b2b71c92922d385fa2254a24b55ff50904
Author: Baptiste Coudurier <baptiste.coudurier@gmail.com>
Date:   Thu Dec 3 01:50:30 2026 -0800

    avfilter/trim: export the duration cutoff

    Expose the established cutoff and allow typed end_pts updates after
    link configuration.

    Assisted-by: Claude Opus 5.5
    Assisted-by: OpenAI Codex
    Signed-off-by: Baptiste Coudurier <baptiste.coudurier@gmail.com>
    Assisted-by: Fairy

diff --git a/doc/filters.texi b/doc/filters.texi
index 5ccdae0a3d..b467678234 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -3876,6 +3876,16 @@ ffmpeg -i INPUT -af atrim=end_sample=1000

 @end itemize

+The read-only AVOption @option{duration_end_pts} reports the exclusive
+cutoff established by @option{duration}, in samples. It returns
+@code{AV_NOPTS_VALUE} until a representable duration cutoff is established.
+
+@subsection Commands
+
+The @option{end_pts} command replaces the timestamp end boundary, including
+one initialized with @option{end}. Other end constraints, such as
+@option{duration}, continue to apply.
+
 @section axcorrelate
 Calculate normalized windowed cross-correlation between two input audio streams.

@@ -25285,6 +25295,16 @@ ffmpeg -i INPUT -vf trim=duration=1

 @end itemize

+The read-only AVOption @option{duration_end_pts} reports the exclusive
+cutoff established by @option{duration}, in input-link ticks. It returns
+@code{AV_NOPTS_VALUE} until a representable duration cutoff is established.
+
+@subsection Commands
+
+The @option{end_pts} command replaces the timestamp end boundary, including
+one initialized with @option{end}. Other end constraints, such as
+@option{duration}, continue to apply.
+
 @section unpremultiply
 Apply alpha unpremultiply effect to input video stream using first plane
 of second stream as alpha.
diff --git a/libavfilter/trim.c b/libavfilter/trim.c
index 1077ff3d1a..bd0fa4c58b 100644
--- a/libavfilter/trim.c
+++ b/libavfilter/trim.c
@@ -40,6 +40,7 @@ typedef struct TrimContext {
      * AVOptions
      */
     int64_t duration;
+    int disable_commands;
     int64_t start_time, end_time;
     int64_t start_frame, end_frame;
     /*
@@ -65,6 +66,7 @@ typedef struct TrimContext {
      * duration in the timebase units
      */
     int64_t duration_tb;
+    int64_t duration_end_pts;

     int64_t next_pts;

@@ -77,11 +79,18 @@ static av_cold int init(AVFilterContext *ctx)
 {
     TrimContext *s = ctx->priv;

-    s->first_pts = AV_NOPTS_VALUE;
+    s->first_pts = s->duration_end_pts = AV_NOPTS_VALUE;

     return 0;
 }

+static void set_first_pts(TrimContext *s, int64_t pts)
+{
+    s->first_pts = pts;
+    if (s->duration_tb > 0 && pts <= INT64_MAX - s->duration_tb)
+        s->duration_end_pts = pts + s->duration_tb;
+}
+
 #if CONFIG_TRIM_FILTER
 static int trim_filter_frame(AVFilterLink *inlink, AVFrame *frame)
 {
@@ -105,7 +114,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;
+        set_first_pts(s, frame->pts);

     if (s->end_frame != INT64_MAX || s->end_pts != AV_NOPTS_VALUE || s->duration_tb) {
         drop = 1;
@@ -181,7 +190,7 @@ static int atrim_filter_frame(AVFilterLink *inlink, AVFrame *frame)
     }

     if (s->first_pts == AV_NOPTS_VALUE)
-        s->first_pts = pts + start_sample;
+        set_first_pts(s, 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) {
@@ -307,6 +316,16 @@ static int activate(AVFilterContext *ctx)
     return FFERROR_NOT_READY;
 }

+static int process_command(AVFilterContext *ctx, const char *cmd, const char *arg,
+                           char *res, int res_len, int flags)
+{
+    TrimContext *s = ctx->priv;
+
+    if (s->disable_commands)
+        return AVERROR(ENOSYS);
+    return ff_filter_process_command(ctx, cmd, arg, res, res_len, flags);
+}
+
 #define OFFSET(x) offsetof(TrimContext, x)
 #define COMMON_OPTS                                                                                                                                                         \
     { "start",       "Timestamp of the first frame that "                                                                                                        \
@@ -320,9 +339,12 @@ static int activate(AVFilterContext *ctx)
     { "start_pts",   "Timestamp of the first frame that should be "                                                                                                         \
        " 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 }, \
+        "dropped again",                                                 OFFSET(end_pts),     AV_OPT_TYPE_INT64,  { .i64 = AV_NOPTS_VALUE }, INT64_MIN, INT64_MAX, FLAGS | AV_OPT_FLAG_RUNTIME_PARAM }, \
     { "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 },
+    { "durationi",   "Maximum duration of the output",                   OFFSET(duration),    AV_OPT_TYPE_DURATION, { .i64 = 0 },                    0, INT64_MAX, FLAGS }, \
+    { "disable_commands", NULL, OFFSET(disable_commands), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, 0 }, \
+    { "duration_end_pts", "Established duration cutoff in video ticks or audio samples", \
+      OFFSET(duration_end_pts), AV_OPT_TYPE_INT64, { .i64 = AV_NOPTS_VALUE }, INT64_MIN, INT64_MAX, FLAGS | AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY },


 #if CONFIG_TRIM_FILTER
@@ -355,6 +377,7 @@ const FFFilter ff_vf_trim = {
     .p.flags       = AVFILTER_FLAG_METADATA_ONLY,
     .init        = init,
     .activate    = activate,
+    .process_command = process_command,
     .priv_size   = sizeof(TrimContext),
     FILTER_INPUTS(trim_inputs),
     FILTER_OUTPUTS(ff_video_default_filterpad),
@@ -392,6 +415,7 @@ const FFFilter ff_af_atrim = {
     .p.flags       = AVFILTER_FLAG_METADATA_ONLY,
     .init        = init,
     .activate    = activate,
+    .process_command = process_command,
     .priv_size   = sizeof(TrimContext),
     FILTER_INPUTS(atrim_inputs),
     FILTER_OUTPUTS(ff_audio_default_filterpad),
diff --git a/libavfilter/version.h b/libavfilter/version.h
index 64cd692ab6..4239736a2d 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -32,7 +32,7 @@
 #include "version_major.h"

 #define LIBAVFILTER_VERSION_MINOR  12
-#define LIBAVFILTER_VERSION_MICRO 100
+#define LIBAVFILTER_VERSION_MICRO 101


 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \