Browse code

ffprobe: add -show_data option.

Nicolas George authored on 2012/04/08 02:18:09
Showing 3 changed files
... ...
@@ -8,6 +8,7 @@ version next:
8 8
 - channelsplit audio filter
9 9
 - setnsamples audio filter
10 10
 - atempo filter
11
+- ffprobe -show_data option
11 12
 
12 13
 
13 14
 version 0.11:
... ...
@@ -94,6 +94,13 @@ For example for printing the output in JSON format, specify:
94 94
 For more details on the available output printing formats, see the
95 95
 Writers section below.
96 96
 
97
+@item -show_data
98
+Show payload data, as an hexadecimal and ASCII dump. Coupled with
99
+@option{-show_packets}, it will dump the packets' data. Coupled with
100
+@option{-show_streams}, it will dump the codec extradata.
101
+
102
+The dump is printed as the "data" field. It may contain newlines.
103
+
97 104
 @item -show_error
98 105
 Show information about the error found when trying to probe the input.
99 106
 
... ...
@@ -53,6 +53,7 @@ static int do_show_frames  = 0;
53 53
 static AVDictionary *fmt_entries_to_show = NULL;
54 54
 static int do_show_packets = 0;
55 55
 static int do_show_streams = 0;
56
+static int do_show_data    = 0;
56 57
 static int do_show_program_version  = 0;
57 58
 static int do_show_library_versions = 0;
58 59
 
... ...
@@ -361,6 +362,34 @@ static inline void writer_show_tags(WriterContext *wctx, AVDictionary *dict)
361 361
     wctx->writer->show_tags(wctx, dict);
362 362
 }
363 363
 
364
+static void writer_print_data(WriterContext *wctx, const char *name,
365
+                              uint8_t *data, int size)
366
+{
367
+    AVBPrint bp;
368
+    int offset = 0, l, i;
369
+
370
+    av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
371
+    av_bprintf(&bp, "\n");
372
+    while (size) {
373
+        av_bprintf(&bp, "%08x: ", offset);
374
+        l = FFMIN(size, 16);
375
+        for (i = 0; i < l; i++) {
376
+            av_bprintf(&bp, "%02x", data[i]);
377
+            if (i & 1)
378
+                av_bprintf(&bp, " ");
379
+        }
380
+        av_bprint_chars(&bp, ' ', 41 - 2 * i - i / 2);
381
+        for (i = 0; i < l; i++)
382
+            av_bprint_chars(&bp, data[i] - 32U < 95 ? data[i] : '.', 1);
383
+        av_bprintf(&bp, "\n");
384
+        offset += l;
385
+        data   += l;
386
+        size   -= l;
387
+    }
388
+    writer_print_string(wctx, name, bp.str, 0);
389
+    av_bprint_finalize(&bp, NULL);
390
+}
391
+
364 392
 #define MAX_REGISTERED_WRITERS_NB 64
365 393
 
366 394
 static const Writer *registered_writers[MAX_REGISTERED_WRITERS_NB + 1];
... ...
@@ -1556,6 +1585,8 @@ static void show_packet(WriterContext *w, AVFormatContext *fmt_ctx, AVPacket *pk
1556 1556
     if (pkt->pos != -1) print_fmt    ("pos", "%"PRId64, pkt->pos);
1557 1557
     else                print_str_opt("pos", "N/A");
1558 1558
     print_fmt("flags", "%c",      pkt->flags & AV_PKT_FLAG_KEY ? 'K' : '_');
1559
+    if (do_show_data)
1560
+        writer_print_data(w, "data", pkt->data, pkt->size);
1559 1561
     print_section_footer("packet");
1560 1562
 
1561 1563
     av_bprint_finalize(&pbuf, NULL);
... ...
@@ -1796,6 +1827,9 @@ static void show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_i
1796 1796
     if (nb_streams_packets[stream_idx]) print_fmt    ("nb_read_packets", "%"PRIu64, nb_streams_packets[stream_idx]);
1797 1797
     else                                print_str_opt("nb_read_packets", "N/A");
1798 1798
     show_tags(stream->metadata);
1799
+    if (do_show_data)
1800
+        writer_print_data(w, "extradata", dec_ctx->extradata,
1801
+                                          dec_ctx->extradata_size);
1799 1802
 
1800 1803
     print_section_footer("stream");
1801 1804
     av_bprint_finalize(&pbuf, NULL);
... ...
@@ -2079,6 +2113,7 @@ static const OptionDef options[] = {
2079 2079
     { "print_format", OPT_STRING | HAS_ARG, {(void*)&print_format},
2080 2080
       "set the output printing format (available formats are: default, compact, csv, flat, ini, json, xml)", "format" },
2081 2081
     { "of", OPT_STRING | HAS_ARG, {(void*)&print_format}, "alias for -print_format", "format" },
2082
+    { "show_data",    OPT_BOOL, {(void*)&do_show_data}, "show packets data" },
2082 2083
     { "show_error",   OPT_BOOL, {(void*)&do_show_error} ,  "show probing error" },
2083 2084
     { "show_format",  OPT_BOOL, {(void*)&do_show_format} , "show format/container info" },
2084 2085
     { "show_frames",  OPT_BOOL, {(void*)&do_show_frames} , "show frames info" },