From patchwork Tue Jun 11 22:02:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: greg Luce X-Patchwork-Id: 13507 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 EC1C44493EE for ; Wed, 12 Jun 2019 01:09:08 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C5BB96883B2; Wed, 12 Jun 2019 01:09:08 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 067086805A9 for ; Wed, 12 Jun 2019 01:09:01 +0300 (EEST) Received: by mail-lj1-f196.google.com with SMTP id h10so7337268ljg.0 for ; Tue, 11 Jun 2019 15:09:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=LapQ78fKRLNwExl0C9ubztp3tCdkFpdZfrBBlkCl8xQ=; b=K7kd2pkCTFber+e+LaklDM+ZlEdFNtTJXDGsBBii56H3Qw6pnMZo6RQR4jkQVbOk2T rRHydLo21HtdqqUqR4ejD1zrNWUT0uNvCxCnxC9MnMM4FyMpN+CAxwXKJGFCA76KEFET t3hQBE4odE+af+aM9GgsxEedTF/52tSalMyfp70lonh8B8Dk6Ib5hDLeXcEfsoFBFrr4 v1PZBPIFreCZimicmvQ3pHctNKcRa7UuQE7Kg8sF9vFTNcNizR7R+nHFouFX9msCPGyT 2eVIktL09VE7k4n6TXyC3tjgwe1fR6IsCMEAQmgtUmJd4X66DiQxw/rafbVuCjP06xSr RnEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=LapQ78fKRLNwExl0C9ubztp3tCdkFpdZfrBBlkCl8xQ=; b=eb4/eqtRq/9TXhUxioWs/FYMCoFiOceM/Nc9YdqoIOhbvRaGGPp3+H4NaD7BtAeJGj vRKTmLLnuYJ73vNcvavYkCTInXRPnCbm3XXUy3Runu7UOOpztChyx8e8DIigVvj2TQR6 8k9X3osnImHUWBCxnBG6AekdRraM7o64W2w7U29uxCeEnsW16cdSlivn1gE7NojPJ550 1v6oX+NKEnhBrhtE28+NbcKFhpRl2MlB0MPxwOjgbBdmTGCYyBqv4hnKWTJ24VB0KnbU 7EaavnmHLJ9ceJeOmhBDKty9WKX7Z7cf1N5JBwedbkkylsARh8EXnB7La7KTgOjQeb3s FZwg== X-Gm-Message-State: APjAAAXkQSfLK/esmmrzb1bzRBQrLf9hiDArmXS8+1lpWFY87IecrOj8 IvN2fZWPKidWE9PBRtXIoZb1Xwe+TGsPRZAUPQM+KveR X-Google-Smtp-Source: APXvYqzvc3XIhxB25WV7OrysccAGY5NIKnIczxDmKFy8feWjeet9+ajH+7pZHNkTkzxCQ1ZaH/0Jfmf4uHluzWx/nP8= X-Received: by 2002:a2e:b0c4:: with SMTP id g4mr5029188ljl.155.1560290593340; Tue, 11 Jun 2019 15:03:13 -0700 (PDT) MIME-Version: 1.0 From: greg Luce Date: Tue, 11 Jun 2019 18:02:10 -0400 Message-ID: To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v2] vf_drawtext: Add pkt_pos, pkt_duration, pkt_size as variables 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This is on the bug tracker at https://trac.ffmpeg.org/ticket/7947 Created with the help of the excellent Calvin Walton and rewritten with the advice of the excellent Gyan --- doc/filters.texi | 24 +++++++++++++++++++++++- libavfilter/vf_drawtext.c | 9 +++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) draw_text(ctx, frame, frame->width, frame->height); diff --git a/doc/filters.texi b/doc/filters.texi index ec1c7c7591..e2ca2a8c08 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -8961,8 +8961,23 @@ the width of the rendered text @item y the x and y offset coordinates where the text is drawn. -These parameters allow the @var{x} and @var{y} expressions to refer +These parameters allow the @var{x} and @var{y} expressions to refer to each other, so you can for example specify @code{y=x/dar}. + +@item pict_type +A 1 character description of the current packet's input picture type. + +@item pkt_pos +The current packet's position in the input datastream (in bytes from the head of the source file). + +A value of -1 indicates this info is not available. + +@item pkt_duration +The current packet's input duration. + +@item pkt_size +The current packet's input size (in bytes). + @end table @anchor{drawtext_expansion} @@ -9032,6 +9047,13 @@ The first argument is mandatory and specifies the metadata key. The second argument is optional and specifies a default value, used when the metadata key is not found or empty. +Available metadata can be identified by inspecting entries starting with +TAG included within each frame section printed by running @code{ffprobe +-show_frames}. + +String metadata generated in filters leading to the drawtext filter are +also available. + @item n, frame_num The frame number, starting from 0. diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index 01cd7fa122..8f4badbdb5 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -88,6 +88,9 @@ static const char *const var_names[] = { "x", "y", "pict_type", + "pkt_pos", + "pkt_duration", + "pkt_size", NULL }; @@ -125,6 +128,9 @@ enum var_name { VAR_X, VAR_Y, VAR_PICT_TYPE, + VAR_PKT_POS, + VAR_PKT_DURATION, + VAR_PKT_SIZE, VAR_VARS_NB }; @@ -1516,6 +1522,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) NAN : frame->pts * av_q2d(inlink->time_base); s->var_values[VAR_PICT_TYPE] = frame->pict_type; + s->var_values[VAR_PKT_POS] = frame->pkt_pos; + s->var_values[VAR_PKT_DURATION] = frame->pkt_duration * av_q2d(inlink->time_base); + s->var_values[VAR_PKT_SIZE] = frame->pkt_size; s->metadata = frame->metadata;