From patchwork Tue Jun 8 16:42:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thilo Borgmann X-Patchwork-Id: 28171 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp61981iol; Tue, 8 Jun 2021 09:43:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwDypfZKuHHiRiwoHa8fXhesmbiLim0+GnawN4exYN1SI890aooJWcxa17u8IYu6DktzWaD X-Received: by 2002:a17:906:af7b:: with SMTP id os27mr24257223ejb.154.1623170594143; Tue, 08 Jun 2021 09:43:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623170594; cv=none; d=google.com; s=arc-20160816; b=Yg5a4GXeFcsCbykWCDnxlSh4LRbeDLND59awDLUuLFAaom7YpKl8wA4K9wyVEP7Mxj 0IKrkNMhmnCTjH3hQOZGSD2kPAxZWy4b8bda6yAMfwgRd9lQE4nlrlTVZY2AdoauYL2b 6z3MZrwIozA7GPbtRzvF2S+VJxtpt5MqtCvuVXLezIrcJ+pJfA6X3lHpA9rDDbOrnZK9 zFgCuKZsfYagHcx43qZmiaaMDsUu5ROWSniR0l6KWLwlzFjw933e22PtVHYSoE7AkDn0 o38/1EgnP48DSZ9h9SJztoxXEX1NHn3u/8axoPdosB3KlAOvUBgzNylM6d6NpHHoNbNd W6UA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :content-language:mime-version:date:message-id:from:to :dkim-signature:delivered-to; bh=W/t3rCRo/cpm45Jm3gMeI92p/oX4IrLG/+cwquqx9jc=; b=zX5b4zAAZ1WQ+PN8AVjw/jo0pZfG0UFLF6tbvUTgBfMo0k4Qwc8U8QikdsLCi4hEWo VknDH4W7kJ44w2zGMinQPxcdVAhfer9cEr+V+/SksD8pYAYYqHhZ6+7QOOLUtNuGkGvn MmmLJrlSGamPTS4mErT7/VVNHDUL4xXsBnjs+SWbQq/3gqvb+Xbbw5fwePxrbMAaNEgV SqMjcZ3STcew+0f/kIV8w1REMRyvPxVyNXHeRub+7Tdy3eaCjs8QUqQ49F7YqjWN1M7+ 3JK0mrrA1giTMJmOVZrjT5sRyDAdRXv88hsWCAU7KAfDptlmvPlgbri8SyIr0MwKggK1 GB6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mail.de header.s=mailde202009 header.b=cl0nSDzg; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mail.de Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 18si153573ejr.397.2021.06.08.09.43.06; Tue, 08 Jun 2021 09:43:14 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@mail.de header.s=mailde202009 header.b=cl0nSDzg; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mail.de Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1F18B680923; Tue, 8 Jun 2021 19:43:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from shout01.mail.de (shout01.mail.de [62.201.172.24]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 52489680134 for ; Tue, 8 Jun 2021 19:42:56 +0300 (EEST) Received: from postfix01.mail.de (postfix03.bt.mail.de [10.0.121.127]) by shout01.mail.de (Postfix) with ESMTP id B9E9F1000DE for ; Tue, 8 Jun 2021 18:42:55 +0200 (CEST) Received: from smtp02.mail.de (smtp02.bt.mail.de [10.0.121.212]) by postfix01.mail.de (Postfix) with ESMTP id A189C8011C for ; Tue, 8 Jun 2021 18:42:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mail.de; s=mailde202009; t=1623170575; bh=OsUIw2azE5UGiOqXT2d8CV/FkpDVDl/fU3VVqOVOC34=; h=To:From:Subject:Date:From; b=cl0nSDzgFsWLo5iJ8JmPs/gl+FXj7lLEmbKpDg6P9ZmQGJkTsTbsFZB2Kv5DvKc22 mpspkKFYfwrW9QUpWOtKI6uoP6I2RjKuscbfc/htzRgBUU/ks38Irp1GSc39Aze0zZ B9UGo1lnu3tY3uarXT+DSOrJeqWwvPnV0jmsZZFNBGQ66knAtYh22GIw2WQH3q0PZI +PlCpjHhUY38TdVOOk99hw6UneS2ykOWvzVxQ8kvF6EzOQ+xS96hs8TD5VEOQdM8/g DIRK6EqKTzPz+1/PeCYa4FnyVYiOqKgSyBB1/mKkdvMvh5faEhGyR73mrwpPAHLeDz N12/7SpLx/ruQ== 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 smtp02.mail.de (Postfix) with ESMTPSA id 6E539A0687 for ; Tue, 8 Jun 2021 18:42:55 +0200 (CEST) To: FFmpeg development discussions and patches From: Thilo Borgmann Message-ID: Date: Tue, 8 Jun 2021 18:42:54 +0200 MIME-Version: 1.0 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: 4650 X-purgate-ID: 154282::1623170575-000001E5-103C9FD0/0/0 Subject: [FFmpeg-devel] [PATCH] 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" X-TUID: UAQ8LQm9z0CL Hi, add %{localtime_ms} function to the drawtext filter. Same as %{localtime} but with additional millisecond part. -Thilo From f3b32f3e2b01f50b4fa41f8432ccd5a5eeea1ec1 Mon Sep 17 00:00:00 2001 From: Kirill Pugin Date: Tue, 8 Jun 2021 18:32:45 +0200 Subject: [PATCH] lavfi/drawtext: Add localtime_ms for millisecond precision Suggested-By: ffmpeg@fb.com --- doc/filters.texi | 4 ++++ libavfilter/vf_drawtext.c | 20 +++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/doc/filters.texi b/doc/filters.texi index 78faf767cf..bf073e0560 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -10953,6 +10953,10 @@ It can accept an argument: a strftime() format string. 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 382d589e26..684f954236 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -53,6 +53,7 @@ #include "libavutil/parseutils.h" #include "libavutil/timecode.h" #include "libavutil/time_internal.h" +#include "libavutil/time.h" #include "libavutil/tree.h" #include "libavutil/lfg.h" #include "libavutil/detection_bbox.h" @@ -1049,11 +1050,27 @@ static int func_strftime(AVFilterContext *ctx, AVBPrint *bp, struct tm tm; time(&now); - if (tag == 'L') + if (tag == 'L' || tag == 'M') localtime_r(&now, &tm); else tm = *gmtime_r(&now, &tm); av_bprint_strftime(bp, fmt, &tm); + + if (tag == 'M') { + char ms[5] = {0}; + // get time returns time since epoch in micro seconds, localtime_r would + // already take care of representing seconds part, so we need to get + // milliseconds, to do that we round up microseconds to seconds + // then convert seconds back to microseconds - this will drop microsecond + // precision, then compute difference between av_gettime result and + // rounded up sec -> usec representation and convert that to milliseconds + int64_t usecs = av_gettime(); + int64_t secs = usecs / 1000000; + int64_t msec_delta = (usecs - secs * 1000000) / 1000; + snprintf(ms, 5, ".%03d", (int)msec_delta); + av_bprint_append_data(bp, ms, 4); + } + return 0; } @@ -1153,6 +1170,7 @@ static const struct drawtext_function { { "pts", 0, 3, 0, func_pts }, { "gmtime", 0, 1, 'G', 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 },