avprobe: output proper INI format
[platform/upstream/libav.git] / avprobe.c
1 /*
2  * avprobe : Simple Media Prober based on the Libav libraries
3  * Copyright (c) 2007-2010 Stefano Sabatini
4  *
5  * This file is part of Libav.
6  *
7  * Libav is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * Libav is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21
22 #include "config.h"
23
24 #include "libavformat/avformat.h"
25 #include "libavcodec/avcodec.h"
26 #include "libavutil/opt.h"
27 #include "libavutil/pixdesc.h"
28 #include "libavutil/dict.h"
29 #include "libavdevice/avdevice.h"
30 #include "cmdutils.h"
31
32 const char program_name[] = "avprobe";
33 const int program_birth_year = 2007;
34
35 static int do_show_format  = 0;
36 static AVDictionary *fmt_entries_to_show = NULL;
37 static int nb_fmt_entries_to_show;
38 static int do_show_packets = 0;
39 static int do_show_streams = 0;
40
41 static int show_value_unit              = 0;
42 static int use_value_prefix             = 0;
43 static int use_byte_value_binary_prefix = 0;
44 static int use_value_sexagesimal_format = 0;
45
46 /* globals */
47 static const OptionDef options[];
48
49 /* AVprobe context */
50 static const char *input_filename;
51 static AVInputFormat *iformat = NULL;
52
53 static const char *const binary_unit_prefixes [] = { "", "Ki", "Mi", "Gi", "Ti", "Pi" };
54 static const char *const decimal_unit_prefixes[] = { "", "K" , "M" , "G" , "T" , "P"  };
55
56 static const char unit_second_str[]         = "s"    ;
57 static const char unit_hertz_str[]          = "Hz"   ;
58 static const char unit_byte_str[]           = "byte" ;
59 static const char unit_bit_per_second_str[] = "bit/s";
60
61 void exit_program(int ret)
62 {
63     av_dict_free(&fmt_entries_to_show);
64     exit(ret);
65 }
66
67 /*
68  * The output is structured in array and objects that might contain items
69  * Array could require the objects within to not be named.
70  * Object could require the items within to be named.
71  *
72  * For flat representation the name of each section is saved on prefix so it
73  * can be rendered in order to represent nested structures (e.g. array of
74  * objects for the packets list).
75  *
76  * Within an array each element can need an unique identifier or an index.
77  *
78  * Nesting level is accounted separately.
79  */
80
81 typedef enum {
82     ARRAY,
83     OBJECT
84 } ProbeElementType;
85
86 typedef struct {
87     const char *name;
88     ProbeElementType type;
89     int64_t index;
90     int64_t nb_elems;
91 } ProbeElement;
92
93 typedef struct {
94     ProbeElement *prefix;
95     int level;
96 } OutputContext;
97
98 static AVIOContext *probe_out = NULL;
99 static OutputContext octx;
100
101 /*
102  * Default format, INI
103  *
104  * - all key and values are utf8
105  * - '.' is the subgroup separator
106  * - newlines and the following characters are escaped
107  * - '\' is the escape character
108  * - '#' is the comment
109  * - '=' is the key/value separators
110  * - ':' is not used but usually parsed as key/value separator
111  */
112
113 static void ini_print_header(void)
114 {
115     avio_printf(probe_out, "# avprobe output\n\n");
116 }
117 static void ini_print_footer(void)
118 {
119     avio_w8(probe_out, '\n');
120 }
121
122 static void ini_escape_print(const char *s)
123 {
124     int i = 0;
125     char c = 0;
126
127     while (c = s[i++]) {
128         switch (c) {
129         case '\r': avio_printf(probe_out, "%s", "\\r"); break;
130         case '\n': avio_printf(probe_out, "%s", "\\n"); break;
131         case '\f': avio_printf(probe_out, "%s", "\\f"); break;
132         case '\b': avio_printf(probe_out, "%s", "\\b"); break;
133         case '\t': avio_printf(probe_out, "%s", "\\t"); break;
134         case '\\':
135         case '#' :
136         case '=' :
137         case ':' : avio_w8(probe_out, '\\');
138         default:
139             if ((unsigned char)c < 32)
140                 avio_printf(probe_out, "\\x00%02x", c & 0xff);
141             else
142                 avio_w8(probe_out, c);
143         break;
144         }
145     }
146 }
147
148 static void ini_print_array_header(const char *name)
149 {
150     if (octx.prefix[octx.level -1].nb_elems)
151         avio_printf(probe_out, "\n");
152 }
153
154 static void ini_print_object_header(const char *name)
155 {
156     int i;
157     ProbeElement *el = octx.prefix + octx.level -1;
158
159     if (el->nb_elems)
160         avio_printf(probe_out, "\n");
161
162     avio_printf(probe_out, "[");
163
164     for (i = 1; i < octx.level; i++) {
165         el = octx.prefix + i;
166         avio_printf(probe_out, "%s.", el->name);
167         if (el->index >= 0)
168             avio_printf(probe_out, "%"PRId64".", el->index);
169     }
170
171     avio_printf(probe_out, "%s", name);
172     if (el && el->type == ARRAY)
173         avio_printf(probe_out, ".%"PRId64"", el->nb_elems);
174     avio_printf(probe_out, "]\n");
175 }
176
177 static void ini_print_integer(const char *key, int64_t value)
178 {
179     ini_escape_print(key);
180     avio_printf(probe_out, "=%"PRId64"\n", value);
181 }
182
183
184 static void ini_print_string(const char *key, const char *value)
185 {
186     ini_escape_print(key);
187     avio_printf(probe_out, "=");
188     ini_escape_print(value);
189     avio_w8(probe_out, '\n');
190 }
191
192 /*
193  * Simple Formatter for single entries.
194  */
195
196 static void show_format_entry_integer(const char *key, int64_t value)
197 {
198     if (key && av_dict_get(fmt_entries_to_show, key, NULL, 0)) {
199         if (nb_fmt_entries_to_show > 1)
200             avio_printf(probe_out, "%s=", key);
201         avio_printf(probe_out, "%"PRId64"\n", value);
202     }
203 }
204
205 static void show_format_entry_string(const char *key, const char *value)
206 {
207     if (key && av_dict_get(fmt_entries_to_show, key, NULL, 0)) {
208         if (nb_fmt_entries_to_show > 1)
209             avio_printf(probe_out, "%s=", key);
210         avio_printf(probe_out, "%s\n", value);
211     }
212 }
213
214
215 void (*print_header)(void) = ini_print_header;
216 void (*print_footer)(void) = ini_print_footer;
217
218 void (*print_array_header) (const char *name) = ini_print_array_header;
219 void (*print_array_footer) (const char *name);
220 void (*print_object_header)(const char *name) = ini_print_object_header;
221 void (*print_object_footer)(const char *name);
222
223 void (*print_integer) (const char *key, int64_t value)     = ini_print_integer;
224 void (*print_string)  (const char *key, const char *value) = ini_print_string;
225
226
227 static void probe_group_enter(const char *name, int type)
228 {
229     int64_t count = -1;
230
231     octx.prefix =
232         av_realloc(octx.prefix, sizeof(ProbeElement) * (octx.level + 1));
233
234     if (!octx.prefix || !name) {
235         fprintf(stderr, "Out of memory\n");
236         exit(1);
237     }
238
239     if (octx.level) {
240         ProbeElement *parent = octx.prefix + octx.level -1;
241         if (parent->type == ARRAY)
242             count = parent->nb_elems;
243         parent->nb_elems++;
244     }
245
246     octx.prefix[octx.level++] = (ProbeElement){name, type, count, 0};
247 }
248
249 static void probe_group_leave(void)
250 {
251     --octx.level;
252 }
253
254 static void probe_header(void)
255 {
256     if (print_header)
257         print_header();
258     probe_group_enter("root", OBJECT);
259 }
260
261 static void probe_footer(void)
262 {
263     if (print_footer)
264         print_footer();
265     probe_group_leave();
266 }
267
268
269 static void probe_array_header(const char *name)
270 {
271     if (print_array_header)
272         print_array_header(name);
273
274     probe_group_enter(name, ARRAY);
275 }
276
277 static void probe_array_footer(const char *name)
278 {
279     probe_group_leave();
280     if (print_array_footer)
281         print_array_footer(name);
282 }
283
284 static void probe_object_header(const char *name)
285 {
286     if (print_object_header)
287         print_object_header(name);
288
289     probe_group_enter(name, OBJECT);
290 }
291
292 static void probe_object_footer(const char *name)
293 {
294     probe_group_leave();
295     if (print_object_footer)
296         print_object_footer(name);
297 }
298
299 static void probe_int(const char *key, int64_t value)
300 {
301     print_integer(key, value);
302     octx.prefix[octx.level -1].nb_elems++;
303 }
304
305 static void probe_str(const char *key, const char *value)
306 {
307     print_string(key, value);
308     octx.prefix[octx.level -1].nb_elems++;
309 }
310
311 static void probe_dict(AVDictionary *dict, const char *name)
312 {
313     AVDictionaryEntry *entry = NULL;
314     if (!dict)
315         return;
316     probe_object_header(name);
317     while ((entry = av_dict_get(dict, "", entry, AV_DICT_IGNORE_SUFFIX))) {
318         probe_str(entry->key, entry->value);
319     }
320     probe_object_footer(name);
321 }
322
323 static char *value_string(char *buf, int buf_size, double val, const char *unit)
324 {
325     if (unit == unit_second_str && use_value_sexagesimal_format) {
326         double secs;
327         int hours, mins;
328         secs  = val;
329         mins  = (int)secs / 60;
330         secs  = secs - mins * 60;
331         hours = mins / 60;
332         mins %= 60;
333         snprintf(buf, buf_size, "%d:%02d:%09.6f", hours, mins, secs);
334     } else if (use_value_prefix) {
335         const char *prefix_string;
336         int index;
337
338         if (unit == unit_byte_str && use_byte_value_binary_prefix) {
339             index = (int) (log(val)/log(2)) / 10;
340             index = av_clip(index, 0, FF_ARRAY_ELEMS(binary_unit_prefixes) - 1);
341             val  /= pow(2, index * 10);
342             prefix_string = binary_unit_prefixes[index];
343         } else {
344             index = (int) (log10(val)) / 3;
345             index = av_clip(index, 0, FF_ARRAY_ELEMS(decimal_unit_prefixes) - 1);
346             val  /= pow(10, index * 3);
347             prefix_string = decimal_unit_prefixes[index];
348         }
349         snprintf(buf, buf_size, "%.*f%s%s",
350                  index ? 3 : 0, val,
351                  prefix_string,
352                  show_value_unit ? unit : "");
353     } else {
354         snprintf(buf, buf_size, "%f%s", val, show_value_unit ? unit : "");
355     }
356
357     return buf;
358 }
359
360 static char *time_value_string(char *buf, int buf_size, int64_t val,
361                                const AVRational *time_base)
362 {
363     if (val == AV_NOPTS_VALUE) {
364         snprintf(buf, buf_size, "N/A");
365     } else {
366         value_string(buf, buf_size, val * av_q2d(*time_base), unit_second_str);
367     }
368
369     return buf;
370 }
371
372 static char *ts_value_string(char *buf, int buf_size, int64_t ts)
373 {
374     if (ts == AV_NOPTS_VALUE) {
375         snprintf(buf, buf_size, "N/A");
376     } else {
377         snprintf(buf, buf_size, "%"PRId64, ts);
378     }
379
380     return buf;
381 }
382
383 static char *rational_string(char *buf, int buf_size, const char *sep,
384                              const AVRational *rat)
385 {
386     snprintf(buf, buf_size, "%d%s%d", rat->num, sep, rat->den);
387     return buf;
388 }
389
390 static char *tag_string(char *buf, int buf_size, int tag)
391 {
392     snprintf(buf, buf_size, "0x%04x", tag);
393     return buf;
394 }
395
396
397
398 static const char *media_type_string(enum AVMediaType media_type)
399 {
400     switch (media_type) {
401     case AVMEDIA_TYPE_VIDEO:      return "video";
402     case AVMEDIA_TYPE_AUDIO:      return "audio";
403     case AVMEDIA_TYPE_DATA:       return "data";
404     case AVMEDIA_TYPE_SUBTITLE:   return "subtitle";
405     case AVMEDIA_TYPE_ATTACHMENT: return "attachment";
406     default:                      return "unknown";
407     }
408 }
409
410 static void show_packet(AVFormatContext *fmt_ctx, AVPacket *pkt)
411 {
412     char val_str[128];
413     AVStream *st = fmt_ctx->streams[pkt->stream_index];
414
415     probe_object_header("packet");
416     probe_str("codec_type", media_type_string(st->codec->codec_type));
417     probe_int("stream_index", pkt->stream_index);
418     probe_str("pts", ts_value_string(val_str, sizeof(val_str), pkt->pts));
419     probe_str("pts_time", time_value_string(val_str, sizeof(val_str),
420                                                pkt->pts, &st->time_base));
421     probe_str("dts", ts_value_string(val_str, sizeof(val_str), pkt->dts));
422     probe_str("dts_time", time_value_string(val_str, sizeof(val_str),
423                                                pkt->dts, &st->time_base));
424     probe_str("duration", ts_value_string(val_str, sizeof(val_str),
425                                              pkt->duration));
426     probe_str("duration_time", time_value_string(val_str, sizeof(val_str),
427                                                     pkt->duration,
428                                                     &st->time_base));
429     probe_str("size", value_string(val_str, sizeof(val_str),
430                                       pkt->size, unit_byte_str));
431     probe_int("pos", pkt->pos);
432     probe_str("flags", pkt->flags & AV_PKT_FLAG_KEY ? "K" : "_");
433     probe_object_footer("packet");
434 }
435
436 static void show_packets(AVFormatContext *fmt_ctx)
437 {
438     AVPacket pkt;
439
440     av_init_packet(&pkt);
441     probe_array_header("packets");
442     while (!av_read_frame(fmt_ctx, &pkt))
443         show_packet(fmt_ctx, &pkt);
444     probe_array_footer("packets");
445 }
446
447 static void show_stream(AVFormatContext *fmt_ctx, int stream_idx)
448 {
449     AVStream *stream = fmt_ctx->streams[stream_idx];
450     AVCodecContext *dec_ctx;
451     AVCodec *dec;
452     char val_str[128];
453     AVRational display_aspect_ratio;
454
455     probe_object_header("stream");
456
457     probe_int("index", stream->index);
458
459     if ((dec_ctx = stream->codec)) {
460         if ((dec = dec_ctx->codec)) {
461             probe_str("codec_name", dec->name);
462             probe_str("codec_long_name", dec->long_name);
463         } else {
464             probe_str("codec_name", "unknown");
465         }
466
467         probe_str("codec_type", media_type_string(dec_ctx->codec_type));
468         probe_str("codec_time_base",
469                   rational_string(val_str, sizeof(val_str),
470                                   "/", &dec_ctx->time_base));
471
472         /* print AVI/FourCC tag */
473         av_get_codec_tag_string(val_str, sizeof(val_str), dec_ctx->codec_tag);
474         probe_str("codec_tag_string", val_str);
475         probe_str("codec_tag", tag_string(val_str, sizeof(val_str),
476                                           dec_ctx->codec_tag));
477
478         switch (dec_ctx->codec_type) {
479         case AVMEDIA_TYPE_VIDEO:
480             probe_int("width", dec_ctx->width);
481             probe_int("height", dec_ctx->height);
482             probe_int("has_b_frames", dec_ctx->has_b_frames);
483             if (dec_ctx->sample_aspect_ratio.num) {
484                 probe_str("sample_aspect_ratio",
485                           rational_string(val_str, sizeof(val_str), ":",
486                           &dec_ctx->sample_aspect_ratio));
487                 av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
488                           dec_ctx->width  * dec_ctx->sample_aspect_ratio.num,
489                           dec_ctx->height * dec_ctx->sample_aspect_ratio.den,
490                           1024*1024);
491                 probe_str("display_aspect_ratio",
492                           rational_string(val_str, sizeof(val_str), ":",
493                           &display_aspect_ratio));
494             }
495             probe_str("pix_fmt",
496                       dec_ctx->pix_fmt != PIX_FMT_NONE ? av_pix_fmt_descriptors[dec_ctx->pix_fmt].name
497                                                     : "unknown");
498             probe_int("level", dec_ctx->level);
499             break;
500
501         case AVMEDIA_TYPE_AUDIO:
502             probe_str("sample_rate",
503                       value_string(val_str, sizeof(val_str),
504                                    dec_ctx->sample_rate,
505                                    unit_hertz_str));
506             probe_int("channels", dec_ctx->channels);
507             probe_int("bits_per_sample",
508                       av_get_bits_per_sample(dec_ctx->codec_id));
509             break;
510         }
511     } else {
512         probe_str("codec_type", "unknown");
513     }
514
515     if (fmt_ctx->iformat->flags & AVFMT_SHOW_IDS)
516         probe_int("id", stream->id);
517     probe_str("r_frame_rate",
518               rational_string(val_str, sizeof(val_str), "/",
519               &stream->r_frame_rate));
520     probe_str("avg_frame_rate",
521               rational_string(val_str, sizeof(val_str), "/",
522               &stream->avg_frame_rate));
523     probe_str("time_base",
524               rational_string(val_str, sizeof(val_str), "/",
525               &stream->time_base));
526     probe_str("start_time",
527               time_value_string(val_str, sizeof(val_str),
528                                 stream->start_time, &stream->time_base));
529     probe_str("duration",
530               time_value_string(val_str, sizeof(val_str),
531                                 stream->duration, &stream->time_base));
532     if (stream->nb_frames)
533         probe_int("nb_frames", stream->nb_frames);
534
535     probe_dict(stream->metadata, "tags");
536
537     probe_object_footer("stream");
538 }
539
540 static void show_format(AVFormatContext *fmt_ctx)
541 {
542     char val_str[128];
543     int64_t size = fmt_ctx->pb ? avio_size(fmt_ctx->pb) : -1;
544
545     probe_object_header("format");
546     probe_str("filename",         fmt_ctx->filename);
547     probe_int("nb_streams",       fmt_ctx->nb_streams);
548     probe_str("format_name",      fmt_ctx->iformat->name);
549     probe_str("format_long_name", fmt_ctx->iformat->long_name);
550     probe_str("start_time",
551                        time_value_string(val_str, sizeof(val_str),
552                                          fmt_ctx->start_time, &AV_TIME_BASE_Q));
553     probe_str("duration",
554                        time_value_string(val_str, sizeof(val_str),
555                                          fmt_ctx->duration, &AV_TIME_BASE_Q));
556     probe_str("size",
557                        size >= 0 ? value_string(val_str, sizeof(val_str),
558                                                 size, unit_byte_str)
559                                   : "unknown");
560     probe_str("bit_rate",
561                        value_string(val_str, sizeof(val_str),
562                                     fmt_ctx->bit_rate, unit_bit_per_second_str));
563
564     probe_dict(fmt_ctx->metadata, "tags");
565
566     probe_object_footer("format");
567 }
568
569 static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename)
570 {
571     int err, i;
572     AVFormatContext *fmt_ctx = NULL;
573     AVDictionaryEntry *t;
574
575     if ((err = avformat_open_input(&fmt_ctx, filename,
576                                    iformat, &format_opts)) < 0) {
577         print_error(filename, err);
578         return err;
579     }
580     if ((t = av_dict_get(format_opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
581         av_log(NULL, AV_LOG_ERROR, "Option %s not found.\n", t->key);
582         return AVERROR_OPTION_NOT_FOUND;
583     }
584
585
586     /* fill the streams in the format context */
587     if ((err = avformat_find_stream_info(fmt_ctx, NULL)) < 0) {
588         print_error(filename, err);
589         return err;
590     }
591
592     av_dump_format(fmt_ctx, 0, filename, 0);
593
594     /* bind a decoder to each input stream */
595     for (i = 0; i < fmt_ctx->nb_streams; i++) {
596         AVStream *stream = fmt_ctx->streams[i];
597         AVCodec *codec;
598
599         if (!(codec = avcodec_find_decoder(stream->codec->codec_id))) {
600             fprintf(stderr,
601                     "Unsupported codec with id %d for input stream %d\n",
602                     stream->codec->codec_id, stream->index);
603         } else if (avcodec_open2(stream->codec, codec, NULL) < 0) {
604             fprintf(stderr, "Error while opening codec for input stream %d\n",
605                     stream->index);
606         }
607     }
608
609     *fmt_ctx_ptr = fmt_ctx;
610     return 0;
611 }
612
613 static void close_input_file(AVFormatContext **ctx_ptr)
614 {
615     int i;
616     AVFormatContext *fmt_ctx = *ctx_ptr;
617
618     /* close decoder for each stream */
619     for (i = 0; i < fmt_ctx->nb_streams; i++) {
620         AVStream *stream = fmt_ctx->streams[i];
621
622         avcodec_close(stream->codec);
623     }
624     avformat_close_input(ctx_ptr);
625 }
626
627 static int probe_file(const char *filename)
628 {
629     AVFormatContext *fmt_ctx;
630     int ret, i;
631
632     if ((ret = open_input_file(&fmt_ctx, filename)))
633         return ret;
634
635     if (do_show_format)
636         show_format(fmt_ctx);
637
638     if (do_show_streams) {
639         probe_array_header("streams");
640         for (i = 0; i < fmt_ctx->nb_streams; i++)
641             show_stream(fmt_ctx, i);
642         probe_array_footer("streams");
643     }
644
645     if (do_show_packets)
646         show_packets(fmt_ctx);
647
648     close_input_file(&fmt_ctx);
649     return 0;
650 }
651
652 static void show_usage(void)
653 {
654     printf("Simple multimedia streams analyzer\n");
655     printf("usage: %s [OPTIONS] [INPUT_FILE]\n", program_name);
656     printf("\n");
657 }
658
659 static int opt_format(const char *opt, const char *arg)
660 {
661     iformat = av_find_input_format(arg);
662     if (!iformat) {
663         fprintf(stderr, "Unknown input format: %s\n", arg);
664         return AVERROR(EINVAL);
665     }
666     return 0;
667 }
668
669 static int opt_show_format_entry(const char *opt, const char *arg)
670 {
671     do_show_format = 1;
672     nb_fmt_entries_to_show++;
673     print_header        = NULL;
674     print_footer        = NULL;
675     print_array_header  = NULL;
676     print_array_footer  = NULL;
677     print_object_header = NULL;
678     print_object_footer = NULL;
679
680     print_integer = show_format_entry_integer;
681     print_string  = show_format_entry_string;
682     av_dict_set(&fmt_entries_to_show, arg, "", 0);
683     return 0;
684 }
685
686 static void opt_input_file(void *optctx, const char *arg)
687 {
688     if (input_filename) {
689         fprintf(stderr,
690                 "Argument '%s' provided as input filename, but '%s' was already specified.\n",
691                 arg, input_filename);
692         exit(1);
693     }
694     if (!strcmp(arg, "-"))
695         arg = "pipe:";
696     input_filename = arg;
697 }
698
699 static void show_help(void)
700 {
701     av_log_set_callback(log_callback_help);
702     show_usage();
703     show_help_options(options, "Main options:\n", 0, 0);
704     printf("\n");
705     show_help_children(avformat_get_class(), AV_OPT_FLAG_DECODING_PARAM);
706 }
707
708 static void opt_pretty(void)
709 {
710     show_value_unit              = 1;
711     use_value_prefix             = 1;
712     use_byte_value_binary_prefix = 1;
713     use_value_sexagesimal_format = 1;
714 }
715
716 static const OptionDef options[] = {
717 #include "cmdutils_common_opts.h"
718     { "f", HAS_ARG, {(void*)opt_format}, "force format", "format" },
719     { "unit", OPT_BOOL, {(void*)&show_value_unit},
720       "show unit of the displayed values" },
721     { "prefix", OPT_BOOL, {(void*)&use_value_prefix},
722       "use SI prefixes for the displayed values" },
723     { "byte_binary_prefix", OPT_BOOL, {(void*)&use_byte_value_binary_prefix},
724       "use binary prefixes for byte units" },
725     { "sexagesimal", OPT_BOOL,  {(void*)&use_value_sexagesimal_format},
726       "use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units" },
727     { "pretty", 0, {(void*)&opt_pretty},
728       "prettify the format of displayed values, make it more human readable" },
729     { "show_format",  OPT_BOOL, {(void*)&do_show_format} , "show format/container info" },
730     { "show_format_entry", HAS_ARG, {(void*)opt_show_format_entry},
731       "show a particular entry from the format/container info", "entry" },
732     { "show_packets", OPT_BOOL, {(void*)&do_show_packets}, "show packets info" },
733     { "show_streams", OPT_BOOL, {(void*)&do_show_streams}, "show streams info" },
734     { "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {(void*)opt_default},
735       "generic catch all option", "" },
736     { NULL, },
737 };
738
739 static int probe_buf_write(void *opaque, uint8_t *buf, int buf_size)
740 {
741     printf("%.*s", buf_size, buf);
742     return 0;
743 }
744
745 #define AVP_BUFFSIZE 4096
746
747 int main(int argc, char **argv)
748 {
749     int ret;
750     uint8_t *buffer = av_malloc(AVP_BUFFSIZE);
751
752     if (!buffer)
753         exit(1);
754
755     parse_loglevel(argc, argv, options);
756     av_register_all();
757     avformat_network_init();
758     init_opts();
759 #if CONFIG_AVDEVICE
760     avdevice_register_all();
761 #endif
762
763     show_banner();
764     parse_options(NULL, argc, argv, options, opt_input_file);
765
766     if (!input_filename) {
767         show_usage();
768         fprintf(stderr, "You have to specify one input file.\n");
769         fprintf(stderr,
770                 "Use -h to get full help or, even better, run 'man %s'.\n",
771                 program_name);
772         exit(1);
773     }
774
775     probe_out = avio_alloc_context(buffer, AVP_BUFFSIZE, 1, NULL, NULL,
776                                  probe_buf_write, NULL);
777     if (!probe_out)
778         exit(1);
779
780     probe_header();
781     ret = probe_file(input_filename);
782     probe_footer();
783     avio_flush(probe_out);
784     avio_close(probe_out);
785
786     avformat_network_deinit();
787
788     return ret;
789 }