]> git.sesse.net Git - ffmpeg/blob - ffprobe.c
Merge remote-tracking branch 'hexene/scratchpad'
[ffmpeg] / ffprobe.c
1 /*
2  * ffprobe : Simple Media Prober based on the FFmpeg libraries
3  * Copyright (c) 2007-2010 Stefano Sabatini
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg 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  * FFmpeg 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 FFmpeg; 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[] = "ffprobe";
33 const int program_birth_year = 2007;
34
35 static int do_show_format  = 0;
36 static int do_show_packets = 0;
37 static int do_show_streams = 0;
38
39 static int show_value_unit              = 0;
40 static int use_value_prefix             = 0;
41 static int use_byte_value_binary_prefix = 0;
42 static int use_value_sexagesimal_format = 0;
43
44 static char *print_format;
45
46 /* globals */
47 static const OptionDef options[];
48
49 /* FFprobe context */
50 static const char *input_filename;
51 static AVInputFormat *iformat = NULL;
52
53 static const char *binary_unit_prefixes [] = { "", "Ki", "Mi", "Gi", "Ti", "Pi" };
54 static const char *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     exit(ret);
64 }
65
66 static char *value_string(char *buf, int buf_size, double val, const char *unit)
67 {
68     if (unit == unit_second_str && use_value_sexagesimal_format) {
69         double secs;
70         int hours, mins;
71         secs  = val;
72         mins  = (int)secs / 60;
73         secs  = secs - mins * 60;
74         hours = mins / 60;
75         mins %= 60;
76         snprintf(buf, buf_size, "%d:%02d:%09.6f", hours, mins, secs);
77     } else if (use_value_prefix) {
78         const char *prefix_string;
79         int index;
80
81         if (unit == unit_byte_str && use_byte_value_binary_prefix) {
82             index = (int) (log(val)/log(2)) / 10;
83             index = av_clip(index, 0, FF_ARRAY_ELEMS(binary_unit_prefixes) -1);
84             val /= pow(2, index*10);
85             prefix_string = binary_unit_prefixes[index];
86         } else {
87             index = (int) (log10(val)) / 3;
88             index = av_clip(index, 0, FF_ARRAY_ELEMS(decimal_unit_prefixes) -1);
89             val /= pow(10, index*3);
90             prefix_string = decimal_unit_prefixes[index];
91         }
92
93         snprintf(buf, buf_size, "%.3f%s%s%s", val, prefix_string || show_value_unit ? " " : "",
94                  prefix_string, show_value_unit ? unit : "");
95     } else {
96         snprintf(buf, buf_size, "%f%s%s", val, show_value_unit ? " " : "",
97                  show_value_unit ? unit : "");
98     }
99
100     return buf;
101 }
102
103 static char *time_value_string(char *buf, int buf_size, int64_t val, const AVRational *time_base)
104 {
105     if (val == AV_NOPTS_VALUE) {
106         snprintf(buf, buf_size, "N/A");
107     } else {
108         value_string(buf, buf_size, val * av_q2d(*time_base), unit_second_str);
109     }
110
111     return buf;
112 }
113
114 static char *ts_value_string (char *buf, int buf_size, int64_t ts)
115 {
116     if (ts == AV_NOPTS_VALUE) {
117         snprintf(buf, buf_size, "N/A");
118     } else {
119         snprintf(buf, buf_size, "%"PRId64, ts);
120     }
121
122     return buf;
123 }
124
125 static const char *media_type_string(enum AVMediaType media_type)
126 {
127     const char *s = av_get_media_type_string(media_type);
128     return s ? s : "unknown";
129 }
130
131
132 struct writer {
133     const char *name;
134     const char *item_sep;           ///< separator between key/value couples
135     const char *items_sep;          ///< separator between sets of key/value couples
136     const char *section_sep;        ///< separator between sections (streams, packets, ...)
137     const char *header, *footer;
138     void (*print_section_start)(const char *, int);
139     void (*print_section_end)  (const char *, int);
140     void (*print_header)(const char *);
141     void (*print_footer)(const char *);
142     void (*print_integer)(const char *, int);
143     void (*print_string)(const char *, const char *);
144     void (*show_tags)(struct writer *w, AVDictionary *dict);
145 };
146
147
148 /* JSON output */
149
150 static void json_print_header(const char *section)
151 {
152     printf("{\n");
153 }
154
155 static char *json_escape_str(const char *s)
156 {
157     static const char json_escape[] = {'"', '\\', '\b', '\f', '\n', '\r', '\t', 0};
158     static const char json_subst[]  = {'"', '\\',  'b',  'f',  'n',  'r',  't', 0};
159     char *ret, *p;
160     int i, len = 0;
161
162     // compute the length of the escaped string
163     for (i = 0; s[i]; i++) {
164         if (strchr(json_escape, s[i]))     len += 2; // simple escape
165         else if ((unsigned char)s[i] < 32) len += 6; // handle non-printable chars
166         else                               len += 1; // char copy
167     }
168
169     p = ret = av_malloc(len + 1);
170     if (!p)
171         return NULL;
172     for (i = 0; s[i]; i++) {
173         char *q = strchr(json_escape, s[i]);
174         if (q) {
175             *p++ = '\\';
176             *p++ = json_subst[q - json_escape];
177         } else if ((unsigned char)s[i] < 32) {
178             snprintf(p, 7, "\\u00%02x", s[i] & 0xff);
179             p += 6;
180         } else {
181             *p++ = s[i];
182         }
183     }
184     *p = 0;
185     return ret;
186 }
187
188 static void json_print_str(const char *key, const char *value)
189 {
190     char *key_esc   = json_escape_str(key);
191     char *value_esc = json_escape_str(value);
192     printf("    \"%s\": \"%s\"",
193            key_esc   ? key_esc   : "",
194            value_esc ? value_esc : "");
195     av_free(key_esc);
196     av_free(value_esc);
197 }
198
199 static void json_print_int(const char *key, int value)
200 {
201     char *key_esc = json_escape_str(key);
202     printf("    \"%s\": %d", key_esc ? key_esc : "", value);
203     av_free(key_esc);
204 }
205
206 static void json_print_footer(const char *section)
207 {
208     printf("\n  }");
209 }
210
211 static void json_print_section_start(const char *section, int multiple_entries)
212 {
213     char *section_esc = json_escape_str(section);
214     printf("\n  \"%s\":%s", section_esc ? section_esc : "",
215            multiple_entries ? " [" : " ");
216     av_free(section_esc);
217 }
218
219 static void json_print_section_end(const char *section, int multiple_entries)
220 {
221     if (multiple_entries)
222         printf("]");
223 }
224
225
226 /* Default output */
227
228 static void default_print_header(const char *section)
229 {
230     printf("[%s]\n", section);
231 }
232
233 static void default_print_str(const char *key, const char *value)
234 {
235     printf("%s=%s", key, value);
236 }
237
238 static void default_print_int(const char *key, int value)
239 {
240     printf("%s=%d", key, value);
241 }
242
243 static void default_print_footer(const char *section)
244 {
245     printf("\n[/%s]", section);
246 }
247
248
249 /* Print helpers */
250
251 struct print_buf {
252     char *s;
253     int len;
254 };
255
256 static char *fast_asprintf(struct print_buf *pbuf, const char *fmt, ...)
257 {
258     va_list va;
259     int len;
260
261     va_start(va, fmt);
262     len = vsnprintf(NULL, 0, fmt, va);
263     va_end(va);
264     if (len < 0)
265         goto fail;
266
267     if (pbuf->len < len) {
268         char *p = av_realloc(pbuf->s, len + 1);
269         if (!p)
270             goto fail;
271         pbuf->s   = p;
272         pbuf->len = len;
273     }
274
275     va_start(va, fmt);
276     len = vsnprintf(pbuf->s, len + 1, fmt, va);
277     va_end(va);
278     if (len < 0)
279         goto fail;
280     return pbuf->s;
281
282 fail:
283     av_freep(&pbuf->s);
284     pbuf->len = 0;
285     return NULL;
286 }
287
288 #define print_fmt0(k, f, ...) do {             \
289     if (fast_asprintf(&pbuf, f, __VA_ARGS__))  \
290         w->print_string(k, pbuf.s);            \
291 } while (0)
292 #define print_fmt( k, f, ...) do {     \
293     if (w->item_sep)                   \
294         printf("%s", w->item_sep);     \
295     print_fmt0(k, f, __VA_ARGS__);     \
296 } while (0)
297
298 #define print_int0(k, v) w->print_integer(k, v)
299 #define print_int( k, v) do {      \
300     if (w->item_sep)               \
301         printf("%s", w->item_sep); \
302     print_int0(k, v);              \
303 } while (0)
304
305 #define print_str0(k, v) print_fmt0(k, "%s", v)
306 #define print_str( k, v) print_fmt (k, "%s", v)
307
308
309 static void show_packet(struct writer *w, AVFormatContext *fmt_ctx, AVPacket *pkt, int packet_idx)
310 {
311     char val_str[128];
312     AVStream *st = fmt_ctx->streams[pkt->stream_index];
313     struct print_buf pbuf = {.s = NULL};
314
315     if (packet_idx)
316         printf("%s", w->items_sep);
317     w->print_header("PACKET");
318     print_str0("codec_type",      media_type_string(st->codec->codec_type));
319     print_int("stream_index",     pkt->stream_index);
320     print_str("pts",              ts_value_string  (val_str, sizeof(val_str), pkt->pts));
321     print_str("pts_time",         time_value_string(val_str, sizeof(val_str), pkt->pts, &st->time_base));
322     print_str("dts",              ts_value_string  (val_str, sizeof(val_str), pkt->dts));
323     print_str("dts_time",         time_value_string(val_str, sizeof(val_str), pkt->dts, &st->time_base));
324     print_str("duration",         ts_value_string  (val_str, sizeof(val_str), pkt->duration));
325     print_str("duration_time",    time_value_string(val_str, sizeof(val_str), pkt->duration, &st->time_base));
326     print_str("size",             value_string     (val_str, sizeof(val_str), pkt->size, unit_byte_str));
327     print_fmt("pos",   "%"PRId64, pkt->pos);
328     print_fmt("flags", "%c",      pkt->flags & AV_PKT_FLAG_KEY ? 'K' : '_');
329     w->print_footer("PACKET");
330     av_free(pbuf.s);
331     fflush(stdout);
332 }
333
334 static void show_packets(struct writer *w, AVFormatContext *fmt_ctx)
335 {
336     AVPacket pkt;
337     int i = 0;
338
339     av_init_packet(&pkt);
340
341     while (!av_read_frame(fmt_ctx, &pkt))
342         show_packet(w, fmt_ctx, &pkt, i++);
343 }
344
345 static void json_show_tags(struct writer *w, AVDictionary *dict)
346 {
347     AVDictionaryEntry *tag = NULL;
348     struct print_buf pbuf = {.s = NULL};
349     int first = 1;
350
351     if (!dict)
352         return;
353     printf(",\n    \"tags\": {\n");
354     while ((tag = av_dict_get(dict, "", tag, AV_DICT_IGNORE_SUFFIX))) {
355         if (first) {
356             print_str0(tag->key, tag->value);
357             first = 0;
358         } else {
359             print_str(tag->key, tag->value);
360         }
361     }
362     printf("\n    }");
363     av_free(pbuf.s);
364 }
365
366 static void default_show_tags(struct writer *w, AVDictionary *dict)
367 {
368     AVDictionaryEntry *tag = NULL;
369     struct print_buf pbuf = {.s = NULL};
370     while ((tag = av_dict_get(dict, "", tag, AV_DICT_IGNORE_SUFFIX))) {
371         printf("\nTAG:");
372         print_str0(tag->key, tag->value);
373     }
374     av_free(pbuf.s);
375 }
376
377 static void show_stream(struct writer *w, AVFormatContext *fmt_ctx, int stream_idx)
378 {
379     AVStream *stream = fmt_ctx->streams[stream_idx];
380     AVCodecContext *dec_ctx;
381     AVCodec *dec;
382     char val_str[128];
383     AVRational display_aspect_ratio;
384     struct print_buf pbuf = {.s = NULL};
385
386     if (stream_idx)
387         printf("%s", w->items_sep);
388     w->print_header("STREAM");
389
390     print_int0("index", stream->index);
391
392     if ((dec_ctx = stream->codec)) {
393         if ((dec = dec_ctx->codec)) {
394             print_str("codec_name",      dec->name);
395             print_str("codec_long_name", dec->long_name);
396         } else {
397             print_str("codec_name",      "unknown");
398         }
399
400         print_str("codec_type",               media_type_string(dec_ctx->codec_type));
401         print_fmt("codec_time_base", "%d/%d", dec_ctx->time_base.num, dec_ctx->time_base.den);
402
403         /* print AVI/FourCC tag */
404         av_get_codec_tag_string(val_str, sizeof(val_str), dec_ctx->codec_tag);
405         print_str("codec_tag_string",    val_str);
406         print_fmt("codec_tag", "0x%04x", dec_ctx->codec_tag);
407
408         switch (dec_ctx->codec_type) {
409         case AVMEDIA_TYPE_VIDEO:
410             print_int("width",        dec_ctx->width);
411             print_int("height",       dec_ctx->height);
412             print_int("has_b_frames", dec_ctx->has_b_frames);
413             if (dec_ctx->sample_aspect_ratio.num) {
414                 print_fmt("sample_aspect_ratio", "%d:%d",
415                           dec_ctx->sample_aspect_ratio.num,
416                           dec_ctx->sample_aspect_ratio.den);
417                 av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
418                           dec_ctx->width  * dec_ctx->sample_aspect_ratio.num,
419                           dec_ctx->height * dec_ctx->sample_aspect_ratio.den,
420                           1024*1024);
421                 print_fmt("display_aspect_ratio", "%d:%d",
422                           display_aspect_ratio.num,
423                           display_aspect_ratio.den);
424             }
425             print_str("pix_fmt", dec_ctx->pix_fmt != PIX_FMT_NONE ? av_pix_fmt_descriptors[dec_ctx->pix_fmt].name : "unknown");
426             print_int("level",   dec_ctx->level);
427             break;
428
429         case AVMEDIA_TYPE_AUDIO:
430             print_str("sample_rate",     value_string(val_str, sizeof(val_str), dec_ctx->sample_rate, unit_hertz_str));
431             print_int("channels",        dec_ctx->channels);
432             print_int("bits_per_sample", av_get_bits_per_sample(dec_ctx->codec_id));
433             break;
434         }
435     } else {
436         print_str("codec_type", "unknown");
437     }
438
439     if (fmt_ctx->iformat->flags & AVFMT_SHOW_IDS)
440         print_fmt("id=", "0x%x", stream->id);
441     print_fmt("r_frame_rate",   "%d/%d", stream->r_frame_rate.num,   stream->r_frame_rate.den);
442     print_fmt("avg_frame_rate", "%d/%d", stream->avg_frame_rate.num, stream->avg_frame_rate.den);
443     print_fmt("time_base",      "%d/%d", stream->time_base.num,      stream->time_base.den);
444     print_str("start_time", time_value_string(val_str, sizeof(val_str), stream->start_time, &stream->time_base));
445     print_str("duration",   time_value_string(val_str, sizeof(val_str), stream->duration,   &stream->time_base));
446     if (stream->nb_frames)
447         print_fmt("nb_frames", "%"PRId64, stream->nb_frames);
448
449     w->show_tags(w, stream->metadata);
450
451     w->print_footer("STREAM");
452     av_free(pbuf.s);
453     fflush(stdout);
454 }
455
456 static void show_streams(struct writer *w, AVFormatContext *fmt_ctx)
457 {
458     int i;
459     for (i = 0; i < fmt_ctx->nb_streams; i++)
460         show_stream(w, fmt_ctx, i);
461 }
462
463 static void show_format(struct writer *w, AVFormatContext *fmt_ctx)
464 {
465     char val_str[128];
466     struct print_buf pbuf = {.s = NULL};
467
468     w->print_header("FORMAT");
469     print_str0("filename",        fmt_ctx->filename);
470     print_int("nb_streams",       fmt_ctx->nb_streams);
471     print_str("format_name",      fmt_ctx->iformat->name);
472     print_str("format_long_name", fmt_ctx->iformat->long_name);
473     print_str("start_time",       time_value_string(val_str, sizeof(val_str), fmt_ctx->start_time, &AV_TIME_BASE_Q));
474     print_str("duration",         time_value_string(val_str, sizeof(val_str), fmt_ctx->duration,   &AV_TIME_BASE_Q));
475     print_str("size",             value_string(val_str, sizeof(val_str), fmt_ctx->file_size, unit_byte_str));
476     print_str("bit_rate",         value_string(val_str, sizeof(val_str), fmt_ctx->bit_rate,  unit_bit_per_second_str));
477     w->show_tags(w, fmt_ctx->metadata);
478     w->print_footer("FORMAT");
479     av_free(pbuf.s);
480     fflush(stdout);
481 }
482
483 static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename)
484 {
485     int err, i;
486     AVFormatContext *fmt_ctx = NULL;
487     AVDictionaryEntry *t;
488
489     if ((err = avformat_open_input(&fmt_ctx, filename, iformat, &format_opts)) < 0) {
490         print_error(filename, err);
491         return err;
492     }
493     if ((t = av_dict_get(format_opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
494         av_log(NULL, AV_LOG_ERROR, "Option %s not found.\n", t->key);
495         return AVERROR_OPTION_NOT_FOUND;
496     }
497
498
499     /* fill the streams in the format context */
500     if ((err = avformat_find_stream_info(fmt_ctx, NULL)) < 0) {
501         print_error(filename, err);
502         return err;
503     }
504
505     av_dump_format(fmt_ctx, 0, filename, 0);
506
507     /* bind a decoder to each input stream */
508     for (i = 0; i < fmt_ctx->nb_streams; i++) {
509         AVStream *stream = fmt_ctx->streams[i];
510         AVCodec *codec;
511
512         if (!(codec = avcodec_find_decoder(stream->codec->codec_id))) {
513             fprintf(stderr, "Unsupported codec with id %d for input stream %d\n",
514                     stream->codec->codec_id, stream->index);
515         } else if (avcodec_open2(stream->codec, codec, NULL) < 0) {
516             fprintf(stderr, "Error while opening codec for input stream %d\n",
517                     stream->index);
518         }
519     }
520
521     *fmt_ctx_ptr = fmt_ctx;
522     return 0;
523 }
524
525 #define WRITER_FUNC(func)                   \
526     .print_header  = func ## _print_header, \
527     .print_footer  = func ## _print_footer, \
528     .print_integer = func ## _print_int,    \
529     .print_string  = func ## _print_str,    \
530     .show_tags     = func ## _show_tags
531
532 static struct writer writers[] = {{
533         .name         = "default",
534         .item_sep     = "\n",
535         .items_sep    = "\n",
536         .section_sep  = "\n",
537         .footer       = "\n",
538         WRITER_FUNC(default),
539     },{
540         .name         = "json",
541         .header       = "{",
542         .item_sep     = ",\n",
543         .items_sep    = ",",
544         .section_sep  = ",",
545         .footer       = "\n}\n",
546         .print_section_start = json_print_section_start,
547         .print_section_end   = json_print_section_end,
548         WRITER_FUNC(json),
549     }
550 };
551
552 static int get_writer(const char *name)
553 {
554     int i;
555     if (!name)
556         return 0;
557     for (i = 0; i < FF_ARRAY_ELEMS(writers); i++)
558         if (!strcmp(writers[i].name, name))
559             return i;
560     return -1;
561 }
562
563 #define SECTION_PRINT(name, multiple_entries, left) do {      \
564     if (do_show_ ## name) {                                   \
565         if (w->print_section_start)                           \
566             w->print_section_start(#name, multiple_entries);  \
567         show_ ## name (w, fmt_ctx);                           \
568         if (w->print_section_end)                             \
569             w->print_section_end(#name, multiple_entries);    \
570         if (left)                                             \
571             printf("%s", w->section_sep);                     \
572     }                                                         \
573 } while (0)
574
575 static int probe_file(const char *filename)
576 {
577     AVFormatContext *fmt_ctx;
578     int ret, writer_id;
579     struct writer *w;
580
581     writer_id = get_writer(print_format);
582     if (writer_id < 0) {
583         fprintf(stderr, "Invalid output format '%s'\n", print_format);
584         return AVERROR(EINVAL);
585     }
586     w = &writers[writer_id];
587
588     if ((ret = open_input_file(&fmt_ctx, filename)))
589         return ret;
590
591     if (w->header)
592         printf("%s", w->header);
593
594     SECTION_PRINT(packets, 1, do_show_streams || do_show_format);
595     SECTION_PRINT(streams, 1, do_show_format);
596     SECTION_PRINT(format,  0, 0);
597
598     if (w->footer)
599         printf("%s", w->footer);
600
601     av_close_input_file(fmt_ctx);
602     return 0;
603 }
604
605 static void show_usage(void)
606 {
607     printf("Simple multimedia streams analyzer\n");
608     printf("usage: %s [OPTIONS] [INPUT_FILE]\n", program_name);
609     printf("\n");
610 }
611
612 static int opt_format(const char *opt, const char *arg)
613 {
614     iformat = av_find_input_format(arg);
615     if (!iformat) {
616         fprintf(stderr, "Unknown input format: %s\n", arg);
617         return AVERROR(EINVAL);
618     }
619     return 0;
620 }
621
622 static void opt_input_file(void *optctx, const char *arg)
623 {
624     if (input_filename) {
625         fprintf(stderr, "Argument '%s' provided as input filename, but '%s' was already specified.\n",
626                 arg, input_filename);
627         exit(1);
628     }
629     if (!strcmp(arg, "-"))
630         arg = "pipe:";
631     input_filename = arg;
632 }
633
634 static int opt_help(const char *opt, const char *arg)
635 {
636     const AVClass *class = avformat_get_class();
637     av_log_set_callback(log_callback_help);
638     show_usage();
639     show_help_options(options, "Main options:\n", 0, 0);
640     printf("\n");
641     av_opt_show2(&class, NULL,
642                  AV_OPT_FLAG_DECODING_PARAM, 0);
643     return 0;
644 }
645
646 static int opt_pretty(const char *opt, const char *arg)
647 {
648     show_value_unit              = 1;
649     use_value_prefix             = 1;
650     use_byte_value_binary_prefix = 1;
651     use_value_sexagesimal_format = 1;
652     return 0;
653 }
654
655 static const OptionDef options[] = {
656 #include "cmdutils_common_opts.h"
657     { "f", HAS_ARG, {(void*)opt_format}, "force format", "format" },
658     { "unit", OPT_BOOL, {(void*)&show_value_unit}, "show unit of the displayed values" },
659     { "prefix", OPT_BOOL, {(void*)&use_value_prefix}, "use SI prefixes for the displayed values" },
660     { "byte_binary_prefix", OPT_BOOL, {(void*)&use_byte_value_binary_prefix},
661       "use binary prefixes for byte units" },
662     { "sexagesimal", OPT_BOOL,  {(void*)&use_value_sexagesimal_format},
663       "use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units" },
664     { "pretty", 0, {(void*)&opt_pretty},
665       "prettify the format of displayed values, make it more human readable" },
666     { "print_format", OPT_STRING | HAS_ARG, {(void*)&print_format}, "set the output printing format (available formats are: default, json)" },
667     { "show_format",  OPT_BOOL, {(void*)&do_show_format} , "show format/container info" },
668     { "show_packets", OPT_BOOL, {(void*)&do_show_packets}, "show packets info" },
669     { "show_streams", OPT_BOOL, {(void*)&do_show_streams}, "show streams info" },
670     { "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {(void*)opt_default}, "generic catch all option", "" },
671     { "i", HAS_ARG, {(void *)opt_input_file}, "read specified file", "input_file"},
672     { NULL, },
673 };
674
675 int main(int argc, char **argv)
676 {
677     int ret;
678
679     av_register_all();
680     init_opts();
681 #if CONFIG_AVDEVICE
682     avdevice_register_all();
683 #endif
684
685     show_banner();
686     parse_options(NULL, argc, argv, options, opt_input_file);
687
688     if (!input_filename) {
689         show_usage();
690         fprintf(stderr, "You have to specify one input file.\n");
691         fprintf(stderr, "Use -h to get full help or, even better, run 'man %s'.\n", program_name);
692         exit(1);
693     }
694
695     ret = probe_file(input_filename);
696
697     return ret;
698 }