Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] ffprobe: add support for printing downmix frame side data (PR #20401)
@ 2025-09-02 16:29 ngaullier via ffmpeg-devel
  0 siblings, 0 replies; only message in thread
From: ngaullier via ffmpeg-devel @ 2025-09-02 16:29 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: ngaullier

PR #20401 opened by ngaullier
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20401
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20401.patch

Also fix honor -byte_binary_prefix as a required preliminary step.


>From 2fdd5a62d46d3b761b451d37775c808e551b7659 Mon Sep 17 00:00:00 2001
From: Nicolas Gaullier <nicolas.gaullier@cji.paris>
Date: Tue, 2 Sep 2025 17:07:35 +0200
Subject: [PATCH 1/4] fftools/textformat: make unit_second and unit_byte
 available externally

This is required to support specific formatting.
Also remove generic units that do no belong to textformat.

Signed-off-by: Nicolas Gaullier <nicolas.gaullier@cji.paris>
---
 fftools/textformat/avtextformat.c | 14 ++++++--------
 fftools/textformat/avtextformat.h |  3 +++
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/fftools/textformat/avtextformat.c b/fftools/textformat/avtextformat.c
index 651a84578c..b6a0577193 100644
--- a/fftools/textformat/avtextformat.c
+++ b/fftools/textformat/avtextformat.c
@@ -242,10 +242,8 @@ fail:
 }
 
 /* Temporary definitions during refactoring */
-static const char unit_second_str[]         = "s";
-static const char unit_hertz_str[]          = "Hz";
-static const char unit_byte_str[]           = "byte";
-static const char unit_bit_per_second_str[] = "bit/s";
+const char avtext_unit_second_str[]         = "s";
+const char avtext_unit_byte_str[]           = "byte";
 
 
 void avtext_print_section_header(AVTextFormatContext *tctx, const void *data, int section_id)
