From patchwork Thu Jun 18 21:13:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: exwm X-Patchwork-Id: 20474 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 0202B449B95 for ; Fri, 19 Jun 2020 00:13:11 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D172168B4DD; Fri, 19 Jun 2020 00:13:10 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-40137.protonmail.ch (mail-40137.protonmail.ch [185.70.40.137]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EAA1168B1AF for ; Fri, 19 Jun 2020 00:13:04 +0300 (EEST) Date: Thu, 18 Jun 2020 21:13:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1592514783; bh=QJHhgxFw8sfLkiMDLjKbK4LOei3gaFcXxTPiNlz9Log=; h=Date:To:From:Cc:Reply-To:Subject:From; b=CcnYHn8TduRBkRNniJiDAJZukGndUZJCIelRX1M53YOH4DwVJTp291tLukdgNjCx3 lPuvf7rAiLWwiwc9uFeSrCrIBjmhHwi5/BkkeJtLPvzY4ZJJSjiZSeuSq29zKHiE/0 OnlVzRYJn+IdHVdOFwr7xsUHE/ibwTFGJ+MQKVbI= To: ffmpeg-devel@ffmpeg.org From: exwm Message-ID: MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=7.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM shortcircuit=no autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mail.protonmail.ch Subject: [FFmpeg-devel] [PATCH] avfilter/zoompan: add in_time variable X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: exwm Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Currently, the zoompan filter exposes a time variable 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 does not rename the time variable to out_time as this may be a breaking change. This patch adds instead an in_time 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 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' Signed-off-by: exwm --- doc/filters.texi | 13 +++++++++++++ libavfilter/vf_zoompan.c | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/doc/filters.texi b/doc/filters.texi index 84567dec16..c9bf6d29d9 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -20733,6 +20733,12 @@ Input frame count. @item on Output frame count. +@item in_time +The input timestamp expressed in seconds. It's NAN if the input timestamp is unknown. + +@item time +The output timestamp expressed in seconds. It's NAN if the input timestamp is unknown. + @item x @item y Last calculated 'x' and 'y' position from 'x' and 'y' expression @@ -20787,6 +20793,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..5fe9e68b3a 100644 --- a/libavfilter/vf_zoompan.c +++ b/libavfilter/vf_zoompan.c @@ -38,6 +38,7 @@ static const char *const var_names[] = { "on", "duration", "pduration", + "in_time", "time", "frame", "zoom", @@ -62,6 +63,7 @@ enum var_name { VAR_DURATION, VAR_PDURATION, VAR_TIME, + VAR_IN_TIME, 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,6 +168,8 @@ 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_IN_TIME] = in->pts == AV_NOPTS_VALUE ? + NAN : in->pts * av_q2d(inlink->time_base); var_values[VAR_TIME] = pts * av_q2d(outlink->time_base); var_values[VAR_FRAME] = i; var_values[VAR_ON] = outlink->frame_count_in;