Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: softworkz <ffmpegagent@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Cc: softworkz <softworkz@hotmail.com>
Subject: [FFmpeg-devel] [PATCH v2 1/3] avutil/log: support logging of date and timing information
Date: Thu, 30 Jan 2025 03:53:24 +0000
Message-ID: <13a7dc164bd64e9d534c6d84053a059bfdd0d06a.1738209206.git.ffmpegagent@gmail.com> (raw)
In-Reply-To: <pull.37.v2.ffstaging.FFmpeg.1738209206.ffmpegagent@gmail.com>

From: softworkz <softworkz@hotmail.com>

Signed-off-by: softworkz <softworkz@hotmail.com>
---
 doc/APIchanges      |  3 +++
 libavutil/log.c     | 32 +++++++++++++++++++++++++++++---
 libavutil/log.h     | 10 ++++++++++
 libavutil/version.h |  2 +-
 4 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 0f2b640601..83d57ae314 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2024-03-07
 
 API changes, most recent first:
 
+2025-01-xx - xxxxxxxxxx - lavu 59.57.100 - log.h
+  Add flags AV_LOG_PRINT_TIME and AV_LOG_PRINT_DATETIME.
+
 2025-01-25 - xxxxxxxxxx - lavu 59.56.100 - frame.h
   Add AV_SIDE_DATA_PROP_CHANNEL_DEPENDENT.
 
diff --git a/libavutil/log.c b/libavutil/log.c
index 46662f3db0..3ea6cb671e 100644
--- a/libavutil/log.c
+++ b/libavutil/log.c
@@ -42,6 +42,8 @@
 #include "internal.h"
 #include "log.h"
 #include "thread.h"
+#include "time.h"
+#include "time_internal.h"
 
 static AVMutex mutex = AV_MUTEX_INITIALIZER;
 
@@ -296,14 +298,32 @@ static const char *item_name(void *obj, const AVClass *cls)
     return (cls->item_name ? cls->item_name : av_default_item_name)(obj);
 }
 
+static void format_date_now(AVBPrint* timeBuf, int include_date)
+{
+    struct tm *ptm, tmbuf;
+    const int64_t time_us = av_gettime();
+    const int64_t time_ms = time_us / 1000;
+    const time_t time_s   = time_ms / 1000;
+    const int millisec    = time_ms - (time_s * 1000);
+    ptm                   = localtime_r(&time_s, &tmbuf);
+    if (ptm) {
+        if (include_date)
+            av_bprint_strftime(timeBuf, "%Y-%m-%d ", ptm);
+
+        av_bprint_strftime(timeBuf, "%H:%M:%S", ptm);
+        av_bprintf(timeBuf, ".%03d ", millisec);
+    }
+}
+
 static void format_line(void *avcl, int level, const char *fmt, va_list vl,
-                        AVBPrint part[4], int *print_prefix, int type[2])
+                        AVBPrint part[5], int *print_prefix, int type[2])
 {
     AVClass* avc = avcl ? *(AVClass **) avcl : NULL;
     av_bprint_init(part+0, 0, AV_BPRINT_SIZE_AUTOMATIC);
     av_bprint_init(part+1, 0, AV_BPRINT_SIZE_AUTOMATIC);
     av_bprint_init(part+2, 0, AV_BPRINT_SIZE_AUTOMATIC);
     av_bprint_init(part+3, 0, 65536);
+    av_bprint_init(part+4, 0, AV_BPRINT_SIZE_AUTOMATIC);
 
     if(type) type[0] = type[1] = AV_CLASS_CATEGORY_NA + 16;
     if (*print_prefix && avc) {
@@ -321,6 +341,9 @@ static void format_line(void *avcl, int level, const char *fmt, va_list vl,
         if(type) type[1] = get_category(avcl);
     }
 
+    if (*print_prefix && (flags & (AV_LOG_PRINT_TIME | AV_LOG_PRINT_DATETIME)))
+        format_date_now(&part[4], flags & AV_LOG_PRINT_DATETIME);
+
     if (*print_prefix && (level > AV_LOG_QUIET) && (flags & AV_LOG_PRINT_LEVEL))
         av_bprintf(part+2, "[%s] ", get_level_str(level));
 
@@ -341,7 +364,7 @@ void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl,
 int av_log_format_line2(void *ptr, int level, const char *fmt, va_list vl,
                         char *line, int line_size, int *print_prefix)
 {
-    AVBPrint part[4];
+    AVBPrint part[5];
     int ret;
 
     format_line(ptr, level, fmt, vl, part, print_prefix, NULL);
@@ -355,7 +378,7 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
     static int print_prefix = 1;
     static int count;
     static char prev[LINE_SZ];
-    AVBPrint part[4];
+    AVBPrint part[5];
     char line[LINE_SZ];
     static int is_atty;
     int type[2];
@@ -390,6 +413,9 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
         count = 0;
     }
     strcpy(prev, line);
+
+    sanitize(part[4].str);
+    colored_fputs(7, 0, part[4].str);
     sanitize(part[0].str);
     colored_fputs(type[0], 0, part[0].str);
     sanitize(part[1].str);
diff --git a/libavutil/log.h b/libavutil/log.h
index 4c8c92266f..dd094307ce 100644
--- a/libavutil/log.h
+++ b/libavutil/log.h
@@ -406,6 +406,16 @@ int av_log_format_line2(void *ptr, int level, const char *fmt, va_list vl,
  */
 #define AV_LOG_PRINT_LEVEL 2
 
+/**
+ * Include system time in log output.
+ */
+#define AV_LOG_PRINT_TIME 4
+
+/**
+ * Include system date and time in log output.
+ */
+#define AV_LOG_PRINT_DATETIME 8
+
 void av_log_set_flags(int arg);
 int av_log_get_flags(void);
 
diff --git a/libavutil/version.h b/libavutil/version.h
index 83b7822125..ee4a36cb17 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  59
-#define LIBAVUTIL_VERSION_MINOR  56
+#define LIBAVUTIL_VERSION_MINOR  57
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
-- 
ffmpeg-codebot

_______________________________________________
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:[~2025-01-30  3:53 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-24 19:37 [FFmpeg-devel] [PATCH 0/3] Add option to log timing ffmpegagent
2022-08-24 19:37 ` [FFmpeg-devel] [PATCH 1/3] avutil/log: support logging of date and timing information softworkz
2022-08-24 19:37 ` [FFmpeg-devel] [PATCH 2/3] fftools/opt_common: add timing and datetiming log flags softworkz
2022-08-24 19:37 ` [FFmpeg-devel] [PATCH 3/3] doc/fftools-common-opts: document log timing flags softworkz
2022-12-12 23:10 ` [FFmpeg-devel] [PATCH 0/3] Add option to log timing Soft Works
2025-01-30  3:53 ` [FFmpeg-devel] [PATCH v2 " ffmpegagent
2025-01-30  3:53   ` softworkz [this message]
2025-01-30  3:53   ` [FFmpeg-devel] [PATCH v2 2/3] fftools/opt_common: add timing and datetiming log flags softworkz
2025-02-02  1:13     ` Michael Niedermayer
2025-02-02  1:38       ` Soft Works
2025-01-30  3:53   ` [FFmpeg-devel] [PATCH v2 3/3] doc/fftools-common-opts: document log timing flags softworkz

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=13a7dc164bd64e9d534c6d84053a059bfdd0d06a.1738209206.git.ffmpegagent@gmail.com \
    --to=ffmpegagent@gmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    --cc=softworkz@hotmail.com \
    /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