From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 9AC2A431EE for ; Tue, 18 Jan 2022 12:52:56 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C299968B0DD; Tue, 18 Jan 2022 14:52:53 +0200 (EET) Received: from shout02.mail.de (shout02.mail.de [62.201.172.25]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C017268AFDE for ; Tue, 18 Jan 2022 14:52:47 +0200 (EET) Received: from postfix01.mail.de (postfix03.bt.mail.de [10.0.121.127]) by shout02.mail.de (Postfix) with ESMTP id 01DCEA1D66 for ; Tue, 18 Jan 2022 13:52:47 +0100 (CET) Received: from smtp01.mail.de (smtp01.bt.mail.de [10.0.121.211]) by postfix01.mail.de (Postfix) with ESMTP id DC95E801A9 for ; Tue, 18 Jan 2022 13:52:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mail.de; s=mailde202009; t=1642510366; bh=zaic0I1zPpuL+0JM8v3tDwzaN4ZmnKGVYtGf3oYE9TM=; h=Subject:To:References:From:Date:In-Reply-To:From; b=of+pjuYFQLHy+vXwOXuLYsx9O1fwx+kwYrrHjj/Sw1xiYr+E25gB0VX7Ih1/yEYqM uYrqI0GYrkUd8hMGJy+avADdM7WYySk1wMiGJQeNSyRtQWBCyaFe7eFzHApqi6ZzCd 7q70Jj1j0XG8bFRG99R7dQEUQ0sdzzVax9pwak9ezILcShU825T6wzF7Kshbm2WrNM qN4Cb95pltnv0wLjiu5FSikFlP2BAfOKSnjsdBbd2MGy71Fw8jpqfcwKcKzvNCb/re afJVlTtSiDu2raSZOX/mqRsag1HE8hmAZk+eFSDUB8foku4YK3JpMdxg2AT+0iQxqD /Ex2aifsg1o0A== Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtp01.mail.de (Postfix) with ESMTPSA id 9DFFD100276 for ; Tue, 18 Jan 2022 13:52:46 +0100 (CET) To: ffmpeg-devel@ffmpeg.org References: <72e9521f-b029-8637-c32c-27cf7c5de170@mail.de> <14470aae-c127-7532-a054-b5d878d415dd@mail.de> <52e4f109-41a4-a609-b583-c001c6077638@mail.de> <350ccc44-07dc-25c6-49a1-4281139d93ac@mail.de> From: Thilo Borgmann Message-ID: <8b8ae2a5-f77f-5a34-8890-fa68de09e475@mail.de> Date: Tue, 18 Jan 2022 13:52:45 +0100 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------C159C508E467D5ABBA72BB67" Content-Language: en-US X-purgate: clean X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate-type: clean X-purgate-Ad: Categorized by eleven eXpurgate (R) http://www.eleven.de X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate: clean X-purgate-size: 6788 X-purgate-ID: 154282::1642510366-00006BE6-09F4FAD6/0/0 Subject: Re: [FFmpeg-devel] [PATCH v2] lavfi/drawtext: Add localtime_ms for millisecond precision X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: This is a multi-part message in MIME format. --------------C159C508E467D5ABBA72BB67 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Am 16.01.22 um 12:06 schrieb Nicolas George: > Thilo Borgman (12022-01-14): >> v6 does: >> >> $> ffmpeg ... drawtext="fontfile=...:text='%{localtime \:%a %b %d %Y %S}'" (seconds) >> $> ffmpeg ... drawtext="fontfile=...:text='%{localtime_ms\:%a %b %d %Y %S}'" (milliseconds) >> >> I suggest v7 should according to your remark: >> >> $> ffmpeg ... drawtext="fontfile=...:text='%{localtime \:%a %b %d %Y %S}'" (seconds) >> $> ffmpeg ... drawtext="fontfile=...:text='%{localtime \:%a %b %d %Y %S}':show_ms=1" (milliseconds) >> >> Good? > > I dislike both versions, from a user interface point of view: if there > is a format string, then it stands to reason, for the user, that the > resulting text is governed by the format string, not by an extra option > somewhere else. > > There is no "use_four_digit_year=1" option, there is %Y instead of %y. > > There is no "use_slashes=1" option, you write %Y/%m/%d instead of > %Y-%m-%d. > > There are no "omit_date=1" and "omit_hour=1" options, you just write > what you want in the format string. > > My proposal goes the same way: > > $> ffmpeg ... drawtext="fontfile=...:text='%{localtime \:%a %b %d %Y %S.%3N}'" > > It has several merits over your proposal: > > - It can be extended later to support printing the milliseconds at > another place than the end (for example to put the time in brackets). > > - It can be extended to support microseconds or centiseconds (%6N, %2N). > > - It is somewhat compatible with GNU date and possibly a few others. > > And I do not think it is harder to implement. Ok, did introduce a variable: %[1-6]N Parsing and clipping value to valid range of 1-6. Default 3. That way it is position independent and can show any number of decimals from 1 to 6. Thanks, Thilo --------------C159C508E467D5ABBA72BB67 Content-Type: text/plain; charset=UTF-8; x-mac-type="0"; x-mac-creator="0"; name="v7-0001-lavfi-drawtext-Add-localtime_ms-for-millisecond-p.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="v7-0001-lavfi-drawtext-Add-localtime_ms-for-millisecond-p.pa"; filename*1="tch" >From 5bcb05253440bae44af01882485e1973f5b9045a Mon Sep 17 00:00:00 2001 From: Thilo Borgmann Date: Tue, 18 Jan 2022 13:51:18 +0100 Subject: [PATCH v7] lavfi/drawtext: Add localtime_ms for millisecond precision Suggested-By: ffmpeg@fb.com --- doc/filters.texi | 4 +++ libavfilter/vf_drawtext.c | 75 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 76 insertions(+), 3 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index 05d4b1a56e..c3895138e0 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -11378,10 +11378,14 @@ It can be used to add padding with zeros from the left. @item gmtime The time at which the filter is running, expressed in UTC. It can accept an argument: a strftime() format string. +The format string is extended to support the variable @var{%[1-6]N} +which prints fractions of the second with optionally specified number of digits. @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. +The format string is extended to support the variable @var{%[1-6]N} +which prints fractions of the second with optionally specified number of digits. @item metadata Frame metadata. Takes one or two arguments. diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index 2a88692cbd..448b174dbb 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,82 @@ 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') + char *begin; + char *tmp; + int len; + char *fmt_new; + const char *fmt_tmp; + int div; + + unow = av_gettime(); + now = unow / 1000000; + if (tag == 'L' || tag == 'm') localtime_r(&now, &tm); else tm = *gmtime_r(&now, &tm); + + // manually parse format for %N (fractional seconds) + begin = (char*)fmt; + while ((begin = av_stristr(begin, "%"))) { + tmp = begin + 1; + len = 0; + // count digits between % and possible N + while (*tmp != '\0' && av_isdigit((int)*tmp)) { + len++; + tmp++; + } + // N encountered, insert time + if (*tmp == 'N') { + int num_digits = 3; // default show millisecond [1,6] + + // if digits given, parse as number in [1,6] + if (len > 0) { + av_sscanf(begin + 1, "%i", &num_digits); + num_digits = av_clip(num_digits, 1, 6); // ensure valid value + } + + len += 2; // add % and N to get length of string part + + switch(num_digits) { + case 1: + fmt_tmp = "%.*s%01d%s"; + div = 100000; + break; + case 2: + fmt_tmp = "%.*s%02d%s"; + div = 10000; + break; + case 3: + fmt_tmp = "%.*s%03d%s"; + div = 1000; + break; + case 4: + fmt_tmp = "%.*s%04d%s"; + div = 100; + break; + case 5: + fmt_tmp = "%.*s%05d%s"; + div = 10; + break; + case 6: + fmt_tmp = "%.*s%06d%s"; + div = 1; + break; + } + + fmt_new = av_asprintf(fmt_tmp, begin - fmt, fmt, (int)(unow % 1000000) / div, begin + len); + if (!fmt_new) + return AVERROR(ENOMEM); + av_bprint_strftime(bp, fmt_new, &tm); + av_freep(&fmt_new); + return 0; + } + begin++; + } + av_bprint_strftime(bp, fmt, &tm); return 0; } -- 2.20.1 (Apple Git-117) --------------C159C508E467D5ABBA72BB67 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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". --------------C159C508E467D5ABBA72BB67--