[FFmpeg-devel] [PATCH] lavfi/drawtext: add support for printing frame numbers

Stefano Sabatini stefasab at gmail.com
Thu Nov 22 12:10:51 CET 2012


Fix trac ticket #1949.

TODO: bump micro
---
 doc/filters.texi          |    5 +++++
 libavfilter/vf_drawtext.c |   11 +++++++++++
 2 files changed, 16 insertions(+)

diff --git a/doc/filters.texi b/doc/filters.texi
index 5bdd745..bc432d8 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -2083,6 +2083,11 @@ It can accept an argument: a strftime() format string.
 The time at which the filter is running, expressed in the local time zone.
 It can accept an argument: a strftime() format string.
 
+ at item n
+The frame number, starting from 0. It can accept one argument: the
+printf() format to use for printing the number, if not specified it
+defaults to @code{%d}.
+
 @item pts
 The timestamp of the current frame, in seconds, with microsecond accuracy.
 
diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
index a78a3ea..04323d5 100644
--- a/libavfilter/vf_drawtext.c
+++ b/libavfilter/vf_drawtext.c
@@ -611,6 +611,16 @@ static int func_pts(AVFilterContext *ctx, AVBPrint *bp,
     return 0;
 }
 
+static int func_n(AVFilterContext *ctx, AVBPrint *bp,
+                  char *fct, unsigned argc, char **argv, int tag)
+{
+    DrawTextContext *dtext = ctx->priv;
+    const char *fmt = argc ? argv[0] : "%d";
+
+    av_bprintf(bp, fmt, (int)dtext->var_values[VAR_N]);
+    return 0;
+}
+
 #if !HAVE_LOCALTIME_R
 static void localtime_r(const time_t *t, struct tm *tm)
 {
@@ -641,6 +651,7 @@ static const struct drawtext_function {
     int (*func)(AVFilterContext *, AVBPrint *, char *, unsigned, char **, int);
 } functions[] = {
     { "pts",       0, 0, 0,   func_pts      },
+    { "n",         0, 1, 0,   func_n        },
     { "gmtime",    0, 1, 'G', func_strftime },
     { "localtime", 0, 1, 'L', func_strftime },
 };
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list