[FFmpeg-devel] [PATCH v3 0/4] avutil/log: Replace addresses in log output with simple ids

ffmpegagent ffmpegagent at gmail.com
Thu Mar 6 22:59:07 EET 2025


..and individual numbering. The benefits are:

 * Smaller log file sizes
 * The disambiguation is much easier to recognize and to follow
 * It eventually allows comparing and viewing log file diffs without almost
   every line being different due to those addresses


Before
======

[hevc @ 0000018e72a89cc0] nal_unit_type:
[hevc @ 0000018e72a89cc0] Decoding PPS
[hevc @ 0000018e72a89cc0] nal_unit_type: 39(SEI_P.. [hevc @
0000018e72a89cc0] Decoding SEI
[mp4 @ 0000018e72a8e240] All [mp4 @ 0000018e72a8e240] Afte [hevc @
0000018e742f6b40] Decoded frame with POC .. detected 16 logical cores
[Parsed_scale_0 @ 0000018e74382f40] Setting 'w' t.. [Parsed_scale_0 @
0000018e74382f40] Setting 'h' t.. [Parsed_scale_1 @ 0000018e74382440]
Setting 'w' t.. [mjpeg @ 0000018e743210c0] Forcing thread count t.. [mjpeg @
0000018e743210c0] intra_quant_bias = 96


After
=====

[hevc #0] nal_unit_type: [hevc #0] Decoding PPS
[hevc #0] nal_unit_type: 39(SEI_P.. [hevc #0] Decoding SEI
[mp4 #0] All info found
[mp4 #0] After avformat_find_ [hevc #1] Decoded frame with POC 2.
[Parsed_scale_0 #0] Setting 'w' t.. [Parsed_scale_0 #0] Setting 'h' t..
[Parsed_scale_1 #1] Setting 'w' t.. [mjpeg #2] Forcing thread count t..
[mjpeg #2] intra_quant_bias = 96


Versions
========


V2
==

 * Added log flag for optionally restoring the previous behavior (as
   requested by Gyan)

softworkz (4):
  avutil/log: Add callback for context prefix formatting
  fftools/opt_common: add memaddresses log flag
  fftools: Provide a log formatting callback for context prefixes
  doc/fftools-common-opts: document memaddresses log flag

 doc/APIchanges               |  4 +++
 doc/fftools-common-opts.texi |  2 ++
 fftools/cmdutils.c           | 69 ++++++++++++++++++++++++++++++++++++
 fftools/cmdutils.h           |  5 +++
 fftools/ffmpeg.c             |  1 +
 fftools/ffplay.c             |  1 +
 fftools/ffprobe.c            |  1 +
 fftools/opt_common.c         |  6 ++++
 libavutil/log.c              | 24 +++++++++----
 libavutil/log.h              | 29 +++++++++++++++
 libavutil/version.h          |  2 +-
 11 files changed, 137 insertions(+), 7 deletions(-)


base-commit: 5c5be37daff4f4ecbe0c20d6a9f0fdad6eadc9c8
Published-As: https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-59%2Fsoftworkz%2Fsubmit_logaddresses-v3
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg pr-ffstaging-59/softworkz/submit_logaddresses-v3
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/59

Range-diff vs v2:

 -:  ---------- > 1:  b8702de13b avutil/log: Add callback for context prefix formatting
 2:  858e2cca9c = 2:  84c0848afc fftools/opt_common: add memaddresses log flag
 1:  3a289533a7 ! 3:  105adac4ba avutil/log: Replace addresses in log output with simple ids
     @@ Metadata
      Author: softworkz <softworkz at hotmail.com>
      
       ## Commit message ##
     -    avutil/log: Replace addresses in log output with simple ids
     +    fftools: Provide a log formatting callback for context prefixes
      
     -    ..and individual numbering. The benefits are:
     +    This allows to print logical ids instead of memory addresses.
     +    The benefits are:
      
          - Smaller log file sizes
          - The disambiguation is much easier to recognize and to follow
          - It eventually allows comparing and viewing log file diffs
            without almost every line being different due to those addresses
      
     -    Signed-off-by: softworkz <softworkz at hotmail.com>
     -
     - ## doc/APIchanges ##
     -@@
     - The last version increases of all libraries were on 2024-03-07
     - 
     -+2025-03-xx - xxxxxxxxxx - lavu 59.59.100 - log.h
     -+  Add flag AV_LOG_PRINT_MEMADDRESSES.
     -+
     - API changes, most recent first:
     + ## fftools/cmdutils.c ##
     +@@ fftools/cmdutils.c: AVDictionary *format_opts, *codec_opts;
       
     - 2025-03-01 - xxxxxxxxxx - lavu 59.58.100 - pixfmt.h
     -
     - ## libavutil/log.c ##
     -@@ libavutil/log.c: static AVMutex mutex = AV_MUTEX_INITIALIZER;
     + int hide_banner = 0;
       
     - static int av_log_level = AV_LOG_INFO;
     - static int flags;
      +static int nb_class_ids;
      +
      +#define NB_CLASS_IDS 1000
     @@ libavutil/log.c: static AVMutex mutex = AV_MUTEX_INITIALIZER;
      +    // exceeded NB_CLASS_IDS entries in class_ids[]
      +    return 0;
      +}
     ++
     + void uninit_opts(void)
     + {
     +     av_dict_free(&swr_opts);
     +@@ fftools/cmdutils.c: static void check_options(const OptionDef *po)
     +     }
     + }
       
     - #define NB_LEVELS 8
     - #if defined(_WIN32) && HAVE_SETCONSOLETEXTATTRIBUTE && HAVE_GETSTDHANDLE
     -@@ libavutil/log.c: static void format_line(void *avcl, int level, const char *fmt, va_list vl,
     - 
     -     if(type) type[0] = type[1] = AV_CLASS_CATEGORY_NA + 16;
     -     if (*print_prefix && avc) {
     -+        const int print_mem = flags & AV_LOG_PRINT_MEMADDRESSES;
     ++static const char *item_name(void *obj, const AVClass *cls)
     ++{
     ++    return (cls->item_name ? cls->item_name : av_default_item_name)(obj);
     ++}
      +
     -         if (avc->parent_log_context_offset) {
     --            AVClass** parent = *(AVClass ***) (((uint8_t *) avcl) +
     --                                   avc->parent_log_context_offset);
     -+            AVClass** parent = *(AVClass ***) ((uint8_t *)avcl + avc->parent_log_context_offset);
     -             if (parent && *parent) {
     --                av_bprintf(part+0, "[%s @ %p] ",
     --                           item_name(parent, *parent), parent);
     -+                if (print_mem)
     -+                    av_bprintf(part+0, "[%s @ %p] ", item_name(parent, *parent), parent);
     -+                else
     -+                    av_bprintf(part+0, "[%s #%u] ", item_name(parent, *parent), get_class_id(parent));
     ++static void log_formatprefix_callback(AVBPrint* buffer, AVClass** avcl, int log_flags)
     ++{
     ++    const int print_mem = log_flags & AV_LOG_PRINT_MEMADDRESSES;
     ++    if (print_mem)
     ++        av_bprintf(buffer+0, "[%s @ %p] ", item_name(avcl, *avcl), avcl);
     ++    else
     ++        av_bprintf(buffer+0, "[%s #%u] ", item_name(avcl, *avcl), get_class_id(avcl));
     ++}
      +
     -                 if(type) type[0] = get_category(parent);
     -             }
     -         }
     --        av_bprintf(part+1, "[%s @ %p] ",
     --                   item_name(avcl, avc), avcl);
     -+        if (print_mem)
     -+            av_bprintf(part+1, "[%s @ %p] ", item_name(avcl, avc), avcl);
     -+        else
     -+            av_bprintf(part+1, "[%s #%u] ", item_name(avcl, avc), get_class_id(avcl));
     ++void init_logformatting(void)
     ++{
     ++    av_log_set_formatprefix_callback(&log_formatprefix_callback);
     ++}
      +
     -         if(type) type[1] = get_category(avcl);
     -     }
     - 
     + void parse_loglevel(int argc, char **argv, const OptionDef *options)
     + {
     +     int idx;
      
     - ## libavutil/log.h ##
     -@@ libavutil/log.h: int av_log_format_line2(void *ptr, int level, const char *fmt, va_list vl,
     + ## fftools/cmdutils.h ##
     +@@ fftools/cmdutils.h: int split_commandline(OptionParseContext *octx, int argc, char *argv[],
        */
     - #define AV_LOG_PRINT_DATETIME 8
     + void uninit_parse_context(OptionParseContext *octx);
       
      +/**
     -+ * Print memory addresses instead of logical ids in the AVClass prefix.
     ++ * Sets up formatting callbacks for logging
      + */
     -+#define AV_LOG_PRINT_MEMADDRESSES 16
     ++void init_logformatting(void);
      +
     - void av_log_set_flags(int arg);
     - int av_log_get_flags(void);
     + /**
     +  * Find the '-loglevel' option in the command line args and apply it.
     +  */
     +
     + ## fftools/ffmpeg.c ##
     +@@ fftools/ffmpeg.c: int main(int argc, char **argv)
     +     setvbuf(stderr,NULL,_IONBF,0); /* win32 runtime needs this */
       
     +     av_log_set_flags(AV_LOG_SKIP_REPEATED);
     ++    init_logformatting();
     +     parse_loglevel(argc, argv, options);
     + 
     + #if CONFIG_AVDEVICE
      
     - ## libavutil/version.h ##
     -@@
     -  */
     + ## fftools/ffplay.c ##
     +@@ fftools/ffplay.c: int main(int argc, char **argv)
     +     init_dynload();
     + 
     +     av_log_set_flags(AV_LOG_SKIP_REPEATED);
     ++    init_logformatting();
     +     parse_loglevel(argc, argv, options);
     + 
     +     /* register all codecs, demux and protocols */
     +
     + ## fftools/ffprobe.c ##
     +@@ fftools/ffprobe.c: int main(int argc, char **argv)
     +     init_dynload();
       
     - #define LIBAVUTIL_VERSION_MAJOR  59
     --#define LIBAVUTIL_VERSION_MINOR  58
     -+#define LIBAVUTIL_VERSION_MINOR  59
     - #define LIBAVUTIL_VERSION_MICRO 100
     +     av_log_set_flags(AV_LOG_SKIP_REPEATED);
     ++    init_logformatting();
       
     - #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
     +     options = real_options;
     +     parse_loglevel(argc, argv, options);
 3:  411c77bdeb = 4:  9dc2cbe5ca doc/fftools-common-opts: document memaddresses log flag

-- 
ffmpeg-codebot


More information about the ffmpeg-devel mailing list