diff options
author | Nicolas George <george@nsup.org> | 2014-04-25 16:01:43 +0400 |
---|---|---|
committer | Nicolas George <george@nsup.org> | 2014-04-29 15:25:59 +0400 |
commit | 41334fcab41fee1a5a869c9f87c4a1d59a627b57 (patch) | |
tree | dbf6fd4243088d9eddb0be5646c0b9c7c8b7e00c /libavfilter/vf_drawtext.c | |
parent | 50ed6e3ce635e47898c0cb9e3d57f3b7e0a67ff4 (diff) |
lavfi/drawtext: allow to format pts as HH:MM:SS.mmm.
Diffstat (limited to 'libavfilter/vf_drawtext.c')
-rw-r--r-- | libavfilter/vf_drawtext.c | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index f7486c9c6e..995a3e2ca3 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 }, |