[FFmpeg-devel] [PATCH] ffprobe: add flat output format.

Clément Bœsch ubitux at gmail.com
Sat May 26 01:14:50 CEST 2012


---
 doc/ffprobe.texi |    6 ++++
 ffprobe.c        |   81 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 86 insertions(+), 1 deletion(-)

diff --git a/doc/ffprobe.texi b/doc/ffprobe.texi
index ed96575..2cab961 100644
--- a/doc/ffprobe.texi
+++ b/doc/ffprobe.texi
@@ -269,6 +269,12 @@ CSV format.
 This writer is equivalent to
 @code{compact=item_sep=,:nokey=1:escape=csv}.
 
+ at section flat
+Flat format.
+
+A free-form output with each line contains an explicit key=value, such as
+"stream.3.tag.25=foobar"
+
 @section json
 JSON based format.
 
diff --git a/ffprobe.c b/ffprobe.c
index d53ec11..43770cb 100644
--- a/ffprobe.c
+++ b/ffprobe.c
@@ -710,6 +710,84 @@ static const Writer csv_writer = {
     .flags = WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS,
 };
 
+/* Flat output */
+
+typedef struct FlatContext {
+    const AVClass *class;
+    const char *section;
+    int section_entry_id;
+} FlatContext;
+
+#undef OFFSET
+#define OFFSET(x) offsetof(FlatContext, x)
+
+static const char *flat_get_name(void *ctx)
+{
+    return "flat";
+}
+
+static const AVClass flat_class = {
+    "FlatContext",
+    flat_get_name,
+};
+
+static void flat_print_section(const FlatContext *flat)
+{
+    printf("%s.", flat->section);
+    if (!strcmp(flat->section, "format") || !strcmp(flat->section, "error"))
+        return;
+    printf("%d.", flat->section_entry_id);
+}
+
+static void flat_print_section_header(WriterContext *wctx, const char *section)
+{
+    FlatContext *flat = wctx->priv;
+    if (flat->section && strcmp(flat->section, section) == 0) {
+        flat->section_entry_id++;
+    } else {
+        flat->section = section;
+        flat->section_entry_id = 0;
+    }
+}
+
+static void flat_print_str(WriterContext *wctx, const char *key, const char *value)
+{
+    FlatContext *flat = wctx->priv;
+
+    flat_print_section(flat);
+    printf("%s=%s\n", key, value);
+}
+
+static void flat_print_int(WriterContext *wctx, const char *key, long long int value)
+{
+    FlatContext *flat = wctx->priv;
+
+    flat_print_section(flat);
+    printf("%s=%lld\n", key, value);
+}
+
+static void flat_show_tags(WriterContext *wctx, AVDictionary *dict)
+{
+    int id = 0;
+    FlatContext *flat = wctx->priv;
+    AVDictionaryEntry *tag = NULL;
+
+    while ((tag = av_dict_get(dict, "", tag, AV_DICT_IGNORE_SUFFIX))) {
+        flat_print_section(flat);
+        printf("tag.%d=%s\n", id++, tag->value);
+    }
+}
+
+static const Writer flat_writer = {
+    .name                 = "flat",
+    .priv_size            = sizeof(FlatContext),
+    .print_section_header = flat_print_section_header,
+    .print_integer        = flat_print_int,
+    .print_string         = flat_print_str,
+    .show_tags            = flat_show_tags,
+    .flags = WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS,
+};
+
 /* JSON output */
 
 typedef struct {
@@ -1172,6 +1250,7 @@ static void writer_register_all(void)
     writer_register(&default_writer);
     writer_register(&compact_writer);
     writer_register(&csv_writer);
+    writer_register(&flat_writer);
     writer_register(&json_writer);
     writer_register(&xml_writer);
 }
@@ -1732,7 +1811,7 @@ static const OptionDef options[] = {
     { "pretty", 0, {(void*)&opt_pretty},
       "prettify the format of displayed values, make it more human readable" },
     { "print_format", OPT_STRING | HAS_ARG, {(void*)&print_format},
-      "set the output printing format (available formats are: default, compact, csv, json, xml)", "format" },
+      "set the output printing format (available formats are: default, compact, csv, flat, json, xml)", "format" },
     { "show_error",   OPT_BOOL, {(void*)&do_show_error} ,  "show probing error" },
     { "show_format",  OPT_BOOL, {(void*)&do_show_format} , "show format/container info" },
     { "show_frames",  OPT_BOOL, {(void*)&do_show_frames} , "show frames info" },
-- 
1.7.10.2



More information about the ffmpeg-devel mailing list