On 11 Dec 2021, at 23:17, Andreas Rheinhardt wrote:
Thilo Borgmann:
On 10 Dec 2021, at 17:46, Michael Niedermayer wrote:
On Fri, Dec 10, 2021 at 12:36:21PM +0100, Thilo Borgmann wrote:
On 10 Dec 2021, at 3:47, zhilizhao(赵志立) wrote:
On Dec 10, 2021, at 3:11 AM, Thilo Borgmann
<thilo.borgm...@mail.de>
wrote:
Hi,
add %{localtime_ms}, %{gmtime_ms} functions to the drawtext
filter.
Same as %{localtime}/%{gmtime} but with additional millisecond
part.
sorry for delay, second version including review remarks:
-get timing once
-also add gmtime_ms instead of just localtime_ms
+ if (tag == 'M' || tag == 'm') {
+ char ms[5] = {0};
+ int64_t dnow = (unow - ((int64_t)now) * 1000000)
/ 1000;
+ snprintf(ms, 5, ".%03d", (int)dnow);
+ av_bprint_append_data(bp, ms, 4);
+ }
How about
av_bprintf(&bp, ".%03d", (int)(unow % 1000000) / 1000);
Makes way too much sense. I need holidays…
Attached v3.
Thanks!
-Thilo
doc/filters.texi | 8 ++++++++
libavfilter/vf_drawtext.c | 12 ++++++++++--
2 files changed, 18 insertions(+), 2 deletions(-)
87d34e4106b829d42c5e57c847c28bed08bf3a81
v3-0001-lavfi-drawtext-Add-localtime_ms-for-millisecond-p.patch
From fd34d1434e2243a881c24f6db4cc0db92289f4bb Mon Sep 17 00:00:00
2001
From: Thilo Borgmann <thilo.borgm...@mail.de>
Date: Fri, 10 Dec 2021 12:34:23 +0100
Subject: [PATCH v3] lavfi/drawtext: Add localtime_ms for
millisecond
precision
Iam missining something here as it doesnt build
AR libavdevice/libavdevice.a
CC libavfilter/vf_drawtext.o
libavfilter/vf_drawtext.c: In function ‘func_strftime’:
libavfilter/vf_drawtext.c:1052:12: error: implicit declaration of
function ‘av_gettime’; did you mean ‘av_get_token’?
[-Werror=implicit-function-declaration]
unow = av_gettime();
^~~~~~~~~~
av_get_token
libavfilter/vf_drawtext.c:1061:20: warning: passing argument 1 of
‘av_bprintf’ from incompatible pointer type
[-Wincompatible-pointer-types]
av_bprintf(&bp, ".%03d", (int)(unow % 1000000) /
1000);
^
In file included from libavfilter/vf_drawtext.c:47:0:
./libavutil/bprint.h:127:6: note: expected ‘AVBPrint * {aka struct
AVBPrint *}’ but argument is of type ‘AVBPrint ** {aka struct
AVBPrint
**}’
void av_bprintf(AVBPrint *buf, const char *fmt, ...)
av_printf_format(2, 3);
^~~~~~~~~~
cc1: some warnings being treated as errors
ffbuild/common.mak:70: recipe for target 'libavfilter/vf_drawtext.o'
failed
make: *** [libavfilter/vf_drawtext.o] Error 1
Works for me on OSX.
av_gettime() is in lavu/time.c which gets included via
lavu/time_internal.h….
av_gettime() is public and resides in lavu/time.h, not
lavu/time_internal.h; the latter does not include the former in any
way.
Ups, <time.h> was it…
But compat/os2threads.h and compat/w32pthreads.h include lavu/time.h.
Maybe you have it from the former? It doesn't work here (Ubuntu 21.10)
either.
Retested and I got no clue how this appeared to be working for me
yesterday - sorry.
v4 attached, including lavu/time.h and fixed pointer type warning.
Thanks!
-Thilo
From 9b70c93c754fa4cd1b55fd3967910727f685a6b6 Mon Sep 17 00:00:00 2001
From: Thilo Borgmann <thilo.borgm...@mail.de>
Date: Sun, 12 Dec 2021 16:17:03 +0100
Subject: [PATCH v4] lavfi/drawtext: Add localtime_ms for millisecond precision
Suggested-By: ffm...@fb.com
---
doc/filters.texi | 8 ++++++++
libavfilter/vf_drawtext.c | 13 +++++++++++--
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/doc/filters.texi b/doc/filters.texi
index 78faf76..db75632 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -10949,10 +10949,18 @@ It can be used to add padding with zeros from the
left.
The time at which the filter is running, expressed in UTC.
It can accept an argument: a strftime() format string.
+@item gmtime_ms
+Same as @code{gmtime} but with millisecond precision.
+It can accept an argument: a strftime() format string.
+
@item localtime
The time at which the filter is running, expressed in the local time zone.
It can accept an argument: a strftime() format string.
+@item localtime_ms
+Same as @code{localtime} but with millisecond precision.
+It can accept an argument: a strftime() format string.
+
@item metadata
Frame metadata. Takes one or two arguments.
diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
index 382d589..d047a8c 100644
--- a/libavfilter/vf_drawtext.c
+++ b/libavfilter/vf_drawtext.c
@@ -51,6 +51,7 @@
#include "libavutil/opt.h"
#include "libavutil/random_seed.h"
#include "libavutil/parseutils.h"
+#include "libavutil/time.h"
#include "libavutil/timecode.h"
#include "libavutil/time_internal.h"
#include "libavutil/tree.h"
@@ -1045,15 +1046,21 @@ static int func_strftime(AVFilterContext *ctx, AVBPrint
*bp,
char *fct, unsigned argc, char **argv, int tag)
{
const char *fmt = argc ? argv[0] : "%Y-%m-%d %H:%M:%S";
+ int64_t unow;
time_t now;
struct tm tm;
- time(&now);
- if (tag == 'L')
+ unow = av_gettime();
+ now = unow / 1000000;
+ if (tag == 'L' || tag == 'm')
localtime_r(&now, &tm);
else
tm = *gmtime_r(&now, &tm);
av_bprint_strftime(bp, fmt, &tm);
+
+ if (tag == 'M' || tag == 'm') {
+ av_bprintf(bp, ".%03d", (int)(unow % 1000000) / 1000);
+ }
return 0;
}
@@ -1152,7 +1159,9 @@ static const struct drawtext_function {
{ "pict_type", 0, 0, 0, func_pict_type },
{ "pts", 0, 3, 0, func_pts },
{ "gmtime", 0, 1, 'G', func_strftime },
+ { "gmtime_ms", 0, 1, 'M', func_strftime },
{ "localtime", 0, 1, 'L', func_strftime },
+ { "localtime_ms", 0, 1, 'm', func_strftime },
{ "frame_num", 0, 0, 0, func_frame_num },
{ "n", 0, 0, 0, func_frame_num },
{ "metadata", 1, 2, 0, func_metadata },
--
1.8.3.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".