On October 10, 2015 at 1:10:25 PM, Nicolas George (geo...@nsup.org) wrote:
Thanks, I was about to apply, after fixing myself very minor details
(trailing spaces, >80 chars lines in the doc and H:M:S -> HH:MM::SS), but I
noticed that your patch is missing the "Signed-Off" tag; we have not been
very careful with it, but for legal reasons it would be better to have it,
and I can not add it myself.
Please see the modified patch attached.
From 0d759b996718de1987741906480534d2e0f739ff Mon Sep 17 00:00:00 2001
From: Alex Agranovsky <a...@sighthound.com>
Date: Sat, 10 Oct 2015 14:52:34 -0400
Subject: [PATCH] avfilter/drawtext: allow to format pts with strftime
Signed-off-by: Alex Agranovsky <a...@sighthound.com>
---
doc/filters.texi | 8 +++++++-
libavfilter/vf_drawtext.c | 12 +++++++++++-
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/doc/filters.texi b/doc/filters.texi
index 9ab7d43..bd90ac8 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -5398,14 +5398,20 @@ A 1 character description of the current picture type.
@item pts
The timestamp of the current frame.
-It can take up to two arguments.
+It can take up to three 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.
+@code{gmtime} stands for the timestamp of the frame formatted as UTC time;
+@code{localtime} stands for the timestamp of the frame formatted as
+local time zone time.
The second argument is an offset added to the timestamp.
+If the format is set to @code{localtime} or @code{gmtime},
+a third argument may be supplied: a strftime() format string.
+By default, @var{YYYY-MM-DD HH:MM:SS} format will be used.
@end table
@subsection Examples
diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
index 9fd9461..8e21693 100644
--- a/libavfilter/vf_drawtext.c
+++ b/libavfilter/vf_drawtext.c
@@ -824,6 +824,16 @@ static int func_pts(AVFilterContext *ctx, AVBPrint *bp,
(int)(ms / 1000) % 60,
(int)ms % 1000);
}
+ } else if (!strcmp(fmt, "localtime") ||
+ !strcmp(fmt, "gmtime")) {
+ struct tm tm;
+ time_t ms = (time_t)pts;
+ const char *timefmt = argc >= 3 ? argv[2] : "%Y-%m-%d %H:%M:%S";
+ if (!strcmp(fmt, "localtime"))
+ localtime_r(&ms, &tm);
+ else
+ gmtime_r(&ms, &tm);
+ av_bprint_strftime(bp, timefmt, &tm);
} else {
av_log(ctx, AV_LOG_ERROR, "Invalid format '%s'\n", fmt);
return AVERROR(EINVAL);
@@ -958,7 +968,7 @@ static const struct drawtext_function {
{ "expr_int_format", 2, 3, 0, func_eval_expr_int_format },
{ "eif", 2, 3, 0, func_eval_expr_int_format },
{ "pict_type", 0, 0, 0, func_pict_type },
- { "pts", 0, 2, 0, func_pts },
+ { "pts", 0, 3, 0, func_pts },
{ "gmtime", 0, 1, 'G', func_strftime },
{ "localtime", 0, 1, 'L', func_strftime },
{ "frame_num", 0, 0, 0, func_frame_num },
--
2.3.8 (Apple Git-58)
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel