ffprobe.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007-2010 Stefano Sabatini
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @file
23  * simple media prober based on the FFmpeg libraries
24  */
25 
26 #include "config.h"
27 #include "version.h"
28 
29 #include <string.h>
30 
31 #include "libavformat/avformat.h"
32 #include "libavcodec/avcodec.h"
33 #include "libavutil/avassert.h"
34 #include "libavutil/avstring.h"
35 #include "libavutil/bprint.h"
36 #include "libavutil/opt.h"
37 #include "libavutil/pixdesc.h"
38 #include "libavutil/dict.h"
39 #include "libavutil/libm.h"
40 #include "libavutil/timecode.h"
41 #include "libavdevice/avdevice.h"
42 #include "libswscale/swscale.h"
45 #include "cmdutils.h"
46 
47 const char program_name[] = "ffprobe";
48 const int program_birth_year = 2007;
49 
50 static int do_bitexact = 0;
51 static int do_count_frames = 0;
52 static int do_count_packets = 0;
53 static int do_read_frames = 0;
54 static int do_read_packets = 0;
55 static int do_show_error = 0;
56 static int do_show_format = 0;
57 static int do_show_frames = 0;
58 static int do_show_packets = 0;
59 static int do_show_streams = 0;
61 static int do_show_data = 0;
62 static int do_show_program_version = 0;
63 static int do_show_library_versions = 0;
64 
65 static int show_value_unit = 0;
66 static int use_value_prefix = 0;
69 static int show_private_data = 1;
70 
71 static char *print_format;
72 static char *stream_specifier;
73 
74 /* section structure definition */
75 
76 #define SECTION_MAX_NB_CHILDREN 10
77 
78 struct section {
79  int id; ///< unique id identifying a section
80  const char *name;
81 
82 #define SECTION_FLAG_IS_WRAPPER 1 ///< the section only contains other sections, but has no data at its own level
83 #define SECTION_FLAG_IS_ARRAY 2 ///< the section contains an array of elements of the same type
84 #define SECTION_FLAG_HAS_VARIABLE_FIELDS 4 ///< the section may contain a variable number of fields with variable keys.
85  /// For these sections the element_name field is mandatory.
86  int flags;
87  int children_ids[SECTION_MAX_NB_CHILDREN+1]; ///< list of children section IDS, terminated by -1
88  const char *element_name; ///< name of the contained element, if provided
89  const char *unique_name; ///< unique section name, in case the name is ambiguous
92 };
93 
94 typedef enum {
113 } SectionID;
114 
115 static struct section sections[] = {
116  [SECTION_ID_ERROR] = { SECTION_ID_ERROR, "error", 0, { -1 } },
117  [SECTION_ID_FORMAT] = { SECTION_ID_FORMAT, "format", 0, { SECTION_ID_FORMAT_TAGS, -1 } },
118  [SECTION_ID_FORMAT_TAGS] = { SECTION_ID_FORMAT_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "format_tags" },
120  [SECTION_ID_FRAME] = { SECTION_ID_FRAME, "frame", 0, { SECTION_ID_FRAME_TAGS, -1 } },
121  [SECTION_ID_FRAME_TAGS] = { SECTION_ID_FRAME_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "frame_tags" },
123  [SECTION_ID_LIBRARY_VERSION] = { SECTION_ID_LIBRARY_VERSION, "library_version", 0, { -1 } },
126  [SECTION_ID_PACKET] = { SECTION_ID_PACKET, "packet", 0, { -1 } },
127  [SECTION_ID_PROGRAM_VERSION] = { SECTION_ID_PROGRAM_VERSION, "program_version", 0, { -1 } },
133  [SECTION_ID_STREAM_DISPOSITION] = { SECTION_ID_STREAM_DISPOSITION, "disposition", 0, { -1 }, .unique_name = "stream_disposition" },
134  [SECTION_ID_STREAM_TAGS] = { SECTION_ID_STREAM_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "stream_tags" },
135 };
136 
137 static const OptionDef *options;
138 
139 /* FFprobe context */
140 static const char *input_filename;
142 
143 static const char *const binary_unit_prefixes [] = { "", "Ki", "Mi", "Gi", "Ti", "Pi" };
144 static const char *const decimal_unit_prefixes[] = { "", "K" , "M" , "G" , "T" , "P" };
145 
146 static const char unit_second_str[] = "s" ;
147 static const char unit_hertz_str[] = "Hz" ;
148 static const char unit_byte_str[] = "byte" ;
149 static const char unit_bit_per_second_str[] = "bit/s";
150 
151 static uint64_t *nb_streams_packets;
152 static uint64_t *nb_streams_frames;
153 static int *selected_streams;
154 
155 static void exit_program(void)
156 {
157  int i;
158  for (i = 0; i < FF_ARRAY_ELEMS(sections); i++)
159  av_dict_free(&(sections[i].entries_to_show));
160 }
161 
162 struct unit_value {
163  union { double d; long long int i; } val;
164  const char *unit;
165 };
166 
167 static char *value_string(char *buf, int buf_size, struct unit_value uv)
168 {
169  double vald;
170  long long int vali;
171  int show_float = 0;
172 
173  if (uv.unit == unit_second_str) {
174  vald = uv.val.d;
175  show_float = 1;
176  } else {
177  vald = vali = uv.val.i;
178  }
179 
181  double secs;
182  int hours, mins;
183  secs = vald;
184  mins = (int)secs / 60;
185  secs = secs - mins * 60;
186  hours = mins / 60;
187  mins %= 60;
188  snprintf(buf, buf_size, "%d:%02d:%09.6f", hours, mins, secs);
189  } else {
190  const char *prefix_string = "";
191 
192  if (use_value_prefix && vald > 1) {
193  long long int index;
194 
196  index = (long long int) (log2(vald)) / 10;
197  index = av_clip(index, 0, FF_ARRAY_ELEMS(binary_unit_prefixes) - 1);
198  vald /= exp2(index * 10);
199  prefix_string = binary_unit_prefixes[index];
200  } else {
201  index = (long long int) (log10(vald)) / 3;
202  index = av_clip(index, 0, FF_ARRAY_ELEMS(decimal_unit_prefixes) - 1);
203  vald /= pow(10, index * 3);
204  prefix_string = decimal_unit_prefixes[index];
205  }
206  }
207 
208  if (show_float || (use_value_prefix && vald != (long long int)vald))
209  snprintf(buf, buf_size, "%f", vald);
210  else
211  snprintf(buf, buf_size, "%lld", vali);
212  av_strlcatf(buf, buf_size, "%s%s%s", *prefix_string || show_value_unit ? " " : "",
213  prefix_string, show_value_unit ? uv.unit : "");
214  }
215 
216  return buf;
217 }
218 
219 /* WRITERS API */
220 
222 
223 #define WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS 1
224 #define WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER 2
225 
226 typedef struct Writer {
227  const AVClass *priv_class; ///< private class of the writer, if any
228  int priv_size; ///< private size for the writer context
229  const char *name;
230 
231  int (*init) (WriterContext *wctx);
233 
236  void (*print_integer) (WriterContext *wctx, const char *, long long int);
237  void (*print_rational) (WriterContext *wctx, AVRational *q, char *sep);
238  void (*print_string) (WriterContext *wctx, const char *, const char *);
239  int flags; ///< a combination or WRITER_FLAG_*
240 } Writer;
241 
242 #define SECTION_MAX_NB_LEVELS 10
243 
245  const AVClass *class; ///< class of the writer
246  const Writer *writer; ///< the Writer of which this is an instance
247  char *name; ///< name of this writer instance
248  void *priv; ///< private data for use by the filter
249 
250  const struct section *sections; ///< array containing all sections
251  int nb_sections; ///< number of sections
252 
253  int level; ///< current level, starting from 0
254 
255  /** number of the item printed in the given section, starting from 0 */
256  unsigned int nb_item[SECTION_MAX_NB_LEVELS];
257 
258  /** section per each level */
260  AVBPrint section_pbuf[SECTION_MAX_NB_LEVELS]; ///< generic print buffer dedicated to each section,
261  /// used by various writers
262 
263  unsigned int nb_section_packet; ///< number of the packet section in case we are in "packets_and_frames" section
264  unsigned int nb_section_frame; ///< number of the frame section in case we are in "packets_and_frames" section
265  unsigned int nb_section_packet_frame; ///< nb_section_packet or nb_section_frame according if is_packets_and_frames
266 };
267 
268 static const char *writer_get_name(void *p)
269 {
270  WriterContext *wctx = p;
271  return wctx->writer->name;
272 }
273 
274 static const AVClass writer_class = {
275  "Writer",
277  NULL,
279 };
280 
281 static void writer_close(WriterContext **wctx)
282 {
283  int i;
284 
285  if (!*wctx)
286  return;
287 
288  if ((*wctx)->writer->uninit)
289  (*wctx)->writer->uninit(*wctx);
290  for (i = 0; i < SECTION_MAX_NB_LEVELS; i++)
291  av_bprint_finalize(&(*wctx)->section_pbuf[i], NULL);
292  if ((*wctx)->writer->priv_class)
293  av_opt_free((*wctx)->priv);
294  av_freep(&((*wctx)->priv));
295  av_freep(wctx);
296 }
297 
298 static int writer_open(WriterContext **wctx, const Writer *writer, const char *args,
299  const struct section *sections, int nb_sections)
300 {
301  int i, ret = 0;
302 
303  if (!(*wctx = av_mallocz(sizeof(WriterContext)))) {
304  ret = AVERROR(ENOMEM);
305  goto fail;
306  }
307 
308  if (!((*wctx)->priv = av_mallocz(writer->priv_size))) {
309  ret = AVERROR(ENOMEM);
310  goto fail;
311  }
312 
313  (*wctx)->class = &writer_class;
314  (*wctx)->writer = writer;
315  (*wctx)->level = -1;
316  (*wctx)->sections = sections;
317  (*wctx)->nb_sections = nb_sections;
318 
319  if (writer->priv_class) {
320  void *priv_ctx = (*wctx)->priv;
321  *((const AVClass **)priv_ctx) = writer->priv_class;
322  av_opt_set_defaults(priv_ctx);
323 
324  if (args &&
325  (ret = av_set_options_string(priv_ctx, args, "=", ":")) < 0)
326  goto fail;
327  }
328 
329  for (i = 0; i < SECTION_MAX_NB_LEVELS; i++)
330  av_bprint_init(&(*wctx)->section_pbuf[i], 1, AV_BPRINT_SIZE_UNLIMITED);
331 
332  if ((*wctx)->writer->init)
333  ret = (*wctx)->writer->init(*wctx);
334  if (ret < 0)
335  goto fail;
336 
337  return 0;
338 
339 fail:
340  writer_close(wctx);
341  return ret;
342 }
343 
345  int section_id)
346 {
347  int parent_section_id;
348  wctx->level++;
350  parent_section_id = wctx->level ?
351  (wctx->section[wctx->level-1])->id : SECTION_ID_NONE;
352 
353  wctx->nb_item[wctx->level] = 0;
354  wctx->section[wctx->level] = &wctx->sections[section_id];
355 
356  if (section_id == SECTION_ID_PACKETS_AND_FRAMES) {
357  wctx->nb_section_packet = wctx->nb_section_frame =
358  wctx->nb_section_packet_frame = 0;
359  } else if (parent_section_id == SECTION_ID_PACKETS_AND_FRAMES) {
360  wctx->nb_section_packet_frame = section_id == SECTION_ID_PACKET ?
361  wctx->nb_section_packet : wctx->nb_section_frame;
362  }
363 
364  if (wctx->writer->print_section_header)
365  wctx->writer->print_section_header(wctx);
366 }
367 
369 {
370  int section_id = wctx->section[wctx->level]->id;
371  int parent_section_id = wctx->level ?
372  wctx->section[wctx->level-1]->id : SECTION_ID_NONE;
373 
374  if (parent_section_id != SECTION_ID_NONE)
375  wctx->nb_item[wctx->level-1]++;
376  if (parent_section_id == SECTION_ID_PACKETS_AND_FRAMES) {
377  if (section_id == SECTION_ID_PACKET) wctx->nb_section_packet++;
378  else wctx->nb_section_frame++;
379  }
380  if (wctx->writer->print_section_footer)
381  wctx->writer->print_section_footer(wctx);
382  wctx->level--;
383 }
384 
385 static inline void writer_print_integer(WriterContext *wctx,
386  const char *key, long long int val)
387 {
388  const struct section *section = wctx->section[wctx->level];
389 
390  if (section->show_all_entries || av_dict_get(section->entries_to_show, key, NULL, 0)) {
391  wctx->writer->print_integer(wctx, key, val);
392  wctx->nb_item[wctx->level]++;
393  }
394 }
395 
396 static inline void writer_print_string(WriterContext *wctx,
397  const char *key, const char *val, int opt)
398 {
399  const struct section *section = wctx->section[wctx->level];
400 
401  if (opt && !(wctx->writer->flags & WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS))
402  return;
403 
404  if (section->show_all_entries || av_dict_get(section->entries_to_show, key, NULL, 0)) {
405  wctx->writer->print_string(wctx, key, val);
406  wctx->nb_item[wctx->level]++;
407  }
408 }
409 
410 static inline void writer_print_rational(WriterContext *wctx,
411  const char *key, AVRational q, char sep)
412 {
413  AVBPrint buf;
415  av_bprintf(&buf, "%d%c%d", q.num, sep, q.den);
416  writer_print_string(wctx, key, buf.str, 0);
417 }
418 
419 static void writer_print_time(WriterContext *wctx, const char *key,
420  int64_t ts, const AVRational *time_base, int is_duration)
421 {
422  char buf[128];
423 
424  if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
425  writer_print_string(wctx, key, "N/A", 1);
426  } else {
427  double d = ts * av_q2d(*time_base);
428  struct unit_value uv;
429  uv.val.d = d;
430  uv.unit = unit_second_str;
431  value_string(buf, sizeof(buf), uv);
432  writer_print_string(wctx, key, buf, 0);
433  }
434 }
435 
436 static void writer_print_ts(WriterContext *wctx, const char *key, int64_t ts, int is_duration)
437 {
438  if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
439  writer_print_string(wctx, key, "N/A", 1);
440  } else {
441  writer_print_integer(wctx, key, ts);
442  }
443 }
444 
445 static void writer_print_data(WriterContext *wctx, const char *name,
446  uint8_t *data, int size)
447 {
448  AVBPrint bp;
449  int offset = 0, l, i;
450 
452  av_bprintf(&bp, "\n");
453  while (size) {
454  av_bprintf(&bp, "%08x: ", offset);
455  l = FFMIN(size, 16);
456  for (i = 0; i < l; i++) {
457  av_bprintf(&bp, "%02x", data[i]);
458  if (i & 1)
459  av_bprintf(&bp, " ");
460  }
461  av_bprint_chars(&bp, ' ', 41 - 2 * i - i / 2);
462  for (i = 0; i < l; i++)
463  av_bprint_chars(&bp, data[i] - 32U < 95 ? data[i] : '.', 1);
464  av_bprintf(&bp, "\n");
465  offset += l;
466  data += l;
467  size -= l;
468  }
469  writer_print_string(wctx, name, bp.str, 0);
470  av_bprint_finalize(&bp, NULL);
471 }
472 
473 #define MAX_REGISTERED_WRITERS_NB 64
474 
476 
477 static int writer_register(const Writer *writer)
478 {
479  static int next_registered_writer_idx = 0;
480 
481  if (next_registered_writer_idx == MAX_REGISTERED_WRITERS_NB)
482  return AVERROR(ENOMEM);
483 
484  registered_writers[next_registered_writer_idx++] = writer;
485  return 0;
486 }
487 
488 static const Writer *writer_get_by_name(const char *name)
489 {
490  int i;
491 
492  for (i = 0; registered_writers[i]; i++)
493  if (!strcmp(registered_writers[i]->name, name))
494  return registered_writers[i];
495 
496  return NULL;
497 }
498 
499 
500 /* WRITERS */
501 
502 #define DEFINE_WRITER_CLASS(name) \
503 static const char *name##_get_name(void *ctx) \
504 { \
505  return #name ; \
506 } \
507 static const AVClass name##_class = { \
508  #name, \
509  name##_get_name, \
510  name##_options \
511 }
512 
513 /* Default output */
514 
515 typedef struct DefaultContext {
516  const AVClass *class;
517  int nokey;
519  int nested_section[SECTION_MAX_NB_LEVELS];
521 
522 #define OFFSET(x) offsetof(DefaultContext, x)
523 
524 static const AVOption default_options[] = {
525  { "noprint_wrappers", "do not print headers and footers", OFFSET(noprint_wrappers), AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
526  { "nw", "do not print headers and footers", OFFSET(noprint_wrappers), AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
527  { "nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
528  { "nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
529  {NULL},
530 };
531 
532 DEFINE_WRITER_CLASS(default);
533 
534 /* lame uppercasing routine, assumes the string is lower case ASCII */
535 static inline char *upcase_string(char *dst, size_t dst_size, const char *src)
536 {
537  int i;
538  for (i = 0; src[i] && i < dst_size-1; i++)
539  dst[i] = av_toupper(src[i]);
540  dst[i] = 0;
541  return dst;
542 }
543 
545 {
546  DefaultContext *def = wctx->priv;
547  char buf[32];
548  const struct section *section = wctx->section[wctx->level];
549  const struct section *parent_section = wctx->level ?
550  wctx->section[wctx->level-1] : NULL;
551 
552  av_bprint_clear(&wctx->section_pbuf[wctx->level]);
553  if (parent_section &&
554  !(parent_section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY))) {
555  def->nested_section[wctx->level] = 1;
556  av_bprintf(&wctx->section_pbuf[wctx->level], "%s%s:",
557  wctx->section_pbuf[wctx->level-1].str,
558  upcase_string(buf, sizeof(buf),
559  av_x_if_null(section->element_name, section->name)));
560  }
561 
562  if (def->noprint_wrappers || def->nested_section[wctx->level])
563  return;
564 
566  printf("[%s]\n", upcase_string(buf, sizeof(buf), section->name));
567 }
568 
570 {
571  DefaultContext *def = wctx->priv;
572  const struct section *section = wctx->section[wctx->level];
573  char buf[32];
574 
575  if (def->noprint_wrappers || def->nested_section[wctx->level])
576  return;
577 
579  printf("[/%s]\n", upcase_string(buf, sizeof(buf), section->name));
580 }
581 
582 static void default_print_str(WriterContext *wctx, const char *key, const char *value)
583 {
584  DefaultContext *def = wctx->priv;
585 
586  if (!def->nokey)
587  printf("%s%s=", wctx->section_pbuf[wctx->level].str, key);
588  printf("%s\n", value);
589 }
590 
591 static void default_print_int(WriterContext *wctx, const char *key, long long int value)
592 {
593  DefaultContext *def = wctx->priv;
594 
595  if (!def->nokey)
596  printf("%s%s=", wctx->section_pbuf[wctx->level].str, key);
597  printf("%lld\n", value);
598 }
599 
600 static const Writer default_writer = {
601  .name = "default",
602  .priv_size = sizeof(DefaultContext),
605  .print_integer = default_print_int,
606  .print_string = default_print_str,
608  .priv_class = &default_class,
609 };
610 
611 /* Compact output */
612 
613 /**
614  * Apply C-language-like string escaping.
615  */
616 static const char *c_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
617 {
618  const char *p;
619 
620  for (p = src; *p; p++) {
621  switch (*p) {
622  case '\b': av_bprintf(dst, "%s", "\\b"); break;
623  case '\f': av_bprintf(dst, "%s", "\\f"); break;
624  case '\n': av_bprintf(dst, "%s", "\\n"); break;
625  case '\r': av_bprintf(dst, "%s", "\\r"); break;
626  case '\\': av_bprintf(dst, "%s", "\\\\"); break;
627  default:
628  if (*p == sep)
629  av_bprint_chars(dst, '\\', 1);
630  av_bprint_chars(dst, *p, 1);
631  }
632  }
633  return dst->str;
634 }
635 
636 /**
637  * Quote fields containing special characters, check RFC4180.
638  */
639 static const char *csv_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
640 {
641  char meta_chars[] = { sep, '"', '\n', '\r', '\0' };
642  int needs_quoting = !!src[strcspn(src, meta_chars)];
643 
644  if (needs_quoting)
645  av_bprint_chars(dst, '"', 1);
646 
647  for (; *src; src++) {
648  if (*src == '"')
649  av_bprint_chars(dst, '"', 1);
650  av_bprint_chars(dst, *src, 1);
651  }
652  if (needs_quoting)
653  av_bprint_chars(dst, '"', 1);
654  return dst->str;
655 }
656 
657 static const char *none_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
658 {
659  return src;
660 }
661 
662 typedef struct CompactContext {
663  const AVClass *class;
665  char item_sep;
666  int nokey;
669  const char * (*escape_str)(AVBPrint *dst, const char *src, const char sep, void *log_ctx);
670  int nested_section[SECTION_MAX_NB_LEVELS];
672 
673 #undef OFFSET
674 #define OFFSET(x) offsetof(CompactContext, x)
675 
676 static const AVOption compact_options[]= {
677  {"item_sep", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str="|"}, CHAR_MIN, CHAR_MAX },
678  {"s", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str="|"}, CHAR_MIN, CHAR_MAX },
679  {"nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
680  {"nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
681  {"escape", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="c"}, CHAR_MIN, CHAR_MAX },
682  {"e", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="c"}, CHAR_MIN, CHAR_MAX },
683  {"print_section", "print section name", OFFSET(print_section), AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
684  {"p", "print section name", OFFSET(print_section), AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
685  {NULL},
686 };
687 
688 DEFINE_WRITER_CLASS(compact);
689 
691 {
692  CompactContext *compact = wctx->priv;
693 
694  if (strlen(compact->item_sep_str) != 1) {
695  av_log(wctx, AV_LOG_ERROR, "Item separator '%s' specified, but must contain a single character\n",
696  compact->item_sep_str);
697  return AVERROR(EINVAL);
698  }
699  compact->item_sep = compact->item_sep_str[0];
700 
701  if (!strcmp(compact->escape_mode_str, "none")) compact->escape_str = none_escape_str;
702  else if (!strcmp(compact->escape_mode_str, "c" )) compact->escape_str = c_escape_str;
703  else if (!strcmp(compact->escape_mode_str, "csv" )) compact->escape_str = csv_escape_str;
704  else {
705  av_log(wctx, AV_LOG_ERROR, "Unknown escape mode '%s'\n", compact->escape_mode_str);
706  return AVERROR(EINVAL);
707  }
708 
709  return 0;
710 }
711 
713 {
714  CompactContext *compact = wctx->priv;
715  const struct section *section = wctx->section[wctx->level];
716  const struct section *parent_section = wctx->level ?
717  wctx->section[wctx->level-1] : NULL;
718 
719  av_bprint_clear(&wctx->section_pbuf[wctx->level]);
720  if (parent_section &&
721  !(parent_section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY))) {
722  compact->nested_section[wctx->level] = 1;
723  av_bprintf(&wctx->section_pbuf[wctx->level], "%s%s:",
724  wctx->section_pbuf[wctx->level-1].str,
725  (char *)av_x_if_null(section->element_name, section->name));
726  wctx->nb_item[wctx->level] = wctx->nb_item[wctx->level-1];
727  } else if (compact->print_section &&
729  printf("%s%c", section->name, compact->item_sep);
730 }
731 
733 {
734  CompactContext *compact = wctx->priv;
735 
736  if (!compact->nested_section[wctx->level] &&
738  printf("\n");
739 }
740 
741 static void compact_print_str(WriterContext *wctx, const char *key, const char *value)
742 {
743  CompactContext *compact = wctx->priv;
744  AVBPrint buf;
745 
746  if (wctx->nb_item[wctx->level]) printf("%c", compact->item_sep);
747  if (!compact->nokey)
748  printf("%s%s=", wctx->section_pbuf[wctx->level].str, key);
750  printf("%s", compact->escape_str(&buf, value, compact->item_sep, wctx));
751  av_bprint_finalize(&buf, NULL);
752 }
753 
754 static void compact_print_int(WriterContext *wctx, const char *key, long long int value)
755 {
756  CompactContext *compact = wctx->priv;
757 
758  if (wctx->nb_item[wctx->level]) printf("%c", compact->item_sep);
759  if (!compact->nokey)
760  printf("%s%s=", wctx->section_pbuf[wctx->level].str, key);
761  printf("%lld", value);
762 }
763 
764 static const Writer compact_writer = {
765  .name = "compact",
766  .priv_size = sizeof(CompactContext),
767  .init = compact_init,
770  .print_integer = compact_print_int,
771  .print_string = compact_print_str,
773  .priv_class = &compact_class,
774 };
775 
776 /* CSV output */
777 
778 #undef OFFSET
779 #define OFFSET(x) offsetof(CompactContext, x)
780 
781 static const AVOption csv_options[] = {
782  {"item_sep", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=","}, CHAR_MIN, CHAR_MAX },
783  {"s", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=","}, CHAR_MIN, CHAR_MAX },
784  {"nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
785  {"nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
786  {"escape", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="csv"}, CHAR_MIN, CHAR_MAX },
787  {"e", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="csv"}, CHAR_MIN, CHAR_MAX },
788  {"print_section", "print section name", OFFSET(print_section), AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
789  {"p", "print section name", OFFSET(print_section), AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
790  {NULL},
791 };
792 
794 
795 static const Writer csv_writer = {
796  .name = "csv",
797  .priv_size = sizeof(CompactContext),
798  .init = compact_init,
801  .print_integer = compact_print_int,
802  .print_string = compact_print_str,
804  .priv_class = &csv_class,
805 };
806 
807 /* Flat output */
808 
809 typedef struct FlatContext {
810  const AVClass *class;
811  const char *sep_str;
812  char sep;
814 } FlatContext;
815 
816 #undef OFFSET
817 #define OFFSET(x) offsetof(FlatContext, x)
818 
819 static const AVOption flat_options[]= {
820  {"sep_char", "set separator", OFFSET(sep_str), AV_OPT_TYPE_STRING, {.str="."}, CHAR_MIN, CHAR_MAX },
821  {"s", "set separator", OFFSET(sep_str), AV_OPT_TYPE_STRING, {.str="."}, CHAR_MIN, CHAR_MAX },
822  {"hierarchical", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
823  {"h", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
824  {NULL},
825 };
826 
827 DEFINE_WRITER_CLASS(flat);
828 
829 static av_cold int flat_init(WriterContext *wctx)
830 {
831  FlatContext *flat = wctx->priv;
832 
833  if (strlen(flat->sep_str) != 1) {
834  av_log(wctx, AV_LOG_ERROR, "Item separator '%s' specified, but must contain a single character\n",
835  flat->sep_str);
836  return AVERROR(EINVAL);
837  }
838  flat->sep = flat->sep_str[0];
839 
840  return 0;
841 }
842 
843 static const char *flat_escape_key_str(AVBPrint *dst, const char *src, const char sep)
844 {
845  const char *p;
846 
847  for (p = src; *p; p++) {
848  if (!((*p >= '0' && *p <= '9') ||
849  (*p >= 'a' && *p <= 'z') ||
850  (*p >= 'A' && *p <= 'Z')))
851  av_bprint_chars(dst, '_', 1);
852  else
853  av_bprint_chars(dst, *p, 1);
854  }
855  return dst->str;
856 }
857 
858 static const char *flat_escape_value_str(AVBPrint *dst, const char *src)
859 {
860  const char *p;
861 
862  for (p = src; *p; p++) {
863  switch (*p) {
864  case '\n': av_bprintf(dst, "%s", "\\n"); break;
865  case '\r': av_bprintf(dst, "%s", "\\r"); break;
866  case '\\': av_bprintf(dst, "%s", "\\\\"); break;
867  case '"': av_bprintf(dst, "%s", "\\\""); break;
868  case '`': av_bprintf(dst, "%s", "\\`"); break;
869  case '$': av_bprintf(dst, "%s", "\\$"); break;
870  default: av_bprint_chars(dst, *p, 1); break;
871  }
872  }
873  return dst->str;
874 }
875 
877 {
878  FlatContext *flat = wctx->priv;
879  AVBPrint *buf = &wctx->section_pbuf[wctx->level];
880  const struct section *section = wctx->section[wctx->level];
881  const struct section *parent_section = wctx->level ?
882  wctx->section[wctx->level-1] : NULL;
883 
884  /* build section header */
885  av_bprint_clear(buf);
886  if (!parent_section)
887  return;
888  av_bprintf(buf, "%s", wctx->section_pbuf[wctx->level-1].str);
889 
890  if (flat->hierarchical ||
892  av_bprintf(buf, "%s%s", wctx->section[wctx->level]->name, flat->sep_str);
893 
894  if (parent_section->flags & SECTION_FLAG_IS_ARRAY) {
895  int n = parent_section->id == SECTION_ID_PACKETS_AND_FRAMES ?
896  wctx->nb_section_packet_frame : wctx->nb_item[wctx->level-1];
897  av_bprintf(buf, "%d%s", n, flat->sep_str);
898  }
899  }
900 }
901 
902 static void flat_print_int(WriterContext *wctx, const char *key, long long int value)
903 {
904  printf("%s%s=%lld\n", wctx->section_pbuf[wctx->level].str, key, value);
905 }
906 
907 static void flat_print_str(WriterContext *wctx, const char *key, const char *value)
908 {
909  FlatContext *flat = wctx->priv;
910  AVBPrint buf;
911 
912  printf("%s", wctx->section_pbuf[wctx->level].str);
914  printf("%s=", flat_escape_key_str(&buf, key, flat->sep));
915  av_bprint_clear(&buf);
916  printf("\"%s\"\n", flat_escape_value_str(&buf, value));
917  av_bprint_finalize(&buf, NULL);
918 }
919 
920 static const Writer flat_writer = {
921  .name = "flat",
922  .priv_size = sizeof(FlatContext),
923  .init = flat_init,
925  .print_integer = flat_print_int,
926  .print_string = flat_print_str,
928  .priv_class = &flat_class,
929 };
930 
931 /* INI format output */
932 
933 typedef struct {
934  const AVClass *class;
936 } INIContext;
937 
938 #undef OFFSET
939 #define OFFSET(x) offsetof(INIContext, x)
940 
941 static const AVOption ini_options[] = {
942  {"hierarchical", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
943  {"h", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
944  {NULL},
945 };
946 
948 
949 static char *ini_escape_str(AVBPrint *dst, const char *src)
950 {
951  int i = 0;
952  char c = 0;
953 
954  while (c = src[i++]) {
955  switch (c) {
956  case '\b': av_bprintf(dst, "%s", "\\b"); break;
957  case '\f': av_bprintf(dst, "%s", "\\f"); break;
958  case '\n': av_bprintf(dst, "%s", "\\n"); break;
959  case '\r': av_bprintf(dst, "%s", "\\r"); break;
960  case '\t': av_bprintf(dst, "%s", "\\t"); break;
961  case '\\':
962  case '#' :
963  case '=' :
964  case ':' : av_bprint_chars(dst, '\\', 1);
965  default:
966  if ((unsigned char)c < 32)
967  av_bprintf(dst, "\\x00%02x", c & 0xff);
968  else
969  av_bprint_chars(dst, c, 1);
970  break;
971  }
972  }
973  return dst->str;
974 }
975 
977 {
978  INIContext *ini = wctx->priv;
979  AVBPrint *buf = &wctx->section_pbuf[wctx->level];
980  const struct section *section = wctx->section[wctx->level];
981  const struct section *parent_section = wctx->level ?
982  wctx->section[wctx->level-1] : NULL;
983 
984  av_bprint_clear(buf);
985  if (!parent_section) {
986  printf("# ffprobe output\n\n");
987  return;
988  }
989 
990  if (wctx->nb_item[wctx->level-1])
991  printf("\n");
992 
993  av_bprintf(buf, "%s", wctx->section_pbuf[wctx->level-1].str);
994  if (ini->hierarchical ||
996  av_bprintf(buf, "%s%s", buf->str[0] ? "." : "", wctx->section[wctx->level]->name);
997 
998  if (parent_section->flags & SECTION_FLAG_IS_ARRAY) {
999  int n = parent_section->id == SECTION_ID_PACKETS_AND_FRAMES ?
1000  wctx->nb_section_packet_frame : wctx->nb_item[wctx->level-1];
1001  av_bprintf(buf, ".%d", n);
1002  }
1003  }
1004 
1006  printf("[%s]\n", buf->str);
1007 }
1008 
1009 static void ini_print_str(WriterContext *wctx, const char *key, const char *value)
1010 {
1011  AVBPrint buf;
1012 
1014  printf("%s=", ini_escape_str(&buf, key));
1015  av_bprint_clear(&buf);
1016  printf("%s\n", ini_escape_str(&buf, value));
1017  av_bprint_finalize(&buf, NULL);
1018 }
1019 
1020 static void ini_print_int(WriterContext *wctx, const char *key, long long int value)
1021 {
1022  printf("%s=%lld\n", key, value);
1023 }
1024 
1025 static const Writer ini_writer = {
1026  .name = "ini",
1027  .priv_size = sizeof(INIContext),
1029  .print_integer = ini_print_int,
1030  .print_string = ini_print_str,
1032  .priv_class = &ini_class,
1033 };
1034 
1035 /* JSON output */
1036 
1037 typedef struct {
1038  const AVClass *class;
1040  int compact;
1041  const char *item_sep, *item_start_end;
1042 } JSONContext;
1043 
1044 #undef OFFSET
1045 #define OFFSET(x) offsetof(JSONContext, x)
1046 
1047 static const AVOption json_options[]= {
1048  { "compact", "enable compact output", OFFSET(compact), AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
1049  { "c", "enable compact output", OFFSET(compact), AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
1050  { NULL }
1051 };
1052 
1053 DEFINE_WRITER_CLASS(json);
1054 
1056 {
1057  JSONContext *json = wctx->priv;
1058 
1059  json->item_sep = json->compact ? ", " : ",\n";
1060  json->item_start_end = json->compact ? " " : "\n";
1061 
1062  return 0;
1063 }
1064 
1065 static const char *json_escape_str(AVBPrint *dst, const char *src, void *log_ctx)
1066 {
1067  static const char json_escape[] = {'"', '\\', '\b', '\f', '\n', '\r', '\t', 0};
1068  static const char json_subst[] = {'"', '\\', 'b', 'f', 'n', 'r', 't', 0};
1069  const char *p;
1070 
1071  for (p = src; *p; p++) {
1072  char *s = strchr(json_escape, *p);
1073  if (s) {
1074  av_bprint_chars(dst, '\\', 1);
1075  av_bprint_chars(dst, json_subst[s - json_escape], 1);
1076  } else if ((unsigned char)*p < 32) {
1077  av_bprintf(dst, "\\u00%02x", *p & 0xff);
1078  } else {
1079  av_bprint_chars(dst, *p, 1);
1080  }
1081  }
1082  return dst->str;
1083 }
1084 
1085 #define JSON_INDENT() printf("%*c", json->indent_level * 4, ' ')
1086 
1088 {
1089  JSONContext *json = wctx->priv;
1090  AVBPrint buf;
1091  const struct section *section = wctx->section[wctx->level];
1092  const struct section *parent_section = wctx->level ?
1093  wctx->section[wctx->level-1] : NULL;
1094 
1095  if (wctx->level && wctx->nb_item[wctx->level-1])
1096  printf(",\n");
1097 
1098  if (section->flags & SECTION_FLAG_IS_WRAPPER) {
1099  printf("{\n");
1100  json->indent_level++;
1101  } else {
1103  json_escape_str(&buf, section->name, wctx);
1104  JSON_INDENT();
1105 
1106  json->indent_level++;
1107  if (section->flags & SECTION_FLAG_IS_ARRAY) {
1108  printf("\"%s\": [\n", buf.str);
1109  } else if (parent_section && !(parent_section->flags & SECTION_FLAG_IS_ARRAY)) {
1110  printf("\"%s\": {%s", buf.str, json->item_start_end);
1111  } else {
1112  printf("{%s", json->item_start_end);
1113 
1114  /* this is required so the parser can distinguish between packets and frames */
1115  if (parent_section && parent_section->id == SECTION_ID_PACKETS_AND_FRAMES) {
1116  if (!json->compact)
1117  JSON_INDENT();
1118  printf("\"type\": \"%s\"%s", section->name, json->item_sep);
1119  }
1120  }
1121  av_bprint_finalize(&buf, NULL);
1122  }
1123 }
1124 
1126 {
1127  JSONContext *json = wctx->priv;
1128  const struct section *section = wctx->section[wctx->level];
1129 
1130  if (wctx->level == 0) {
1131  json->indent_level--;
1132  printf("\n}\n");
1133  } else if (section->flags & SECTION_FLAG_IS_ARRAY) {
1134  printf("\n");
1135  json->indent_level--;
1136  JSON_INDENT();
1137  printf("]");
1138  } else {
1139  printf("%s", json->item_start_end);
1140  json->indent_level--;
1141  if (!json->compact)
1142  JSON_INDENT();
1143  printf("}");
1144  }
1145 }
1146 
1147 static inline void json_print_item_str(WriterContext *wctx,
1148  const char *key, const char *value)
1149 {
1150  AVBPrint buf;
1151 
1153  printf("\"%s\":", json_escape_str(&buf, key, wctx));
1154  av_bprint_clear(&buf);
1155  printf(" \"%s\"", json_escape_str(&buf, value, wctx));
1156  av_bprint_finalize(&buf, NULL);
1157 }
1158 
1159 static void json_print_str(WriterContext *wctx, const char *key, const char *value)
1160 {
1161  JSONContext *json = wctx->priv;
1162 
1163  if (wctx->nb_item[wctx->level])
1164  printf("%s", json->item_sep);
1165  if (!json->compact)
1166  JSON_INDENT();
1167  json_print_item_str(wctx, key, value);
1168 }
1169 
1170 static void json_print_int(WriterContext *wctx, const char *key, long long int value)
1171 {
1172  JSONContext *json = wctx->priv;
1173  AVBPrint buf;
1174 
1175  if (wctx->nb_item[wctx->level])
1176  printf("%s", json->item_sep);
1177  if (!json->compact)
1178  JSON_INDENT();
1179 
1181  printf("\"%s\": %lld", json_escape_str(&buf, key, wctx), value);
1182  av_bprint_finalize(&buf, NULL);
1183 }
1184 
1185 static const Writer json_writer = {
1186  .name = "json",
1187  .priv_size = sizeof(JSONContext),
1188  .init = json_init,
1191  .print_integer = json_print_int,
1192  .print_string = json_print_str,
1194  .priv_class = &json_class,
1195 };
1196 
1197 /* XML output */
1198 
1199 typedef struct {
1200  const AVClass *class;
1205 } XMLContext;
1206 
1207 #undef OFFSET
1208 #define OFFSET(x) offsetof(XMLContext, x)
1209 
1210 static const AVOption xml_options[] = {
1211  {"fully_qualified", "specify if the output should be fully qualified", OFFSET(fully_qualified), AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
1212  {"q", "specify if the output should be fully qualified", OFFSET(fully_qualified), AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
1213  {"xsd_strict", "ensure that the output is XSD compliant", OFFSET(xsd_strict), AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
1214  {"x", "ensure that the output is XSD compliant", OFFSET(xsd_strict), AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
1215  {NULL},
1216 };
1217 
1218 DEFINE_WRITER_CLASS(xml);
1219 
1220 static av_cold int xml_init(WriterContext *wctx)
1221 {
1222  XMLContext *xml = wctx->priv;
1223 
1224  if (xml->xsd_strict) {
1225  xml->fully_qualified = 1;
1226 #define CHECK_COMPLIANCE(opt, opt_name) \
1227  if (opt) { \
1228  av_log(wctx, AV_LOG_ERROR, \
1229  "XSD-compliant output selected but option '%s' was selected, XML output may be non-compliant.\n" \
1230  "You need to disable such option with '-no%s'\n", opt_name, opt_name); \
1231  return AVERROR(EINVAL); \
1232  }
1233  CHECK_COMPLIANCE(show_private_data, "private");
1236 
1238  av_log(wctx, AV_LOG_ERROR,
1239  "Interleaved frames and packets are not allowed in XSD. "
1240  "Select only one between the -show_frames and the -show_packets options.\n");
1241  return AVERROR(EINVAL);
1242  }
1243  }
1244 
1245  return 0;
1246 }
1247 
1248 static const char *xml_escape_str(AVBPrint *dst, const char *src, void *log_ctx)
1249 {
1250  const char *p;
1251 
1252  for (p = src; *p; p++) {
1253  switch (*p) {
1254  case '&' : av_bprintf(dst, "%s", "&amp;"); break;
1255  case '<' : av_bprintf(dst, "%s", "&lt;"); break;
1256  case '>' : av_bprintf(dst, "%s", "&gt;"); break;
1257  case '"' : av_bprintf(dst, "%s", "&quot;"); break;
1258  case '\'': av_bprintf(dst, "%s", "&apos;"); break;
1259  default: av_bprint_chars(dst, *p, 1);
1260  }
1261  }
1262 
1263  return dst->str;
1264 }
1265 
1266 #define XML_INDENT() printf("%*c", xml->indent_level * 4, ' ')
1267 
1269 {
1270  XMLContext *xml = wctx->priv;
1271  const struct section *section = wctx->section[wctx->level];
1272  const struct section *parent_section = wctx->level ?
1273  wctx->section[wctx->level-1] : NULL;
1274 
1275  if (wctx->level == 0) {
1276  const char *qual = " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' "
1277  "xmlns:ffprobe='http://www.ffmpeg.org/schema/ffprobe' "
1278  "xsi:schemaLocation='http://www.ffmpeg.org/schema/ffprobe ffprobe.xsd'";
1279 
1280  printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
1281  printf("<%sffprobe%s>\n",
1282  xml->fully_qualified ? "ffprobe:" : "",
1283  xml->fully_qualified ? qual : "");
1284  return;
1285  }
1286 
1287  if (xml->within_tag) {
1288  xml->within_tag = 0;
1289  printf(">\n");
1290  }
1291  if (section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS) {
1292  xml->indent_level++;
1293  } else {
1294  if (parent_section && (parent_section->flags & SECTION_FLAG_IS_WRAPPER) &&
1295  wctx->level && wctx->nb_item[wctx->level-1])
1296  printf("\n");
1297  xml->indent_level++;
1298 
1299  if (section->flags & SECTION_FLAG_IS_ARRAY) {
1300  XML_INDENT(); printf("<%s>\n", section->name);
1301  } else {
1302  XML_INDENT(); printf("<%s ", section->name);
1303  xml->within_tag = 1;
1304  }
1305  }
1306 }
1307 
1309 {
1310  XMLContext *xml = wctx->priv;
1311  const struct section *section = wctx->section[wctx->level];
1312 
1313  if (wctx->level == 0) {
1314  printf("</%sffprobe>\n", xml->fully_qualified ? "ffprobe:" : "");
1315  } else if (xml->within_tag) {
1316  xml->within_tag = 0;
1317  printf("/>\n");
1318  xml->indent_level--;
1319  } else if (section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS) {
1320  xml->indent_level--;
1321  } else {
1322  XML_INDENT(); printf("</%s>\n", section->name);
1323  xml->indent_level--;
1324  }
1325 }
1326 
1327 static void xml_print_str(WriterContext *wctx, const char *key, const char *value)
1328 {
1329  AVBPrint buf;
1330  XMLContext *xml = wctx->priv;
1331  const struct section *section = wctx->section[wctx->level];
1332 
1334 
1335  if (section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS) {
1336  XML_INDENT();
1337  printf("<%s key=\"%s\"",
1338  section->element_name, xml_escape_str(&buf, key, wctx));
1339  av_bprint_clear(&buf);
1340  printf(" value=\"%s\"/>\n", xml_escape_str(&buf, value, wctx));
1341  } else {
1342  if (wctx->nb_item[wctx->level])
1343  printf(" ");
1344  printf("%s=\"%s\"", key, xml_escape_str(&buf, value, wctx));
1345  }
1346 
1347  av_bprint_finalize(&buf, NULL);
1348 }
1349 
1350 static void xml_print_int(WriterContext *wctx, const char *key, long long int value)
1351 {
1352  if (wctx->nb_item[wctx->level])
1353  printf(" ");
1354  printf("%s=\"%lld\"", key, value);
1355 }
1356 
1357 static Writer xml_writer = {
1358  .name = "xml",
1359  .priv_size = sizeof(XMLContext),
1360  .init = xml_init,
1363  .print_integer = xml_print_int,
1364  .print_string = xml_print_str,
1366  .priv_class = &xml_class,
1367 };
1368 
1369 static void writer_register_all(void)
1370 {
1371  static int initialized;
1372 
1373  if (initialized)
1374  return;
1375  initialized = 1;
1376 
1377  writer_register(&default_writer);
1378  writer_register(&compact_writer);
1379  writer_register(&csv_writer);
1380  writer_register(&flat_writer);
1381  writer_register(&ini_writer);
1382  writer_register(&json_writer);
1383  writer_register(&xml_writer);
1384 }
1385 
1386 #define print_fmt(k, f, ...) do { \
1387  av_bprint_clear(&pbuf); \
1388  av_bprintf(&pbuf, f, __VA_ARGS__); \
1389  writer_print_string(w, k, pbuf.str, 0); \
1390 } while (0)
1391 
1392 #define print_int(k, v) writer_print_integer(w, k, v)
1393 #define print_q(k, v, s) writer_print_rational(w, k, v, s)
1394 #define print_str(k, v) writer_print_string(w, k, v, 0)
1395 #define print_str_opt(k, v) writer_print_string(w, k, v, 1)
1396 #define print_time(k, v, tb) writer_print_time(w, k, v, tb, 0)
1397 #define print_ts(k, v) writer_print_ts(w, k, v, 0)
1398 #define print_duration_time(k, v, tb) writer_print_time(w, k, v, tb, 1)
1399 #define print_duration_ts(k, v) writer_print_ts(w, k, v, 1)
1400 #define print_val(k, v, u) do { \
1401  struct unit_value uv; \
1402  uv.val.i = v; \
1403  uv.unit = u; \
1404  writer_print_string(w, k, value_string(val_str, sizeof(val_str), uv), 0); \
1405 } while (0)
1406 
1407 #define print_section_header(s) writer_print_section_header(w, s)
1408 #define print_section_footer(s) writer_print_section_footer(w, s)
1409 
1410 static inline void show_tags(WriterContext *wctx, AVDictionary *tags, int section_id)
1411 {
1413 
1414  if (!tags)
1415  return;
1416  writer_print_section_header(wctx, section_id);
1417  while ((tag = av_dict_get(tags, "", tag, AV_DICT_IGNORE_SUFFIX)))
1418  writer_print_string(wctx, tag->key, tag->value, 0);
1420 }
1421 
1422 static void show_packet(WriterContext *w, AVFormatContext *fmt_ctx, AVPacket *pkt, int packet_idx)
1423 {
1424  char val_str[128];
1425  AVStream *st = fmt_ctx->streams[pkt->stream_index];
1426  AVBPrint pbuf;
1427  const char *s;
1428 
1430 
1432 
1434  if (s) print_str ("codec_type", s);
1435  else print_str_opt("codec_type", "unknown");
1436  print_int("stream_index", pkt->stream_index);
1437  print_ts ("pts", pkt->pts);
1438  print_time("pts_time", pkt->pts, &st->time_base);
1439  print_ts ("dts", pkt->dts);
1440  print_time("dts_time", pkt->dts, &st->time_base);
1441  print_duration_ts("duration", pkt->duration);
1442  print_duration_time("duration_time", pkt->duration, &st->time_base);
1443  print_duration_ts("convergence_duration", pkt->convergence_duration);
1444  print_duration_time("convergence_duration_time", pkt->convergence_duration, &st->time_base);
1445  print_val("size", pkt->size, unit_byte_str);
1446  if (pkt->pos != -1) print_fmt ("pos", "%"PRId64, pkt->pos);
1447  else print_str_opt("pos", "N/A");
1448  print_fmt("flags", "%c", pkt->flags & AV_PKT_FLAG_KEY ? 'K' : '_');
1449  if (do_show_data)
1450  writer_print_data(w, "data", pkt->data, pkt->size);
1452 
1453  av_bprint_finalize(&pbuf, NULL);
1454  fflush(stdout);
1455 }
1456 
1459 {
1460  AVBPrint pbuf;
1461  const char *s;
1462 
1464 
1466 
1468  if (s) print_str ("media_type", s);
1469  else print_str_opt("media_type", "unknown");
1470  print_int("key_frame", frame->key_frame);
1471  print_ts ("pkt_pts", frame->pkt_pts);
1472  print_time("pkt_pts_time", frame->pkt_pts, &stream->time_base);
1473  print_ts ("pkt_dts", frame->pkt_dts);
1474  print_time("pkt_dts_time", frame->pkt_dts, &stream->time_base);
1475  print_duration_ts ("pkt_duration", av_frame_get_pkt_duration(frame));
1476  print_duration_time("pkt_duration_time", av_frame_get_pkt_duration(frame), &stream->time_base);
1477  if (av_frame_get_pkt_pos (frame) != -1) print_fmt ("pkt_pos", "%"PRId64, av_frame_get_pkt_pos(frame));
1478  else print_str_opt("pkt_pos", "N/A");
1479  if (av_frame_get_pkt_size(frame) != -1) print_fmt ("pkt_size", "%d", av_frame_get_pkt_size(frame));
1480  else print_str_opt("pkt_size", "N/A");
1481 
1482  switch (stream->codec->codec_type) {
1483  AVRational sar;
1484 
1485  case AVMEDIA_TYPE_VIDEO:
1486  print_int("width", frame->width);
1487  print_int("height", frame->height);
1488  s = av_get_pix_fmt_name(frame->format);
1489  if (s) print_str ("pix_fmt", s);
1490  else print_str_opt("pix_fmt", "unknown");
1491  sar = av_guess_sample_aspect_ratio(fmt_ctx, stream, frame);
1492  if (sar.num) {
1493  print_q("sample_aspect_ratio", sar, ':');
1494  } else {
1495  print_str_opt("sample_aspect_ratio", "N/A");
1496  }
1497  print_fmt("pict_type", "%c", av_get_picture_type_char(frame->pict_type));
1498  print_int("coded_picture_number", frame->coded_picture_number);
1499  print_int("display_picture_number", frame->display_picture_number);
1500  print_int("interlaced_frame", frame->interlaced_frame);
1501  print_int("top_field_first", frame->top_field_first);
1502  print_int("repeat_pict", frame->repeat_pict);
1503  break;
1504 
1505  case AVMEDIA_TYPE_AUDIO:
1506  s = av_get_sample_fmt_name(frame->format);
1507  if (s) print_str ("sample_fmt", s);
1508  else print_str_opt("sample_fmt", "unknown");
1509  print_int("nb_samples", frame->nb_samples);
1510  print_int("channels", av_frame_get_channels(frame));
1511  if (av_frame_get_channel_layout(frame)) {
1512  av_bprint_clear(&pbuf);
1515  print_str ("channel_layout", pbuf.str);
1516  } else
1517  print_str_opt("channel_layout", "unknown");
1518  break;
1519  }
1521 
1523 
1524  av_bprint_finalize(&pbuf, NULL);
1525  fflush(stdout);
1526 }
1527 
1531 {
1532  AVCodecContext *dec_ctx = fmt_ctx->streams[pkt->stream_index]->codec;
1533  int ret = 0, got_frame = 0;
1534 
1536  if (dec_ctx->codec) {
1537  switch (dec_ctx->codec_type) {
1538  case AVMEDIA_TYPE_VIDEO:
1539  ret = avcodec_decode_video2(dec_ctx, frame, &got_frame, pkt);
1540  break;
1541 
1542  case AVMEDIA_TYPE_AUDIO:
1543  ret = avcodec_decode_audio4(dec_ctx, frame, &got_frame, pkt);
1544  break;
1545  }
1546  }
1547 
1548  if (ret < 0)
1549  return ret;
1550  ret = FFMIN(ret, pkt->size); /* guard against bogus return values */
1551  pkt->data += ret;
1552  pkt->size -= ret;
1553  if (got_frame) {
1555  if (do_show_frames)
1556  show_frame(w, frame, fmt_ctx->streams[pkt->stream_index], fmt_ctx);
1557  }
1558  return got_frame;
1559 }
1560 
1562 {
1563  AVPacket pkt, pkt1;
1564  AVFrame frame;
1565  int i = 0;
1566 
1567  av_init_packet(&pkt);
1568 
1569  while (!av_read_frame(fmt_ctx, &pkt)) {
1570  if (selected_streams[pkt.stream_index]) {
1571  if (do_read_packets) {
1572  if (do_show_packets)
1573  show_packet(w, fmt_ctx, &pkt, i++);
1575  }
1576  if (do_read_frames) {
1577  pkt1 = pkt;
1578  while (pkt1.size && process_frame(w, fmt_ctx, &frame, &pkt1) > 0);
1579  }
1580  }
1581  av_free_packet(&pkt);
1582  }
1583  av_init_packet(&pkt);
1584  pkt.data = NULL;
1585  pkt.size = 0;
1586  //Flush remaining frames that are cached in the decoder
1587  for (i = 0; i < fmt_ctx->nb_streams; i++) {
1588  pkt.stream_index = i;
1589  if (do_read_frames)
1590  while (process_frame(w, fmt_ctx, &frame, &pkt) > 0);
1591  }
1592 }
1593 
1594 static void show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_idx)
1595 {
1596  AVStream *stream = fmt_ctx->streams[stream_idx];
1598  const AVCodec *dec;
1599  char val_str[128];
1600  const char *s;
1601  AVRational sar, dar;
1602  AVBPrint pbuf;
1603 
1605 
1607 
1608  print_int("index", stream->index);
1609 
1610  if ((dec_ctx = stream->codec)) {
1611  const char *profile = NULL;
1612  dec = dec_ctx->codec;
1613  if (dec) {
1614  print_str("codec_name", dec->name);
1615  if (!do_bitexact) {
1616  if (dec->long_name) print_str ("codec_long_name", dec->long_name);
1617  else print_str_opt("codec_long_name", "unknown");
1618  }
1619  } else {
1620  print_str_opt("codec_name", "unknown");
1621  if (!do_bitexact) {
1622  print_str_opt("codec_long_name", "unknown");
1623  }
1624  }
1625 
1626  if (dec && (profile = av_get_profile_name(dec, dec_ctx->profile)))
1627  print_str("profile", profile);
1628  else
1629  print_str_opt("profile", "unknown");
1630 
1631  s = av_get_media_type_string(dec_ctx->codec_type);
1632  if (s) print_str ("codec_type", s);
1633  else print_str_opt("codec_type", "unknown");
1634  print_q("codec_time_base", dec_ctx->time_base, '/');
1635 
1636  /* print AVI/FourCC tag */
1637  av_get_codec_tag_string(val_str, sizeof(val_str), dec_ctx->codec_tag);
1638  print_str("codec_tag_string", val_str);
1639  print_fmt("codec_tag", "0x%04x", dec_ctx->codec_tag);
1640 
1641  switch (dec_ctx->codec_type) {
1642  case AVMEDIA_TYPE_VIDEO:
1643  print_int("width", dec_ctx->width);
1644  print_int("height", dec_ctx->height);
1645  print_int("has_b_frames", dec_ctx->has_b_frames);
1646  sar = av_guess_sample_aspect_ratio(fmt_ctx, stream, NULL);
1647  if (sar.den) {
1648  print_q("sample_aspect_ratio", sar, ':');
1649  av_reduce(&dar.num, &dar.den,
1650  dec_ctx->width * sar.num,
1651  dec_ctx->height * sar.den,
1652  1024*1024);
1653  print_q("display_aspect_ratio", dar, ':');
1654  } else {
1655  print_str_opt("sample_aspect_ratio", "N/A");
1656  print_str_opt("display_aspect_ratio", "N/A");
1657  }
1658  s = av_get_pix_fmt_name(dec_ctx->pix_fmt);
1659  if (s) print_str ("pix_fmt", s);
1660  else print_str_opt("pix_fmt", "unknown");
1661  print_int("level", dec_ctx->level);
1662  if (dec_ctx->timecode_frame_start >= 0) {
1663  char tcbuf[AV_TIMECODE_STR_SIZE];
1665  print_str("timecode", tcbuf);
1666  } else {
1667  print_str_opt("timecode", "N/A");
1668  }
1669  break;
1670 
1671  case AVMEDIA_TYPE_AUDIO:
1672  s = av_get_sample_fmt_name(dec_ctx->sample_fmt);
1673  if (s) print_str ("sample_fmt", s);
1674  else print_str_opt("sample_fmt", "unknown");
1675  print_val("sample_rate", dec_ctx->sample_rate, unit_hertz_str);
1676  print_int("channels", dec_ctx->channels);
1677  print_int("bits_per_sample", av_get_bits_per_sample(dec_ctx->codec_id));
1678  break;
1679  }
1680  } else {
1681  print_str_opt("codec_type", "unknown");
1682  }
1683  if (dec_ctx->codec && dec_ctx->codec->priv_class && show_private_data) {
1684  const AVOption *opt = NULL;
1685  while (opt = av_opt_next(dec_ctx->priv_data,opt)) {
1686  uint8_t *str;
1687  if (opt->flags) continue;
1688  if (av_opt_get(dec_ctx->priv_data, opt->name, 0, &str) >= 0) {
1689  print_str(opt->name, str);
1690  av_free(str);
1691  }
1692  }
1693  }
1694 
1695  if (fmt_ctx->iformat->flags & AVFMT_SHOW_IDS) print_fmt ("id", "0x%x", stream->id);
1696  else print_str_opt("id", "N/A");
1697  print_q("r_frame_rate", stream->r_frame_rate, '/');
1698  print_q("avg_frame_rate", stream->avg_frame_rate, '/');
1699  print_q("time_base", stream->time_base, '/');
1700  print_ts ("start_pts", stream->start_time);
1701  print_time("start_time", stream->start_time, &stream->time_base);
1702  print_ts ("duration_ts", stream->duration);
1703  print_time("duration", stream->duration, &stream->time_base);
1704  if (dec_ctx->bit_rate > 0) print_val ("bit_rate", dec_ctx->bit_rate, unit_bit_per_second_str);
1705  else print_str_opt("bit_rate", "N/A");
1706  if (stream->nb_frames) print_fmt ("nb_frames", "%"PRId64, stream->nb_frames);
1707  else print_str_opt("nb_frames", "N/A");
1708  if (nb_streams_frames[stream_idx]) print_fmt ("nb_read_frames", "%"PRIu64, nb_streams_frames[stream_idx]);
1709  else print_str_opt("nb_read_frames", "N/A");
1710  if (nb_streams_packets[stream_idx]) print_fmt ("nb_read_packets", "%"PRIu64, nb_streams_packets[stream_idx]);
1711  else print_str_opt("nb_read_packets", "N/A");
1712  if (do_show_data)
1713  writer_print_data(w, "extradata", dec_ctx->extradata,
1714  dec_ctx->extradata_size);
1715 
1716  /* Print disposition information */
1717 #define PRINT_DISPOSITION(flagname, name) do { \
1718  print_int(name, !!(stream->disposition & AV_DISPOSITION_##flagname)); \
1719  } while (0)
1720 
1723  PRINT_DISPOSITION(DEFAULT, "default");
1724  PRINT_DISPOSITION(DUB, "dub");
1725  PRINT_DISPOSITION(ORIGINAL, "original");
1726  PRINT_DISPOSITION(COMMENT, "comment");
1727  PRINT_DISPOSITION(LYRICS, "lyrics");
1728  PRINT_DISPOSITION(KARAOKE, "karaoke");
1729  PRINT_DISPOSITION(FORCED, "forced");
1730  PRINT_DISPOSITION(HEARING_IMPAIRED, "hearing_impaired");
1731  PRINT_DISPOSITION(VISUAL_IMPAIRED, "visual_impaired");
1732  PRINT_DISPOSITION(CLEAN_EFFECTS, "clean_effects");
1733  PRINT_DISPOSITION(ATTACHED_PIC, "attached_pic");
1735  }
1736 
1738 
1740  av_bprint_finalize(&pbuf, NULL);
1741  fflush(stdout);
1742 }
1743 
1745 {
1746  int i;
1748  for (i = 0; i < fmt_ctx->nb_streams; i++)
1749  if (selected_streams[i])
1750  show_stream(w, fmt_ctx, i);
1752 }
1753 
1755 {
1756  char val_str[128];
1757  int64_t size = fmt_ctx->pb ? avio_size(fmt_ctx->pb) : -1;
1758 
1760  print_str("filename", fmt_ctx->filename);
1761  print_int("nb_streams", fmt_ctx->nb_streams);
1762  print_str("format_name", fmt_ctx->iformat->name);
1763  if (!do_bitexact) {
1764  if (fmt_ctx->iformat->long_name) print_str ("format_long_name", fmt_ctx->iformat->long_name);
1765  else print_str_opt("format_long_name", "unknown");
1766  }
1767  print_time("start_time", fmt_ctx->start_time, &AV_TIME_BASE_Q);
1768  print_time("duration", fmt_ctx->duration, &AV_TIME_BASE_Q);
1769  if (size >= 0) print_val ("size", size, unit_byte_str);
1770  else print_str_opt("size", "N/A");
1771  if (fmt_ctx->bit_rate > 0) print_val ("bit_rate", fmt_ctx->bit_rate, unit_bit_per_second_str);
1772  else print_str_opt("bit_rate", "N/A");
1774 
1776  fflush(stdout);
1777 }
1778 
1779 static void show_error(WriterContext *w, int err)
1780 {
1781  char errbuf[128];
1782  const char *errbuf_ptr = errbuf;
1783 
1784  if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)
1785  errbuf_ptr = strerror(AVUNERROR(err));
1786 
1788  print_int("code", err);
1789  print_str("string", errbuf_ptr);
1791 }
1792 
1793 static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename)
1794 {
1795  int err, i, orig_nb_streams;
1798  AVDictionary **opts;
1799 
1800  if ((err = avformat_open_input(&fmt_ctx, filename,
1801  iformat, &format_opts)) < 0) {
1802  print_error(filename, err);
1803  return err;
1804  }
1806  av_log(NULL, AV_LOG_ERROR, "Option %s not found.\n", t->key);
1807  return AVERROR_OPTION_NOT_FOUND;
1808  }
1809 
1810  /* fill the streams in the format context */
1811  opts = setup_find_stream_info_opts(fmt_ctx, codec_opts);
1812  orig_nb_streams = fmt_ctx->nb_streams;
1813 
1814  if ((err = avformat_find_stream_info(fmt_ctx, opts)) < 0) {
1815  print_error(filename, err);
1816  return err;
1817  }
1818  for (i = 0; i < orig_nb_streams; i++)
1819  av_dict_free(&opts[i]);
1820  av_freep(&opts);
1821 
1822  av_dump_format(fmt_ctx, 0, filename, 0);
1823 
1824  /* bind a decoder to each input stream */
1825  for (i = 0; i < fmt_ctx->nb_streams; i++) {
1826  AVStream *stream = fmt_ctx->streams[i];
1827  AVCodec *codec;
1828 
1829  if (stream->codec->codec_id == AV_CODEC_ID_PROBE) {
1831  "Failed to probe codec for input stream %d\n",
1832  stream->index);
1833  } else if (!(codec = avcodec_find_decoder(stream->codec->codec_id))) {
1835  "Unsupported codec with id %d for input stream %d\n",
1836  stream->codec->codec_id, stream->index);
1837  } else {
1839  fmt_ctx, stream, codec);
1840  if (avcodec_open2(stream->codec, codec, &opts) < 0) {
1841  av_log(NULL, AV_LOG_ERROR, "Error while opening codec for input stream %d\n",
1842  stream->index);
1843  }
1844  if ((t = av_dict_get(opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
1845  av_log(NULL, AV_LOG_ERROR, "Option %s for input stream %d not found\n",
1846  t->key, stream->index);
1847  return AVERROR_OPTION_NOT_FOUND;
1848  }
1849  }
1850  }
1851 
1852  *fmt_ctx_ptr = fmt_ctx;
1853  return 0;
1854 }
1855 
1856 static void close_input_file(AVFormatContext **ctx_ptr)
1857 {
1858  int i;
1859  AVFormatContext *fmt_ctx = *ctx_ptr;
1860 
1861  /* close decoder for each stream */
1862  for (i = 0; i < fmt_ctx->nb_streams; i++)
1863  if (fmt_ctx->streams[i]->codec->codec_id != AV_CODEC_ID_NONE)
1864  avcodec_close(fmt_ctx->streams[i]->codec);
1865 
1866  avformat_close_input(ctx_ptr);
1867 }
1868 
1869 static int probe_file(WriterContext *wctx, const char *filename)
1870 {
1872  int ret, i;
1873  int section_id;
1874 
1877 
1878  ret = open_input_file(&fmt_ctx, filename);
1879  if (ret >= 0) {
1882  selected_streams = av_calloc(fmt_ctx->nb_streams, sizeof(*selected_streams));
1883 
1884  for (i = 0; i < fmt_ctx->nb_streams; i++) {
1885  if (stream_specifier) {
1886  ret = avformat_match_stream_specifier(fmt_ctx,
1887  fmt_ctx->streams[i],
1889  if (ret < 0)
1890  goto end;
1891  else
1892  selected_streams[i] = ret;
1893  } else {
1894  selected_streams[i] = 1;
1895  }
1896  }
1897 
1901  section_id = SECTION_ID_PACKETS_AND_FRAMES;
1902  else if (do_show_packets && !do_show_frames)
1903  section_id = SECTION_ID_PACKETS;
1904  else // (!do_show_packets && do_show_frames)
1905  section_id = SECTION_ID_FRAMES;
1907  writer_print_section_header(wctx, section_id);
1908  read_packets(wctx, fmt_ctx);
1911  }
1912  if (do_show_streams)
1913  show_streams(wctx, fmt_ctx);
1914  if (do_show_format)
1915  show_format(wctx, fmt_ctx);
1916 
1917  end:
1918  close_input_file(&fmt_ctx);
1922  }
1923  return ret;
1924 }
1925 
1926 static void show_usage(void)
1927 {
1928  av_log(NULL, AV_LOG_INFO, "Simple multimedia streams analyzer\n");
1929  av_log(NULL, AV_LOG_INFO, "usage: %s [OPTIONS] [INPUT_FILE]\n", program_name);
1930  av_log(NULL, AV_LOG_INFO, "\n");
1931 }
1932 
1934 {
1935  AVBPrint pbuf;
1937 
1939  print_str("version", FFMPEG_VERSION);
1940  print_fmt("copyright", "Copyright (c) %d-%d the FFmpeg developers",
1942  print_str("build_date", __DATE__);
1943  print_str("build_time", __TIME__);
1944  print_str("compiler_ident", CC_IDENT);
1945  print_str("configuration", FFMPEG_CONFIGURATION);
1947 
1948  av_bprint_finalize(&pbuf, NULL);
1949 }
1950 
1951 #define SHOW_LIB_VERSION(libname, LIBNAME) \
1952  do { \
1953  if (CONFIG_##LIBNAME) { \
1954  unsigned int version = libname##_version(); \
1955  writer_print_section_header(w, SECTION_ID_LIBRARY_VERSION); \
1956  print_str("name", "lib" #libname); \
1957  print_int("major", LIB##LIBNAME##_VERSION_MAJOR); \
1958  print_int("minor", LIB##LIBNAME##_VERSION_MINOR); \
1959  print_int("micro", LIB##LIBNAME##_VERSION_MICRO); \
1960  print_int("version", version); \
1961  print_str("ident", LIB##LIBNAME##_IDENT); \
1962  writer_print_section_footer(w); \
1963  } \
1964  } while (0)
1965 
1967 {
1969  SHOW_LIB_VERSION(avutil, AVUTIL);
1970  SHOW_LIB_VERSION(avcodec, AVCODEC);
1971  SHOW_LIB_VERSION(avformat, AVFORMAT);
1972  SHOW_LIB_VERSION(avdevice, AVDEVICE);
1973  SHOW_LIB_VERSION(avfilter, AVFILTER);
1974  SHOW_LIB_VERSION(swscale, SWSCALE);
1975  SHOW_LIB_VERSION(swresample, SWRESAMPLE);
1976  SHOW_LIB_VERSION(postproc, POSTPROC);
1978 }
1979 
1980 static int opt_format(void *optctx, const char *opt, const char *arg)
1981 {
1982  iformat = av_find_input_format(arg);
1983  if (!iformat) {
1984  av_log(NULL, AV_LOG_ERROR, "Unknown input format: %s\n", arg);
1985  return AVERROR(EINVAL);
1986  }
1987  return 0;
1988 }
1989 
1990 static inline void mark_section_show_entries(SectionID section_id,
1991  int show_all_entries, AVDictionary *entries)
1992 {
1993  struct section *section = &sections[section_id];
1994 
1996  if (show_all_entries) {
1997  SectionID *id;
1998  for (id = section->children_ids; *id != -1; id++)
1999  mark_section_show_entries(*id, show_all_entries, entries);
2000  } else {
2001  av_dict_copy(&section->entries_to_show, entries, 0);
2002  }
2003 }
2004 
2005 static int match_section(const char *section_name,
2006  int show_all_entries, AVDictionary *entries)
2007 {
2008  int i, ret = 0;
2009 
2010  for (i = 0; i < FF_ARRAY_ELEMS(sections); i++) {
2011  const struct section *section = &sections[i];
2012  if (!strcmp(section_name, section->name) ||
2013  (section->unique_name && !strcmp(section_name, section->unique_name))) {
2015  "'%s' matches section with unique name '%s'\n", section_name,
2016  (char *)av_x_if_null(section->unique_name, section->name));
2017  ret++;
2018  mark_section_show_entries(section->id, show_all_entries, entries);
2019  }
2020  }
2021  return ret;
2022 }
2023 
2024 static int opt_show_entries(void *optctx, const char *opt, const char *arg)
2025 {
2026  const char *p = arg;
2027  int ret = 0;
2028 
2029  while (*p) {
2030  AVDictionary *entries = NULL;
2031  char *section_name = av_get_token(&p, "=:");
2032  int show_all_entries = 0;
2033 
2034  if (!section_name) {
2036  "Missing section name for option '%s'\n", opt);
2037  return AVERROR(EINVAL);
2038  }
2039 
2040  if (*p == '=') {
2041  p++;
2042  while (*p && *p != ':') {
2043  char *entry = av_get_token(&p, ",:");
2044  if (!entry)
2045  break;
2047  "Adding '%s' to the entries to show in section '%s'\n",
2048  entry, section_name);
2049  av_dict_set(&entries, entry, "", AV_DICT_DONT_STRDUP_KEY);
2050  if (*p == ',')
2051  p++;
2052  }
2053  } else {
2054  show_all_entries = 1;
2055  }
2056 
2057  ret = match_section(section_name, show_all_entries, entries);
2058  if (ret == 0) {
2059  av_log(NULL, AV_LOG_ERROR, "No match for section '%s'\n", section_name);
2060  ret = AVERROR(EINVAL);
2061  }
2062  av_dict_free(&entries);
2063  av_free(section_name);
2064 
2065  if (ret <= 0)
2066  break;
2067  if (*p)
2068  p++;
2069  }
2070 
2071  return ret;
2072 }
2073 
2074 static int opt_show_format_entry(void *optctx, const char *opt, const char *arg)
2075 {
2076  char *buf = av_asprintf("format=%s", arg);
2077  int ret;
2078 
2080  "Option '%s' is deprecated, use '-show_entries format=%s' instead\n",
2081  opt, arg);
2082  ret = opt_show_entries(optctx, opt, buf);
2083  av_free(buf);
2084  return ret;
2085 }
2086 
2087 static void opt_input_file(void *optctx, const char *arg)
2088 {
2089  if (input_filename) {
2091  "Argument '%s' provided as input filename, but '%s' was already specified.\n",
2092  arg, input_filename);
2093  exit(1);
2094  }
2095  if (!strcmp(arg, "-"))
2096  arg = "pipe:";
2097  input_filename = arg;
2098 }
2099 
2100 static int opt_input_file_i(void *optctx, const char *opt, const char *arg)
2101 {
2102  opt_input_file(optctx, arg);
2103  return 0;
2104 }
2105 
2106 void show_help_default(const char *opt, const char *arg)
2107 {
2109  show_usage();
2110  show_help_options(options, "Main options:", 0, 0, 0);
2111  printf("\n");
2112 
2114 }
2115 
2116 static int opt_pretty(void *optctx, const char *opt, const char *arg)
2117 {
2118  show_value_unit = 1;
2119  use_value_prefix = 1;
2122  return 0;
2123 }
2124 
2125 static void print_section(SectionID id, int level)
2126 {
2127  const SectionID *pid;
2128  const struct section *section = &sections[id];
2129  printf("%c%c%c",
2130  section->flags & SECTION_FLAG_IS_WRAPPER ? 'W' : '.',
2131  section->flags & SECTION_FLAG_IS_ARRAY ? 'A' : '.',
2132  section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS ? 'V' : '.');
2133  printf("%*c %s", level * 4, ' ', section->name);
2134  if (section->unique_name)
2135  printf("/%s", section->unique_name);
2136  printf("\n");
2137 
2138  for (pid = section->children_ids; *pid != -1; pid++)
2139  print_section(*pid, level+1);
2140 }
2141 
2142 static int opt_sections(void *optctx, const char *opt, const char *arg)
2143 {
2144  printf("Sections:\n"
2145  "W.. = Section is a wrapper (contains other sections, no local entries)\n"
2146  ".A. = Section contains an array of elements of the same type\n"
2147  "..V = Section may contain a variable number of fields with variable keys\n"
2148  "FLAGS NAME/UNIQUE_NAME\n"
2149  "---\n");
2151  return 0;
2152 }
2153 
2154 static int opt_show_versions(const char *opt, const char *arg)
2155 {
2158  return 0;
2159 }
2160 
2161 #define DEFINE_OPT_SHOW_SECTION(section, target_section_id) \
2162  static int opt_show_##section(const char *opt, const char *arg) \
2163  { \
2164  mark_section_show_entries(SECTION_ID_##target_section_id, 1, NULL); \
2165  return 0; \
2166  }
2167 
2171 DEFINE_OPT_SHOW_SECTION(library_versions, LIBRARY_VERSIONS);
2172 DEFINE_OPT_SHOW_SECTION(packets, PACKETS);
2173 DEFINE_OPT_SHOW_SECTION(program_version, PROGRAM_VERSION);
2174 DEFINE_OPT_SHOW_SECTION(streams, STREAMS);
2175 
2176 static const OptionDef real_options[] = {
2177 #include "cmdutils_common_opts.h"
2178  { "f", HAS_ARG, {.func_arg = opt_format}, "force format", "format" },
2179  { "unit", OPT_BOOL, {&show_value_unit}, "show unit of the displayed values" },
2180  { "prefix", OPT_BOOL, {&use_value_prefix}, "use SI prefixes for the displayed values" },
2181  { "byte_binary_prefix", OPT_BOOL, {&use_byte_value_binary_prefix},
2182  "use binary prefixes for byte units" },
2183  { "sexagesimal", OPT_BOOL, {&use_value_sexagesimal_format},
2184  "use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units" },
2185  { "pretty", 0, {.func_arg = opt_pretty},
2186  "prettify the format of displayed values, make it more human readable" },
2187  { "print_format", OPT_STRING | HAS_ARG, {(void*)&print_format},
2188  "set the output printing format (available formats are: default, compact, csv, flat, ini, json, xml)", "format" },
2189  { "of", OPT_STRING | HAS_ARG, {(void*)&print_format}, "alias for -print_format", "format" },
2190  { "select_streams", OPT_STRING | HAS_ARG, {(void*)&stream_specifier}, "select the specified streams", "stream_specifier" },
2191  { "sections", OPT_EXIT, {.func_arg = opt_sections}, "print sections structure and section information, and exit" },
2192  { "show_data", OPT_BOOL, {(void*)&do_show_data}, "show packets data" },
2193  { "show_error", 0, {(void*)&opt_show_error}, "show probing error" },
2194  { "show_format", 0, {(void*)&opt_show_format}, "show format/container info" },
2195  { "show_frames", 0, {(void*)&opt_show_frames}, "show frames info" },
2196  { "show_format_entry", HAS_ARG, {.func_arg = opt_show_format_entry},
2197  "show a particular entry from the format/container info", "entry" },
2198  { "show_entries", HAS_ARG, {.func_arg = opt_show_entries},
2199  "show a set of specified entries", "entry_list" },
2200  { "show_packets", 0, {(void*)&opt_show_packets}, "show packets info" },
2201  { "show_streams", 0, {(void*)&opt_show_streams}, "show streams info" },
2202  { "count_frames", OPT_BOOL, {(void*)&do_count_frames}, "count the number of frames per stream" },
2203  { "count_packets", OPT_BOOL, {(void*)&do_count_packets}, "count the number of packets per stream" },
2204  { "show_program_version", 0, {(void*)&opt_show_program_version}, "show ffprobe version" },
2205  { "show_library_versions", 0, {(void*)&opt_show_library_versions}, "show library versions" },
2206  { "show_versions", 0, {(void*)&opt_show_versions}, "show program and library versions" },
2207  { "show_private_data", OPT_BOOL, {(void*)&show_private_data}, "show private data" },
2208  { "private", OPT_BOOL, {(void*)&show_private_data}, "same as show_private_data" },
2209  { "bitexact", OPT_BOOL, {&do_bitexact}, "force bitexact output" },
2210  { "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {.func_arg = opt_default}, "generic catch all option", "" },
2211  { "i", HAS_ARG, {.func_arg = opt_input_file_i}, "read specified file", "input_file"},
2212  { NULL, },
2213 };
2214 
2215 static inline int check_section_show_entries(int section_id)
2216 {
2217  int *id;
2218  struct section *section = &sections[section_id];
2219  if (sections[section_id].show_all_entries || sections[section_id].entries_to_show)
2220  return 1;
2221  for (id = section->children_ids; *id != -1; id++)
2222  if (check_section_show_entries(*id))
2223  return 1;
2224  return 0;
2225 }
2226 
2227 #define SET_DO_SHOW(id, varname) do { \
2228  if (check_section_show_entries(SECTION_ID_##id)) \
2229  do_show_##varname = 1; \
2230  } while (0)
2231 
2232 int main(int argc, char **argv)
2233 {
2234  const Writer *w;
2235  WriterContext *wctx;
2236  char *buf;
2237  char *w_name = NULL, *w_args = NULL;
2238  int ret, i;
2239 
2241  atexit(exit_program);
2242 
2243  options = real_options;
2244  parse_loglevel(argc, argv, options);
2245  av_register_all();
2247  init_opts();
2248 #if CONFIG_AVDEVICE
2250 #endif
2251 
2252  show_banner(argc, argv, options);
2253  parse_options(NULL, argc, argv, options, opt_input_file);
2254 
2255  /* mark things to show, based on -show_entries */
2256  SET_DO_SHOW(ERROR, error);
2257  SET_DO_SHOW(FORMAT, format);
2258  SET_DO_SHOW(FRAMES, frames);
2259  SET_DO_SHOW(LIBRARY_VERSIONS, library_versions);
2260  SET_DO_SHOW(PACKETS, packets);
2261  SET_DO_SHOW(PROGRAM_VERSION, program_version);
2262  SET_DO_SHOW(STREAMS, streams);
2263  SET_DO_SHOW(STREAM_DISPOSITION, stream_disposition);
2264 
2267  "-bitexact and -show_program_version or -show_library_versions "
2268  "options are incompatible\n");
2269  ret = AVERROR(EINVAL);
2270  goto end;
2271  }
2272 
2274 
2275  if (!print_format)
2276  print_format = av_strdup("default");
2277  if (!print_format) {
2278  ret = AVERROR(ENOMEM);
2279  goto end;
2280  }
2281  w_name = av_strtok(print_format, "=", &buf);
2282  w_args = buf;
2283 
2284  w = writer_get_by_name(w_name);
2285  if (!w) {
2286  av_log(NULL, AV_LOG_ERROR, "Unknown output format with name '%s'\n", w_name);
2287  ret = AVERROR(EINVAL);
2288  goto end;
2289  }
2290 
2291  if ((ret = writer_open(&wctx, w, w_args,
2292  sections, FF_ARRAY_ELEMS(sections))) >= 0) {
2294 
2299 
2300  if (!input_filename &&
2303  show_usage();
2304  av_log(NULL, AV_LOG_ERROR, "You have to specify one input file.\n");
2305  av_log(NULL, AV_LOG_ERROR, "Use -h to get full help or, even better, run 'man %s'.\n", program_name);
2306  ret = AVERROR(EINVAL);
2307  } else if (input_filename) {
2308  ret = probe_file(wctx, input_filename);
2309  if (ret < 0 && do_show_error)
2310  show_error(wctx, ret);
2311  }
2312 
2314  writer_close(&wctx);
2315  }
2316 
2317 end:
2319 
2320  uninit_opts();
2321  for (i = 0; i < FF_ARRAY_ELEMS(sections); i++)
2322  av_dict_free(&(sections[i].entries_to_show));
2323 
2325 
2326  return ret;
2327 }
codec_id is not known (like AV_CODEC_ID_NONE) but lavf should attempt to identify it ...
const struct section * section[SECTION_MAX_NB_LEVELS]
section per each level
Definition: ffprobe.c:259
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:205
const struct AVCodec * codec
static char * value_string(char *buf, int buf_size, struct unit_value uv)
Definition: ffprobe.c:167
const char * s
Definition: avisynth_c.h:668
unsigned int nb_item[SECTION_MAX_NB_LEVELS]
number of the item printed in the given section, starting from 0
Definition: ffprobe.c:256
#define OPT_EXPERT
Definition: cmdutils.h:149
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:261
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:93
void(* print_string)(WriterContext *wctx, const char *, const char *)
Definition: ffprobe.c:238
int nested_section[SECTION_MAX_NB_LEVELS]
Definition: ffprobe.c:519
void av_free_packet(AVPacket *pkt)
Free a packet.
Definition: avpacket.c:242
This structure describes decoded (raw) audio or video data.
Definition: frame.h:76
static void show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_idx)
Definition: ffprobe.c:1594
static void json_print_int(WriterContext *wctx, const char *key, long long int value)
Definition: ffprobe.c:1170
static void default_print_section_header(WriterContext *wctx)
Definition: ffprobe.c:544
static int writer_register(const Writer *writer)
Definition: ffprobe.c:477
AVOption.
Definition: opt.h:251
#define print_ts(k, v)
Definition: ffprobe.c:1397
static int opt_input_file_i(void *optctx, const char *opt, const char *arg)
Definition: ffprobe.c:2100
static int opt_format(void *optctx, const char *opt, const char *arg)
Definition: ffprobe.c:1980
int within_tag
Definition: ffprobe.c:1201
#define SHOW_LIB_VERSION(libname, LIBNAME)
Definition: ffprobe.c:1951
#define OPT_VIDEO
Definition: cmdutils.h:151
static void writer_print_rational(WriterContext *wctx, const char *key, AVRational q, char sep)
Definition: ffprobe.c:410
static int opt_show_format_entry(void *optctx, const char *opt, const char *arg)
Definition: ffprobe.c:2074
static const char unit_hertz_str[]
Definition: ffprobe.c:147
const char * sep_str
Definition: ffprobe.c:811
static const char *const decimal_unit_prefixes[]
Definition: ffprobe.c:144
int64_t pos
byte position in stream, -1 if unknown
int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
static const char * xml_escape_str(AVBPrint *dst, const char *src, void *log_ctx)
Definition: ffprobe.c:1248
static void json_print_section_footer(WriterContext *wctx)
Definition: ffprobe.c:1125
static void writer_close(WriterContext **wctx)
Definition: ffprobe.c:281
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
static int do_show_data
Definition: ffprobe.c:61
static void writer_print_integer(WriterContext *wctx, const char *key, long long int val)
Definition: ffprobe.c:385
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:154
static char * ini_escape_str(AVBPrint *dst, const char *src)
Definition: ffprobe.c:949
AVRational av_guess_sample_aspect_ratio(AVFormatContext *format, AVStream *stream, AVFrame *frame)
Guess the sample aspect ratio of a frame, based on both the stream and the frame aspect ratio...
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition: opt.c:942
#define OPT_AUDIO
Definition: cmdutils.h:152
static char * print_format
Definition: ffprobe.c:71
static const Writer json_writer
Definition: ffprobe.c:1185
int num
numerator
Definition: rational.h:44
int repeat_pict
When decoding, this signals how much the picture must be delayed.
Definition: frame.h:265
int index
stream index in AVFormatContext
Definition: avformat.h:644
int av_set_options_string(void *ctx, const char *opts, const char *key_val_sep, const char *pairs_sep)
Parse the key/value pairs list in opts.
Definition: opt.c:1062
#define print_str_opt(k, v)
Definition: ffprobe.c:1395
static void close_input_file(AVFormatContext **ctx_ptr)
Definition: ffprobe.c:1856
int show_all_entries
Definition: ffprobe.c:91
void show_banner(int argc, char **argv, const OptionDef *options)
Print the program banner to stderr.
Definition: cmdutils.c:1055
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static const AVClass writer_class
Definition: ffprobe.c:274
static int do_show_packets
Definition: ffprobe.c:58
static int writer_open(WriterContext **wctx, const Writer *writer, const char *args, const struct section *sections, int nb_sections)
Definition: ffprobe.c:298
void avdevice_register_all(void)
Initialize libavdevice and register all the input and output devices.
Definition: alldevices.c:40
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.
#define FF_ARRAY_ELEMS(a)
static void json_print_item_str(WriterContext *wctx, const char *key, const char *value)
Definition: ffprobe.c:1147
char * escape_mode_str
Definition: ffprobe.c:668
static const Writer default_writer
Definition: ffprobe.c:600
Timecode helpers header.
static void show_frame(WriterContext *w, AVFrame *frame, AVStream *stream, AVFormatContext *fmt_ctx)
Definition: ffprobe.c:1457
static const char * json_escape_str(AVBPrint *dst, const char *src, void *log_ctx)
Definition: ffprobe.c:1065
static void xml_print_section_footer(WriterContext *wctx)
Definition: ffprobe.c:1308
static void mark_section_show_entries(SectionID section_id, int show_all_entries, AVDictionary *entries)
Definition: ffprobe.c:1990
static int do_show_error
Definition: ffprobe.c:55
void av_log_set_callback(void(*callback)(void *, int, const char *, va_list))
Definition: log.c:279
AVDictionaryEntry * av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:39
static uint64_t * nb_streams_frames
Definition: ffprobe.c:152
AVDictionary * filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id, AVFormatContext *s, AVStream *st, AVCodec *codec)
Filter out options for given codec.
Definition: cmdutils.c:1836
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:193
static int do_count_frames
Definition: ffprobe.c:51
#define SECTION_MAX_NB_LEVELS
Definition: ffprobe.c:242
output residual component w
int indent_level
Definition: ffprobe.c:1202
char * av_timecode_make_mpeg_tc_string(char *buf, uint32_t tc25bit)
Get the timecode string from the 25-bit timecode format (MPEG GOP format).
static const AVOption default_options[]
Definition: ffprobe.c:524
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
#define AV_DICT_DONT_STRDUP_KEY
Take ownership of a key that&#39;s been allocated with av_malloc() and children.
Definition: dict.h:69
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:198
set threshold d
#define AVFMT_SHOW_IDS
Show format stream IDs numbers.
Definition: avformat.h:347
Format I/O context.
Definition: avformat.h:944
#define OFFSET(x)
Definition: ffprobe.c:1208
const char * element_name
name of the contained element, if provided
Definition: ffprobe.c:88
static void writer_print_section_header(WriterContext *wctx, int section_id)
Definition: ffprobe.c:344
static void compact_print_section_footer(WriterContext *wctx)
Definition: ffprobe.c:732
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
Public dictionary API.
const char * name
Definition: opt.h:252
unsigned int nb_section_packet
number of the packet section in case we are in "packets_and_frames" section
Definition: ffprobe.c:263
static void ini_print_section_header(WriterContext *wctx)
Definition: ffprobe.c:976
#define print_duration_ts(k, v)
Definition: ffprobe.c:1399
enum AVSampleFormat sample_fmt
audio sample format
void log_callback_help(void *ptr, int level, const char *fmt, va_list vl)
Trivial log callback.
Definition: cmdutils.c:95
uint8_t
#define av_cold
Definition: attributes.h:78
static int do_read_packets
Definition: ffprobe.c:54
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:483
static av_cold int uninit(AVCodecContext *avctx)
Definition: crystalhd.c:334
static int * selected_streams
Definition: ffprobe.c:153
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, AVFMT_SEEK_TO_PTS.
Definition: avformat.h:475
#define HAS_ARG
Definition: cmdutils.h:147
static AVFormatContext * fmt_ctx
Definition: demuxing.c:37
static const char * flat_escape_value_str(AVBPrint *dst, const char *src)
Definition: ffprobe.c:858
static void writer_print_time(WriterContext *wctx, const char *key, int64_t ts, const AVRational *time_base, int is_duration)
Definition: ffprobe.c:419
static AVPacket pkt
Definition: demuxing.c:56
static av_cold int compact_init(WriterContext *wctx)
Definition: ffprobe.c:690
int id
Format-specific stream ID.
Definition: avformat.h:650
static void show_streams(WriterContext *w, AVFormatContext *fmt_ctx)
Definition: ffprobe.c:1744
end end
static int do_show_library_versions
Definition: ffprobe.c:63
#define DEFAULT
static void compact_print_section_header(WriterContext *wctx)
Definition: ffprobe.c:712
int avformat_match_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Check if the stream st contained in s is matched by the stream specifier spec.
#define AV_LOG_SKIP_REPEATED
Skip repeated messages, this requires the user app to use av_log() instead of (f)printf as the 2 woul...
Definition: log.h:219
static int match_section(const char *section_name, int show_all_entries, AVDictionary *entries)
Definition: ffprobe.c:2005
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
void init_opts(void)
Initialize the cmdutils option system, in particular allocate the *_opts contexts.
Definition: cmdutils.c:74
AVStream ** streams
Definition: avformat.h:992
const char * name
Definition: ffprobe.c:80
static const AVOption json_options[]
Definition: ffprobe.c:1047
static double av_q2d(AVRational a)
Convert rational to double.
Definition: rational.h:69
static const char *const binary_unit_prefixes[]
Definition: ffprobe.c:143
static const char * writer_get_name(void *p)
Definition: ffprobe.c:268
#define PRINT_DISPOSITION(flagname, name)
uint8_t * data
void parse_options(void *optctx, int argc, char **argv, const OptionDef *options, void(*parse_arg_function)(void *, const char *))
Definition: cmdutils.c:345
#define SECTION_MAX_NB_CHILDREN
Definition: ffprobe.c:76
uint32_t tag
Definition: movenc.c:894
int avformat_network_init(void)
Do global initialization of network components.
char av_get_picture_type_char(enum AVPictureType pict_type)
Return a single letter to describe the given picture type pict_type.
const AVClass * priv_class
private class of the writer, if any
Definition: ffprobe.c:227
static int check_section_show_entries(int section_id)
Definition: ffprobe.c:2215
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:270
int64_t av_frame_get_pkt_duration(const AVFrame *frame)
const AVClass * avformat_get_class(void)
Get the AVClass for AVFormatContext.
static void print_section(SectionID id, int level)
Definition: ffprobe.c:2125
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:459
external API header
void show_help_default(const char *opt, const char *arg)
Per-fftool specific help handler.
Definition: ffprobe.c:2106
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:147
static const char * c_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
Apply C-language-like string escaping.
Definition: ffprobe.c:616
static void writer_register_all(void)
Definition: ffprobe.c:1369
static void xml_print_str(WriterContext *wctx, const char *key, const char *value)
Definition: ffprobe.c:1327
int children_ids[SECTION_MAX_NB_CHILDREN+1]
list of children section IDS, terminated by -1
Definition: ffprobe.c:87
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
struct DefaultContext DefaultContext
static const char * input_filename
Definition: ffprobe.c:140
static void json_print_section_header(WriterContext *wctx)
Definition: ffprobe.c:1087
void(* print_section_footer)(WriterContext *wctx)
Definition: ffprobe.c:235
#define AV_TIMECODE_STR_SIZE
int print_section
Definition: ffprobe.c:667
static void ffprobe_show_program_version(WriterContext *w)
Definition: ffprobe.c:1933
AVDictionary ** setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *codec_opts)
Setup AVCodecContext options for avformat_find_stream_info().
Definition: cmdutils.c:1892
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
AVDictionary * format_opts
Definition: cmdutils.c:68
frame
Definition: stft.m:14
int hierarchical
Definition: ffprobe.c:935
static int do_show_frames
Definition: ffprobe.c:57
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
Definition: avutil.h:250
void av_dump_format(AVFormatContext *ic, int index, const char *url, int is_output)
void av_dict_copy(AVDictionary **dst, AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:176
Main libavdevice API header.
#define U(x)
int avcodec_close(AVCodecContext *avctx)
Close a given AVCodecContext and free all the data associated with it (but not the AVCodecContext its...
double d
Definition: ffprobe.c:163
libswresample public header
static int opt_show_versions(const char *opt, const char *arg)
Definition: ffprobe.c:2154
static const char unit_byte_str[]
Definition: ffprobe.c:148
const int program_birth_year
program birth year, defined by the program for show_banner()
Definition: ffprobe.c:48
int level
current level, starting from 0
Definition: ffprobe.c:253
int width
width and height of the video frame
Definition: frame.h:122
AVDictionary * entries_to_show
Definition: ffprobe.c:90
AVDictionary * metadata
Definition: avformat.h:1092
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
int has_b_frames
Size of the frame reordering buffer in the decoder.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:183
static void read_packets(WriterContext *w, AVFormatContext *fmt_ctx)
Definition: ffprobe.c:1561
int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, const AVPacket *avpkt)
Decode the video frame of size avpkt->size from avpkt->data into picture.
#define AV_BPRINT_SIZE_UNLIMITED
Convenience macros for special values for av_bprint_init() size_max parameter.
Definition: bprint.h:89
int xsd_strict
Definition: ffprobe.c:1204
#define print_int(k, v)
Definition: ffprobe.c:1392
static void opt_input_file(void *optctx, const char *arg)
Definition: ffprobe.c:2087
static int opt_pretty(void *optctx, const char *opt, const char *arg)
Definition: ffprobe.c:2116
#define SET_DO_SHOW(id, varname)
Definition: ffprobe.c:2227
int priv_size
private size for the writer context
Definition: ffprobe.c:228
static const AVOption xml_options[]
Definition: ffprobe.c:1210
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Init a print buffer.
Definition: bprint.c:68
#define SECTION_FLAG_HAS_VARIABLE_FIELDS
the section may contain a variable number of fields with variable keys.
Definition: ffprobe.c:84
Spectrum Plot time data
int64_t convergence_duration
Time difference in AVStream->time_base units from the pts of this packet to the point at which the ou...
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:162
const char * arg
int nested_section[SECTION_MAX_NB_LEVELS]
Definition: ffprobe.c:670
const AVOption * av_opt_next(void *obj, const AVOption *last)
Iterate over all AVOptions belonging to obj.
Definition: opt.c:63
#define print_q(k, v, s)
Definition: ffprobe.c:1393
static void default_print_int(WriterContext *wctx, const char *key, long long int value)
Definition: ffprobe.c:591
static av_cold int json_init(WriterContext *wctx)
Definition: ffprobe.c:1055
simple assert() macros that are a bit more flexible than ISO C assert().
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
#define JSON_INDENT()
Definition: ffprobe.c:1085
const char * name
Name of the codec implementation.
static void flat_print_str(WriterContext *wctx, const char *key, const char *value)
Definition: ffprobe.c:907
int id
unique id identifying a section
Definition: ffprobe.c:79
static const uint8_t offset[127][2]
Definition: vf_spp.c:70
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:716
external API header
char * av_get_token(const char **buf, const char *term)
Unescape the given string until a non escaped terminating char, and return the token corresponding to...
Definition: avstring.c:148
int size
const char * unit
Definition: ffprobe.c:164
int flags
A combination of AV_PKT_FLAG values.
void * priv
private data for use by the filter
Definition: ffprobe.c:248
char * name
name of this writer instance
Definition: ffprobe.c:247
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:662
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:36
char * av_asprintf(const char *fmt,...)
Definition: avstring.c:112
#define SECTION_FLAG_IS_WRAPPER
the section only contains other sections, but has no data at its own level
Definition: ffprobe.c:82
unsigned int nb_streams
A list of all streams in the file.
Definition: avformat.h:991
static void writer_print_data(WriterContext *wctx, const char *name, uint8_t *data, int size)
Definition: ffprobe.c:445
#define AV_LOG_VERBOSE
Definition: log.h:157
static void show_format(WriterContext *w, AVFormatContext *fmt_ctx)
Definition: ffprobe.c:1754
AVInputFormat * av_find_input_format(const char *short_name)
Find AVInputFormat based on the short name of the input format.
AVBPrint section_pbuf[SECTION_MAX_NB_LEVELS]
generic print buffer dedicated to each section, used by various writers
Definition: ffprobe.c:260
Buffer to print data progressively.
Definition: bprint.h:75
int bit_rate
the average bitrate
#define print_section_footer(s)
Definition: ffprobe.c:1408
int64_t timecode_frame_start
GOP timecode frame start number.
int av_frame_get_channels(const AVFrame *frame)
static const char * csv_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
Quote fields containing special characters, check RFC4180.
Definition: ffprobe.c:639
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:144
char filename[1024]
input or output filename
Definition: avformat.h:994
static const char unit_bit_per_second_str[]
Definition: ffprobe.c:149
static const Writer * registered_writers[MAX_REGISTERED_WRITERS_NB+1]
Definition: ffprobe.c:475
#define FFMIN(a, b)
Definition: common.h:58
int display_picture_number
picture number in display order
Definition: frame.h:180
static struct section sections[]
Definition: ffprobe.c:115
static void writer_print_string(WriterContext *wctx, const char *key, const char *val, int opt)
Definition: ffprobe.c:396
static int do_read_frames
Definition: ffprobe.c:53
struct FlatContext FlatContext
ret
Definition: avfilter.c:821
int width
picture width / height.
#define print_fmt(k, f,...)
Definition: ffprobe.c:1386
t
Definition: genspecsines3.m:6
static void show_usage(void)
Definition: ffprobe.c:1926
char sep
Definition: ffprobe.c:812
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate.The lists are not just lists
static int show_private_data
Definition: ffprobe.c:69
static int probe_file(WriterContext *wctx, const char *filename)
Definition: ffprobe.c:1869
#define OPT_EXIT
Definition: cmdutils.h:157
static av_cold int xml_init(WriterContext *wctx)
Definition: ffprobe.c:1220
int nb_sections
number of sections
Definition: ffprobe.c:251
int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, const AVPacket *avpkt)
Decode the audio frame of size avpkt->size from avpkt->data into frame.
const struct section * sections
array containing all sections
Definition: ffprobe.c:250
static const Writer flat_writer
Definition: ffprobe.c:920
static void flat_print_int(WriterContext *wctx, const char *key, long long int value)
Definition: ffprobe.c:902
if it could not because there are no more frames
static int opt_sections(void *optctx, const char *opt, const char *arg)
Definition: ffprobe.c:2142
AVDictionary * metadata
Definition: avformat.h:711
static const OptionDef real_options[]
Definition: ffprobe.c:2176
#define WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS
Definition: ffprobe.c:223
struct Writer Writer
FIXME Range Coding of cr are level
Definition: snow.txt:367
static int do_show_format
Definition: ffprobe.c:56
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
Definition: samplefmt.c:47
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
const char * item_start_end
Definition: ffprobe.c:1041
static const Writer ini_writer
Definition: ffprobe.c:1025
int flags
Definition: opt.h:280
static void compact_print_str(WriterContext *wctx, const char *key, const char *value)
Definition: ffprobe.c:741
const char * long_name
Descriptive name for the format, meant to be more human-readable than name.
Definition: avformat.h:468
Stream structure.
Definition: avformat.h:643
const char program_name[]
program name, defined by the program for show_version().
Definition: ffprobe.c:47
static const Writer compact_writer
Definition: ffprobe.c:764
static void compact_print_int(WriterContext *wctx, const char *key, long long int value)
Definition: ffprobe.c:754
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:134
const char * name
Definition: ffprobe.c:229
const char * av_get_profile_name(const AVCodec *codec, int profile)
Return a name for the specified profile, if available.
int avformat_network_deinit(void)
Undo the initialization done by avformat_network_init.
external API header
const char * long_name
Descriptive name for the codec, meant to be more human readable than name.
NULL
Definition: eval.c:55
int coded_picture_number
picture number in bitstream order
Definition: frame.h:176
static AVInputFormat * iformat
Definition: ffprobe.c:141
unsigned int nb_section_frame
number of the frame section in case we are in "packets_and_frames" section
Definition: ffprobe.c:264
#define ERROR(...)
#define AV_BPRINT_SIZE_AUTOMATIC
Definition: bprint.h:90
AVS_Value src
Definition: avisynth_c.h:523
enum AVMediaType codec_type
typedef void(RENAME(mix_any_func_type))
enum AVCodecID codec_id
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:202
char * av_strdup(const char *s)
Duplicate the string s.
Definition: mem.c:220
int av_frame_get_pkt_size(const AVFrame *frame)
int sample_rate
samples per second
AVIOContext * pb
I/O context.
Definition: avformat.h:977
#define XML_INDENT()
Definition: ffprobe.c:1266
void av_log_set_flags(int arg)
Definition: log.c:274
static void xml_print_int(WriterContext *wctx, const char *key, long long int value)
Definition: ffprobe.c:1350
static int do_bitexact
Definition: ffprobe.c:50
main external API structure.
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
static Writer xml_writer
Definition: ffprobe.c:1357
static const Writer csv_writer
Definition: ffprobe.c:795
static void show_error(WriterContext *w, int err)
Definition: ffprobe.c:1779
const char * item_sep
Definition: ffprobe.c:1041
static void ini_print_str(WriterContext *wctx, const char *key, const char *value)
Definition: ffprobe.c:1009
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> (&#39;D&#39;<<24) + (&#39;C&#39;<<16) + (&#39;B&#39;<<8) + &#39;A&#39;).
#define WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER
Definition: ffprobe.c:224
AVDictionary * av_frame_get_metadata(const AVFrame *frame)
void * buf
Definition: avisynth_c.h:594
unsigned int nb_section_packet_frame
nb_section_packet or nb_section_frame according if is_packets_and_frames
Definition: ffprobe.c:265
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:62
Replacements for frequently missing libm functions.
static int show_value_unit
Definition: ffprobe.c:65
static int use_value_sexagesimal_format
Definition: ffprobe.c:68
#define print_duration_time(k, v, tb)
Definition: ffprobe.c:1398
double value
Definition: eval.c:82
void avcodec_get_frame_defaults(AVFrame *frame)
Set the fields of the given AVFrame to default values.
Describe the class of an AVClass context structure.
Definition: log.h:50
int index
Definition: gxfenc.c:89
char * item_sep_str
Definition: ffprobe.c:664
synthesis window for stochastic i
#define DEFINE_WRITER_CLASS(name)
Definition: ffprobe.c:502
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:282
#define OPT_STRING
Definition: cmdutils.h:150
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition: avstring.c:100
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
#define snprintf
Definition: snprintf.h:34
void(* print_section_header)(WriterContext *wctx)
Definition: ffprobe.c:234
#define SECTION_FLAG_IS_ARRAY
the section contains an array of elements of the same type
Definition: ffprobe.c:83
SectionID
Definition: ffprobe.c:94
static const AVOption compact_options[]
Definition: ffprobe.c:676
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
#define FFMPEG_VERSION
Definition: version.h:1
int64_t pkt_pts
PTS copied from the AVPacket that was decoded to produce this frame.
Definition: frame.h:164
static void writer_print_ts(WriterContext *wctx, const char *key, int64_t ts, int is_duration)
Definition: ffprobe.c:436
void * av_calloc(size_t nmemb, size_t size)
Allocate a block of nmemb * size bytes with alignment suitable for all memory accesses (including vec...
Definition: mem.c:213
static uint64_t * nb_streams_packets
Definition: ffprobe.c:151
const char * av_get_media_type_string(enum AVMediaType media_type)
Return a string describing the media_type enum, NULL if media_type is unknown.
static void ffprobe_show_library_versions(WriterContext *w)
Definition: ffprobe.c:1966
static int use_value_prefix
Definition: ffprobe.c:66
void(* print_integer)(WriterContext *wctx, const char *, long long int)
Definition: ffprobe.c:236
int64_t start_time
Decoding: position of the first frame of the component, in AV_TIME_BASE fractional seconds...
Definition: avformat.h:1001
const AVClass * priv_class
AVClass for the private context.
static void flat_print_section_header(WriterContext *wctx)
Definition: ffprobe.c:876
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
Put a description of the AVERROR code errnum in errbuf.
Definition: error.c:53
static char * upcase_string(char *dst, size_t dst_size, const char *src)
Definition: ffprobe.c:535
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
Definition: bprint.c:185
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok()...
Definition: avstring.c:183
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:696
static int av_toupper(int c)
Locale-independent conversion of ASCII characters to uppercase.
Definition: avstring.h:206
static const OptionDef * options
Definition: ffprobe.c:137
#define OPT_BOOL
Definition: cmdutils.h:148
int64_t pkt_dts
DTS copied from the AVPacket that triggered returning this frame.
Definition: frame.h:171
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:982
const int this_year
this year, defined by the program for show_banner()
Definition: cmdutils.c:70
void av_opt_free(void *obj)
Free all string and binary options in obj.
Definition: opt.c:1194
AVDictionary * codec_opts
Definition: cmdutils.c:68
static void xml_print_section_header(WriterContext *wctx)
Definition: ffprobe.c:1268
static int do_show_stream_disposition
Definition: ffprobe.c:60
int flags
For these sections the element_name field is mandatory.
Definition: ffprobe.c:86
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:162
#define exp2(x)
Definition: libm.h:77
static void default_print_str(WriterContext *wctx, const char *key, const char *value)
Definition: ffprobe.c:582
#define CC_IDENT
Definition: config.h:8
static int do_count_packets
Definition: ffprobe.c:52
const char *(* escape_str)(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
Definition: ffprobe.c:669
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base...
Definition: avformat.h:689
static double c[64]
static const char unit_second_str[]
Definition: ffprobe.c:146
static AVCodecContext * dec_ctx
static void show_tags(WriterContext *wctx, AVDictionary *tags, int section_id)
Definition: ffprobe.c:1410
static av_cold int flat_init(WriterContext *wctx)
Definition: ffprobe.c:829
static void show_packet(WriterContext *w, AVFormatContext *fmt_ctx, AVPacket *pkt, int packet_idx)
Definition: ffprobe.c:1422
char item_sep
Definition: ffprobe.c:665
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
Definition: avpacket.c:56
int64_t nb_frames
number of frames in this stream if known or 0
Definition: avformat.h:698
char * key
Definition: dict.h:81
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:82
static const AVOption csv_options[]
Definition: ffprobe.c:781
struct AVInputFormat * iformat
Can only be iformat or oformat, not both at the same time.
Definition: avformat.h:957
static const char * flat_escape_key_str(AVBPrint *dst, const char *src, const char sep)
Definition: ffprobe.c:843
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
#define FFMPEG_CONFIGURATION
Definition: config.h:4
#define AVUNERROR(e)
Definition: error.h:44
struct CompactContext CompactContext
static int opt_show_entries(void *optctx, const char *opt, const char *arg)
Definition: ffprobe.c:2024
static const AVOption flat_options[]
Definition: ffprobe.c:819
static int do_show_program_version
Definition: ffprobe.c:62
static int use_byte_value_binary_prefix
Definition: ffprobe.c:67
int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
Definition: opt.c:566
#define AVERROR_OPTION_NOT_FOUND
Option not found.
Definition: error.h:61
char * value
Definition: dict.h:82
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:275
int channels
number of audio channels
static av_always_inline int process_frame(WriterContext *w, AVFormatContext *fmt_ctx, AVFrame *frame, AVPacket *pkt)
Definition: ffprobe.c:1528
printf("static const uint8_t my_array[100] = {\n")
else dst[i][x+y *dst_stride[i]]
Definition: vf_mcdeint.c:160
static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename)
Definition: ffprobe.c:1793
static const AVOption ini_options[]
Definition: ffprobe.c:941
#define CHECK_COMPLIANCE(opt, opt_name)
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:139
int64_t av_frame_get_pkt_pos(const AVFrame *frame)
static const char * none_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
Definition: ffprobe.c:657
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:176
static void json_print_str(WriterContext *wctx, const char *key, const char *value)
Definition: ffprobe.c:1159
static void ini_print_int(WriterContext *wctx, const char *key, long long int value)
Definition: ffprobe.c:1020
int noprint_wrappers
Definition: ffprobe.c:518
#define print_str(k, v)
Definition: ffprobe.c:1394
#define print_val(k, v, u)
Definition: ffprobe.c:1400
union unit_value::@26 val
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
static char * stream_specifier
Definition: ffprobe.c:72
int bit_rate
Decoding: total stream bitrate in bit/s, 0 if not available.
Definition: avformat.h:1016
#define print_time(k, v, tb)
Definition: ffprobe.c:1396
int64_t duration
Decoding: duration of the stream, in AV_TIME_BASE fractional seconds.
Definition: avformat.h:1009
int64_t av_frame_get_channel_layout(const AVFrame *frame)
int height
Definition: frame.h:122
#define AV_LOG_INFO
Definition: log.h:156
int compact
Definition: ffprobe.c:1040
static void default_print_section_footer(WriterContext *wctx)
Definition: ffprobe.c:569
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:461
#define AV_DICT_IGNORE_SUFFIX
Definition: dict.h:68
#define av_always_inline
Definition: attributes.h:41
integer integer log2
Definition: avutil.txt:2
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:1700
int main(int argc, char **argv)
Definition: ffprobe.c:2232
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:679
const Writer * writer
the Writer of which this is an instance
Definition: ffprobe.c:246
int hierarchical
Definition: ffprobe.c:813
AVRational r_frame_rate
Real base framerate of the stream.
Definition: avformat.h:738
static void exit_program(void)
Definition: ffprobe.c:155
static const Writer * writer_get_by_name(const char *name)
Definition: ffprobe.c:488
const char * unique_name
unique section name, in case the name is ambiguous
Definition: ffprobe.c:89
This structure stores compressed data.
void av_register_all(void)
Initialize libavformat and register all the muxers, demuxers and protocols.
Definition: allformats.c:52
long long int i
Definition: ffprobe.c:163
#define DEFINE_OPT_SHOW_SECTION(section, target_section_id)
Definition: ffprobe.c:2161
int indent_level
Definition: ffprobe.c:1039
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:127
#define MAX_REGISTERED_WRITERS_NB
Definition: ffprobe.c:473
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
static void writer_print_section_footer(WriterContext *wctx)
Definition: ffprobe.c:368
int fully_qualified
Definition: ffprobe.c:1203
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:190
static int do_show_streams
Definition: ffprobe.c:59
void av_bprint_channel_layout(struct AVBPrint *bp, int nb_channels, uint64_t channel_layout)
Append a description of a channel layout to a bprint buffer.
#define print_section_header(s)
Definition: ffprobe.c:1407
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.
Definition: bprint.c:116
int flags
a combination or WRITER_FLAG_*
Definition: ffprobe.c:239