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/display.h"
28 #include "libavutil/opt.h"
29 #include "libavutil/pixdesc.h"
30 #include "libavutil/dict.h"
31 #include "libavutil/libm.h"
32 #include "libavdevice/avdevice.h"
35 const char program_name[] = "avprobe";
36 const int program_birth_year = 2007;
38 static int do_show_format = 0;
39 static AVDictionary *fmt_entries_to_show = NULL;
40 static int nb_fmt_entries_to_show;
41 static int do_show_packets = 0;
42 static int do_show_streams = 0;
44 static int show_value_unit = 0;
45 static int use_value_prefix = 0;
46 static int use_byte_value_binary_prefix = 0;
47 static int use_value_sexagesimal_format = 0;
50 static const OptionDef *options;
53 static const char *input_filename;
54 static AVInputFormat *iformat = NULL;
56 static const char *const binary_unit_prefixes [] = { "", "Ki", "Mi", "Gi", "Ti", "Pi" };
57 static const char *const decimal_unit_prefixes[] = { "", "K" , "M" , "G" , "T" , "P" };
59 static const char unit_second_str[] = "s" ;
60 static const char unit_hertz_str[] = "Hz" ;
61 static const char unit_byte_str[] = "byte" ;
62 static const char unit_bit_per_second_str[] = "bit/s";
64 static void avprobe_cleanup(int ret)
66 av_dict_free(&fmt_entries_to_show);
70 * The output is structured in array and objects that might contain items
71 * Array could require the objects within to not be named.
72 * Object could require the items within to be named.
74 * For flat representation the name of each section is saved on prefix so it
75 * can be rendered in order to represent nested structures (e.g. array of
76 * objects for the packets list).
78 * Within an array each element can need an unique identifier or an index.
80 * Nesting level is accounted separately.
88 typedef struct PrintElement {
90 PrintElementType type;
95 typedef struct PrintContext {
98 void (*print_header)(void);
99 void (*print_footer)(void);
101 void (*print_array_header) (const char *name, int plain_values);
102 void (*print_array_footer) (const char *name, int plain_values);
103 void (*print_object_header)(const char *name);
104 void (*print_object_footer)(const char *name);
106 void (*print_integer) (const char *key, int64_t value);
107 void (*print_string) (const char *key, const char *value);
110 static AVIOContext *probe_out = NULL;
111 static PrintContext octx;
112 #define AVP_INDENT() avio_printf(probe_out, "%*c", octx.level * 2, ' ')
115 * Default format, INI
117 * - all key and values are utf8
118 * - '.' is the subgroup separator
119 * - newlines and the following characters are escaped
120 * - '\' is the escape character
121 * - '#' is the comment
122 * - '=' is the key/value separators
123 * - ':' is not used but usually parsed as key/value separator
126 static void ini_print_header(void)
128 avio_printf(probe_out, "# avprobe output\n\n");
130 static void ini_print_footer(void)
132 avio_w8(probe_out, '\n');
135 static void ini_escape_print(const char *s)
142 case '\r': avio_printf(probe_out, "%s", "\\r"); break;
143 case '\n': avio_printf(probe_out, "%s", "\\n"); break;
144 case '\f': avio_printf(probe_out, "%s", "\\f"); break;
145 case '\b': avio_printf(probe_out, "%s", "\\b"); break;
146 case '\t': avio_printf(probe_out, "%s", "\\t"); break;
150 case ':' : avio_w8(probe_out, '\\');
152 if ((unsigned char)c < 32)
153 avio_printf(probe_out, "\\x00%02x", c & 0xff);
155 avio_w8(probe_out, c);
161 static void ini_print_array_header(const char *name, int plain_values)
164 /* Add a new line if we create a new full group */
165 if (octx.prefix[octx.level -1].nb_elems)
166 avio_printf(probe_out, "\n");
168 ini_escape_print(name);
169 avio_w8(probe_out, '=');
173 static void ini_print_array_footer(const char *name, int plain_values)
176 avio_printf(probe_out, "\n");
179 static void ini_print_object_header(const char *name)
182 PrintElement *el = octx.prefix + octx.level -1;
185 avio_printf(probe_out, "\n");
187 avio_printf(probe_out, "[");
189 for (i = 1; i < octx.level; i++) {
190 el = octx.prefix + i;
191 avio_printf(probe_out, "%s.", el->name);
193 avio_printf(probe_out, "%"PRId64".", el->index);
196 avio_printf(probe_out, "%s", name);
197 if (el->type == ARRAY)
198 avio_printf(probe_out, ".%"PRId64"", el->nb_elems);
199 avio_printf(probe_out, "]\n");
202 static void ini_print_integer(const char *key, int64_t value)
205 ini_escape_print(key);
206 avio_printf(probe_out, "=%"PRId64"\n", value);
208 if (octx.prefix[octx.level -1].nb_elems)
209 avio_printf(probe_out, ",");
210 avio_printf(probe_out, "%"PRId64, value);
215 static void ini_print_string(const char *key, const char *value)
217 ini_escape_print(key);
218 avio_printf(probe_out, "=");
219 ini_escape_print(value);
220 avio_w8(probe_out, '\n');
224 * Alternate format, JSON
227 static void json_print_header(void)
229 avio_printf(probe_out, "{");
231 static void json_print_footer(void)
233 avio_printf(probe_out, "}\n");
236 static void json_print_array_header(const char *name, int plain_values)
238 if (octx.prefix[octx.level -1].nb_elems)
239 avio_printf(probe_out, ",\n");
241 avio_printf(probe_out, "\"%s\" : ", name);
242 avio_printf(probe_out, "[\n");
245 static void json_print_array_footer(const char *name, int plain_values)
247 avio_printf(probe_out, "\n");
249 avio_printf(probe_out, "]");
252 static void json_print_object_header(const char *name)
254 if (octx.prefix[octx.level -1].nb_elems)
255 avio_printf(probe_out, ",\n");
257 if (octx.prefix[octx.level -1].type == OBJECT)
258 avio_printf(probe_out, "\"%s\" : ", name);
259 avio_printf(probe_out, "{\n");
262 static void json_print_object_footer(const char *name)
264 avio_printf(probe_out, "\n");
266 avio_printf(probe_out, "}");
269 static void json_print_integer(const char *key, int64_t value)
272 if (octx.prefix[octx.level -1].nb_elems)
273 avio_printf(probe_out, ",\n");
275 avio_printf(probe_out, "\"%s\" : ", key);
277 if (octx.prefix[octx.level -1].nb_elems)
278 avio_printf(probe_out, ", ");
282 avio_printf(probe_out, "%"PRId64, value);
285 static void json_escape_print(const char *s)
292 case '\r': avio_printf(probe_out, "%s", "\\r"); break;
293 case '\n': avio_printf(probe_out, "%s", "\\n"); break;
294 case '\f': avio_printf(probe_out, "%s", "\\f"); break;
295 case '\b': avio_printf(probe_out, "%s", "\\b"); break;
296 case '\t': avio_printf(probe_out, "%s", "\\t"); break;
298 case '"' : avio_w8(probe_out, '\\');
300 if ((unsigned char)c < 32)
301 avio_printf(probe_out, "\\u00%02x", c & 0xff);
303 avio_w8(probe_out, c);
309 static void json_print_string(const char *key, const char *value)
311 if (octx.prefix[octx.level -1].nb_elems)
312 avio_printf(probe_out, ",\n");
314 avio_w8(probe_out, '\"');
315 json_escape_print(key);
316 avio_printf(probe_out, "\" : \"");
317 json_escape_print(value);
318 avio_w8(probe_out, '\"');
322 * old-style pseudo-INI
324 static void old_print_object_header(const char *name)
328 if (!strcmp(name, "tags"))
331 str = p = av_strdup(name);
339 avio_printf(probe_out, "[%s]\n", str);
343 static void old_print_object_footer(const char *name)
347 if (!strcmp(name, "tags"))
350 str = p = av_strdup(name);
358 avio_printf(probe_out, "[/%s]\n", str);
362 static void old_print_string(const char *key, const char *value)
364 if (!strcmp(octx.prefix[octx.level - 1].name, "tags"))
365 avio_printf(probe_out, "TAG:");
366 ini_print_string(key, value);
370 * Simple Formatter for single entries.
373 static void show_format_entry_integer(const char *key, int64_t value)
375 if (key && av_dict_get(fmt_entries_to_show, key, NULL, 0)) {
376 if (nb_fmt_entries_to_show > 1)
377 avio_printf(probe_out, "%s=", key);
378 avio_printf(probe_out, "%"PRId64"\n", value);
382 static void show_format_entry_string(const char *key, const char *value)
384 if (key && av_dict_get(fmt_entries_to_show, key, NULL, 0)) {
385 if (nb_fmt_entries_to_show > 1)
386 avio_printf(probe_out, "%s=", key);
387 avio_printf(probe_out, "%s\n", value);
391 static void probe_group_enter(const char *name, int type)
396 av_realloc(octx.prefix, sizeof(PrintElement) * (octx.level + 1));
398 if (!octx.prefix || !name) {
399 fprintf(stderr, "Out of memory\n");
404 PrintElement *parent = octx.prefix + octx.level -1;
405 if (parent->type == ARRAY)
406 count = parent->nb_elems;
410 octx.prefix[octx.level++] = (PrintElement){name, type, count, 0};
413 static void probe_group_leave(void)
418 static void probe_header(void)
420 if (octx.print_header)
422 probe_group_enter("root", OBJECT);
425 static void probe_footer(void)
427 if (octx.print_footer)
433 static void probe_array_header(const char *name, int plain_values)
435 if (octx.print_array_header)
436 octx.print_array_header(name, plain_values);
438 probe_group_enter(name, ARRAY);
441 static void probe_array_footer(const char *name, int plain_values)
444 if (octx.print_array_footer)
445 octx.print_array_footer(name, plain_values);
448 static void probe_object_header(const char *name)
450 if (octx.print_object_header)
451 octx.print_object_header(name);
453 probe_group_enter(name, OBJECT);
456 static void probe_object_footer(const char *name)
459 if (octx.print_object_footer)
460 octx.print_object_footer(name);
463 static void probe_int(const char *key, int64_t value)
465 octx.print_integer(key, value);
466 octx.prefix[octx.level -1].nb_elems++;
469 static void probe_str(const char *key, const char *value)
471 octx.print_string(key, value);
472 octx.prefix[octx.level -1].nb_elems++;
475 static void probe_dict(AVDictionary *dict, const char *name)
477 AVDictionaryEntry *entry = NULL;
480 probe_object_header(name);
481 while ((entry = av_dict_get(dict, "", entry, AV_DICT_IGNORE_SUFFIX))) {
482 probe_str(entry->key, entry->value);
484 probe_object_footer(name);
487 static char *value_string(char *buf, int buf_size, double val, const char *unit)
489 if (unit == unit_second_str && use_value_sexagesimal_format) {
493 mins = (int)secs / 60;
494 secs = secs - mins * 60;
497 snprintf(buf, buf_size, "%d:%02d:%09.6f", hours, mins, secs);
498 } else if (use_value_prefix) {
499 const char *prefix_string;
502 if (unit == unit_byte_str && use_byte_value_binary_prefix) {
503 index = (int) log2(val) / 10;
504 index = av_clip(index, 0, FF_ARRAY_ELEMS(binary_unit_prefixes) - 1);
505 val /= pow(2, index * 10);
506 prefix_string = binary_unit_prefixes[index];
508 index = (int) (log10(val)) / 3;
509 index = av_clip(index, 0, FF_ARRAY_ELEMS(decimal_unit_prefixes) - 1);
510 val /= pow(10, index * 3);
511 prefix_string = decimal_unit_prefixes[index];
513 snprintf(buf, buf_size, "%.*f%s%s",
516 show_value_unit ? unit : "");
518 snprintf(buf, buf_size, "%f%s", val, show_value_unit ? unit : "");
524 static char *time_value_string(char *buf, int buf_size, int64_t val,
525 const AVRational *time_base)
527 if (val == AV_NOPTS_VALUE) {
528 snprintf(buf, buf_size, "N/A");
530 value_string(buf, buf_size, val * av_q2d(*time_base), unit_second_str);
536 static char *ts_value_string(char *buf, int buf_size, int64_t ts)
538 if (ts == AV_NOPTS_VALUE) {
539 snprintf(buf, buf_size, "N/A");
541 snprintf(buf, buf_size, "%"PRId64, ts);
547 static char *rational_string(char *buf, int buf_size, const char *sep,
548 const AVRational *rat)
550 snprintf(buf, buf_size, "%d%s%d", rat->num, sep, rat->den);
554 static char *tag_string(char *buf, int buf_size, int tag)
556 snprintf(buf, buf_size, "0x%04x", tag);
560 static void show_packet(AVFormatContext *fmt_ctx, AVPacket *pkt)
563 AVStream *st = fmt_ctx->streams[pkt->stream_index];
565 probe_object_header("packet");
566 probe_str("codec_type", media_type_string(st->codec->codec_type));
567 probe_int("stream_index", pkt->stream_index);
568 probe_str("pts", ts_value_string(val_str, sizeof(val_str), pkt->pts));
569 probe_str("pts_time", time_value_string(val_str, sizeof(val_str),
570 pkt->pts, &st->time_base));
571 probe_str("dts", ts_value_string(val_str, sizeof(val_str), pkt->dts));
572 probe_str("dts_time", time_value_string(val_str, sizeof(val_str),
573 pkt->dts, &st->time_base));
574 probe_str("duration", ts_value_string(val_str, sizeof(val_str),
576 probe_str("duration_time", time_value_string(val_str, sizeof(val_str),
579 probe_str("size", value_string(val_str, sizeof(val_str),
580 pkt->size, unit_byte_str));
581 probe_int("pos", pkt->pos);
582 probe_str("flags", pkt->flags & AV_PKT_FLAG_KEY ? "K" : "_");
583 probe_object_footer("packet");
586 static void show_packets(AVFormatContext *fmt_ctx)
590 av_init_packet(&pkt);
591 probe_array_header("packets", 0);
592 while (!av_read_frame(fmt_ctx, &pkt)) {
593 show_packet(fmt_ctx, &pkt);
594 av_packet_unref(&pkt);
596 probe_array_footer("packets", 0);
599 static void show_stream(AVFormatContext *fmt_ctx, int stream_idx)
601 AVStream *stream = fmt_ctx->streams[stream_idx];
602 AVCodecContext *dec_ctx;
606 AVRational display_aspect_ratio, *sar = NULL;
607 const AVPixFmtDescriptor *desc;
609 probe_object_header("stream");
611 probe_int("index", stream->index);
613 if ((dec_ctx = stream->codec)) {
614 if ((dec = dec_ctx->codec)) {
615 probe_str("codec_name", dec->name);
616 probe_str("codec_long_name", dec->long_name);
618 probe_str("codec_name", "unknown");
621 probe_str("codec_type", media_type_string(dec_ctx->codec_type));
622 probe_str("codec_time_base",
623 rational_string(val_str, sizeof(val_str),
624 "/", &dec_ctx->time_base));
626 /* print AVI/FourCC tag */
627 av_get_codec_tag_string(val_str, sizeof(val_str), dec_ctx->codec_tag);
628 probe_str("codec_tag_string", val_str);
629 probe_str("codec_tag", tag_string(val_str, sizeof(val_str),
630 dec_ctx->codec_tag));
632 /* print profile, if there is one */
633 if (dec && (profile = av_get_profile_name(dec, dec_ctx->profile)))
634 probe_str("profile", profile);
636 switch (dec_ctx->codec_type) {
637 case AVMEDIA_TYPE_VIDEO:
638 probe_int("width", dec_ctx->width);
639 probe_int("height", dec_ctx->height);
640 probe_int("coded_width", dec_ctx->coded_width);
641 probe_int("coded_height", dec_ctx->coded_height);
642 probe_int("has_b_frames", dec_ctx->has_b_frames);
643 if (dec_ctx->sample_aspect_ratio.num)
644 sar = &dec_ctx->sample_aspect_ratio;
645 else if (stream->sample_aspect_ratio.num)
646 sar = &stream->sample_aspect_ratio;
649 probe_str("sample_aspect_ratio",
650 rational_string(val_str, sizeof(val_str), ":", sar));
651 av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
652 dec_ctx->width * sar->num, dec_ctx->height * sar->den,
654 probe_str("display_aspect_ratio",
655 rational_string(val_str, sizeof(val_str), ":",
656 &display_aspect_ratio));
658 desc = av_pix_fmt_desc_get(dec_ctx->pix_fmt);
659 probe_str("pix_fmt", desc ? desc->name : "unknown");
660 probe_int("level", dec_ctx->level);
662 probe_str("color_range", av_color_range_name(dec_ctx->color_range));
663 probe_str("color_space", av_color_space_name(dec_ctx->colorspace));
664 probe_str("color_trc", av_color_transfer_name(dec_ctx->color_trc));
665 probe_str("color_pri", av_color_primaries_name(dec_ctx->color_primaries));
666 probe_str("chroma_loc", av_chroma_location_name(dec_ctx->chroma_sample_location));
669 case AVMEDIA_TYPE_AUDIO:
670 probe_str("sample_rate",
671 value_string(val_str, sizeof(val_str),
672 dec_ctx->sample_rate,
674 probe_int("channels", dec_ctx->channels);
675 probe_int("bits_per_sample",
676 av_get_bits_per_sample(dec_ctx->codec_id));
680 probe_str("codec_type", "unknown");
683 if (fmt_ctx->iformat->flags & AVFMT_SHOW_IDS)
684 probe_int("id", stream->id);
685 probe_str("avg_frame_rate",
686 rational_string(val_str, sizeof(val_str), "/",
687 &stream->avg_frame_rate));
688 if (dec_ctx->bit_rate)
689 probe_str("bit_rate",
690 value_string(val_str, sizeof(val_str),
691 dec_ctx->bit_rate, unit_bit_per_second_str));
692 probe_str("time_base",
693 rational_string(val_str, sizeof(val_str), "/",
694 &stream->time_base));
695 probe_str("start_time",
696 time_value_string(val_str, sizeof(val_str),
697 stream->start_time, &stream->time_base));
698 probe_str("duration",
699 time_value_string(val_str, sizeof(val_str),
700 stream->duration, &stream->time_base));
701 if (stream->nb_frames)
702 probe_int("nb_frames", stream->nb_frames);
704 probe_dict(stream->metadata, "tags");
706 if (stream->nb_side_data) {
708 probe_object_header("sidedata");
709 for (i = 0; i < stream->nb_side_data; i++) {
710 const AVPacketSideData* sd = &stream->side_data[i];
712 case AV_PKT_DATA_DISPLAYMATRIX:
713 probe_object_header("displaymatrix");
714 probe_array_header("matrix", 1);
715 for (j = 0; j < 9; j++)
716 probe_int(NULL, ((int32_t *)sd->data)[j]);
717 probe_array_footer("matrix", 1);
718 probe_int("rotation",
719 av_display_rotation_get((int32_t *)sd->data));
720 probe_object_footer("displaymatrix");
724 probe_object_footer("sidedata");
727 probe_object_footer("stream");
730 static void show_format(AVFormatContext *fmt_ctx)
733 int64_t size = fmt_ctx->pb ? avio_size(fmt_ctx->pb) : -1;
735 probe_object_header("format");
736 probe_str("filename", fmt_ctx->filename);
737 probe_int("nb_streams", fmt_ctx->nb_streams);
738 probe_str("format_name", fmt_ctx->iformat->name);
739 probe_str("format_long_name", fmt_ctx->iformat->long_name);
740 probe_str("start_time",
741 time_value_string(val_str, sizeof(val_str),
742 fmt_ctx->start_time, &AV_TIME_BASE_Q));
743 probe_str("duration",
744 time_value_string(val_str, sizeof(val_str),
745 fmt_ctx->duration, &AV_TIME_BASE_Q));
747 size >= 0 ? value_string(val_str, sizeof(val_str),
750 probe_str("bit_rate",
751 value_string(val_str, sizeof(val_str),
752 fmt_ctx->bit_rate, unit_bit_per_second_str));
754 probe_dict(fmt_ctx->metadata, "tags");
756 probe_object_footer("format");
759 static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename)
762 AVFormatContext *fmt_ctx = NULL;
763 AVDictionaryEntry *t;
765 if ((err = avformat_open_input(&fmt_ctx, filename,
766 iformat, &format_opts)) < 0) {
767 print_error(filename, err);
770 if ((t = av_dict_get(format_opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
771 av_log(NULL, AV_LOG_ERROR, "Option %s not found.\n", t->key);
772 return AVERROR_OPTION_NOT_FOUND;
776 /* fill the streams in the format context */
777 if ((err = avformat_find_stream_info(fmt_ctx, NULL)) < 0) {
778 print_error(filename, err);
782 av_dump_format(fmt_ctx, 0, filename, 0);
784 /* bind a decoder to each input stream */
785 for (i = 0; i < fmt_ctx->nb_streams; i++) {
786 AVStream *stream = fmt_ctx->streams[i];
789 if (stream->codec->codec_id == AV_CODEC_ID_PROBE) {
790 fprintf(stderr, "Failed to probe codec for input stream %d\n",
792 } else if (!(codec = avcodec_find_decoder(stream->codec->codec_id))) {
794 "Unsupported codec with id %d for input stream %d\n",
795 stream->codec->codec_id, stream->index);
796 } else if (avcodec_open2(stream->codec, codec, NULL) < 0) {
797 fprintf(stderr, "Error while opening codec for input stream %d\n",
802 *fmt_ctx_ptr = fmt_ctx;
806 static void close_input_file(AVFormatContext **ctx_ptr)
809 AVFormatContext *fmt_ctx = *ctx_ptr;
811 /* close decoder for each stream */
812 for (i = 0; i < fmt_ctx->nb_streams; i++) {
813 AVStream *stream = fmt_ctx->streams[i];
815 avcodec_close(stream->codec);
817 avformat_close_input(ctx_ptr);
820 static int probe_file(const char *filename)
822 AVFormatContext *fmt_ctx;
825 if ((ret = open_input_file(&fmt_ctx, filename)))
829 show_format(fmt_ctx);
831 if (do_show_streams) {
832 probe_array_header("streams", 0);
833 for (i = 0; i < fmt_ctx->nb_streams; i++)
834 show_stream(fmt_ctx, i);
835 probe_array_footer("streams", 0);
839 show_packets(fmt_ctx);
841 close_input_file(&fmt_ctx);
845 static void show_usage(void)
847 printf("Simple multimedia streams analyzer\n");
848 printf("usage: %s [OPTIONS] [INPUT_FILE]\n", program_name);
852 static int opt_format(void *optctx, const char *opt, const char *arg)
854 iformat = av_find_input_format(arg);
856 fprintf(stderr, "Unknown input format: %s\n", arg);
857 return AVERROR(EINVAL);
862 static int opt_output_format(void *optctx, const char *opt, const char *arg)
865 if (!strcmp(arg, "json")) {
866 octx.print_header = json_print_header;
867 octx.print_footer = json_print_footer;
868 octx.print_array_header = json_print_array_header;
869 octx.print_array_footer = json_print_array_footer;
870 octx.print_object_header = json_print_object_header;
871 octx.print_object_footer = json_print_object_footer;
873 octx.print_integer = json_print_integer;
874 octx.print_string = json_print_string;
875 } else if (!strcmp(arg, "ini")) {
876 octx.print_header = ini_print_header;
877 octx.print_footer = ini_print_footer;
878 octx.print_array_header = ini_print_array_header;
879 octx.print_array_footer = ini_print_array_footer;
880 octx.print_object_header = ini_print_object_header;
882 octx.print_integer = ini_print_integer;
883 octx.print_string = ini_print_string;
884 } else if (!strcmp(arg, "old")) {
885 octx.print_header = NULL;
886 octx.print_object_header = old_print_object_header;
887 octx.print_object_footer = old_print_object_footer;
889 octx.print_string = old_print_string;
891 av_log(NULL, AV_LOG_ERROR, "Unsupported formatter %s\n", arg);
892 return AVERROR(EINVAL);
897 static int opt_show_format_entry(void *optctx, const char *opt, const char *arg)
900 nb_fmt_entries_to_show++;
901 octx.print_header = NULL;
902 octx.print_footer = NULL;
903 octx.print_array_header = NULL;
904 octx.print_array_footer = NULL;
905 octx.print_object_header = NULL;
906 octx.print_object_footer = NULL;
908 octx.print_integer = show_format_entry_integer;
909 octx.print_string = show_format_entry_string;
910 av_dict_set(&fmt_entries_to_show, arg, "", 0);
914 static void opt_input_file(void *optctx, const char *arg)
916 if (input_filename) {
918 "Argument '%s' provided as input filename, but '%s' was already specified.\n",
919 arg, input_filename);
922 if (!strcmp(arg, "-"))
924 input_filename = arg;
927 void show_help_default(const char *opt, const char *arg)
929 av_log_set_callback(log_callback_help);
931 show_help_options(options, "Main options:", 0, 0, 0);
933 show_help_children(avformat_get_class(), AV_OPT_FLAG_DECODING_PARAM);
936 static int opt_pretty(void *optctx, const char *opt, const char *arg)
939 use_value_prefix = 1;
940 use_byte_value_binary_prefix = 1;
941 use_value_sexagesimal_format = 1;
945 static const OptionDef real_options[] = {
946 #include "cmdutils_common_opts.h"
947 { "f", HAS_ARG, {.func_arg = opt_format}, "force format", "format" },
948 { "of", HAS_ARG, {.func_arg = opt_output_format}, "output the document either as ini or json", "output_format" },
949 { "unit", OPT_BOOL, {&show_value_unit},
950 "show unit of the displayed values" },
951 { "prefix", OPT_BOOL, {&use_value_prefix},
952 "use SI prefixes for the displayed values" },
953 { "byte_binary_prefix", OPT_BOOL, {&use_byte_value_binary_prefix},
954 "use binary prefixes for byte units" },
955 { "sexagesimal", OPT_BOOL, {&use_value_sexagesimal_format},
956 "use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units" },
957 { "pretty", 0, {.func_arg = opt_pretty},
958 "prettify the format of displayed values, make it more human readable" },
959 { "show_format", OPT_BOOL, {&do_show_format} , "show format/container info" },
960 { "show_format_entry", HAS_ARG, {.func_arg = opt_show_format_entry},
961 "show a particular entry from the format/container info", "entry" },
962 { "show_packets", OPT_BOOL, {&do_show_packets}, "show packets info" },
963 { "show_streams", OPT_BOOL, {&do_show_streams}, "show streams info" },
964 { "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {.func_arg = opt_default},
965 "generic catch all option", "" },
969 static int probe_buf_write(void *opaque, uint8_t *buf, int buf_size)
971 printf("%.*s", buf_size, buf);
975 #define AVP_BUFFSIZE 4096
977 int main(int argc, char **argv)
980 uint8_t *buffer = av_malloc(AVP_BUFFSIZE);
985 register_exit(avprobe_cleanup);
987 options = real_options;
988 parse_loglevel(argc, argv, options);
990 avformat_network_init();
993 avdevice_register_all();
998 octx.print_header = ini_print_header;
999 octx.print_footer = ini_print_footer;
1001 octx.print_array_header = ini_print_array_header;
1002 octx.print_array_footer = ini_print_array_footer;
1003 octx.print_object_header = ini_print_object_header;
1005 octx.print_integer = ini_print_integer;
1006 octx.print_string = ini_print_string;
1008 parse_options(NULL, argc, argv, options, opt_input_file);
1010 if (!input_filename) {
1012 fprintf(stderr, "You have to specify one input file.\n");
1014 "Use -h to get full help or, even better, run 'man %s'.\n",
1019 probe_out = avio_alloc_context(buffer, AVP_BUFFSIZE, 1, NULL, NULL,
1020 probe_buf_write, NULL);
1025 ret = probe_file(input_filename);
1027 avio_flush(probe_out);
1028 avio_close(probe_out);
1030 avformat_network_deinit();