From d415752e795b79008f15052ef86aadbe1ca52b46 Mon Sep 17 00:00:00 2001
From: greg Luce <electron.rotoscope@gmail.com> 
Date: Wed, 19 Jun 2019 16:39:33 -0400
Subject: [PATCH v3] vf_drawtext - Add variables
 <electron.rotoscope@gmail.com>

---
 doc/filters.texi          | 23 +++++++++++++++++++++++
 libavfilter/version.h     |  2 +-
 libavfilter/vf_drawtext.c |  9 +++++++++
 3 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 3313f96bd4..63e6f21165 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -8963,6 +8963,22 @@ the x and y offset coordinates where the text is drawn.
 
 These parameters allow the @var{x} and @var{y} expressions to refer
 each other, so you can for example specify @code{y=x/dar}.
+
+@item pict_type
+A 1 character description of the current packet's picture type.
+
+@item pkt_pos
+The current packet's position in the 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 duration.
+
+@item pkt_size
+The current packet's size (in bytes).
+
 @end table
 
 @anchor{drawtext_expansion}
@@ -9032,6 +9048,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/version.h b/libavfilter/version.h
index 91a5a1604e..c0a4b969f1 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -31,7 +31,7 @@
 
 #define LIBAVFILTER_VERSION_MAJOR   7
 #define LIBAVFILTER_VERSION_MINOR  55
-#define LIBAVFILTER_VERSION_MICRO 100
+#define LIBAVFILTER_VERSION_MICRO 101
 
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
                                                LIBAVFILTER_VERSION_MINOR, \
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;
 
     draw_text(ctx, frame, frame->width, frame->height);
-- 
2.22.0.windows.1

