Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Thilo Borgmann <thilo.borgmann@mail.de>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH v2] lavfi/drawtext: Add localtime_ms for millisecond precision
Date: Fri, 14 Jan 2022 18:40:55 +0100
Message-ID: <3ac67c79-7c88-4019-6726-06e50f0b29b8@mail.de> (raw)
In-Reply-To: <tencent_D1F3A7EDAA895308DC444B95661F50AFA606@qq.com>

[-- Attachment #1: Type: text/plain, Size: 1846 bytes --]

Am 14.01.22 um 14:17 schrieb "zhilizhao(赵志立)":
> 
> 
>> On Jan 14, 2022, at 8:14 PM, Thilo Borgmann <thilo.borgmann@mail.de> wrote:
>>
>> Am 06.01.22 um 12:27 schrieb Thilo Borgmann:
>>> Am 03.01.22 um 16:22 schrieb Thilo Borgmann:
>>>> Am 29.12.21 um 12:46 schrieb Nicolas George:
>>>>> "zhilizhao(赵志立)" (12021-12-29):
>>>>>> How about add a restriction like this:
>>>>>>
>>>>>> if (format.endsWith(“%S"))
>>>>>>    enable the feature
>>>>>> else
>>>>>>    warning message
>>>>>>
>>>>>> It’s a useful feature, it shouldn't create unexpected results, but
>>>>>> doesn’t need to support every use case.
>>>>>
>>>>> I would not oppose it, but I find it inelegant, especially because it
>>>>> requires a different expansion function, localtime_ms instead of
>>>>> localtime.
>>>>>
>>>>> What about this: with the original function "localtime", if the format
>>>>> ends in "%3N", then append the millisecond. It can later be expanded to
>>>>> support %xN at any place in the format for any value of x.
>>>>
>>>> I think best will be to scan the format string for %S and extend it there with .ms part before expanding the rest of it, not? Shouldn't be too expensive for the filter.
>>>>
>>>> Just need to find time to actually implement it. 
>>>
>>> Like v5 as attached.
> 
> 
>> +    if (tag == 'M' || tag == 'm') {
>> +        char *seconds = av_stristr(fmt, "%S");
>> +        if (seconds) {
>> +            seconds += 2;
>> +            int len = seconds - fmt + 1;
>> +            char *tmp = av_malloc(len);
>> +            av_strlcpy(tmp, fmt, len);
> 
> Firstly, mixed variable declaration and statements.
> 
> Secondly, I think you don’t need ’tmp’, something like
> 
> av_asprintf(“%.*s.%03d%s", len, fmt, (int)(unow % 1000000) / 1000, seconds);

You know your printf format-string :)

Thanks, v6 attached.
-Thilo


[-- Attachment #2: v6-0001-lavfi-drawtext-Add-localtime_ms-for-millisecond-p.patch --]
[-- Type: text/plain, Size: 3065 bytes --]

From 603a52a2bb86e558acdd754d8322e89e984dad08 Mon Sep 17 00:00:00 2001
From: Thilo Borgmann <thilo.borgmann@mail.de>
Date: Fri, 14 Jan 2022 18:38:14 +0100
Subject: [PATCH v6] lavfi/drawtext: Add localtime_ms for millisecond precision

Suggested-By: ffmpeg@fb.com
---
 doc/filters.texi          |  8 ++++++++
 libavfilter/vf_drawtext.c | 20 ++++++++++++++++++--
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 05d4b1a56e..967021e48b 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -11379,10 +11379,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 2a88692cbd..7e3771fdca 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,14 +1046,27 @@ 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);
+
+    if (tag == 'M' || tag == 'm') {
+        char *seconds = av_stristr(fmt, "%S");
+        if (seconds) {
+            int len = seconds + 2 - fmt;
+            char *fmt_new = av_asprintf("%.*s.%03d%s", len, fmt, (int)(unow % 1000000) / 1000, seconds + 2);
+            av_bprint_strftime(bp, fmt_new, &tm);
+            return 0;
+        }
+    }
+
     av_bprint_strftime(bp, fmt, &tm);
     return 0;
 }
@@ -1152,7 +1166,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 },
-- 
2.20.1 (Apple Git-117)


[-- Attachment #3: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  reply	other threads:[~2022-01-14 17:41 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <280498BE-226E-41E2-BE17-DE2D47EAFFC0@mail.de>
     [not found] ` <tencent_9187CFF05512A70F389C961C4D142031CD07@qq.com>
     [not found]   ` <0768FA6E-731F-4214-8B90-A3F38764010F@mail.de>
     [not found]     ` <20211210164657.GF2829255@pb2>
     [not found]       ` <727CF2F6-C834-415A-B771-4F70661F8BE8@mail.de>
     [not found]         ` <AM7PR03MB6660ED0E212D1CCB2134A4DD8F729@AM7PR03MB6660.eurprd03.prod.outlook.com>
     [not found]           ` <3E808BD2-808B-4C53-B1F7-B9DFFE2BF687@mail.de>
     [not found]             ` <YbZXwy3d8Z9rG/hD@phare.normalesup.org>
2021-12-29 10:47               ` "zhilizhao(赵志立)"
2021-12-29 11:46                 ` Nicolas George
2022-01-03 15:22                   ` Thilo Borgmann
2022-01-06 11:27                     ` Thilo Borgmann
2022-01-14 12:14                       ` Thilo Borgmann
2022-01-14 13:17                         ` "zhilizhao(赵志立)"
2022-01-14 17:40                           ` Thilo Borgmann [this message]
2022-01-14 18:02                             ` Zhao Zhili
2022-01-14 18:05                             ` Andreas Rheinhardt
2022-01-14 18:15                               ` Thilo Borgmann
2022-01-14 18:22                                 ` Andreas Rheinhardt
2022-01-14 17:57                         ` Nicolas George
2022-01-14 18:04                           ` Thilo Borgmann
2022-01-14 18:08                             ` Nicolas George
2022-01-14 18:20                               ` Thilo Borgmann
2022-01-16 11:06                                 ` Nicolas George
2022-01-18 12:52                                   ` Thilo Borgmann
2022-01-19  3:16                                     ` "zhilizhao(赵志立)"
2022-01-20 12:04                                       ` Thilo Borgmann
2022-01-20 14:58                                         ` Thilo Borgmann
2022-01-20 15:03                                           ` Andreas Rheinhardt
2022-01-20 15:32                                             ` Thilo Borgmann
2022-01-31 10:13                                               ` Thilo Borgmann
2022-01-31 13:08                                                 ` Nicolas George
2022-01-31 20:59                                                   ` Thilo Borgmann
2022-01-31 23:10                                                     ` Andreas Rheinhardt
2022-01-31 23:40                                                     ` Andreas Rheinhardt
2022-02-08  9:17                                                       ` Thilo Borgmann
2022-02-08  9:27                                                         ` Andreas Rheinhardt
2022-02-08 10:41                                                           ` Thilo Borgmann
2022-02-22 11:36                                                             ` Thilo Borgmann
2022-03-06 20:38                                                               ` Thilo Borgmann
2022-03-08 12:30                                                                 ` Thilo Borgmann
2022-01-14 13:10                       ` James Almer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3ac67c79-7c88-4019-6726-06e50f0b29b8@mail.de \
    --to=thilo.borgmann@mail.de \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git