Browse code

ffprobe: add support to option -show_error

Stefano Sabatini authored on 2011/12/29 21:24:59
Showing 4 changed files
... ...
@@ -15,6 +15,7 @@ version next:
15 15
 - amerge audio filter
16 16
 - Automatic thread count based on detection number of (available) CPU cores
17 17
 - y41p Brooktree Uncompressed 4:1:1 12-bit encoder and decoder
18
+- ffprobe -show_error option
18 19
 
19 20
 
20 21
 version 0.9:
... ...
@@ -94,6 +94,11 @@ 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_error
98
+Show information about the error found when trying to probe the input.
99
+
100
+The error information is printed within a section with name "ERROR".
101
+
97 102
 @item -show_format
98 103
 Show information about the container format of the input multimedia
99 104
 stream.
... ...
@@ -11,6 +11,7 @@
11 11
             <xsd:element name="packets"  type="ffprobe:packetsType" minOccurs="0" maxOccurs="1" />
12 12
             <xsd:element name="streams"  type="ffprobe:streamsType" minOccurs="0" maxOccurs="1" />
13 13
             <xsd:element name="format"   type="ffprobe:formatType"  minOccurs="0" maxOccurs="1" />
14
+            <xsd:element name="error"    type="ffprobe:errorType"   minOccurs="0" maxOccurs="1" />
14 15
         </xsd:sequence>
15 16
     </xsd:complexType>
16 17
 
... ...
@@ -93,4 +94,9 @@
93 93
       <xsd:attribute name="key"   type="xsd:string" use="required"/>
94 94
       <xsd:attribute name="value" type="xsd:string" use="required"/>
95 95
     </xsd:complexType>
96
+
97
+    <xsd:complexType name="errorType">
98
+      <xsd:attribute name="code"   type="xsd:int"    use="required"/>
99
+      <xsd:attribute name="string" type="xsd:string" use="required"/>
100
+    </xsd:complexType>
96 101
 </xsd:schema>
... ...
@@ -37,6 +37,7 @@
37 37
 const char program_name[] = "ffprobe";
38 38
 const int program_birth_year = 2007;
39 39
 
40
+static int do_show_error   = 0;
40 41
 static int do_show_format  = 0;
41 42
 static int do_show_packets = 0;
42 43
 static int do_show_streams = 0;
... ...
@@ -1322,6 +1323,22 @@ static void show_format(WriterContext *w, AVFormatContext *fmt_ctx)
1322 1322
     fflush(stdout);
1323 1323
 }
1324 1324
 
1325
+static void show_error(WriterContext *w, int err)
1326
+{
1327
+    char errbuf[128];
1328
+    const char *errbuf_ptr = errbuf;
1329
+
1330
+    if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)
1331
+        errbuf_ptr = strerror(AVUNERROR(err));
1332
+
1333
+    writer_print_chapter_header(w, "error");
1334
+    print_section_header("error");
1335
+    print_int("code", err);
1336
+    print_str("string", errbuf_ptr);
1337
+    print_section_footer("error");
1338
+    writer_print_chapter_footer(w, "error");
1339
+}
1340
+
1325 1341
 static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename)
1326 1342
 {
1327 1343
     int err, i;
... ...
@@ -1405,6 +1422,8 @@ static int probe_file(const char *filename)
1405 1405
         PRINT_CHAPTER(streams);
1406 1406
         PRINT_CHAPTER(format);
1407 1407
         avformat_close_input(&fmt_ctx);
1408
+    } else if (do_show_error) {
1409
+        show_error(wctx, ret);
1408 1410
     }
1409 1411
     writer_print_footer(wctx);
1410 1412
     writer_close(&wctx);
... ...
@@ -1478,6 +1497,7 @@ static const OptionDef options[] = {
1478 1478
       "prettify the format of displayed values, make it more human readable" },
1479 1479
     { "print_format", OPT_STRING | HAS_ARG, {(void*)&print_format},
1480 1480
       "set the output printing format (available formats are: default, compact, csv, json, xml)", "format" },
1481
+    { "show_error",   OPT_BOOL, {(void*)&do_show_error} ,  "show probing error" },
1481 1482
     { "show_format",  OPT_BOOL, {(void*)&do_show_format} , "show format/container info" },
1482 1483
     { "show_packets", OPT_BOOL, {(void*)&do_show_packets}, "show packets info" },
1483 1484
     { "show_streams", OPT_BOOL, {(void*)&do_show_streams}, "show streams info" },