[FFmpeg-cvslog] lavfi/drawtext: allow to format pts as HH:MM:SS.mmm.

Nicolas George git at videolan.org
Tue Apr 29 19:43:52 CEST 2014


ffmpeg | branch: master | Nicolas George <george at nsup.org> | Fri Apr 25 14:01:43 2014 +0200| [41334fcab41fee1a5a869c9f87c4a1d59a627b57] | committer: Nicolas George

lavfi/drawtext: allow to format pts as HH:MM:SS.mmm.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=41334fcab41fee1a5a869c9f87c4a1d59a627b57
---

 doc/filters.texi          |    9 ++++++++-
 libavfilter/vf_drawtext.c |   37 +++++++++++++++++++++++++++++++++++--
 2 files changed, 43 insertions(+), 3 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index e943923..a8b2668 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -3850,7 +3850,14 @@ The frame number, starting from 0.
 A 1 character description of the current picture type.
 
 @item pts
-The timestamp of the current frame, in seconds, with microsecond accuracy.
+The timestamp of the current frame.
+It can take up to two arguments.
+
+The first argument is the format of the timestamp; it defaults to @code{flt}
+for seconds as a decimal number with microsecond accuracy; @code{hms} stands
+for a formatted @var{[-]HH:MM:SS.mmm} timestamp with millisecond accuracy.
+
+The second argument is an offset added to the timestamp.
 
 @end table
 
diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
index f7486c9..995a3e2 100644
--- a/libavfilter/vf_drawtext.c
+++ b/libavfilter/vf_drawtext.c
@@ -699,8 +699,41 @@ static int func_pts(AVFilterContext *ctx, AVBPrint *bp,
                     char *fct, unsigned argc, char **argv, int tag)
 {
     DrawTextContext *s = ctx->priv;
+    const char *fmt;
+    double pts = s->var_values[VAR_T];
+    int ret;
 
-    av_bprintf(bp, "%.6f", s->var_values[VAR_T]);
+    fmt = argc >= 1 ? argv[0] : "flt";
+    if (argc >= 2) {
+        int64_t delta;
+        if ((ret = av_parse_time(&delta, argv[1], 1)) < 0) {
+            av_log(ctx, AV_LOG_ERROR, "Invalid delta '%s'\n", argv[1]);
+            return ret;
+        }
+        pts += (double)delta / AV_TIME_BASE;
+    }
+    if (!strcmp(fmt, "flt")) {
+        av_bprintf(bp, "%.6f", s->var_values[VAR_T]);
+    } else if (!strcmp(fmt, "hms")) {
+        if (isnan(pts)) {
+            av_bprintf(bp, " ??:??:??.???");
+        } else {
+            int64_t ms = round(pts * 1000);
+            char sign = ' ';
+            if (ms < 0) {
+                sign = '-';
+                ms = -ms;
+            }
+            av_bprintf(bp, "%c%02d:%02d:%02d.%03d", sign,
+                       (int)(ms / (60 * 60 * 1000)),
+                       (int)(ms / (60 * 1000)) % 60,
+                       (int)(ms / 1000) % 60,
+                       (int)ms % 1000);
+        }
+    } else {
+        av_log(ctx, AV_LOG_ERROR, "Invalid format '%s'\n", fmt);
+        return AVERROR(EINVAL);
+    }
     return 0;
 }
 
@@ -776,7 +809,7 @@ static const struct drawtext_function {
     { "expr",      1, 1, 0,   func_eval_expr },
     { "e",         1, 1, 0,   func_eval_expr },
     { "pict_type", 0, 0, 0,   func_pict_type },
-    { "pts",       0, 0, 0,   func_pts      },
+    { "pts",       0, 2, 0,   func_pts      },
     { "gmtime",    0, 1, 'G', func_strftime },
     { "localtime", 0, 1, 'L', func_strftime },
     { "frame_num", 0, 0, 0,   func_frame_num },



More information about the ffmpeg-cvslog mailing list