]> git.sesse.net Git - ffmpeg/commitdiff
avfilter/f_sendcmd: add more useful variables
authorPaul B Mahol <onemda@gmail.com>
Fri, 13 Mar 2020 16:19:33 +0000 (17:19 +0100)
committerPaul B Mahol <onemda@gmail.com>
Fri, 13 Mar 2020 16:19:33 +0000 (17:19 +0100)
doc/filters.texi
libavfilter/f_sendcmd.c

index ff008b119ff6cd5da05a759c0caf4b3d3b17f3e0..328e984e922175187f62fb4d3ca6efd073a429eb 100644 (file)
@@ -23711,6 +23711,15 @@ The count of the input frame for video or audio, starting from 0.
 
 @item T
 The time in seconds of the current frame.
+
+@item TS
+The start time in seconds of the current command interval.
+
+@item TE
+The end time in seconds of the current command interval.
+
+@item TI
+The interpolated time of the current command interval, TI = (T - TS) / (TE - TS).
 @end table
 
 @end table
index 5a62a338eec811cf0498c5ef57b52ece0d06cd0c..0ac87e07ef413d3ed2057d25c1d714a93856907e 100644 (file)
@@ -43,6 +43,9 @@ static const char *const var_names[] = {
     "T",     /* frame time in seconds */
     "POS",   /* original position in the file of the frame */
     "PTS",   /* frame pts */
+    "TS",    /* interval start time in seconds */
+    "TE",    /* interval end time in seconds */
+    "TI",    /* interval interpolated value: TI = (T - TS) / (TE - TS) */
     NULL
 };
 
@@ -51,6 +54,9 @@ enum var_name {
     VAR_T,
     VAR_POS,
     VAR_PTS,
+    VAR_TS,
+    VAR_TE,
+    VAR_TI,
     VAR_VARS_NB
 };
 
@@ -517,11 +523,17 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *ref)
                 if (cmd->flags & flags) {
                     if (cmd->flags & COMMAND_FLAG_EXPR) {
                         double var_values[VAR_VARS_NB], res;
+                        double start = TS2T(interval->start_ts, AV_TIME_BASE_Q);
+                        double end = TS2T(interval->end_ts, AV_TIME_BASE_Q);
+                        double current = TS2T(ref->pts, inlink->time_base);
 
                         var_values[VAR_N]   = inlink->frame_count_in;
                         var_values[VAR_POS] = ref->pkt_pos == -1 ? NAN : ref->pkt_pos;
                         var_values[VAR_PTS] = TS2D(ref->pts);
-                        var_values[VAR_T]   = TS2T(ref->pts, inlink->time_base);
+                        var_values[VAR_T]   = current;
+                        var_values[VAR_TS]  = start;
+                        var_values[VAR_TE]  = end;
+                        var_values[VAR_TI]  = (current - start) / (end - start);
 
                         if ((ret = av_expr_parse_and_eval(&res, cmd->arg, var_names, var_values,
                                                           NULL, NULL, NULL, NULL, NULL, 0, NULL)) < 0) {