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 0/2] fftools/ffprobe: Add YAML output writer
@ 2025-02-19 20:07 ffmpegagent
  2025-02-19 20:07 ` [FFmpeg-devel] [PATCH 1/2] " softworkz
  2025-02-19 20:07 ` [FFmpeg-devel] [PATCH 2/2] docs: Add documentation about " softworkz
  0 siblings, 2 replies; 3+ messages in thread
From: ffmpegagent @ 2025-02-19 20:07 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: softworkz

fftools/ffprobe: Add YAML output writer

Motivation

While YAML might not be the greatest format as such, its strengths are in
human readability, probably better than any other format we have currently,
which makes it worthwhile to add afaic.

softworkz (2):
  fftools/ffprobe: Add YAML output writer
  docs: Add documentation about YAML output writer

 doc/ffprobe.texi  |  16 +++++
 fftools/ffprobe.c | 147 +++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 162 insertions(+), 1 deletion(-)


base-commit: 0e7c2a6287f977c30e08e2a211385c6a80614fe8
Published-As: https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-55%2Fsoftworkz%2Fsubmit_yaml-v1
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg pr-ffstaging-55/softworkz/submit_yaml-v1
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/55
-- 
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".

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [FFmpeg-devel] [PATCH 1/2] fftools/ffprobe: Add YAML output writer
  2025-02-19 20:07 [FFmpeg-devel] [PATCH 0/2] fftools/ffprobe: Add YAML output writer ffmpegagent
@ 2025-02-19 20:07 ` softworkz
  2025-02-19 20:07 ` [FFmpeg-devel] [PATCH 2/2] docs: Add documentation about " softworkz
  1 sibling, 0 replies; 3+ messages in thread
From: softworkz @ 2025-02-19 20:07 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: softworkz

From: softworkz <softworkz@hotmail.com>

Signed-off-by: softworkz <softworkz@hotmail.com>
---
 fftools/ffprobe.c | 147 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 146 insertions(+), 1 deletion(-)

diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 0270878ead..843c8df7f3 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -1980,6 +1980,150 @@ static Writer xml_writer = {
     .priv_class           = &xml_class,
 };
 
