From 8f222573e9b1d98a38fcc5578676b109592ac982 Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Fri, 13 Mar 2020 17:19:33 +0100 Subject: [PATCH] avfilter/f_sendcmd: add more useful variables --- doc/filters.texi | 9 +++++++++ libavfilter/f_sendcmd.c | 14 +++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/doc/filters.texi b/doc/filters.texi index ff008b119f..328e984e92 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -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 diff --git a/libavfilter/f_sendcmd.c b/libavfilter/f_sendcmd.c index 5a62a338ee..0ac87e07ef 100644 --- a/libavfilter/f_sendcmd.c +++ b/libavfilter/f_sendcmd.c @@ -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) {