Message ID | wIWWbeRKtJVcP_bV2DMkeZGsPF9LcFgshL4YqWgocVJDP2Mnym7Y5ceHbW7-spGGq_gejhYpSTGvymIvsZsm0WGxUrGdOh_myYoKsT98BJ0=@protonmail.com |
---|---|
State | Accepted |
Commit | 32d6fe23b66075565894a5432278c95ab479584a |
Headers | show |
Series | [FFmpeg-devel,V3] avfilter/zoompan: add in_time variable | expand |
Context | Check | Description |
---|---|---|
andriy/default | pending | |
andriy/make | success | Make finished |
andriy/make_fate | success | Make fate finished |
LGTM On 6/19/20, exwm <thighsman@protonmail.com> wrote: > Currently, the zoompan filter exposes a 'time' variable (missing from docs) > for use in > the 'zoom', 'x', and 'y' expressions. This variable is perhaps better named > 'out_time' as it represents the timestamp in seconds of each output frame > produced by zoompan. This patch adds aliases 'out_time' and 'ot' for 'time'. > > This patch also adds an 'in_time' (alias 'it') variable that provides access > to the timestamp in seconds of each input frame to the zoompan filter. > This helps to design zoompan filters that depend on the input video > timestamps. > For example, it makes it easy to zoom in instantly for only some portion of > a video. > Both the 'out_time' and 'in_time' variables have been added in the > documentation > for zoompan. > > Example usage of 'in_time' in the zoompan filter to zoom in 2x for the > first second of the input video and 1x for the rest: > zoompan=z='if(between(in_time,0,1),2,1):d=1' > > V2: Fix zoompan filter documentation stating that the time variable > would be NAN if the input timestamp is unknown. > > V3: Add 'it' alias for 'in_time. Add 'out_time' and 'ot' aliases for 'time'. > Minor corrections to zoompan docs. > > Signed-off-by: exwm <thighsman@protonmail.com> > --- > doc/filters.texi | 17 +++++++++++++++-- > libavfilter/vf_zoompan.c | 12 +++++++++--- > 2 files changed, 24 insertions(+), 5 deletions(-) > > diff --git a/doc/filters.texi b/doc/filters.texi > index 5f0eb28f76..fe46e7192f 100644 > --- a/doc/filters.texi > +++ b/doc/filters.texi > @@ -20739,6 +20739,12 @@ Input frame count. > @item on > Output frame count. > > +@item in_time, it > +The input timestamp expressed in seconds. It's NAN if the input timestamp > is unknown. > + > +@item out_time, time, ot > +The output timestamp expressed in seconds. > + > @item x > @item y > Last calculated 'x' and 'y' position from 'x' and 'y' expression > @@ -20777,13 +20783,13 @@ display aspect ratio > > @itemize > @item > -Zoom-in up to 1.5 and pan at same time to some spot near center of picture: > +Zoom in up to 1.5x and pan at same time to some spot near center of > picture: > @example > zoompan=z='min(zoom+0.0015,1.5)':d=700:x='if(gte(zoom,1.5),x,x+1/a)':y='if(gte(zoom,1.5),y,y+1)':s=640x360 > @end example > > @item > -Zoom-in up to 1.5 and pan always at center of picture: > +Zoom in up to 1.5x and pan always at center of picture: > @example > zoompan=z='min(zoom+0.0015,1.5)':d=700:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)' > @end example > @@ -20793,6 +20799,13 @@ Same as above but without pausing: > @example > zoompan=z='min(max(zoom,pzoom)+0.0015,1.5)':d=1:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)' > @end example > + > +@item > +Zoom in 2x into center of picture only for the first second of the input > video: > +@example > +zoompan=z='if(between(in_time,0,1),2,1)':d=1:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)' > +@end example > + > @end itemize > > @anchor{zscale} > diff --git a/libavfilter/vf_zoompan.c b/libavfilter/vf_zoompan.c > index 59c9b19ec8..d9d53decf4 100644 > --- a/libavfilter/vf_zoompan.c > +++ b/libavfilter/vf_zoompan.c > @@ -38,7 +38,8 @@ static const char *const var_names[] = { > "on", > "duration", > "pduration", > - "time", > + "in_time", "it", > + "out_time", "time", "ot", > "frame", > "zoom", > "pzoom", > @@ -61,7 +62,8 @@ enum var_name { > VAR_ON, > VAR_DURATION, > VAR_PDURATION, > - VAR_TIME, > + VAR_IN_TIME, VAR_IT, > + VAR_TIME, VAR_OUT_TIME, VAR_OT, > VAR_FRAME, > VAR_ZOOM, > VAR_PZOOM, > @@ -155,6 +157,7 @@ static int output_single_frame(AVFilterContext *ctx, > AVFrame *in, double *var_va > { > ZPContext *s = ctx->priv; > AVFilterLink *outlink = ctx->outputs[0]; > + AVFilterLink *inlink = ctx->inputs[0]; > int64_t pts = s->frame_count; > int k, x, y, w, h, ret = 0; > uint8_t *input[4]; > @@ -165,7 +168,10 @@ static int output_single_frame(AVFilterContext *ctx, > AVFrame *in, double *var_va > var_values[VAR_PY] = s->y; > var_values[VAR_PZOOM] = s->prev_zoom; > var_values[VAR_PDURATION] = s->prev_nb_frames; > - var_values[VAR_TIME] = pts * av_q2d(outlink->time_base); > + var_values[VAR_IN_TIME] = var_values[VAR_IT] = in->pts == > AV_NOPTS_VALUE ? > + NAN : in->pts * av_q2d(inlink->time_base); > + var_values[VAR_OUT_TIME] = pts * av_q2d(outlink->time_base); > + var_values[VAR_TIME] = var_values[VAR_OT] = var_values[VAR_OUT_TIME]; > var_values[VAR_FRAME] = i; > var_values[VAR_ON] = outlink->frame_count_in; > > -- > 2.26.0 > > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff --git a/doc/filters.texi b/doc/filters.texi index 5f0eb28f76..fe46e7192f 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -20739,6 +20739,12 @@ Input frame count. @item on Output frame count. +@item in_time, it +The input timestamp expressed in seconds. It's NAN if the input timestamp is unknown. + +@item out_time, time, ot +The output timestamp expressed in seconds. + @item x @item y Last calculated 'x' and 'y' position from 'x' and 'y' expression @@ -20777,13 +20783,13 @@ display aspect ratio @itemize @item -Zoom-in up to 1.5 and pan at same time to some spot near center of picture: +Zoom in up to 1.5x and pan at same time to some spot near center of picture: @example zoompan=z='min(zoom+0.0015,1.5)':d=700:x='if(gte(zoom,1.5),x,x+1/a)':y='if(gte(zoom,1.5),y,y+1)':s=640x360 @end example @item -Zoom-in up to 1.5 and pan always at center of picture: +Zoom in up to 1.5x and pan always at center of picture: @example zoompan=z='min(zoom+0.0015,1.5)':d=700:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)' @end example @@ -20793,6 +20799,13 @@ Same as above but without pausing: @example zoompan=z='min(max(zoom,pzoom)+0.0015,1.5)':d=1:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)' @end example + +@item +Zoom in 2x into center of picture only for the first second of the input video: +@example +zoompan=z='if(between(in_time,0,1),2,1)':d=1:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)' +@end example + @end itemize @anchor{zscale} diff --git a/libavfilter/vf_zoompan.c b/libavfilter/vf_zoompan.c index 59c9b19ec8..d9d53decf4 100644 --- a/libavfilter/vf_zoompan.c +++ b/libavfilter/vf_zoompan.c @@ -38,7 +38,8 @@ static const char *const var_names[] = { "on", "duration", "pduration", - "time", + "in_time", "it", + "out_time", "time", "ot", "frame", "zoom", "pzoom", @@ -61,7 +62,8 @@ enum var_name { VAR_ON, VAR_DURATION, VAR_PDURATION, - VAR_TIME, + VAR_IN_TIME, VAR_IT, + VAR_TIME, VAR_OUT_TIME, VAR_OT, VAR_FRAME, VAR_ZOOM, VAR_PZOOM, @@ -155,6 +157,7 @@ static int output_single_frame(AVFilterContext *ctx, AVFrame *in, double *var_va { ZPContext *s = ctx->priv; AVFilterLink *outlink = ctx->outputs[0]; + AVFilterLink *inlink = ctx->inputs[0]; int64_t pts = s->frame_count; int k, x, y, w, h, ret = 0; uint8_t *input[4]; @@ -165,7 +168,10 @@ static int output_single_frame(AVFilterContext *ctx, AVFrame *in, double *var_va var_values[VAR_PY] = s->y; var_values[VAR_PZOOM] = s->prev_zoom; var_values[VAR_PDURATION] = s->prev_nb_frames; - var_values[VAR_TIME] = pts * av_q2d(outlink->time_base); + var_values[VAR_IN_TIME] = var_values[VAR_IT] = in->pts == AV_NOPTS_VALUE ? + NAN : in->pts * av_q2d(inlink->time_base); + var_values[VAR_OUT_TIME] = pts * av_q2d(outlink->time_base); + var_values[VAR_TIME] = var_values[VAR_OT] = var_values[VAR_OUT_TIME]; var_values[VAR_FRAME] = i; var_values[VAR_ON] = outlink->frame_count_in;
Currently, the zoompan filter exposes a 'time' variable (missing from docs) for use in the 'zoom', 'x', and 'y' expressions. This variable is perhaps better named 'out_time' as it represents the timestamp in seconds of each output frame produced by zoompan. This patch adds aliases 'out_time' and 'ot' for 'time'. This patch also adds an 'in_time' (alias 'it') variable that provides access to the timestamp in seconds of each input frame to the zoompan filter. This helps to design zoompan filters that depend on the input video timestamps. For example, it makes it easy to zoom in instantly for only some portion of a video. Both the 'out_time' and 'in_time' variables have been added in the documentation for zoompan. Example usage of 'in_time' in the zoompan filter to zoom in 2x for the first second of the input video and 1x for the rest: zoompan=z='if(between(in_time,0,1),2,1):d=1' V2: Fix zoompan filter documentation stating that the time variable would be NAN if the input timestamp is unknown. V3: Add 'it' alias for 'in_time. Add 'out_time' and 'ot' aliases for 'time'. Minor corrections to zoompan docs. Signed-off-by: exwm <thighsman@protonmail.com> --- doc/filters.texi | 17 +++++++++++++++-- libavfilter/vf_zoompan.c | 12 +++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-)