+
+/* YAML output */
+
+typedef struct YMLContext {
+    const AVClass *class;
+    int indent_level;
+    int blank_lines;
+} YMLContext;
+
+#undef OFFSET
+#define OFFSET(x) offsetof(YMLContext, x)
+
+static const AVOption yml_options[] = {
+    { "blank_lines", "print blank lines for better readability", OFFSET(blank_lines), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
+    { NULL }
+};
+
+DEFINE_WRITER_CLASS(yml);
+
+static av_cold int yml_init(WriterContext *wctx)
+{
+    YMLContext *yml = wctx->priv;
+    yml->indent_level = 0;
+    return 0;
+}
+
+static int yml_is_plain(const char *s)
+{
+    if (!s || !*s)
+        return 0;
+    for (; *s; s++) {
+        if (!( (*s >= 'a' && *s <= 'z') ||
+               (*s >= 'A' && *s <= 'Z') ||
+               (*s >= '0' && *s <= '9') ||
+               *s == '_' || *s == '-' || *s == '.' ))
+            return 0;
+    }
+    return 1;
+}
+
+static void yml_print_quote_escape(WriterContext *wctx, const char *src)
+{
+    if (yml_is_plain(src)) {
+        writer_put_str(wctx, src);
+    } else {
+        writer_w8(wctx, '"');
+        for (const char *p = src; *p; p++) {
+            unsigned char c = *p;
+            if (c == '\\' || c == '"') {
+                writer_w8(wctx, '\\');
+                writer_w8(wctx, c);
+            } else if (c < 32 || c > 126) {
+                writer_printf(wctx, "\\u%04x", c);
+            } else {
+                writer_w8(wctx, c);
+            }
+        }
+        writer_w8(wctx, '"');
+    }
+}
+
+#define YML_INDENT() if (yml->indent_level > 0) writer_printf(wctx, "%*c", yml->indent_level * 2, ' ')
+#define YML_BLANKLINE() if (yml->blank_lines ) writer_put_str(wctx, "\n");
+
+/* At the top level, print yaml start marker '---'. If parent section is array,
+ * output a dash. If the section isn't merely a wrapper, its name as a mapping key.
+ * Otherwise, output the section name as a mapping key. */
+static void yml_print_section_header(WriterContext *wctx, const void *data)
+{
+    YMLContext *yml = wctx->priv;
+    const struct section *section = wctx->section[wctx->level];
+    const struct section *parent = (wctx->level > 0) ? wctx->section[wctx->level-1] : NULL;
+
+    if (wctx->level == 0) {
+        writer_put_str(wctx, "---\n");
+        return;
+    }
+
+    int parent_is_array = parent && (parent->flags & SECTION_FLAG_IS_ARRAY);
+    if (parent_is_array) {
+        YML_BLANKLINE();
+        writer_printf(wctx, "%*c- ", yml->indent_level * 2, ' ');
+        if (!(section->flags & SECTION_FLAG_IS_WRAPPER)) {
+            writer_printf(wctx, "%s:\n", section->name);
+        } else {
+            writer_put_str(wctx, "\n");
+        }
+        yml->indent_level++;
+        return;
+    }
+
+    YML_INDENT();
+    writer_put_str(wctx, section->name);
+    writer_put_str(wctx, ":\n");
+    yml->indent_level++;
+}
+
+static void yml_print_section_footer(WriterContext *wctx)
+{
+    YMLContext *yml = wctx->priv;
+    if (wctx->level == 0) {
+        writer_put_str(wctx, "...\n"); // yaml end document marker
+    } else {
+        if (wctx->level == 1)
+            YML_BLANKLINE();
+        yml->indent_level--;
+    }
+}
+
+static void yml_print_str(WriterContext *wctx, const char *key, const char *value)
+{
+    YMLContext *yml = wctx->priv;
+    YML_INDENT();
+
+    yml_print_quote_escape(wctx, key);
+    writer_put_str(wctx, ": ");
+
+    yml_print_quote_escape(wctx, value);
+    writer_put_str(wctx, "\n");
+}
+
+static void yml_print_int(WriterContext *wctx, const char *key, int64_t value)
+{
+    YMLContext *yml = wctx->priv;
+    YML_INDENT();
+
+    yml_print_quote_escape(wctx, key);
+    writer_put_str(wctx, ": ");
+
+    writer_printf(wctx, "%"PRId64"\n", value);
+}
+
+static const Writer yml_writer = {
+    .name                 = "yml",
+    .priv_size            = sizeof(YMLContext),
+    .init                 = yml_init,
+    .print_section_header = yml_print_section_header,
+    .print_section_footer = yml_print_section_footer,
+    .print_integer        = yml_print_int,
+    .print_string         = yml_print_str,
+    .flags                = WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER,
+    .priv_class           = &yml_class,
+};
+
 static void writer_register_all(void)
 {
     static int initialized;
@@ -1995,6 +2139,7 @@ static void writer_register_all(void)
     writer_register(&ini_writer);
     writer_register(&json_writer);
     writer_register(&xml_writer);
+    writer_register(&yml_writer);
 }
 
 #define print_fmt(k, f, ...) do {              \
@@ -4597,7 +4742,7 @@ static const OptionDef real_options[] = {
     { "pretty",                OPT_TYPE_FUNC,        0, {.func_arg = opt_pretty},
       "prettify the format of displayed values, make it more human readable" },
     { "output_format",         OPT_TYPE_STRING,      0, { &output_format },
-      "set the output printing format (available formats are: default, compact, csv, flat, ini, json, xml)", "format" },
+      "set the output printing format (available formats are: default, compact, csv, flat, ini, yml, json, xml)", "format" },
     { "print_format",          OPT_TYPE_STRING,      0, { &output_format }, "alias for -output_format (deprecated)" },
     { "of",                    OPT_TYPE_STRING,      0, { &output_format }, "alias for -output_format", "format" },
     { "select_streams",        OPT_TYPE_STRING,      0, { &stream_specifier }, "select the specified streams", "stream_specifier" },
-- 
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".

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [FFmpeg-devel] [PATCH 2/2] docs: Add documentation about YAML output writer
  2025-02-19 20:07 [FFmpeg-devel] [PATCH 0/2] fftools/ffprobe: Add YAML output writer ffmpegagent
  2025-02-19 20:07 ` [FFmpeg-devel] [PATCH 1/2] " softworkz
@ 2025-02-19 20:07 ` softworkz
  1 sibling, 0 replies; 3+ messages in thread
From: softworkz @ 2025-02-19 20:07 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: softworkz

From: softworkz <softworkz@hotmail.com>

Signed-off-by: softworkz <softworkz@hotmail.com>
---
 doc/ffprobe.texi | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/doc/ffprobe.texi b/doc/ffprobe.texi
index ceedc8793b..106d865e18 100644
--- a/doc/ffprobe.texi
+++ b/doc/ffprobe.texi
@@ -626,6 +626,22 @@ This option automatically sets @option{fully_qualified} to 1.
 
 For more information about the XML format, see
 @url{https://www.w3.org/XML/}.
+
+@section yaml
+YAML based format.
+
+Each section is printed using YAML notation.
+
+The description of the accepted options follows.
+
+@table @option
+
+@item blank_lines
+If set to 1, blank lines are inserted between sections for
+better readability. Default value is 1.
+@end table
+
+For more information about YAML, see @url{https://yaml.org/}.
 @c man end WRITERS
 
 @chapter Timecode
-- 
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".

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-02-19 20:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-19 20:07 [FFmpeg-devel] [PATCH 0/2] fftools/ffprobe: Add YAML output writer ffmpegagent
2025-02-19 20:07 ` [FFmpeg-devel] [PATCH 1/2] " softworkz
2025-02-19 20:07 ` [FFmpeg-devel] [PATCH 2/2] docs: Add documentation about " softworkz

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