Libav
avprobe.c
Go to the documentation of this file.
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/avstring.h"
27 #include "libavutil/display.h"
28 #include "libavutil/opt.h"
29 #include "libavutil/pixdesc.h"
30 #include "libavutil/stereo3d.h"
31 #include "libavutil/dict.h"
32 #include "libavutil/libm.h"
33 #include "libavdevice/avdevice.h"
34 #include "cmdutils.h"
35 
36 typedef struct InputStream {
37  AVStream *st;
38 
40 } InputStream;
41 
42 typedef struct InputFile {
44 
46  int nb_streams;
47 } InputFile;
48 
49 const char program_name[] = "avprobe";
50 const int program_birth_year = 2007;
51 
52 static int do_show_format = 0;
55 static int do_show_packets = 0;
56 static int do_show_streams = 0;
57 
58 static int show_value_unit = 0;
59 static int use_value_prefix = 0;
62 
63 /* globals */
64 static const OptionDef *options;
65 
66 /* avprobe context */
67 static const char *input_filename;
69 
70 static const char *const binary_unit_prefixes [] = { "", "Ki", "Mi", "Gi", "Ti", "Pi" };
71 static const char *const decimal_unit_prefixes[] = { "", "K" , "M" , "G" , "T" , "P" };
72 
73 static const char unit_second_str[] = "s" ;
74 static const char unit_hertz_str[] = "Hz" ;
75 static const char unit_byte_str[] = "byte" ;
76 static const char unit_bit_per_second_str[] = "bit/s";
77 
78 static void avprobe_cleanup(int ret)
79 {
80  av_dict_free(&fmt_entries_to_show);
81 }
82 
83 /*
84  * The output is structured in array and objects that might contain items
85  * Array could require the objects within to not be named.
86  * Object could require the items within to be named.
87  *
88  * For flat representation the name of each section is saved on prefix so it
89  * can be rendered in order to represent nested structures (e.g. array of
90  * objects for the packets list).
91  *
92  * Within an array each element can need an unique identifier or an index.
93  *
94  * Nesting level is accounted separately.
95  */
96 
97 typedef enum {
101 
102 typedef struct PrintElement {
103  const char *name;
105  int64_t index;
106  int64_t nb_elems;
107 } PrintElement;
108 
109 typedef struct PrintContext {
111  int level;
112  void (*print_header)(void);
113  void (*print_footer)(void);
114 
115  void (*print_array_header) (const char *name, int plain_values);
116  void (*print_array_footer) (const char *name, int plain_values);
117  void (*print_object_header)(const char *name);
118  void (*print_object_footer)(const char *name);
119 
120  void (*print_integer) (const char *key, int64_t value);
121  void (*print_string) (const char *key, const char *value);
122 } PrintContext;
123 
126 #define AVP_INDENT() avio_printf(probe_out, "%*c", octx.level * 2, ' ')
127 
128 /*
129  * Default format, INI
130  *
131  * - all key and values are utf8
132  * - '.' is the subgroup separator
133  * - newlines and the following characters are escaped
134  * - '\' is the escape character
135  * - '#' is the comment
136  * - '=' is the key/value separators
137  * - ':' is not used but usually parsed as key/value separator
138  */
139 
140 static void ini_print_header(void)
141 {
142  avio_printf(probe_out, "# avprobe output\n\n");
143 }
144 static void ini_print_footer(void)
145 {
146  avio_w8(probe_out, '\n');
147 }
148 
149 static void ini_escape_print(const char *s)
150 {
151  int i = 0;
152  char c = 0;
153 
154  while (c = s[i++]) {
155  switch (c) {
156  case '\r': avio_printf(probe_out, "%s", "\\r"); break;
157  case '\n': avio_printf(probe_out, "%s", "\\n"); break;
158  case '\f': avio_printf(probe_out, "%s", "\\f"); break;
159  case '\b': avio_printf(probe_out, "%s", "\\b"); break;
160  case '\t': avio_printf(probe_out, "%s", "\\t"); break;
161  case '\\':
162  case '#' :
163  case '=' :
164  case ':' : avio_w8(probe_out, '\\');
165  default:
166  if ((unsigned char)c < 32)
167  avio_printf(probe_out, "\\x00%02x", c & 0xff);
168  else
169  avio_w8(probe_out, c);
170  break;
171  }
172  }
173 }
174 
175 static void ini_print_array_header(const char *name, int plain_values)
176 {
177  if (!plain_values) {
178  /* Add a new line if we create a new full group */
179  if (octx.prefix[octx.level -1].nb_elems)
180  avio_printf(probe_out, "\n");
181  } else {
182  ini_escape_print(name);
183  avio_w8(probe_out, '=');
184  }
185 }
186 
187 static void ini_print_array_footer(const char *name, int plain_values)
188 {
189  if (plain_values)
190  avio_printf(probe_out, "\n");
191 }
192 
193 static void ini_print_object_header(const char *name)
194 {
195  int i;
196  PrintElement *el = octx.prefix + octx.level -1;
197 
198  if (el->nb_elems)
199  avio_printf(probe_out, "\n");
200 
201  avio_printf(probe_out, "[");
202 
203  for (i = 1; i < octx.level; i++) {
204  el = octx.prefix + i;
205  avio_printf(probe_out, "%s.", el->name);
206  if (el->index >= 0)
207  avio_printf(probe_out, "%"PRId64".", el->index);
208  }
209 
210  avio_printf(probe_out, "%s", name);
211  if (el->type == ARRAY)
212  avio_printf(probe_out, ".%"PRId64"", el->nb_elems);
213  avio_printf(probe_out, "]\n");
214 }
215 
216 static void ini_print_integer(const char *key, int64_t value)
217 {
218  if (key) {
219  ini_escape_print(key);
220  avio_printf(probe_out, "=%"PRId64"\n", value);
221  } else {
222  if (octx.prefix[octx.level -1].nb_elems)
223  avio_printf(probe_out, ",");
224  avio_printf(probe_out, "%"PRId64, value);
225  }
226 }
227 
228 
229 static void ini_print_string(const char *key, const char *value)
230 {
231  ini_escape_print(key);
232  avio_printf(probe_out, "=");
233  ini_escape_print(value);
234  avio_w8(probe_out, '\n');
235 }
236 
237 /*
238  * Alternate format, JSON
239  */
240 
241 static void json_print_header(void)
242 {
243  avio_printf(probe_out, "{");
244 }
245 static void json_print_footer(void)
246 {
247  avio_printf(probe_out, "}\n");
248 }
249 
250 static void json_print_array_header(const char *name, int plain_values)
251 {
252  if (octx.prefix[octx.level -1].nb_elems)
253  avio_printf(probe_out, ",\n");
254  AVP_INDENT();
255  avio_printf(probe_out, "\"%s\" : ", name);
256  avio_printf(probe_out, "[\n");
257 }
258 
259 static void json_print_array_footer(const char *name, int plain_values)
260 {
261  avio_printf(probe_out, "\n");
262  AVP_INDENT();
263  avio_printf(probe_out, "]");
264 }
265 
266 static void json_print_object_header(const char *name)
267 {
268  if (octx.prefix[octx.level -1].nb_elems)
269  avio_printf(probe_out, ",\n");
270  AVP_INDENT();
271  if (octx.prefix[octx.level -1].type == OBJECT)
272  avio_printf(probe_out, "\"%s\" : ", name);
273  avio_printf(probe_out, "{\n");
274 }
275 
276 static void json_print_object_footer(const char *name)
277 {
278  avio_printf(probe_out, "\n");
279  AVP_INDENT();
280  avio_printf(probe_out, "}");
281 }
282 
283 static void json_print_integer(const char *key, int64_t value)
284 {
285  if (key) {
286  if (octx.prefix[octx.level -1].nb_elems)
287  avio_printf(probe_out, ",\n");
288  AVP_INDENT();
289  avio_printf(probe_out, "\"%s\" : ", key);
290  } else {
291  if (octx.prefix[octx.level -1].nb_elems)
292  avio_printf(probe_out, ", ");
293  else
294  AVP_INDENT();
295  }
296  avio_printf(probe_out, "%"PRId64, value);
297 }
298 
299 static void json_escape_print(const char *s)
300 {
301  int i = 0;
302  char c = 0;
303 
304  while (c = s[i++]) {
305  switch (c) {
306  case '\r': avio_printf(probe_out, "%s", "\\r"); break;
307  case '\n': avio_printf(probe_out, "%s", "\\n"); break;
308  case '\f': avio_printf(probe_out, "%s", "\\f"); break;
309  case '\b': avio_printf(probe_out, "%s", "\\b"); break;
310  case '\t': avio_printf(probe_out, "%s", "\\t"); break;
311  case '\\':
312  case '"' : avio_w8(probe_out, '\\');
313  default:
314  if ((unsigned char)c < 32)
315  avio_printf(probe_out, "\\u00%02x", c & 0xff);
316  else
317  avio_w8(probe_out, c);
318  break;
319  }
320  }
321 }
322 
323 static void json_print_string(const char *key, const char *value)
324 {
325  if (octx.prefix[octx.level -1].nb_elems)
326  avio_printf(probe_out, ",\n");
327  AVP_INDENT();
328  avio_w8(probe_out, '\"');
329  json_escape_print(key);
330  avio_printf(probe_out, "\" : \"");
331  json_escape_print(value);
332  avio_w8(probe_out, '\"');
333 }
334 
335 /*
336  * old-style pseudo-INI
337  */
338 static void old_print_object_header(const char *name)
339 {
340  char *str, *p;
341 
342  if (!strcmp(name, "tags"))
343  return;
344 
345  str = p = av_strdup(name);
346  if (!str)
347  return;
348  while (*p) {
349  *p = av_toupper(*p);
350  p++;
351  }
352 
353  avio_printf(probe_out, "[%s]\n", str);
354  av_freep(&str);
355 }
356 
357 static void old_print_object_footer(const char *name)
358 {
359  char *str, *p;
360 
361  if (!strcmp(name, "tags"))
362  return;
363 
364  str = p = av_strdup(name);
365  if (!str)
366  return;
367  while (*p) {
368  *p = av_toupper(*p);
369  p++;
370  }
371 
372  avio_printf(probe_out, "[/%s]\n", str);
373  av_freep(&str);
374 }
375 
376 static void old_print_string(const char *key, const char *value)
377 {
378  if (!strcmp(octx.prefix[octx.level - 1].name, "tags"))
379  avio_printf(probe_out, "TAG:");
380  ini_print_string(key, value);
381 }
382 
383 /*
384  * Simple Formatter for single entries.
385  */
386 
387 static void show_format_entry_integer(const char *key, int64_t value)
388 {
389  if (key && av_dict_get(fmt_entries_to_show, key, NULL, 0)) {
390  if (nb_fmt_entries_to_show > 1)
391  avio_printf(probe_out, "%s=", key);
392  avio_printf(probe_out, "%"PRId64"\n", value);
393  }
394 }
395 
396 static void show_format_entry_string(const char *key, const char *value)
397 {
398  if (key && av_dict_get(fmt_entries_to_show, key, NULL, 0)) {
399  if (nb_fmt_entries_to_show > 1)
400  avio_printf(probe_out, "%s=", key);
401  avio_printf(probe_out, "%s\n", value);
402  }
403 }
404 
405 static void probe_group_enter(const char *name, int type)
406 {
407  int64_t count = -1;
408 
409  octx.prefix =
410  av_realloc(octx.prefix, sizeof(PrintElement) * (octx.level + 1));
411 
412  if (!octx.prefix || !name) {
413  fprintf(stderr, "Out of memory\n");
414  exit_program(1);
415  }
416 
417  if (octx.level) {
418  PrintElement *parent = octx.prefix + octx.level -1;
419  if (parent->type == ARRAY)
420  count = parent->nb_elems;
421  parent->nb_elems++;
422  }
423 
424  octx.prefix[octx.level++] = (PrintElement){name, type, count, 0};
425 }
426 
427 static void probe_group_leave(void)
428 {
429  --octx.level;
430 }
431 
432 static void probe_header(void)
433 {
434  if (octx.print_header)
435  octx.print_header();
436  probe_group_enter("root", OBJECT);
437 }
438 
439 static void probe_footer(void)
440 {
441  if (octx.print_footer)
442  octx.print_footer();
444 }
445 
446 
447 static void probe_array_header(const char *name, int plain_values)
448 {
449  if (octx.print_array_header)
450  octx.print_array_header(name, plain_values);
451 
452  probe_group_enter(name, ARRAY);
453 }
454 
455 static void probe_array_footer(const char *name, int plain_values)
456 {
458  if (octx.print_array_footer)
459  octx.print_array_footer(name, plain_values);
460 }
461 
462 static void probe_object_header(const char *name)
463 {
464  if (octx.print_object_header)
465  octx.print_object_header(name);
466 
467  probe_group_enter(name, OBJECT);
468 }
469 
470 static void probe_object_footer(const char *name)
471 {
473  if (octx.print_object_footer)
474  octx.print_object_footer(name);
475 }
476 
477 static void probe_int(const char *key, int64_t value)
478 {
479  octx.print_integer(key, value);
480  octx.prefix[octx.level -1].nb_elems++;
481 }
482 
483 static void probe_str(const char *key, const char *value)
484 {
485  octx.print_string(key, value);
486  octx.prefix[octx.level -1].nb_elems++;
487 }
488 
489 static void probe_dict(AVDictionary *dict, const char *name)
490 {
491  AVDictionaryEntry *entry = NULL;
492  if (!dict)
493  return;
494  probe_object_header(name);
495  while ((entry = av_dict_get(dict, "", entry, AV_DICT_IGNORE_SUFFIX))) {
496  probe_str(entry->key, entry->value);
497  }
498  probe_object_footer(name);
499 }
500 
501 static char *value_string(char *buf, int buf_size, double val, const char *unit)
502 {
504  double secs;
505  int hours, mins;
506  secs = val;
507  mins = (int)secs / 60;
508  secs = secs - mins * 60;
509  hours = mins / 60;
510  mins %= 60;
511  snprintf(buf, buf_size, "%d:%02d:%09.6f", hours, mins, secs);
512  } else if (use_value_prefix) {
513  const char *prefix_string;
514  int index;
515 
517  index = (int) log2(val) / 10;
518  index = av_clip(index, 0, FF_ARRAY_ELEMS(binary_unit_prefixes) - 1);
519  val /= pow(2, index * 10);
520  prefix_string = binary_unit_prefixes[index];
521  } else {
522  index = (int) (log10(val)) / 3;
523  index = av_clip(index, 0, FF_ARRAY_ELEMS(decimal_unit_prefixes) - 1);
524  val /= pow(10, index * 3);
525  prefix_string = decimal_unit_prefixes[index];
526  }
527  snprintf(buf, buf_size, "%.*f%s%s",
528  index ? 3 : 0, val,
529  prefix_string,
530  show_value_unit ? unit : "");
531  } else {
532  snprintf(buf, buf_size, "%f%s", val, show_value_unit ? unit : "");
533  }
534 
535  return buf;
536 }
537 
538 static char *time_value_string(char *buf, int buf_size, int64_t val,
539  const AVRational *time_base)
540 {
541  if (val == AV_NOPTS_VALUE) {
542  snprintf(buf, buf_size, "N/A");
543  } else {
544  value_string(buf, buf_size, val * av_q2d(*time_base), unit_second_str);
545  }
546 
547  return buf;
548 }
549 
550 static char *ts_value_string(char *buf, int buf_size, int64_t ts)
551 {
552  if (ts == AV_NOPTS_VALUE) {
553  snprintf(buf, buf_size, "N/A");
554  } else {
555  snprintf(buf, buf_size, "%"PRId64, ts);
556  }
557 
558  return buf;
559 }
560 
561 static char *rational_string(char *buf, int buf_size, const char *sep,
562  const AVRational *rat)
563 {
564  snprintf(buf, buf_size, "%d%s%d", rat->num, sep, rat->den);
565  return buf;
566 }
567 
568 static char *tag_string(char *buf, int buf_size, int tag)
569 {
570  snprintf(buf, buf_size, "0x%04x", tag);
571  return buf;
572 }
573 
574 static char *unknown_string(char *buf, int buf_size, int val)
575 {
576  snprintf(buf, buf_size, "Unknown (%d)", val);
577  return buf;
578 }
579 
580 static void show_packet(AVFormatContext *fmt_ctx, AVPacket *pkt)
581 {
582  char val_str[128];
583  AVStream *st = fmt_ctx->streams[pkt->stream_index];
584 
585  probe_object_header("packet");
586  probe_str("codec_type", media_type_string(st->codecpar->codec_type));
587  probe_int("stream_index", pkt->stream_index);
588  probe_str("pts", ts_value_string(val_str, sizeof(val_str), pkt->pts));
589  probe_str("pts_time", time_value_string(val_str, sizeof(val_str),
590  pkt->pts, &st->time_base));
591  probe_str("dts", ts_value_string(val_str, sizeof(val_str), pkt->dts));
592  probe_str("dts_time", time_value_string(val_str, sizeof(val_str),
593  pkt->dts, &st->time_base));
594  probe_str("duration", ts_value_string(val_str, sizeof(val_str),
595  pkt->duration));
596  probe_str("duration_time", time_value_string(val_str, sizeof(val_str),
597  pkt->duration,
598  &st->time_base));
599  probe_str("size", value_string(val_str, sizeof(val_str),
600  pkt->size, unit_byte_str));
601  probe_int("pos", pkt->pos);
602  probe_str("flags", pkt->flags & AV_PKT_FLAG_KEY ? "K" : "_");
603  probe_object_footer("packet");
604 }
605 
606 static void show_packets(InputFile *ifile)
607 {
608  AVFormatContext *fmt_ctx = ifile->fmt_ctx;
609  AVPacket pkt;
610 
611  av_init_packet(&pkt);
612  probe_array_header("packets", 0);
613  while (!av_read_frame(fmt_ctx, &pkt)) {
614  show_packet(fmt_ctx, &pkt);
615  av_packet_unref(&pkt);
616  }
617  probe_array_footer("packets", 0);
618 }
619 
620 static void show_stream(InputFile *ifile, InputStream *ist)
621 {
622  AVFormatContext *fmt_ctx = ifile->fmt_ctx;
623  AVStream *stream = ist->st;
624  AVCodecParameters *par;
626  const AVCodecDescriptor *codec_desc;
627  const char *profile;
628  char val_str[128];
629  AVRational display_aspect_ratio, *sar = NULL;
630  const AVPixFmtDescriptor *desc;
631  const char *val;
632 
633  probe_object_header("stream");
634 
635  probe_int("index", stream->index);
636 
637  par = stream->codecpar;
638  dec_ctx = ist->dec_ctx;
639  codec_desc = avcodec_descriptor_get(par->codec_id);
640  if (codec_desc) {
641  probe_str("codec_name", codec_desc->name);
642  probe_str("codec_long_name", codec_desc->long_name);
643  } else {
644  probe_str("codec_name", "unknown");
645  }
646 
647  probe_str("codec_type", media_type_string(par->codec_type));
648 
649  /* print AVI/FourCC tag */
650  av_get_codec_tag_string(val_str, sizeof(val_str), par->codec_tag);
651  probe_str("codec_tag_string", val_str);
652  probe_str("codec_tag", tag_string(val_str, sizeof(val_str),
653  par->codec_tag));
654 
655  /* print profile, if there is one */
656  profile = avcodec_profile_name(par->codec_id, par->profile);
657  if (profile)
658  probe_str("profile", profile);
659 
660  switch (par->codec_type) {
661  case AVMEDIA_TYPE_VIDEO:
662  probe_int("width", par->width);
663  probe_int("height", par->height);
664  if (dec_ctx) {
665  probe_int("coded_width", dec_ctx->coded_width);
666  probe_int("coded_height", dec_ctx->coded_height);
667  probe_int("has_b_frames", dec_ctx->has_b_frames);
668  }
669  if (dec_ctx && dec_ctx->sample_aspect_ratio.num)
670  sar = &dec_ctx->sample_aspect_ratio;
671  else if (par->sample_aspect_ratio.num)
672  sar = &par->sample_aspect_ratio;
673  else if (stream->sample_aspect_ratio.num)
674  sar = &stream->sample_aspect_ratio;
675 
676  if (sar) {
677  probe_str("sample_aspect_ratio",
678  rational_string(val_str, sizeof(val_str), ":", sar));
679  av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
680  par->width * sar->num, par->height * sar->den,
681  1024*1024);
682  probe_str("display_aspect_ratio",
683  rational_string(val_str, sizeof(val_str), ":",
684  &display_aspect_ratio));
685  }
686  desc = av_pix_fmt_desc_get(par->format);
687  probe_str("pix_fmt", desc ? desc->name : "unknown");
688  probe_int("level", par->level);
689 
690  val = av_color_range_name(par->color_range);
691  if (!val)
692  val = unknown_string(val_str, sizeof(val_str), par->color_range);
693  probe_str("color_range", val);
694 
695  val = av_color_space_name(par->color_space);
696  if (!val)
697  val = unknown_string(val_str, sizeof(val_str), par->color_space);
698  probe_str("color_space", val);
699 
700  val = av_color_transfer_name(par->color_trc);
701  if (!val)
702  val = unknown_string(val_str, sizeof(val_str), par->color_trc);
703  probe_str("color_trc", val);
704 
706  if (!val)
707  val = unknown_string(val_str, sizeof(val_str), par->color_primaries);
708  probe_str("color_pri", val);
709 
711  if (!val)
712  val = unknown_string(val_str, sizeof(val_str), par->chroma_location);
713  probe_str("chroma_loc", val);
714  break;
715 
716  case AVMEDIA_TYPE_AUDIO:
717  probe_str("sample_rate",
718  value_string(val_str, sizeof(val_str),
719  par->sample_rate,
720  unit_hertz_str));
721  probe_int("channels", par->channels);
722  probe_int("bits_per_sample",
724  break;
725  }
726 
727  if (fmt_ctx->iformat->flags & AVFMT_SHOW_IDS)
728  probe_int("id", stream->id);
729  probe_str("avg_frame_rate",
730  rational_string(val_str, sizeof(val_str), "/",
731  &stream->avg_frame_rate));
732 
733  if (par->bit_rate)
734  probe_str("bit_rate",
735  value_string(val_str, sizeof(val_str),
737  probe_str("time_base",
738  rational_string(val_str, sizeof(val_str), "/",
739  &stream->time_base));
740  probe_str("start_time",
741  time_value_string(val_str, sizeof(val_str),
742  stream->start_time, &stream->time_base));
743  probe_str("duration",
744  time_value_string(val_str, sizeof(val_str),
745  stream->duration, &stream->time_base));
746  if (stream->nb_frames)
747  probe_int("nb_frames", stream->nb_frames);
748 
749  probe_dict(stream->metadata, "tags");
750 
751  if (stream->nb_side_data) {
752  int i, j;
753 
754  probe_object_header("sidedata");
755  for (i = 0; i < stream->nb_side_data; i++) {
756  const AVPacketSideData* sd = &stream->side_data[i];
757  AVStereo3D *stereo;
758 
759  switch (sd->type) {
761  probe_object_header("displaymatrix");
762  probe_array_header("matrix", 1);
763  for (j = 0; j < 9; j++)
764  probe_int(NULL, ((int32_t *)sd->data)[j]);
765  probe_array_footer("matrix", 1);
766  probe_int("rotation",
768  probe_object_footer("displaymatrix");
769  break;
771  stereo = (AVStereo3D *)sd->data;
772  probe_object_header("stereo3d");
773  probe_str("type", av_stereo3d_type_name(stereo->type));
774  probe_int("inverted",
775  !!(stereo->flags & AV_STEREO3D_FLAG_INVERT));
776  probe_object_footer("stereo3d");
777  break;
778  }
779  }
780  probe_object_footer("sidedata");
781  }
782 
783  probe_object_footer("stream");
784 }
785 
786 static void show_format(InputFile *ifile)
787 {
788  AVFormatContext *fmt_ctx = ifile->fmt_ctx;
789  char val_str[128];
790  int64_t size = fmt_ctx->pb ? avio_size(fmt_ctx->pb) : -1;
791 
792  probe_object_header("format");
793  probe_str("filename", fmt_ctx->filename);
794  probe_int("nb_streams", fmt_ctx->nb_streams);
795  probe_str("format_name", fmt_ctx->iformat->name);
796  probe_str("format_long_name", fmt_ctx->iformat->long_name);
797  probe_str("start_time",
798  time_value_string(val_str, sizeof(val_str),
799  fmt_ctx->start_time, &AV_TIME_BASE_Q));
800  probe_str("duration",
801  time_value_string(val_str, sizeof(val_str),
802  fmt_ctx->duration, &AV_TIME_BASE_Q));
803  probe_str("size",
804  size >= 0 ? value_string(val_str, sizeof(val_str),
805  size, unit_byte_str)
806  : "unknown");
807  probe_str("bit_rate",
808  value_string(val_str, sizeof(val_str),
809  fmt_ctx->bit_rate, unit_bit_per_second_str));
810 
811  probe_dict(fmt_ctx->metadata, "tags");
812 
813  probe_object_footer("format");
814 }
815 
816 static int open_input_file(InputFile *ifile, const char *filename)
817 {
818  int err, i;
819  AVFormatContext *fmt_ctx = NULL;
821 
822  if ((err = avformat_open_input(&fmt_ctx, filename,
823  iformat, &format_opts)) < 0) {
824  print_error(filename, err);
825  return err;
826  }
828  av_log(NULL, AV_LOG_ERROR, "Option %s not found.\n", t->key);
830  }
831 
832 
833  /* fill the streams in the format context */
834  if ((err = avformat_find_stream_info(fmt_ctx, NULL)) < 0) {
835  print_error(filename, err);
836  return err;
837  }
838 
839  av_dump_format(fmt_ctx, 0, filename, 0);
840 
841  ifile->streams = av_mallocz_array(fmt_ctx->nb_streams,
842  sizeof(*ifile->streams));
843  if (!ifile->streams)
844  exit(1);
845  ifile->nb_streams = fmt_ctx->nb_streams;
846 
847  /* bind a decoder to each input stream */
848  for (i = 0; i < fmt_ctx->nb_streams; i++) {
849  InputStream *ist = &ifile->streams[i];
850  AVStream *stream = fmt_ctx->streams[i];
851  AVCodec *codec;
852 
853  ist->st = stream;
854 
855  if (stream->codecpar->codec_id == AV_CODEC_ID_PROBE) {
856  fprintf(stderr, "Failed to probe codec for input stream %d\n",
857  stream->index);
858  continue;
859  }
860 
861  codec = avcodec_find_decoder(stream->codecpar->codec_id);
862  if (!codec) {
863  fprintf(stderr,
864  "Unsupported codec with id %d for input stream %d\n",
865  stream->codecpar->codec_id, stream->index);
866  continue;
867  }
868 
869  ist->dec_ctx = avcodec_alloc_context3(codec);
870  if (!ist->dec_ctx)
871  exit(1);
872 
873  err = avcodec_parameters_to_context(ist->dec_ctx, stream->codecpar);
874  if (err < 0)
875  exit(1);
876 
877  err = avcodec_open2(ist->dec_ctx, NULL, NULL);
878  if (err < 0) {
879  fprintf(stderr, "Error while opening codec for input stream %d\n",
880  stream->index);
881  exit(1);
882 
883  }
884  }
885 
886  ifile->fmt_ctx = fmt_ctx;
887  return 0;
888 }
889 
890 static void close_input_file(InputFile *ifile)
891 {
892  int i;
893 
894  /* close decoder for each stream */
895  for (i = 0; i < ifile->nb_streams; i++) {
896  InputStream *ist = &ifile->streams[i];
897 
899  }
900 
901  av_freep(&ifile->streams);
902  ifile->nb_streams = 0;
903 
904  avformat_close_input(&ifile->fmt_ctx);
905 }
906 
907 static int probe_file(const char *filename)
908 {
909  InputFile ifile;
910  int ret, i;
911 
912  ret = open_input_file(&ifile, filename);
913  if (ret < 0)
914  return ret;
915 
916  if (do_show_format)
917  show_format(&ifile);
918 
919  if (do_show_streams) {
920  probe_array_header("streams", 0);
921  for (i = 0; i < ifile.nb_streams; i++)
922  show_stream(&ifile, &ifile.streams[i]);
923  probe_array_footer("streams", 0);
924  }
925 
926  if (do_show_packets)
927  show_packets(&ifile);
928 
929  close_input_file(&ifile);
930  return 0;
931 }
932 
933 static void show_usage(void)
934 {
935  printf("Simple multimedia streams analyzer\n");
936  printf("usage: %s [OPTIONS] [INPUT_FILE]\n", program_name);
937  printf("\n");
938 }
939 
940 static int opt_format(void *optctx, const char *opt, const char *arg)
941 {
942  iformat = av_find_input_format(arg);
943  if (!iformat) {
944  fprintf(stderr, "Unknown input format: %s\n", arg);
945  return AVERROR(EINVAL);
946  }
947  return 0;
948 }
949 
950 static int opt_output_format(void *optctx, const char *opt, const char *arg)
951 {
952 
953  if (!strcmp(arg, "json")) {
960 
963  } else if (!strcmp(arg, "ini")) {
969 
972  } else if (!strcmp(arg, "old")) {
973  octx.print_header = NULL;
976 
978  } else {
979  av_log(NULL, AV_LOG_ERROR, "Unsupported formatter %s\n", arg);
980  return AVERROR(EINVAL);
981  }
982  return 0;
983 }
984 
985 static int opt_show_format_entry(void *optctx, const char *opt, const char *arg)
986 {
987  do_show_format = 1;
989  octx.print_header = NULL;
990  octx.print_footer = NULL;
991  octx.print_array_header = NULL;
992  octx.print_array_footer = NULL;
993  octx.print_object_header = NULL;
994  octx.print_object_footer = NULL;
995 
998  av_dict_set(&fmt_entries_to_show, arg, "", 0);
999  return 0;
1000 }
1001 
1002 static void opt_input_file(void *optctx, const char *arg)
1003 {
1004  if (input_filename) {
1005  fprintf(stderr,
1006  "Argument '%s' provided as input filename, but '%s' was already specified.\n",
1007  arg, input_filename);
1008  exit_program(1);
1009  }
1010  if (!strcmp(arg, "-"))
1011  arg = "pipe:";
1012  input_filename = arg;
1013 }
1014 
1015 void show_help_default(const char *opt, const char *arg)
1016 {
1018  show_usage();
1019  show_help_options(options, "Main options:", 0, 0, 0);
1020  printf("\n");
1022 }
1023 
1024 static int opt_pretty(void *optctx, const char *opt, const char *arg)
1025 {
1026  show_value_unit = 1;
1027  use_value_prefix = 1;
1030  return 0;
1031 }
1032 
1033 static const OptionDef real_options[] = {
1034 #include "cmdutils_common_opts.h"
1035  { "f", HAS_ARG, {.func_arg = opt_format}, "force format", "format" },
1036  { "of", HAS_ARG, {.func_arg = opt_output_format}, "output the document either as ini or json", "output_format" },
1037  { "unit", OPT_BOOL, {&show_value_unit},
1038  "show unit of the displayed values" },
1039  { "prefix", OPT_BOOL, {&use_value_prefix},
1040  "use SI prefixes for the displayed values" },
1041  { "byte_binary_prefix", OPT_BOOL, {&use_byte_value_binary_prefix},
1042  "use binary prefixes for byte units" },
1043  { "sexagesimal", OPT_BOOL, {&use_value_sexagesimal_format},
1044  "use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units" },
1045  { "pretty", 0, {.func_arg = opt_pretty},
1046  "prettify the format of displayed values, make it more human readable" },
1047  { "show_format", OPT_BOOL, {&do_show_format} , "show format/container info" },
1048  { "show_format_entry", HAS_ARG, {.func_arg = opt_show_format_entry},
1049  "show a particular entry from the format/container info", "entry" },
1050  { "show_packets", OPT_BOOL, {&do_show_packets}, "show packets info" },
1051  { "show_streams", OPT_BOOL, {&do_show_streams}, "show streams info" },
1052  { "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {.func_arg = opt_default},
1053  "generic catch all option", "" },
1054  { NULL, },
1055 };
1056 
1057 static int probe_buf_write(void *opaque, uint8_t *buf, int buf_size)
1058 {
1059  printf("%.*s", buf_size, buf);
1060  return 0;
1061 }
1062 
1063 #define AVP_BUFFSIZE 4096
1064 
1065 int main(int argc, char **argv)
1066 {
1067  int ret;
1069 
1070  if (!buffer)
1071  exit(1);
1072 
1074 
1075  options = real_options;
1076  parse_loglevel(argc, argv, options);
1077  av_register_all();
1079  init_opts();
1080 #if CONFIG_AVDEVICE
1082 #endif
1083 
1084  show_banner();
1085 
1088 
1092 
1095 
1096  parse_options(NULL, argc, argv, options, opt_input_file);
1097 
1098  if (!input_filename) {
1099  show_usage();
1100  fprintf(stderr, "You have to specify one input file.\n");
1101  fprintf(stderr,
1102  "Use -h to get full help or, even better, run 'man %s'.\n",
1103  program_name);
1104  exit_program(1);
1105  }
1106 
1107  probe_out = avio_alloc_context(buffer, AVP_BUFFSIZE, 1, NULL, NULL,
1109  if (!probe_out)
1110  exit_program(1);
1111 
1112  probe_header();
1113  ret = probe_file(input_filename);
1114  probe_footer();
1115  avio_flush(probe_out);
1116  av_freep(&probe_out);
1117  av_freep(&buffer);
1118  uninit_opts();
1120 
1121  return ret;
1122 }
static void ini_print_integer(const char *key, int64_t value)
Definition: avprobe.c:216
codec_id is not known (like AV_CODEC_ID_NONE) but lavf should attempt to identify it ...
Definition: avcodec.h:565
enum AVChromaLocation chroma_location
Definition: avcodec.h:3549
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:62
const char * name
Definition: avprobe.c:103
Bytestream IO Context.
Definition: avio.h:104
enum AVColorTransferCharacteristic color_trc
Definition: avcodec.h:3547
#define OPT_EXPERT
Definition: cmdutils.h:144
static char * time_value_string(char *buf, int buf_size, int64_t val, const AVRational *time_base)
Definition: avprobe.c:538
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:297
int size
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1768
static void probe_header(void)
Definition: avprobe.c:432
static void probe_footer(void)
Definition: avprobe.c:439
static void close_input_file(InputFile *ifile)
Definition: avprobe.c:890
#define OPT_VIDEO
Definition: cmdutils.h:146
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:1595
int64_t pos
byte position in stream, -1 if unknown
Definition: avcodec.h:1366
int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
Definition: utils.c:284
const char * desc
Definition: nvenc.c:101
static PrintContext octx
Definition: avprobe.c:125
void show_banner(void)
Print the program banner to stderr.
Definition: cmdutils.c:820
AVRational sample_aspect_ratio
Video only.
Definition: avcodec.h:3535
static void show_format_entry_string(const char *key, const char *value)
Definition: avprobe.c:396
static void probe_group_enter(const char *name, int type)
Definition: avprobe.c:405
This side data should be associated with a video stream and contains Stereoscopic 3D information in f...
Definition: avcodec.h:1260
#define OPT_AUDIO
Definition: cmdutils.h:147
static const char *const binary_unit_prefixes[]
Definition: avprobe.c:70
static void probe_array_header(const char *name, int plain_values)
Definition: avprobe.c:447
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3483
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:770
int num
numerator
Definition: rational.h:44
int index
stream index in AVFormatContext
Definition: avformat.h:706
int size
Definition: avcodec.h:1347
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
void(* print_string)(const char *key, const char *value)
Definition: avprobe.c:121
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
Definition: avcodec.h:1804
static const char * input_filename
Definition: avprobe.c:67
void avdevice_register_all(void)
Initialize libavdevice and register all the input and output devices.
Definition: alldevices.c:41
size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag)
Put a string representing the codec tag codec_tag in buf.
Definition: utils.c:2071
#define FF_ARRAY_ELEMS(a)
AVPacketSideData * side_data
An array of side data that applies to the whole stream (i.e.
Definition: avformat.h:808
static void json_print_integer(const char *key, int64_t value)
Definition: avprobe.c:283
static void ini_print_array_footer(const char *name, int plain_values)
Definition: avprobe.c:187
AVCodec.
Definition: avcodec.h:3120
int64_t nb_elems
Definition: avprobe.c:106
int64_t index
Definition: avprobe.c:105
This struct describes the properties of an encoded stream.
Definition: avcodec.h:3475
static void probe_int(const char *key, int64_t value)
Definition: avprobe.c:477
enum AVColorSpace color_space
Definition: avcodec.h:3548
const char * av_color_space_name(enum AVColorSpace space)
Definition: pixdesc.c:1890
#define log2(x)
Definition: libm.h:111
PrintElement * prefix
Definition: avprobe.c:110
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:202
#define AVFMT_SHOW_IDS
Show format stream IDs numbers.
Definition: avformat.h:414
Format I/O context.
Definition: avformat.h:940
Public dictionary API.
static char buffer[20]
Definition: seek.c:32
void register_exit(void(*cb)(int ret))
Register a program-specific cleanup routine.
Definition: cmdutils.c:89
void log_callback_help(void *ptr, int level, const char *fmt, va_list vl)
Trivial log callback.
Definition: cmdutils.c:82
uint8_t
static void ini_escape_print(const char *s)
Definition: avprobe.c:149
int opt_default(void *optctx, const char *opt, const char *arg)
Fallback for options that are not explicitly handled, these will be parsed through AVOptions...
Definition: cmdutils.c:439
int width
Video only.
Definition: avcodec.h:3525
static char * ts_value_string(char *buf, int buf_size, int64_t ts)
Definition: avprobe.c:550
AVOptions.
int flags
Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS, AVFMT_GENERIC_INDEX, AVFMT_TS_DISCONT, AVFMT_NOBINSEARCH, AVFMT_NOGENSEARCH, AVFMT_NO_BYTE_SEEK.
Definition: avformat.h:543
#define HAS_ARG
Definition: cmdutils.h:142
const char * av_stereo3d_type_name(unsigned int type)
Provide a human-readable name of a given stereo3d type.
Definition: stereo3d.c:57
static int opt_format(void *optctx, const char *opt, const char *arg)
Definition: avprobe.c:940
Stereo 3D type: this structure describes how two videos are packed within a single video surface...
Definition: stereo3d.h:123
const char * av_color_range_name(enum AVColorRange range)
Definition: pixdesc.c:1872
static int opt_show_format_entry(void *optctx, const char *opt, const char *arg)
Definition: avprobe.c:985
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: avcodec.h:1364
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition: avcodec.h:1254
int id
Format-specific stream ID.
Definition: avformat.h:712
static const char *const decimal_unit_prefixes[]
Definition: avprobe.c:71
static void json_escape_print(const char *s)
Definition: avprobe.c:299
int nb_side_data
The number of elements in the AVStream.side_data array.
Definition: avformat.h:812
void init_opts(void)
Initialize the cmdutils option system, in particular allocate the *_opts contexts.
Definition: cmdutils.c:63
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1008
int avcodec_parameters_to_context(AVCodecContext *codec, const AVCodecParameters *par)
Fill the codec context based on the values from the supplied codec parameters.
Definition: utils.c:2885
static double av_q2d(AVRational a)
Convert rational to double.
Definition: rational.h:69
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:38
int nb_streams
Definition: avconv.h:327
void parse_options(void *optctx, int argc, char **argv, const OptionDef *options, void(*parse_arg_function)(void *, const char *))
Definition: cmdutils.c:339
uint32_t tag
Definition: movenc.c:854
int avformat_network_init(void)
Do global initialization of network components.
Definition: utils.c:3100
uint8_t * data
Definition: avcodec.h:1290
const AVClass * avformat_get_class(void)
Get the AVClass for AVFormatContext.
Definition: options.c:153
void parse_loglevel(int argc, char **argv, const OptionDef *options)
Find the &#39;-loglevel&#39; option in the command line args and apply it.
Definition: cmdutils.c:429
void show_help_options(const OptionDef *options, const char *msg, int req_flags, int rej_flags, int alt_flags)
Print help for all options matching specified flags.
Definition: cmdutils.c:135
static void old_print_object_header(const char *name)
Definition: avprobe.c:338
static void show_usage(void)
Definition: avprobe.c:933
const char * name
Definition: pixdesc.h:81
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1378
AVDictionary * format_opts
Definition: cmdutils.c:59
static void probe_dict(AVDictionary *dict, const char *name)
Definition: avprobe.c:489
void av_dump_format(AVFormatContext *ic, int index, const char *url, int is_output)
Print detailed information about the input or output format, such as duration, bitrate, streams, container, programs, metadata, side data, codec and time base.
Definition: dump.c:453
Main libavdevice API header.
static void probe_str(const char *key, const char *value)
Definition: avprobe.c:483
AVIOContext * avio_alloc_context(unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
Allocate and initialize an AVIOContext for buffered I/O.
Definition: aviobuf.c:151
static void json_print_object_footer(const char *name)
Definition: avprobe.c:276
static void ini_print_object_header(const char *name)
Definition: avprobe.c:193
const char * av_chroma_location_name(enum AVChromaLocation location)
Definition: pixdesc.c:1896
static void show_stream(InputFile *ifile, InputStream *ist)
Definition: avprobe.c:620
static const OptionDef real_options[]
Definition: avprobe.c:1033
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:124
AVDictionary * metadata
Metadata that applies to the whole file.
Definition: avformat.h:1148
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
Definition: utils.c:2348
int has_b_frames
Size of the frame reordering buffer in the decoder.
Definition: avcodec.h:1715
int flags
Additional information about the frame packing.
Definition: stereo3d.h:132
static int do_show_format
Definition: avprobe.c:52
#define AVERROR(e)
Definition: error.h:43
static void json_print_array_footer(const char *name, int plain_values)
Definition: avprobe.c:259
static AVDictionary * fmt_entries_to_show
Definition: avprobe.c:53
static int probe_buf_write(void *opaque, uint8_t *buf, int buf_size)
Definition: avprobe.c:1057
static void show_format_entry_integer(const char *key, int64_t value)
Definition: avprobe.c:387
enum AVColorPrimaries color_primaries
Definition: avcodec.h:3546
static char * unknown_string(char *buf, int buf_size, int val)
Definition: avprobe.c:574
static char * tag_string(char *buf, int buf_size, int tag)
Definition: avprobe.c:568
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:175
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3479
enum AVPacketSideDataType type
Definition: avcodec.h:1292
const char * long_name
A more descriptive name for this codec.
Definition: avcodec.h:592
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:781
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1352
const char * av_color_primaries_name(enum AVColorPrimaries primaries)
Definition: pixdesc.c:1878
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:2462
static int nb_fmt_entries_to_show
Definition: avprobe.c:54
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
int bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: avcodec.h:3512
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:996
AVInputFormat * av_find_input_format(const char *short_name)
Find AVInputFormat based on the short name of the input format.
Definition: format.c:162
const char * name
Definition: qsvenc.c:44
void(* print_integer)(const char *key, int64_t value)
Definition: avprobe.c:120
int void avio_flush(AVIOContext *s)
Definition: aviobuf.c:236
static int use_value_sexagesimal_format
Definition: avprobe.c:61
char filename[1024]
input or output filename
Definition: avformat.h:1016
static void ini_print_array_header(const char *name, int plain_values)
Definition: avprobe.c:175
const char * media_type_string(enum AVMediaType media_type)
Get a string describing a media type.
Definition: cmdutils.c:1692
static void avprobe_cleanup(int ret)
Definition: avprobe.c:78
void av_log_set_callback(void(*callback)(void *, int, const char *, va_list))
Set the logging callback.
Definition: log.c:215
#define AVP_BUFFSIZE
Definition: avprobe.c:1063
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition: options.c:136
void(* print_array_footer)(const char *name, int plain_values)
Definition: avprobe.c:116
void show_help_default(const char *opt, const char *arg)
Per-avtool specific help handler.
Definition: avprobe.c:1015
Definition: avprobe.c:99
void(* print_footer)(void)
Definition: avprobe.c:113
int32_t
#define AV_STEREO3D_FLAG_INVERT
Inverted views, Right/Bottom represents the left view.
Definition: stereo3d.h:114
void(* print_object_footer)(const char *name)
Definition: avprobe.c:118
static void probe_array_footer(const char *name, int plain_values)
Definition: avprobe.c:455
static void probe_object_header(const char *name)
Definition: avprobe.c:462
Definition: avprobe.c:98
static const char unit_byte_str[]
Definition: avprobe.c:75
AVDictionary * metadata
Definition: avformat.h:772
const int program_birth_year
program birth year, defined by the program for show_banner()
Definition: avprobe.c:50
enum AVColorRange color_range
Video only.
Definition: avcodec.h:3545
static void opt_input_file(void *optctx, const char *arg)
Definition: avprobe.c:1002
static int opt_pretty(void *optctx, const char *opt, const char *arg)
Definition: avprobe.c:1024
static char * value_string(char *buf, int buf_size, double val, const char *unit)
Definition: avprobe.c:501
static const OptionDef * options
Definition: avprobe.c:64
void exit_program(int ret)
Wraps exit with a program-specific cleanup routine.
Definition: cmdutils.c:94
const char * long_name
Descriptive name for the format, meant to be more human-readable than name.
Definition: avformat.h:536
Stream structure.
Definition: avformat.h:705
int avformat_network_deinit(void)
Undo the initialization done by avformat_network_init.
Definition: utils.c:3112
NULL
Definition: eval.c:55
AVStream * st
Definition: avconv.h:256
enum AVStereo3DType type
How views are packed within the video.
Definition: stereo3d.h:127
PrintElementType
Definition: avprobe.c:97
Libavcodec external API header.
static const char unit_second_str[]
Definition: avprobe.c:73
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer...
Definition: options.c:151
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:247
char * av_strdup(const char *s)
Duplicate the string s.
Definition: mem.c:219
AVIOContext * pb
I/O context.
Definition: avformat.h:982
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:80
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:200
main external API structure.
Definition: avcodec.h:1409
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: utils.c:2029
static void(WINAPI *cond_broadcast)(pthread_cond_t *cond)
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:347
static void show_format(InputFile *ifile)
Definition: avprobe.c:786
static int use_byte_value_binary_prefix
Definition: avprobe.c:60
static void json_print_string(const char *key, const char *value)
Definition: avprobe.c:323
InputStream * streams
Definition: avprobe.c:45
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:68
Replacements for frequently missing libm functions.
static void old_print_string(const char *key, const char *value)
Definition: avprobe.c:376
int coded_height
Definition: avcodec.h:1595
static const char unit_bit_per_second_str[]
Definition: avprobe.c:76
static av_const int av_toupper(int c)
Locale-independent conversion of ASCII characters to uppercase.
Definition: avstring.h:182
int index
Definition: gxfenc.c:72
rational number numerator/denominator
Definition: rational.h:43
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
Definition: opt.h:265
AVCodecContext * dec_ctx
Definition: avconv.h:259
const char * name
Name of the codec described by this descriptor.
Definition: avcodec.h:588
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
Definition: utils.c:850
static void ini_print_string(const char *key, const char *value)
Definition: avprobe.c:229
static void json_print_footer(void)
Definition: avprobe.c:245
static void ini_print_header(void)
Definition: avprobe.c:140
static void json_print_object_header(const char *name)
Definition: avprobe.c:266
void(* print_object_header)(const char *name)
Definition: avprobe.c:117
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
Definition: utils.c:1021
mfxU16 profile
Definition: qsvenc.c:43
This struct describes the properties of a single codec described by an AVCodecID. ...
Definition: avcodec.h:580
int main(int argc, char **argv)
Definition: avprobe.c:1065
static int probe_file(const char *filename)
Definition: avprobe.c:907
static AVIOContext * probe_out
Definition: avprobe.c:124
int64_t start_time
Position of the first frame of the component, in AV_TIME_BASE fractional seconds. ...
Definition: avformat.h:1025
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:757
int sample_rate
Audio only.
Definition: avcodec.h:3564
#define OPT_BOOL
Definition: cmdutils.h:143
static int opt_output_format(void *optctx, const char *opt, const char *arg)
Definition: avprobe.c:950
void(* print_array_header)(const char *name, int plain_values)
Definition: avprobe.c:115
const char program_name[]
program name, defined by the program for show_version().
Definition: avprobe.c:49
Main libavformat public API header.
void print_error(const char *filename, int err)
Print an error message to stderr, indicating filename and a human readable description of the error c...
Definition: cmdutils.c:765
static int do_show_streams
Definition: avprobe.c:56
void(* print_header)(void)
Definition: avprobe.c:112
static void old_print_object_footer(const char *name)
Definition: avprobe.c:357
static void json_print_array_header(const char *name, int plain_values)
Definition: avprobe.c:250
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
Definition: mem.c:117
static AVInputFormat * iformat
Definition: avprobe.c:68
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
Definition: utils.c:2092
int64_t start_time
Decoding: pts of the first frame of the stream, in stream time base.
Definition: avformat.h:750
int profile
Codec-specific bitstream restrictions that the stream conforms to.
Definition: avcodec.h:3519
const char * av_color_transfer_name(enum AVColorTransferCharacteristic transfer)
Definition: pixdesc.c:1884
static void probe_group_leave(void)
Definition: avprobe.c:427
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
Definition: avpacket.c:31
int64_t nb_frames
number of frames in this stream if known or 0
Definition: avformat.h:759
char * key
Definition: dict.h:73
int den
denominator
Definition: rational.h:45
void uninit_opts(void)
Uninitialize the cmdutils option system, in particular free the *_opts contexts and their contents...
Definition: cmdutils.c:71
struct AVInputFormat * iformat
The input container format.
Definition: avformat.h:952
double av_display_rotation_get(const int32_t matrix[9])
The display transformation matrix specifies an affine transformation that should be applied to video ...
Definition: display.c:34
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
Definition: utils.c:2626
static void show_packet(AVFormatContext *fmt_ctx, AVPacket *pkt)
Definition: avprobe.c:580
#define AVP_INDENT()
Definition: avprobe.c:126
static void ini_print_footer(void)
Definition: avprobe.c:144
#define AVERROR_OPTION_NOT_FOUND
Option not found.
Definition: error.h:56
char * value
Definition: dict.h:74
static void json_print_header(void)
Definition: avprobe.c:241
static const char unit_hertz_str[]
Definition: avprobe.c:74
static int show_value_unit
Definition: avprobe.c:58
PrintElementType type
Definition: avprobe.c:104
void show_help_children(const AVClass *class, int flags)
Show help for all options with given flags in class and all its children.
Definition: cmdutils.c:164
int channels
Audio only.
Definition: avcodec.h:3560
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:1345
static void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.h:205
int bit_rate
Total stream bitrate in bit/s, 0 if not available.
Definition: avformat.h:1042
AVFormatContext * fmt_ctx
Definition: avprobe.c:43
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
Definition: avformat.h:1035
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:529
#define AV_DICT_IGNORE_SUFFIX
Definition: dict.h:60
AVCodecParameters * codecpar
Definition: avformat.h:831
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: avcodec.h:3487
static char * rational_string(char *buf, int buf_size, const char *sep, const AVRational *rat)
Definition: avprobe.c:561
static int do_show_packets
Definition: avprobe.c:55
int stream_index
Definition: avcodec.h:1348
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:742
static int use_value_prefix
Definition: avprobe.c:59
static void probe_object_footer(const char *name)
Definition: avprobe.c:470
static void show_packets(InputFile *ifile)
Definition: avprobe.c:606
This structure stores compressed data.
Definition: avcodec.h:1323
void av_register_all(void)
Initialize libavformat and register all the muxers, demuxers and protocols.
Definition: allformats.c:44
const char * avcodec_profile_name(enum AVCodecID codec_id, int profile)
Return a name for the specified profile, if available.
Definition: utils.c:2254
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1339
static int open_input_file(InputFile *ifile, const char *filename)
Definition: avprobe.c:816
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:235
int avio_printf(AVIOContext *s, const char *fmt,...) av_printf_format(2