@@ -383,7 +381,7 @@ static char *value_string(const AVTextFormatContext *tctx, char *buf, int buf_si
     int64_t vali = 0;
     int show_float = 0;
 
-    if (uv.unit == unit_second_str) {
+    if (uv.unit == avtext_unit_second_str) {
         vald = uv.val.d;
         show_float = 1;
     } else {
@@ -391,7 +389,7 @@ static char *value_string(const AVTextFormatContext *tctx, char *buf, int buf_si
         vali = uv.val.i;
     }
 
-    if (uv.unit == unit_second_str && tctx->use_value_sexagesimal_format) {
+    if (uv.unit == avtext_unit_second_str && tctx->use_value_sexagesimal_format) {
         double secs;
         int hours, mins;
         secs  = vald;
@@ -406,7 +404,7 @@ static char *value_string(const AVTextFormatContext *tctx, char *buf, int buf_si
         if (tctx->use_value_prefix && vald > 1) {
             int64_t index;
 
-            if (uv.unit == unit_byte_str && tctx->use_byte_value_binary_prefix) {
+            if (uv.unit == avtext_unit_byte_str && tctx->use_byte_value_binary_prefix) {
                 index = (int64_t)(log2(vald) / 10);
                 index = av_clip64(index, 0, FF_ARRAY_ELEMS(si_prefixes) - 1);
                 vald /= si_prefixes[index].bin_val;
@@ -502,7 +500,7 @@ void avtext_print_time(AVTextFormatContext *tctx, const char *key,
         double d = av_q2d(*time_base) * ts;
         struct unit_value uv;
         uv.val.d = d;
-        uv.unit = unit_second_str;
+        uv.unit = avtext_unit_second_str;
         value_string(tctx, buf, sizeof(buf), uv);
         avtext_print_string(tctx, key, buf, 0);
     }
diff --git a/fftools/textformat/avtextformat.h b/fftools/textformat/avtextformat.h
index d9c14069eb..d6a5caed61 100644
--- a/fftools/textformat/avtextformat.h
+++ b/fftools/textformat/avtextformat.h
@@ -155,6 +155,9 @@ typedef struct AVTextFormatOptions {
 #define AV_TEXTFORMAT_PRINT_STRING_OPTIONAL 1
 #define AV_TEXTFORMAT_PRINT_STRING_VALIDATE 2
 
+extern const char avtext_unit_second_str[];
+extern const char avtext_unit_byte_str[];
+
 int avtext_context_open(AVTextFormatContext **ptctx, const AVTextFormatter *formatter, AVTextWriterContext *writer_context, const char *args,
                         const AVTextFormatSection *sections, int nb_sections, AVTextFormatOptions options, char *show_data_hash);
 
-- 
2.49.1


>From 45caeb682522cbe566c9d26b2e45d0c995ef3557 Mon Sep 17 00:00:00 2001
From: Nicolas Gaullier <nicolas.gaullier@cji.paris>
Date: Tue, 2 Sep 2025 17:12:08 +0200
Subject: [PATCH 2/4] fftools/ffprobe: honor -byte_binary_prefix

Also remove a static duplicate of unit_second which is both unused
and misleading as avtext_unit_second has to be used instead.

See previous commit.

Signed-off-by: Nicolas Gaullier <nicolas.gaullier@cji.paris>
---
 fftools/ffprobe.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index f4eb87aefa..67ab21c140 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -332,9 +332,7 @@ static const char *print_input_filename;
 static const AVInputFormat *iformat = NULL;
 static const char *output_filename = NULL;
 
-static const char unit_second_str[]         = "s"    ;
 static const char unit_hertz_str[]          = "Hz"   ;
-static const char unit_byte_str[]           = "byte" ;
 static const char unit_bit_per_second_str[] = "bit/s";
 
 static int nb_streams;
@@ -1227,7 +1225,7 @@ static void show_packet(AVTextFormatContext *tfc, InputFile *ifile, AVPacket *pk
     print_time("dts_time",        pkt->dts, &st->time_base);
     print_duration_ts("duration",        pkt->duration);
     print_duration_time("duration_time", pkt->duration, &st->time_base);
-    print_val("size",             pkt->size, unit_byte_str);
+    print_val("size",             pkt->size, avtext_unit_byte_str);
     if (pkt->pos != -1) print_fmt    ("pos", "%"PRId64, pkt->pos);
     else                print_str_opt("pos", "N/A");
     print_fmt("flags", "%c%c%c",      pkt->flags & AV_PKT_FLAG_KEY ? 'K' : '_',
@@ -1379,7 +1377,7 @@ static void show_frame(AVTextFormatContext *tfc, AVFrame *frame, AVStream *strea
     print_duration_time("duration_time",     frame->duration, &stream->time_base);
     if (fd && fd->pkt_pos != -1)  print_fmt    ("pkt_pos", "%"PRId64, fd->pkt_pos);
     else                          print_str_opt("pkt_pos", "N/A");
-    if (fd && fd->pkt_size != -1) print_val    ("pkt_size", fd->pkt_size, unit_byte_str);
+    if (fd && fd->pkt_size != -1) print_val    ("pkt_size", fd->pkt_size, avtext_unit_byte_str);
     else                          print_str_opt("pkt_size", "N/A");
 
     switch (stream->codecpar->codec_type) {
@@ -2273,7 +2271,7 @@ static int show_format(AVTextFormatContext *tfc, InputFile *ifile)
     }
     print_time("start_time",      fmt_ctx->start_time, &AV_TIME_BASE_Q);
     print_time("duration",        fmt_ctx->duration,   &AV_TIME_BASE_Q);
-    if (size >= 0) print_val    ("size", size, unit_byte_str);
+    if (size >= 0) print_val    ("size", size, avtext_unit_byte_str);
     else           print_str_opt("size", "N/A");
     if (fmt_ctx->bit_rate > 0) print_val    ("bit_rate", fmt_ctx->bit_rate, unit_bit_per_second_str);
     else                       print_str_opt("bit_rate", "N/A");
-- 
2.49.1


>From da5e8fc5b9dc642d5d0a3a2e0455b11c7c897a41 Mon Sep 17 00:00:00 2001
From: Nicolas Gaullier <nicolas.gaullier@cji.paris>
Date: Tue, 2 Sep 2025 17:40:42 +0200
Subject: [PATCH 3/4] fftools/textformat: add support for decibel formatting

Signed-off-by: Nicolas Gaullier <nicolas.gaullier@cji.paris>
---
 fftools/textformat/avtextformat.c | 23 +++++++++++++++++++----
 fftools/textformat/avtextformat.h |  3 +++
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/fftools/textformat/avtextformat.c b/fftools/textformat/avtextformat.c
index b6a0577193..01413492ed 100644
--- a/fftools/textformat/avtextformat.c
+++ b/fftools/textformat/avtextformat.c
@@ -244,6 +244,7 @@ fail:
 /* Temporary definitions during refactoring */
 const char avtext_unit_second_str[]         = "s";
 const char avtext_unit_byte_str[]           = "byte";
+const char avtext_unit_decibel_str[]        = "dB";
 
 
 void avtext_print_section_header(AVTextFormatContext *tctx, const void *data, int section_id)
@@ -375,15 +376,21 @@ struct unit_value {
     const char *unit;
 };
 
+static const char float_fmt_default[] = "%f";
+static const char float_fmt_full[] = "%f";
+static const char float_fmt_singledigit[] = "%.1f";
 static char *value_string(const AVTextFormatContext *tctx, char *buf, int buf_size, struct unit_value uv)
 {
     double vald;
     int64_t vali = 0;
-    int show_float = 0;
+    const char *float_fmt = float_fmt_default;
 
     if (uv.unit == avtext_unit_second_str) {
         vald = uv.val.d;
-        show_float = 1;
+        float_fmt = float_fmt_full;
+    } else if (uv.unit == avtext_unit_decibel_str) {
+        vald = 20 * log10(uv.val.d);
+        float_fmt = float_fmt_singledigit;
     } else {
         vald = (double)uv.val.i;
         vali = uv.val.i;
@@ -418,8 +425,8 @@ static char *value_string(const AVTextFormatContext *tctx, char *buf, int buf_si
             vali = (int64_t)vald;
         }
 
-        if (show_float || (tctx->use_value_prefix && vald != (int64_t)vald))
-            snprintf(buf, buf_size, "%f", vald);
+        if (float_fmt != float_fmt_default || (tctx->use_value_prefix && vald != (int64_t)vald))
+            snprintf(buf, buf_size, float_fmt, vald);
         else
             snprintf(buf, buf_size, "%"PRId64, vali);
 
@@ -440,6 +447,14 @@ void avtext_print_unit_integer(AVTextFormatContext *tctx, const char *key, int64
     avtext_print_string(tctx, key, value_string(tctx, val_str, sizeof(val_str), uv), 0);
 }
 
+void avtext_print_unit_double(AVTextFormatContext *tctx, const char *key, double val, const char *unit)
+{
+    char val_str[128];
+    struct unit_value uv;
+    uv.val.d = val;
+    uv.unit = unit;
+    avtext_print_string(tctx, key, value_string(tctx, val_str, sizeof(val_str), uv), 0);
+}
 
 int avtext_print_string(AVTextFormatContext *tctx, const char *key, const char *val, int flags)
 {
diff --git a/fftools/textformat/avtextformat.h b/fftools/textformat/avtextformat.h
index d6a5caed61..375cc1703c 100644
--- a/fftools/textformat/avtextformat.h
+++ b/fftools/textformat/avtextformat.h
@@ -157,6 +157,7 @@ typedef struct AVTextFormatOptions {
 
 extern const char avtext_unit_second_str[];
 extern const char avtext_unit_byte_str[];
+extern const char avtext_unit_decibel_str[];
 
 int avtext_context_open(AVTextFormatContext **ptctx, const AVTextFormatter *formatter, AVTextWriterContext *writer_context, const char *args,
                         const AVTextFormatSection *sections, int nb_sections, AVTextFormatOptions options, char *show_data_hash);
@@ -174,6 +175,8 @@ int avtext_print_string(AVTextFormatContext *tctx, const char *key, const char *
 
 void avtext_print_unit_integer(AVTextFormatContext *tctx, const char *key, int64_t val, const char *unit);
 
+void avtext_print_unit_double(AVTextFormatContext *tctx, const char *key, double val, const char *unit);
+
 void avtext_print_rational(AVTextFormatContext *tctx, const char *key, AVRational q, char sep);
 
 void avtext_print_time(AVTextFormatContext *tctx, const char *key, int64_t ts, const AVRational *time_base, int is_duration);
-- 
2.49.1


>From 1441e454b14b36645c1699dec830ab1c6dd64800 Mon Sep 17 00:00:00 2001
From: Nicolas Gaullier <nicolas.gaullier@cji.paris>
Date: Tue, 2 Sep 2025 17:27:46 +0200
Subject: [PATCH 4/4] fftools/ffprobe: add support for downmix_info frame side
 data

Signed-off-by: Nicolas Gaullier <nicolas.gaullier@cji.paris>
---
 fftools/ffprobe.c | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 67ab21c140..43996b2d5a 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -39,6 +39,7 @@
 #include "libavutil/avutil.h"
 #include "libavutil/bprint.h"
 #include "libavutil/channel_layout.h"
+#include "libavutil/downmix_info.h"
 #include "libavutil/display.h"
 #include "libavutil/film_grain_params.h"
 #include "libavutil/hdr_dynamic_metadata.h"
@@ -434,6 +435,7 @@ static void log_callback(void *ptr, int level, const char *fmt, va_list vl)
 #define print_duration_time(k, v, tb) avtext_print_time(tfc, k, v, tb, 1)
 #define print_duration_ts(k, v)       avtext_print_ts(tfc, k, v, 1)
 #define print_val(k, v, u)      avtext_print_unit_integer(tfc, k, v, u)
+#define print_val_double(k, v, u) avtext_print_unit_double(tfc, k, v, u)
 
 #define REALLOCZ_ARRAY_STREAM(ptr, cur_n, new_n)                        \
 {                                                                       \
@@ -461,6 +463,34 @@ static inline int show_tags(AVTextFormatContext *tfc, AVDictionary *tags, int se
     return ret;
 }
 
+static void print_downmix_info(AVTextFormatContext *tfc,
+                                      const AVDownmixInfo *downmix_info)
+{
+    AVBPrint pbuf;
+
+    switch (downmix_info->preferred_downmix_type) {
+    case AV_DOWNMIX_TYPE_LORO:
+        print_str("preferred_downmix_type", "loro");
+        break;
+    case AV_DOWNMIX_TYPE_LTRT:
+        print_str("preferred_downmix_type", "ltrt");
+        break;
+    case AV_DOWNMIX_TYPE_DPLII:
+        print_str("preferred_downmix_type", "dplII");
+        break;
+    default:
+        print_str("preferred_downmix_type", "unknown");
+        break;
+    }
+    av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
+    print_val_double("center_mix_level", downmix_info->center_mix_level, avtext_unit_decibel_str);
+    print_val_double("center_mix_level_ltrt", downmix_info->center_mix_level_ltrt, avtext_unit_decibel_str);
+    print_val_double("surround_mix_level", downmix_info->surround_mix_level, avtext_unit_decibel_str);
+    print_val_double("surround_mix_level_ltrt", downmix_info->surround_mix_level_ltrt, avtext_unit_decibel_str);
+    print_val_double("lfe_mix_level", downmix_info->lfe_mix_level, avtext_unit_decibel_str);
+    av_bprint_finalize(&pbuf, NULL);
+}
+
 static void print_displaymatrix(AVTextFormatContext *tfc, const int32_t matrix[9])
 {
     double rotation = av_display_rotation_get(matrix);
@@ -1298,7 +1328,9 @@ static void print_frame_side_data(AVTextFormatContext *tfc,
         avtext_print_section_header(tfc, sd, SECTION_ID_FRAME_SIDE_DATA);
         name = av_frame_side_data_name(sd->type);
         print_str("side_data_type", name ? name : "unknown");
-        if (sd->type == AV_FRAME_DATA_DISPLAYMATRIX && sd->size >= 9*4) {
+        if (sd->type == AV_FRAME_DATA_DOWNMIX_INFO && sd->size > 0) {
+            print_downmix_info(tfc, (AVDownmixInfo *)sd->data);
+        } else if (sd->type == AV_FRAME_DATA_DISPLAYMATRIX && sd->size >= 9*4) {
             print_displaymatrix(tfc, (const int32_t*)sd->data);
         } else if (sd->type == AV_FRAME_DATA_AFD && sd->size > 0) {
             print_int("active_format", *sd->data);
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-09-02 16:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-02 16:29 [FFmpeg-devel] [PATCH] ffprobe: add support for printing downmix frame side data (PR #20401) ngaullier via ffmpeg-devel

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