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

This commit is contained in:
Nicolas George 2014-04-25 14:01:43 +02:00
parent 50ed6e3ce6
commit 41334fcab4
2 changed files with 43 additions and 3 deletions

View File

@ -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

View File

@ -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 },