[FFmpeg-cvslog] ffprobe: add "noprint_wrappers" option to default writer

Stefano Sabatini git at videolan.org
Mon May 14 13:01:36 CEST 2012


ffmpeg | branch: master | Stefano Sabatini <stefasab at gmail.com> | Wed May  9 01:20:21 2012 +0200| [f48f03a400ac97a18db59387250d5631a6b329a7] | committer: Stefano Sabatini

ffprobe: add "noprint_wrappers" option to default writer

The option is useful for simplifying parsing.

Also use the new option in fate, in order to fix the regression
introduced by the previous commit.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f48f03a400ac97a18db59387250d5631a6b329a7
---

 doc/ffprobe.texi  |   13 +++++++++++
 ffprobe.c         |   60 +++++++++++++++++++++++++++++++++++++++++++++++++---
 tests/fate-run.sh |    2 +-
 3 files changed, 70 insertions(+), 5 deletions(-)

diff --git a/doc/ffprobe.texi b/doc/ffprobe.texi
index 47c2156..a1af680 100644
--- a/doc/ffprobe.texi
+++ b/doc/ffprobe.texi
@@ -195,6 +195,19 @@ keyN=valN
 Metadata tags are printed as a line in the corresponding FORMAT or
 STREAM section, and are prefixed by the string "TAG:".
 
+This writer accepts options as a list of @var{key}=@var{value} pairs,
+separated by ":".
+
+A description of the accepted options follows.
+
+ at table @option
+
+ at item noprint_wrappers, nw
+If set to 1 specify not to print the section header and footer.
+Default value is 0.
+
+ at end table
+
 @section compact
 Compact format.
 
diff --git a/ffprobe.c b/ffprobe.c
index fb37d08..5a8c9e8 100644
--- a/ffprobe.c
+++ b/ffprobe.c
@@ -401,14 +401,60 @@ fail:
 
 /* Default output */
 
+typedef struct DefaultContext {
+    const AVClass *class;
+    int noprint_wrappers;
+} DefaultContext;
+
+#define OFFSET(x) offsetof(DefaultContext, x)
+
+static const AVOption default_options[] = {
+    { "noprint_wrappers", "do not print headers and footers", OFFSET(noprint_wrappers), AV_OPT_TYPE_INT, {.dbl=0}, 0, 1 },
+    { "nw",               "do not print headers and footers", OFFSET(noprint_wrappers), AV_OPT_TYPE_INT, {.dbl=0}, 0, 1 },
+    {NULL},
+};
+
+static const char *default_get_name(void *ctx)
+{
+    return "default";
+}
+
+static const AVClass default_class = {
+    "DefaultContext",
+    default_get_name,
+    default_options
+};
+
+static av_cold int default_init(WriterContext *wctx, const char *args, void *opaque)
+{
+    DefaultContext *def = wctx->priv;
+    int err;
+
+    def->class = &default_class;
+    av_opt_set_defaults(def);
+
+    if (args &&
+        (err = (av_set_options_string(def, args, "=", ":"))) < 0) {
+        av_log(wctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args);
+        return err;
+    }
+
+    return 0;
+}
+
 static void default_print_footer(WriterContext *wctx)
 {
-    printf("\n");
+    DefaultContext *def = wctx->priv;
+
+    if (!def->noprint_wrappers)
+        printf("\n");
 }
 
 static void default_print_chapter_header(WriterContext *wctx, const char *chapter)
 {
-    if (wctx->nb_chapter)
+    DefaultContext *def = wctx->priv;
+
+    if (!def->noprint_wrappers && wctx->nb_chapter)
         printf("\n");
 }
 
@@ -424,18 +470,22 @@ static inline char *upcase_string(char *dst, size_t dst_size, const char *src)
 
 static void default_print_section_header(WriterContext *wctx, const char *section)
 {
+    DefaultContext *def = wctx->priv;
     char buf[32];
 
     if (wctx->nb_section)
         printf("\n");
-    printf("[%s]\n", upcase_string(buf, sizeof(buf), section));
+    if (!def->noprint_wrappers)
+        printf("[%s]\n", upcase_string(buf, sizeof(buf), section));
 }
 
 static void default_print_section_footer(WriterContext *wctx, const char *section)
 {
+    DefaultContext *def = wctx->priv;
     char buf[32];
 
-    printf("[/%s]", upcase_string(buf, sizeof(buf), section));
+    if (!def->noprint_wrappers)
+        printf("[/%s]", upcase_string(buf, sizeof(buf), section));
 }
 
 static void default_print_str(WriterContext *wctx, const char *key, const char *value)
@@ -460,6 +510,7 @@ static void default_show_tags(WriterContext *wctx, AVDictionary *dict)
 
 static const Writer default_writer = {
     .name                  = "default",
+    .init                  = default_init,
     .print_footer          = default_print_footer,
     .print_chapter_header  = default_print_chapter_header,
     .print_section_header  = default_print_section_header,
@@ -534,6 +585,7 @@ typedef struct CompactContext {
     const char * (*escape_str)(AVBPrint *dst, const char *src, const char sep, void *log_ctx);
 } CompactContext;
 
+#undef OFFSET
 #define OFFSET(x) offsetof(CompactContext, x)
 
 static const AVOption compact_options[]= {
diff --git a/tests/fate-run.sh b/tests/fate-run.sh
index b3f1b68..c205169 100755
--- a/tests/fate-run.sh
+++ b/tests/fate-run.sh
@@ -72,7 +72,7 @@ run(){
 }
 
 probefmt(){
-    run ffprobe -show_format_entry format_name -v 0 "$@"
+    run ffprobe -show_format_entry format_name -print_format default=nw=1 -v 0 "$@"
 }
 
 avconv(){



More information about the ffmpeg-cvslog mailing list