2 * avprobe : Simple Media Prober based on the Libav libraries
3 * Copyright (c) 2007-2010 Stefano Sabatini
5 * This file is part of Libav.
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.
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.
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
24 #include "libavformat/avformat.h"
25 #include "libavcodec/avcodec.h"
26 #include "libavutil/avstring.h"
27 #include "libavutil/opt.h"
28 #include "libavutil/pixdesc.h"
29 #include "libavutil/dict.h"
30 #include "libavutil/libm.h"
31 #include "libavdevice/avdevice.h"
34 const char program_name[] = "avprobe";
35 const int program_birth_year = 2007;
37 static int do_show_format = 0;
38 static AVDictionary *fmt_entries_to_show = NULL;
39 static int nb_fmt_entries_to_show;
40 static int do_show_packets = 0;
41 static int do_show_streams = 0;
43 static int show_value_unit = 0;
44 static int use_value_prefix = 0;
45 static int use_byte_value_binary_prefix = 0;
46 static int use_value_sexagesimal_format = 0;
49 static const OptionDef *options;
52 static const char *input_filename;
53 static AVInputFormat *iformat = NULL;
55 static const char *const binary_unit_prefixes [] = { "", "Ki", "Mi", "Gi", "Ti", "Pi" };
56 static const char *const decimal_unit_prefixes[] = { "", "K" , "M" , "G" , "T" , "P" };
58 static const char unit_second_str[] = "s" ;
59 static const char unit_hertz_str[] = "Hz" ;
60 static const char unit_byte_str[] = "byte" ;
61 static const char unit_bit_per_second_str[] = "bit/s";
63 static void avprobe_cleanup(int ret)
65 av_dict_free(&fmt_entries_to_show);
69 * The output is structured in array and objects that might contain items
70 * Array could require the objects within to not be named.
71 * Object could require the items within to be named.
73 * For flat representation the name of each section is saved on prefix so it
74 * can be rendered in order to represent nested structures (e.g. array of
75 * objects for the packets list).
77 * Within an array each element can need an unique identifier or an index.
79 * Nesting level is accounted separately.
87 typedef struct PrintElement {
89 PrintElementType type;
94 typedef struct PrintContext {
97 void (*print_header)(void);
98 void (*print_footer)(void);
100 void (*print_array_header) (const char *name);
101 void (*print_array_footer) (const char *name);
102 void (*print_object_header)(const char *name);
103 void (*print_object_footer)(const char *name);
105 void (*print_integer) (const char *key, int64_t value);
106 void (*print_string) (const char *key, const char *value);
109 static AVIOContext *probe_out = NULL;
110 static PrintContext octx;
111 #define AVP_INDENT() avio_printf(probe_out, "%*c", octx.level * 2, ' ')
114 * Default format, INI
116 * - all key and values are utf8
117 * - '.' is the subgroup separator
118 * - newlines and the following characters are escaped
119 * - '\' is the escape character
120 * - '#' is the comment
121 * - '=' is the key/value separators
122 * - ':' is not used but usually parsed as key/value separator
125 static void ini_print_header(void)
127 avio_printf(probe_out, "# avprobe output\n\n");
129 static void ini_print_footer(void)
131 avio_w8(probe_out, '\n');
134 static void ini_escape_print(const char *s)
141 case '\r': avio_printf(probe_out, "%s", "\\r"); break;
142 case '\n': avio_printf(probe_out, "%s", "\\n"); break;
143 case '\f': avio_printf(probe_out, "%s", "\\f"); break;
144 case '\b': avio_printf(probe_out, "%s", "\\b"); break;
145 case '\t': avio_printf(probe_out, "%s", "\\t"); break;
149 case ':' : avio_w8(probe_out, '\\');
151 if ((unsigned char)c < 32)
152 avio_printf(probe_out, "\\x00%02x", c & 0xff);
154 avio_w8(probe_out, c);
160 static void ini_print_array_header(const char *name)
162 if (octx.prefix[octx.level -1].nb_elems)
163 avio_printf(probe_out, "\n");
166 static void ini_print_object_header(const char *name)
169 PrintElement *el = octx.prefix + octx.level -1;
172 avio_printf(probe_out, "\n");
174 avio_printf(probe_out, "[");
176 for (i = 1; i < octx.level; i++) {
177 el = octx.prefix + i;
178 avio_printf(probe_out, "%s.", el->name);
180 avio_printf(probe_out, "%"PRId64".", el->index);
183 avio_printf(probe_out, "%s", name);
184 if (el->type == ARRAY)
185 avio_printf(probe_out, ".%"PRId64"", el->nb_elems);
186 avio_printf(probe_out, "]\n");
189 static void ini_print_integer(const char *key, int64_t value)
191 ini_escape_print(key);
192 avio_printf(probe_out, "=%"PRId64"\n", value);
196 static void ini_print_string(const char *key, const char *value)
198 ini_escape_print(key);
199 avio_printf(probe_out, "=");
200 ini_escape_print(value);
201 avio_w8(probe_out, '\n');
205 * Alternate format, JSON
208 static void json_print_header(void)
210 avio_printf(probe_out, "{");
212 static void json_print_footer(void)
214 avio_printf(probe_out, "}\n");
217 static void json_print_array_header(const char *name)
219 if (octx.prefix[octx.level -1].nb_elems)
220 avio_printf(probe_out, ",\n");
222 avio_printf(probe_out, "\"%s\" : ", name);
223 avio_printf(probe_out, "[\n");
226 static void json_print_array_footer(const char *name)
228 avio_printf(probe_out, "\n");
230 avio_printf(probe_out, "]");
233 static void json_print_object_header(const char *name)
235 if (octx.prefix[octx.level -1].nb_elems)
236 avio_printf(probe_out, ",\n");
238 if (octx.prefix[octx.level -1].type == OBJECT)
239 avio_printf(probe_out, "\"%s\" : ", name);
240 avio_printf(probe_out, "{\n");
243 static void json_print_object_footer(const char *name)
245 avio_printf(probe_out, "\n");
247 avio_printf(probe_out, "}");
250 static void json_print_integer(const char *key, int64_t value)
252 if (octx.prefix[octx.level -1].nb_elems)
253 avio_printf(probe_out, ",\n");
255 avio_printf(probe_out, "\"%s\" : %"PRId64"", key, value);
258 static void json_escape_print(const char *s)
265 case '\r': avio_printf(probe_out, "%s", "\\r"); break;
266 case '\n': avio_printf(probe_out, "%s", "\\n"); break;
267 case '\f': avio_printf(probe_out, "%s", "\\f"); break;
268 case '\b': avio_printf(probe_out, "%s", "\\b"); break;
269 case '\t': avio_printf(probe_out, "%s", "\\t"); break;
271 case '"' : avio_w8(probe_out, '\\');
273 if ((unsigned char)c < 32)
274 avio_printf(probe_out, "\\u00%02x", c & 0xff);
276 avio_w8(probe_out, c);
282 static void json_print_string(const char *key, const char *value)
284 if (octx.prefix[octx.level -1].nb_elems)
285 avio_printf(probe_out, ",\n");
287 avio_w8(probe_out, '\"');
288 json_escape_print(key);
289 avio_printf(probe_out, "\" : \"");
290 json_escape_print(value);
291 avio_w8(probe_out, '\"');
295 * old-style pseudo-INI
297 static void old_print_object_header(const char *name)
301 if (!strcmp(name, "tags"))
304 str = p = av_strdup(name);
312 avio_printf(probe_out, "[%s]\n", str);
316 static void old_print_object_footer(const char *name)
320 if (!strcmp(name, "tags"))
323 str = p = av_strdup(name);
331 avio_printf(probe_out, "[/%s]\n", str);
335 static void old_print_string(const char *key, const char *value)
337 if (!strcmp(octx.prefix[octx.level - 1].name, "tags"))
338 avio_printf(probe_out, "TAG:");
339 ini_print_string(key, value);
343 * Simple Formatter for single entries.
346 static void show_format_entry_integer(const char *key, int64_t value)
348 if (key && av_dict_get(fmt_entries_to_show, key, NULL, 0)) {
349 if (nb_fmt_entries_to_show > 1)
350 avio_printf(probe_out, "%s=", key);
351 avio_printf(probe_out, "%"PRId64"\n", value);
355 static void show_format_entry_string(const char *key, const char *value)
357 if (key && av_dict_get(fmt_entries_to_show, key, NULL, 0)) {
358 if (nb_fmt_entries_to_show > 1)
359 avio_printf(probe_out, "%s=", key);
360 avio_printf(probe_out, "%s\n", value);
364 static void probe_group_enter(const char *name, int type)
369 av_realloc(octx.prefix, sizeof(PrintElement) * (octx.level + 1));
371 if (!octx.prefix || !name) {
372 fprintf(stderr, "Out of memory\n");
377 PrintElement *parent = octx.prefix + octx.level -1;
378 if (parent->type == ARRAY)
379 count = parent->nb_elems;
383 octx.prefix[octx.level++] = (PrintElement){name, type, count, 0};
386 static void probe_group_leave(void)
391 static void probe_header(void)
393 if (octx.print_header)
395 probe_group_enter("root", OBJECT);
398 static void probe_footer(void)
400 if (octx.print_footer)
406 static void probe_array_header(const char *name)
408 if (octx.print_array_header)
409 octx.print_array_header(name);
411 probe_group_enter(name, ARRAY);
414 static void probe_array_footer(const char *name)
417 if (octx.print_array_footer)
418 octx.print_array_footer(name);
421 static void probe_object_header(const char *name)
423 if (octx.print_object_header)
424 octx.print_object_header(name);
426 probe_group_enter(name, OBJECT);
429 static void probe_object_footer(const char *name)
432 if (octx.print_object_footer)
433 octx.print_object_footer(name);
436 static void probe_int(const char *key, int64_t value)
438 octx.print_integer(key, value);
439 octx.prefix[octx.level -1].nb_elems++;
442 static void probe_str(const char *key, const char *value)
444 octx.print_string(key, value);
445 octx.prefix[octx.level -1].nb_elems++;
448 static void probe_dict(AVDictionary *dict, const char *name)
450 AVDictionaryEntry *entry = NULL;
453 probe_object_header(name);
454 while ((entry = av_dict_get(dict, "", entry, AV_DICT_IGNORE_SUFFIX))) {
455 probe_str(entry->key, entry->value);
457 probe_object_footer(name);
460 static char *value_string(char *buf, int buf_size, double val, const char *unit)
462 if (unit == unit_second_str && use_value_sexagesimal_format) {
466 mins = (int)secs / 60;
467 secs = secs - mins * 60;
470 snprintf(buf, buf_size, "%d:%02d:%09.6f", hours, mins, secs);
471 } else if (use_value_prefix) {
472 const char *prefix_string;
475 if (unit == unit_byte_str && use_byte_value_binary_prefix) {
476 index = (int) log2(val) / 10;
477 index = av_clip(index, 0, FF_ARRAY_ELEMS(binary_unit_prefixes) - 1);
478 val /= pow(2, index * 10);
479 prefix_string = binary_unit_prefixes[index];
481 index = (int) (log10(val)) / 3;
482 index = av_clip(index, 0, FF_ARRAY_ELEMS(decimal_unit_prefixes) - 1);
483 val /= pow(10, index * 3);
484 prefix_string = decimal_unit_prefixes[index];
486 snprintf(buf, buf_size, "%.*f%s%s",
489 show_value_unit ? unit : "");
491 snprintf(buf, buf_size, "%f%s", val, show_value_unit ? unit : "");
497 static char *time_value_string(char *buf, int buf_size, int64_t val,
498 const AVRational *time_base)
500 if (val == AV_NOPTS_VALUE) {
501 snprintf(buf, buf_size, "N/A");
503 value_string(buf, buf_size, val * av_q2d(*time_base), unit_second_str);
509 static char *ts_value_string(char *buf, int buf_size, int64_t ts)
511 if (ts == AV_NOPTS_VALUE) {
512 snprintf(buf, buf_size, "N/A");
514 snprintf(buf, buf_size, "%"PRId64, ts);
520 static char *rational_string(char *buf, int buf_size, const char *sep,
521 const AVRational *rat)
523 snprintf(buf, buf_size, "%d%s%d", rat->num, sep, rat->den);
527 static char *tag_string(char *buf, int buf_size, int tag)
529 snprintf(buf, buf_size, "0x%04x", tag);
533 static void show_packet(AVFormatContext *fmt_ctx, AVPacket *pkt)
536 AVStream *st = fmt_ctx->streams[pkt->stream_index];
538 probe_object_header("packet");
539 probe_str("codec_type", media_type_string(st->codec->codec_type));
540 probe_int("stream_index", pkt->stream_index);
541 probe_str("pts", ts_value_string(val_str, sizeof(val_str), pkt->pts));
542 probe_str("pts_time", time_value_string(val_str, sizeof(val_str),
543 pkt->pts, &st->time_base));
544 probe_str("dts", ts_value_string(val_str, sizeof(val_str), pkt->dts));
545 probe_str("dts_time", time_value_string(val_str, sizeof(val_str),
546 pkt->dts, &st->time_base));
547 probe_str("duration", ts_value_string(val_str, sizeof(val_str),
549 probe_str("duration_time", time_value_string(val_str, sizeof(val_str),
552 probe_str("size", value_string(val_str, sizeof(val_str),
553 pkt->size, unit_byte_str));
554 probe_int("pos", pkt->pos);
555 probe_str("flags", pkt->flags & AV_PKT_FLAG_KEY ? "K" : "_");
556 probe_object_footer("packet");
559 static void show_packets(AVFormatContext *fmt_ctx)
563 av_init_packet(&pkt);
564 probe_array_header("packets");
565 while (!av_read_frame(fmt_ctx, &pkt))
566 show_packet(fmt_ctx, &pkt);
567 probe_array_footer("packets");
570 static void show_stream(AVFormatContext *fmt_ctx, int stream_idx)
572 AVStream *stream = fmt_ctx->streams[stream_idx];
573 AVCodecContext *dec_ctx;
577 AVRational display_aspect_ratio, *sar = NULL;
578 const AVPixFmtDescriptor *desc;
580 probe_object_header("stream");
582 probe_int("index", stream->index);
584 if ((dec_ctx = stream->codec)) {
585 if ((dec = dec_ctx->codec)) {
586 probe_str("codec_name", dec->name);
587 probe_str("codec_long_name", dec->long_name);
589 probe_str("codec_name", "unknown");
592 probe_str("codec_type", media_type_string(dec_ctx->codec_type));
593 probe_str("codec_time_base",
594 rational_string(val_str, sizeof(val_str),
595 "/", &dec_ctx->time_base));
597 /* print AVI/FourCC tag */
598 av_get_codec_tag_string(val_str, sizeof(val_str), dec_ctx->codec_tag);
599 probe_str("codec_tag_string", val_str);
600 probe_str("codec_tag", tag_string(val_str, sizeof(val_str),
601 dec_ctx->codec_tag));
603 /* print profile, if there is one */
604 if (dec && (profile = av_get_profile_name(dec, dec_ctx->profile)))
605 probe_str("profile", profile);
607 switch (dec_ctx->codec_type) {
608 case AVMEDIA_TYPE_VIDEO:
609 probe_int("width", dec_ctx->width);
610 probe_int("height", dec_ctx->height);
611 probe_int("coded_width", dec_ctx->coded_width);
612 probe_int("coded_height", dec_ctx->coded_height);
613 probe_int("has_b_frames", dec_ctx->has_b_frames);
614 if (dec_ctx->sample_aspect_ratio.num)
615 sar = &dec_ctx->sample_aspect_ratio;
616 else if (stream->sample_aspect_ratio.num)
617 sar = &stream->sample_aspect_ratio;
620 probe_str("sample_aspect_ratio",
621 rational_string(val_str, sizeof(val_str), ":", sar));
622 av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
623 dec_ctx->width * sar->num, dec_ctx->height * sar->den,
625 probe_str("display_aspect_ratio",
626 rational_string(val_str, sizeof(val_str), ":",
627 &display_aspect_ratio));
629 desc = av_pix_fmt_desc_get(dec_ctx->pix_fmt);
630 probe_str("pix_fmt", desc ? desc->name : "unknown");
631 probe_int("level", dec_ctx->level);
633 probe_str("color_range", av_color_range_name(dec_ctx->color_range));
634 probe_str("color_space", av_color_space_name(dec_ctx->colorspace));
635 probe_str("color_trc", av_color_transfer_name(dec_ctx->color_trc));
636 probe_str("color_pri", av_color_primaries_name(dec_ctx->color_primaries));
637 probe_str("chroma_loc", av_chroma_location_name(dec_ctx->chroma_sample_location));
640 case AVMEDIA_TYPE_AUDIO:
641 probe_str("sample_rate",
642 value_string(val_str, sizeof(val_str),
643 dec_ctx->sample_rate,
645 probe_int("channels", dec_ctx->channels);
646 probe_int("bits_per_sample",
647 av_get_bits_per_sample(dec_ctx->codec_id));
651 probe_str("codec_type", "unknown");
654 if (fmt_ctx->iformat->flags & AVFMT_SHOW_IDS)
655 probe_int("id", stream->id);
656 probe_str("avg_frame_rate",
657 rational_string(val_str, sizeof(val_str), "/",
658 &stream->avg_frame_rate));
659 if (dec_ctx->bit_rate)
660 probe_str("bit_rate",
661 value_string(val_str, sizeof(val_str),
662 dec_ctx->bit_rate, unit_bit_per_second_str));
663 probe_str("time_base",
664 rational_string(val_str, sizeof(val_str), "/",
665 &stream->time_base));
666 probe_str("start_time",
667 time_value_string(val_str, sizeof(val_str),
668 stream->start_time, &stream->time_base));
669 probe_str("duration",
670 time_value_string(val_str, sizeof(val_str),
671 stream->duration, &stream->time_base));
672 if (stream->nb_frames)
673 probe_int("nb_frames", stream->nb_frames);
675 probe_dict(stream->metadata, "tags");
677 probe_object_footer("stream");
680 static void show_format(AVFormatContext *fmt_ctx)
683 int64_t size = fmt_ctx->pb ? avio_size(fmt_ctx->pb) : -1;
685 probe_object_header("format");
686 probe_str("filename", fmt_ctx->filename);
687 probe_int("nb_streams", fmt_ctx->nb_streams);
688 probe_str("format_name", fmt_ctx->iformat->name);
689 probe_str("format_long_name", fmt_ctx->iformat->long_name);
690 probe_str("start_time",
691 time_value_string(val_str, sizeof(val_str),
692 fmt_ctx->start_time, &AV_TIME_BASE_Q));
693 probe_str("duration",
694 time_value_string(val_str, sizeof(val_str),
695 fmt_ctx->duration, &AV_TIME_BASE_Q));
697 size >= 0 ? value_string(val_str, sizeof(val_str),
700 probe_str("bit_rate",
701 value_string(val_str, sizeof(val_str),
702 fmt_ctx->bit_rate, unit_bit_per_second_str));
704 probe_dict(fmt_ctx->metadata, "tags");
706 probe_object_footer("format");
709 static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename)
712 AVFormatContext *fmt_ctx = NULL;
713 AVDictionaryEntry *t;
715 if ((err = avformat_open_input(&fmt_ctx, filename,
716 iformat, &format_opts)) < 0) {
717 print_error(filename, err);
720 if ((t = av_dict_get(format_opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
721 av_log(NULL, AV_LOG_ERROR, "Option %s not found.\n", t->key);
722 return AVERROR_OPTION_NOT_FOUND;
726 /* fill the streams in the format context */
727 if ((err = avformat_find_stream_info(fmt_ctx, NULL)) < 0) {
728 print_error(filename, err);
732 av_dump_format(fmt_ctx, 0, filename, 0);
734 /* bind a decoder to each input stream */
735 for (i = 0; i < fmt_ctx->nb_streams; i++) {
736 AVStream *stream = fmt_ctx->streams[i];
739 if (stream->codec->codec_id == AV_CODEC_ID_PROBE) {
740 fprintf(stderr, "Failed to probe codec for input stream %d\n",
742 } else if (!(codec = avcodec_find_decoder(stream->codec->codec_id))) {
744 "Unsupported codec with id %d for input stream %d\n",
745 stream->codec->codec_id, stream->index);
746 } else if (avcodec_open2(stream->codec, codec, NULL) < 0) {
747 fprintf(stderr, "Error while opening codec for input stream %d\n",
752 *fmt_ctx_ptr = fmt_ctx;
756 static void close_input_file(AVFormatContext **ctx_ptr)
759 AVFormatContext *fmt_ctx = *ctx_ptr;
761 /* close decoder for each stream */
762 for (i = 0; i < fmt_ctx->nb_streams; i++) {
763 AVStream *stream = fmt_ctx->streams[i];
765 avcodec_close(stream->codec);
767 avformat_close_input(ctx_ptr);
770 static int probe_file(const char *filename)
772 AVFormatContext *fmt_ctx;
775 if ((ret = open_input_file(&fmt_ctx, filename)))
779 show_format(fmt_ctx);
781 if (do_show_streams) {
782 probe_array_header("streams");
783 for (i = 0; i < fmt_ctx->nb_streams; i++)
784 show_stream(fmt_ctx, i);
785 probe_array_footer("streams");
789 show_packets(fmt_ctx);
791 close_input_file(&fmt_ctx);
795 static void show_usage(void)
797 printf("Simple multimedia streams analyzer\n");
798 printf("usage: %s [OPTIONS] [INPUT_FILE]\n", program_name);
802 static int opt_format(void *optctx, const char *opt, const char *arg)
804 iformat = av_find_input_format(arg);
806 fprintf(stderr, "Unknown input format: %s\n", arg);
807 return AVERROR(EINVAL);
812 static int opt_output_format(void *optctx, const char *opt, const char *arg)
815 if (!strcmp(arg, "json")) {
816 octx.print_header = json_print_header;
817 octx.print_footer = json_print_footer;
818 octx.print_array_header = json_print_array_header;
819 octx.print_array_footer = json_print_array_footer;
820 octx.print_object_header = json_print_object_header;
821 octx.print_object_footer = json_print_object_footer;
823 octx.print_integer = json_print_integer;
824 octx.print_string = json_print_string;
825 } else if (!strcmp(arg, "ini")) {
826 octx.print_header = ini_print_header;
827 octx.print_footer = ini_print_footer;
828 octx.print_array_header = ini_print_array_header;
829 octx.print_object_header = ini_print_object_header;
831 octx.print_integer = ini_print_integer;
832 octx.print_string = ini_print_string;
833 } else if (!strcmp(arg, "old")) {
834 octx.print_header = NULL;
835 octx.print_object_header = old_print_object_header;
836 octx.print_object_footer = old_print_object_footer;
838 octx.print_string = old_print_string;
840 av_log(NULL, AV_LOG_ERROR, "Unsupported formatter %s\n", arg);
841 return AVERROR(EINVAL);
846 static int opt_show_format_entry(void *optctx, const char *opt, const char *arg)
849 nb_fmt_entries_to_show++;
850 octx.print_header = NULL;
851 octx.print_footer = NULL;
852 octx.print_array_header = NULL;
853 octx.print_array_footer = NULL;
854 octx.print_object_header = NULL;
855 octx.print_object_footer = NULL;
857 octx.print_integer = show_format_entry_integer;
858 octx.print_string = show_format_entry_string;
859 av_dict_set(&fmt_entries_to_show, arg, "", 0);
863 static void opt_input_file(void *optctx, const char *arg)
865 if (input_filename) {
867 "Argument '%s' provided as input filename, but '%s' was already specified.\n",
868 arg, input_filename);
871 if (!strcmp(arg, "-"))
873 input_filename = arg;
876 void show_help_default(const char *opt, const char *arg)
878 av_log_set_callback(log_callback_help);
880 show_help_options(options, "Main options:", 0, 0, 0);
882 show_help_children(avformat_get_class(), AV_OPT_FLAG_DECODING_PARAM);
885 static int opt_pretty(void *optctx, const char *opt, const char *arg)
888 use_value_prefix = 1;
889 use_byte_value_binary_prefix = 1;
890 use_value_sexagesimal_format = 1;
894 static const OptionDef real_options[] = {
895 #include "cmdutils_common_opts.h"
896 { "f", HAS_ARG, {.func_arg = opt_format}, "force format", "format" },
897 { "of", HAS_ARG, {.func_arg = opt_output_format}, "output the document either as ini or json", "output_format" },
898 { "unit", OPT_BOOL, {&show_value_unit},
899 "show unit of the displayed values" },
900 { "prefix", OPT_BOOL, {&use_value_prefix},
901 "use SI prefixes for the displayed values" },
902 { "byte_binary_prefix", OPT_BOOL, {&use_byte_value_binary_prefix},
903 "use binary prefixes for byte units" },
904 { "sexagesimal", OPT_BOOL, {&use_value_sexagesimal_format},
905 "use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units" },
906 { "pretty", 0, {.func_arg = opt_pretty},
907 "prettify the format of displayed values, make it more human readable" },
908 { "show_format", OPT_BOOL, {&do_show_format} , "show format/container info" },
909 { "show_format_entry", HAS_ARG, {.func_arg = opt_show_format_entry},
910 "show a particular entry from the format/container info", "entry" },
911 { "show_packets", OPT_BOOL, {&do_show_packets}, "show packets info" },
912 { "show_streams", OPT_BOOL, {&do_show_streams}, "show streams info" },
913 { "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {.func_arg = opt_default},
914 "generic catch all option", "" },
918 static int probe_buf_write(void *opaque, uint8_t *buf, int buf_size)
920 printf("%.*s", buf_size, buf);
924 #define AVP_BUFFSIZE 4096
926 int main(int argc, char **argv)
929 uint8_t *buffer = av_malloc(AVP_BUFFSIZE);
934 register_exit(avprobe_cleanup);
936 options = real_options;
937 parse_loglevel(argc, argv, options);
939 avformat_network_init();
942 avdevice_register_all();
947 octx.print_header = ini_print_header;
948 octx.print_footer = ini_print_footer;
950 octx.print_array_header = ini_print_array_header;
951 octx.print_object_header = ini_print_object_header;
953 octx.print_integer = ini_print_integer;
954 octx.print_string = ini_print_string;
956 parse_options(NULL, argc, argv, options, opt_input_file);
958 if (!input_filename) {
960 fprintf(stderr, "You have to specify one input file.\n");
962 "Use -h to get full help or, even better, run 'man %s'.\n",
967 probe_out = avio_alloc_context(buffer, AVP_BUFFSIZE, 1, NULL, NULL,
968 probe_buf_write, NULL);
973 ret = probe_file(input_filename);
975 avio_flush(probe_out);
976 avio_close(probe_out);
978 avformat_network_deinit();