FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 "libavutil/ffversion.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/display.h"
37 #include "libavutil/hash.h"
38 #include "libavutil/opt.h"
39 #include "libavutil/pixdesc.h"
40 #include "libavutil/spherical.h"
41 #include "libavutil/stereo3d.h"
42 #include "libavutil/dict.h"
43 #include "libavutil/intreadwrite.h"
44 #include "libavutil/libm.h"
45 #include "libavutil/parseutils.h"
46 #include "libavutil/timecode.h"
47 #include "libavutil/timestamp.h"
48 #include "libavdevice/avdevice.h"
49 #include "libswscale/swscale.h"
52 #include "cmdutils.h"
53 
54 typedef struct InputStream {
55  AVStream *st;
56 
58 } InputStream;
59 
60 typedef struct InputFile {
62 
64  int nb_streams;
65 } InputFile;
66 
67 const char program_name[] = "ffprobe";
68 const int program_birth_year = 2007;
69 
70 static int do_bitexact = 0;
71 static int do_count_frames = 0;
72 static int do_count_packets = 0;
73 static int do_read_frames = 0;
74 static int do_read_packets = 0;
75 static int do_show_chapters = 0;
76 static int do_show_error = 0;
77 static int do_show_format = 0;
78 static int do_show_frames = 0;
79 static int do_show_packets = 0;
80 static int do_show_programs = 0;
81 static int do_show_streams = 0;
83 static int do_show_data = 0;
84 static int do_show_program_version = 0;
85 static int do_show_library_versions = 0;
86 static int do_show_pixel_formats = 0;
89 
90 static int do_show_chapter_tags = 0;
91 static int do_show_format_tags = 0;
92 static int do_show_frame_tags = 0;
93 static int do_show_program_tags = 0;
94 static int do_show_stream_tags = 0;
95 static int do_show_packet_tags = 0;
96 
97 static int show_value_unit = 0;
98 static int use_value_prefix = 0;
101 static int show_private_data = 1;
102 
103 static char *print_format;
104 static char *stream_specifier;
105 static char *show_data_hash;
106 
107 typedef struct ReadInterval {
108  int id; ///< identifier
109  int64_t start, end; ///< start, end in second/AV_TIME_BASE units
113 } ReadInterval;
114 
116 static int read_intervals_nb = 0;
117 
118 /* section structure definition */
119 
120 #define SECTION_MAX_NB_CHILDREN 10
121 
122 struct section {
123  int id; ///< unique id identifying a section
124  const char *name;
125 
126 #define SECTION_FLAG_IS_WRAPPER 1 ///< the section only contains other sections, but has no data at its own level
127 #define SECTION_FLAG_IS_ARRAY 2 ///< the section contains an array of elements of the same type
128 #define SECTION_FLAG_HAS_VARIABLE_FIELDS 4 ///< the section may contain a variable number of fields with variable keys.
129  /// For these sections the element_name field is mandatory.
130  int flags;
131  int children_ids[SECTION_MAX_NB_CHILDREN+1]; ///< list of children section IDS, terminated by -1
132  const char *element_name; ///< name of the contained element, if provided
133  const char *unique_name; ///< unique section name, in case the name is ambiguous
136 };
137 
138 typedef enum {
180 } SectionID;
181 
182 static struct section sections[] = {
184  [SECTION_ID_CHAPTER] = { SECTION_ID_CHAPTER, "chapter", 0, { SECTION_ID_CHAPTER_TAGS, -1 } },
185  [SECTION_ID_CHAPTER_TAGS] = { SECTION_ID_CHAPTER_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "chapter_tags" },
186  [SECTION_ID_ERROR] = { SECTION_ID_ERROR, "error", 0, { -1 } },
187  [SECTION_ID_FORMAT] = { SECTION_ID_FORMAT, "format", 0, { SECTION_ID_FORMAT_TAGS, -1 } },
188  [SECTION_ID_FORMAT_TAGS] = { SECTION_ID_FORMAT_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "format_tags" },
191  [SECTION_ID_FRAME_TAGS] = { SECTION_ID_FRAME_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "frame_tags" },
192  [SECTION_ID_FRAME_SIDE_DATA_LIST] ={ SECTION_ID_FRAME_SIDE_DATA_LIST, "side_data_list", SECTION_FLAG_IS_ARRAY, { SECTION_ID_FRAME_SIDE_DATA, -1 }, .element_name = "side_data", .unique_name = "frame_side_data_list" },
193  [SECTION_ID_FRAME_SIDE_DATA] = { SECTION_ID_FRAME_SIDE_DATA, "side_data", 0, { -1 } },
195  [SECTION_ID_LIBRARY_VERSION] = { SECTION_ID_LIBRARY_VERSION, "library_version", 0, { -1 } },
199  [SECTION_ID_PACKET_TAGS] = { SECTION_ID_PACKET_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "packet_tags" },
200  [SECTION_ID_PACKET_SIDE_DATA_LIST] ={ SECTION_ID_PACKET_SIDE_DATA_LIST, "side_data_list", SECTION_FLAG_IS_ARRAY, { SECTION_ID_PACKET_SIDE_DATA, -1 }, .element_name = "side_data", .unique_name = "packet_side_data_list" },
201  [SECTION_ID_PACKET_SIDE_DATA] = { SECTION_ID_PACKET_SIDE_DATA, "side_data", 0, { -1 } },
204  [SECTION_ID_PIXEL_FORMAT_FLAGS] = { SECTION_ID_PIXEL_FORMAT_FLAGS, "flags", 0, { -1 }, .unique_name = "pixel_format_flags" },
205  [SECTION_ID_PIXEL_FORMAT_COMPONENTS] = { SECTION_ID_PIXEL_FORMAT_COMPONENTS, "components", SECTION_FLAG_IS_ARRAY, {SECTION_ID_PIXEL_FORMAT_COMPONENT, -1 }, .unique_name = "pixel_format_components" },
207  [SECTION_ID_PROGRAM_STREAM_DISPOSITION] = { SECTION_ID_PROGRAM_STREAM_DISPOSITION, "disposition", 0, { -1 }, .unique_name = "program_stream_disposition" },
208  [SECTION_ID_PROGRAM_STREAM_TAGS] = { SECTION_ID_PROGRAM_STREAM_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "program_stream_tags" },
210  [SECTION_ID_PROGRAM_STREAMS] = { SECTION_ID_PROGRAM_STREAMS, "streams", SECTION_FLAG_IS_ARRAY, { SECTION_ID_PROGRAM_STREAM, -1 }, .unique_name = "program_streams" },
212  [SECTION_ID_PROGRAM_TAGS] = { SECTION_ID_PROGRAM_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "program_tags" },
213  [SECTION_ID_PROGRAM_VERSION] = { SECTION_ID_PROGRAM_VERSION, "program_version", 0, { -1 } },
221  [SECTION_ID_STREAM_DISPOSITION] = { SECTION_ID_STREAM_DISPOSITION, "disposition", 0, { -1 }, .unique_name = "stream_disposition" },
222  [SECTION_ID_STREAM_TAGS] = { SECTION_ID_STREAM_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "stream_tags" },
223  [SECTION_ID_STREAM_SIDE_DATA_LIST] ={ SECTION_ID_STREAM_SIDE_DATA_LIST, "side_data_list", SECTION_FLAG_IS_ARRAY, { SECTION_ID_STREAM_SIDE_DATA, -1 }, .element_name = "side_data", .unique_name = "stream_side_data_list" },
224  [SECTION_ID_STREAM_SIDE_DATA] = { SECTION_ID_STREAM_SIDE_DATA, "side_data", 0, { -1 } },
225  [SECTION_ID_SUBTITLE] = { SECTION_ID_SUBTITLE, "subtitle", 0, { -1 } },
226 };
227 
228 static const OptionDef *options;
229 
230 /* FFprobe context */
231 static const char *input_filename;
233 
234 static struct AVHashContext *hash;
235 
236 static const struct {
237  double bin_val;
238  double dec_val;
239  const char *bin_str;
240  const char *dec_str;
241 } si_prefixes[] = {
242  { 1.0, 1.0, "", "" },
243  { 1.024e3, 1e3, "Ki", "K" },
244  { 1.048576e6, 1e6, "Mi", "M" },
245  { 1.073741824e9, 1e9, "Gi", "G" },
246  { 1.099511627776e12, 1e12, "Ti", "T" },
247  { 1.125899906842624e15, 1e15, "Pi", "P" },
248 };
249 
250 static const char unit_second_str[] = "s" ;
251 static const char unit_hertz_str[] = "Hz" ;
252 static const char unit_byte_str[] = "byte" ;
253 static const char unit_bit_per_second_str[] = "bit/s";
254 
255 static int nb_streams;
256 static uint64_t *nb_streams_packets;
257 static uint64_t *nb_streams_frames;
258 static int *selected_streams;
259 
260 static void ffprobe_cleanup(int ret)
261 {
262  int i;
263  for (i = 0; i < FF_ARRAY_ELEMS(sections); i++)
264  av_dict_free(&(sections[i].entries_to_show));
265 }
266 
267 struct unit_value {
268  union { double d; long long int i; } val;
269  const char *unit;
270 };
271 
272 static char *value_string(char *buf, int buf_size, struct unit_value uv)
273 {
274  double vald;
275  long long int vali;
276  int show_float = 0;
277 
278  if (uv.unit == unit_second_str) {
279  vald = uv.val.d;
280  show_float = 1;
281  } else {
282  vald = vali = uv.val.i;
283  }
284 
286  double secs;
287  int hours, mins;
288  secs = vald;
289  mins = (int)secs / 60;
290  secs = secs - mins * 60;
291  hours = mins / 60;
292  mins %= 60;
293  snprintf(buf, buf_size, "%d:%02d:%09.6f", hours, mins, secs);
294  } else {
295  const char *prefix_string = "";
296 
297  if (use_value_prefix && vald > 1) {
298  long long int index;
299 
301  index = (long long int) (log2(vald)) / 10;
302  index = av_clip(index, 0, FF_ARRAY_ELEMS(si_prefixes) - 1);
303  vald /= si_prefixes[index].bin_val;
304  prefix_string = si_prefixes[index].bin_str;
305  } else {
306  index = (long long int) (log10(vald)) / 3;
307  index = av_clip(index, 0, FF_ARRAY_ELEMS(si_prefixes) - 1);
308  vald /= si_prefixes[index].dec_val;
309  prefix_string = si_prefixes[index].dec_str;
310  }
311  vali = vald;
312  }
313 
314  if (show_float || (use_value_prefix && vald != (long long int)vald))
315  snprintf(buf, buf_size, "%f", vald);
316  else
317  snprintf(buf, buf_size, "%lld", vali);
318  av_strlcatf(buf, buf_size, "%s%s%s", *prefix_string || show_value_unit ? " " : "",
319  prefix_string, show_value_unit ? uv.unit : "");
320  }
321 
322  return buf;
323 }
324 
325 /* WRITERS API */
326 
327 typedef struct WriterContext WriterContext;
328 
329 #define WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS 1
330 #define WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER 2
331 
332 typedef enum {
338 
339 typedef struct Writer {
340  const AVClass *priv_class; ///< private class of the writer, if any
341  int priv_size; ///< private size for the writer context
342  const char *name;
343 
344  int (*init) (WriterContext *wctx);
346 
349  void (*print_integer) (WriterContext *wctx, const char *, long long int);
350  void (*print_rational) (WriterContext *wctx, AVRational *q, char *sep);
351  void (*print_string) (WriterContext *wctx, const char *, const char *);
352  int flags; ///< a combination or WRITER_FLAG_*
353 } Writer;
354 
355 #define SECTION_MAX_NB_LEVELS 10
356 
358  const AVClass *class; ///< class of the writer
359  const Writer *writer; ///< the Writer of which this is an instance
360  char *name; ///< name of this writer instance
361  void *priv; ///< private data for use by the filter
362 
363  const struct section *sections; ///< array containing all sections
364  int nb_sections; ///< number of sections
365 
366  int level; ///< current level, starting from 0
367 
368  /** number of the item printed in the given section, starting from 0 */
370 
371  /** section per each level */
373  AVBPrint section_pbuf[SECTION_MAX_NB_LEVELS]; ///< generic print buffer dedicated to each section,
374  /// used by various writers
375 
376  unsigned int nb_section_packet; ///< number of the packet section in case we are in "packets_and_frames" section
377  unsigned int nb_section_frame; ///< number of the frame section in case we are in "packets_and_frames" section
378  unsigned int nb_section_packet_frame; ///< nb_section_packet or nb_section_frame according if is_packets_and_frames
379 
383 };
384 
385 static const char *writer_get_name(void *p)
386 {
387  WriterContext *wctx = p;
388  return wctx->writer->name;
389 }
390 
391 #define OFFSET(x) offsetof(WriterContext, x)
392 
393 static const AVOption writer_options[] = {
394  { "string_validation", "set string validation mode",
395  OFFSET(string_validation), AV_OPT_TYPE_INT, {.i64=WRITER_STRING_VALIDATION_REPLACE}, 0, WRITER_STRING_VALIDATION_NB-1, .unit = "sv" },
396  { "sv", "set string validation mode",
397  OFFSET(string_validation), AV_OPT_TYPE_INT, {.i64=WRITER_STRING_VALIDATION_REPLACE}, 0, WRITER_STRING_VALIDATION_NB-1, .unit = "sv" },
398  { "ignore", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = WRITER_STRING_VALIDATION_IGNORE}, .unit = "sv" },
399  { "replace", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = WRITER_STRING_VALIDATION_REPLACE}, .unit = "sv" },
400  { "fail", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = WRITER_STRING_VALIDATION_FAIL}, .unit = "sv" },
401  { "string_validation_replacement", "set string validation replacement string", OFFSET(string_validation_replacement), AV_OPT_TYPE_STRING, {.str=""}},
402  { "svr", "set string validation replacement string", OFFSET(string_validation_replacement), AV_OPT_TYPE_STRING, {.str="\xEF\xBF\xBD"}},
403  { NULL }
404 };
405 
406 static void *writer_child_next(void *obj, void *prev)
407 {
408  WriterContext *ctx = obj;
409  if (!prev && ctx->writer && ctx->writer->priv_class && ctx->priv)
410  return ctx->priv;
411  return NULL;
412 }
413 
414 static const AVClass writer_class = {
415  .class_name = "Writer",
416  .item_name = writer_get_name,
417  .option = writer_options,
418  .version = LIBAVUTIL_VERSION_INT,
419  .child_next = writer_child_next,
420 };
421 
422 static void writer_close(WriterContext **wctx)
423 {
424  int i;
425 
426  if (!*wctx)
427  return;
428 
429  if ((*wctx)->writer->uninit)
430  (*wctx)->writer->uninit(*wctx);
431  for (i = 0; i < SECTION_MAX_NB_LEVELS; i++)
432  av_bprint_finalize(&(*wctx)->section_pbuf[i], NULL);
433  if ((*wctx)->writer->priv_class)
434  av_opt_free((*wctx)->priv);
435  av_freep(&((*wctx)->priv));
436  av_opt_free(*wctx);
437  av_freep(wctx);
438 }
439 
440 static void bprint_bytes(AVBPrint *bp, const uint8_t *ubuf, size_t ubuf_size)
441 {
442  int i;
443  av_bprintf(bp, "0X");
444  for (i = 0; i < ubuf_size; i++)
445  av_bprintf(bp, "%02X", ubuf[i]);
446 }
447 
448 
449 static int writer_open(WriterContext **wctx, const Writer *writer, const char *args,
450  const struct section *sections, int nb_sections)
451 {
452  int i, ret = 0;
453 
454  if (!(*wctx = av_mallocz(sizeof(WriterContext)))) {
455  ret = AVERROR(ENOMEM);
456  goto fail;
457  }
458 
459  if (!((*wctx)->priv = av_mallocz(writer->priv_size))) {
460  ret = AVERROR(ENOMEM);
461  goto fail;
462  }
463 
464  (*wctx)->class = &writer_class;
465  (*wctx)->writer = writer;
466  (*wctx)->level = -1;
467  (*wctx)->sections = sections;
468  (*wctx)->nb_sections = nb_sections;
469 
470  av_opt_set_defaults(*wctx);
471 
472  if (writer->priv_class) {
473  void *priv_ctx = (*wctx)->priv;
474  *((const AVClass **)priv_ctx) = writer->priv_class;
475  av_opt_set_defaults(priv_ctx);
476  }
477 
478  /* convert options to dictionary */
479  if (args) {
481  AVDictionaryEntry *opt = NULL;
482 
483  if ((ret = av_dict_parse_string(&opts, args, "=", ":", 0)) < 0) {
484  av_log(*wctx, AV_LOG_ERROR, "Failed to parse option string '%s' provided to writer context\n", args);
485  av_dict_free(&opts);
486  goto fail;
487  }
488 
489  while ((opt = av_dict_get(opts, "", opt, AV_DICT_IGNORE_SUFFIX))) {
490  if ((ret = av_opt_set(*wctx, opt->key, opt->value, AV_OPT_SEARCH_CHILDREN)) < 0) {
491  av_log(*wctx, AV_LOG_ERROR, "Failed to set option '%s' with value '%s' provided to writer context\n",
492  opt->key, opt->value);
493  av_dict_free(&opts);
494  goto fail;
495  }
496  }
497 
498  av_dict_free(&opts);
499  }
500 
501  /* validate replace string */
502  {
503  const uint8_t *p = (*wctx)->string_validation_replacement;
504  const uint8_t *endp = p + strlen(p);
505  while (*p) {
506  const uint8_t *p0 = p;
507  int32_t code;
508  ret = av_utf8_decode(&code, &p, endp, (*wctx)->string_validation_utf8_flags);
509  if (ret < 0) {
510  AVBPrint bp;
512  bprint_bytes(&bp, p0, p-p0),
513  av_log(wctx, AV_LOG_ERROR,
514  "Invalid UTF8 sequence %s found in string validation replace '%s'\n",
515  bp.str, (*wctx)->string_validation_replacement);
516  return ret;
517  }
518  }
519  }
520 
521  for (i = 0; i < SECTION_MAX_NB_LEVELS; i++)
522  av_bprint_init(&(*wctx)->section_pbuf[i], 1, AV_BPRINT_SIZE_UNLIMITED);
523 
524  if ((*wctx)->writer->init)
525  ret = (*wctx)->writer->init(*wctx);
526  if (ret < 0)
527  goto fail;
528 
529  return 0;
530 
531 fail:
532  writer_close(wctx);
533  return ret;
534 }
535 
537  int section_id)
538 {
539  int parent_section_id;
540  wctx->level++;
542  parent_section_id = wctx->level ?
543  (wctx->section[wctx->level-1])->id : SECTION_ID_NONE;
544 
545  wctx->nb_item[wctx->level] = 0;
546  wctx->section[wctx->level] = &wctx->sections[section_id];
547 
548  if (section_id == SECTION_ID_PACKETS_AND_FRAMES) {
549  wctx->nb_section_packet = wctx->nb_section_frame =
550  wctx->nb_section_packet_frame = 0;
551  } else if (parent_section_id == SECTION_ID_PACKETS_AND_FRAMES) {
552  wctx->nb_section_packet_frame = section_id == SECTION_ID_PACKET ?
553  wctx->nb_section_packet : wctx->nb_section_frame;
554  }
555 
556  if (wctx->writer->print_section_header)
557  wctx->writer->print_section_header(wctx);
558 }
559 
561 {
562  int section_id = wctx->section[wctx->level]->id;
563  int parent_section_id = wctx->level ?
564  wctx->section[wctx->level-1]->id : SECTION_ID_NONE;
565 
566  if (parent_section_id != SECTION_ID_NONE)
567  wctx->nb_item[wctx->level-1]++;
568  if (parent_section_id == SECTION_ID_PACKETS_AND_FRAMES) {
569  if (section_id == SECTION_ID_PACKET) wctx->nb_section_packet++;
570  else wctx->nb_section_frame++;
571  }
572  if (wctx->writer->print_section_footer)
573  wctx->writer->print_section_footer(wctx);
574  wctx->level--;
575 }
576 
577 static inline void writer_print_integer(WriterContext *wctx,
578  const char *key, long long int val)
579 {
580  const struct section *section = wctx->section[wctx->level];
581 
582  if (section->show_all_entries || av_dict_get(section->entries_to_show, key, NULL, 0)) {
583  wctx->writer->print_integer(wctx, key, val);
584  wctx->nb_item[wctx->level]++;
585  }
586 }
587 
588 static inline int validate_string(WriterContext *wctx, char **dstp, const char *src)
589 {
590  const uint8_t *p, *endp;
591  AVBPrint dstbuf;
592  int invalid_chars_nb = 0, ret = 0;
593 
595 
596  endp = src + strlen(src);
597  for (p = (uint8_t *)src; *p;) {
598  uint32_t code;
599  int invalid = 0;
600  const uint8_t *p0 = p;
601 
602  if (av_utf8_decode(&code, &p, endp, wctx->string_validation_utf8_flags) < 0) {
603  AVBPrint bp;
605  bprint_bytes(&bp, p0, p-p0);
606  av_log(wctx, AV_LOG_DEBUG,
607  "Invalid UTF-8 sequence %s found in string '%s'\n", bp.str, src);
608  invalid = 1;
609  }
610 
611  if (invalid) {
612  invalid_chars_nb++;
613 
614  switch (wctx->string_validation) {
616  av_log(wctx, AV_LOG_ERROR,
617  "Invalid UTF-8 sequence found in string '%s'\n", src);
618  ret = AVERROR_INVALIDDATA;
619  goto end;
620  break;
621 
623  av_bprintf(&dstbuf, "%s", wctx->string_validation_replacement);
624  break;
625  }
626  }
627 
628  if (!invalid || wctx->string_validation == WRITER_STRING_VALIDATION_IGNORE)
629  av_bprint_append_data(&dstbuf, p0, p-p0);
630  }
631 
632  if (invalid_chars_nb && wctx->string_validation == WRITER_STRING_VALIDATION_REPLACE) {
633  av_log(wctx, AV_LOG_WARNING,
634  "%d invalid UTF-8 sequence(s) found in string '%s', replaced with '%s'\n",
635  invalid_chars_nb, src, wctx->string_validation_replacement);
636  }
637 
638 end:
639  av_bprint_finalize(&dstbuf, dstp);
640  return ret;
641 }
642 
643 #define PRINT_STRING_OPT 1
644 #define PRINT_STRING_VALIDATE 2
645 
646 static inline int writer_print_string(WriterContext *wctx,
647  const char *key, const char *val, int flags)
648 {
649  const struct section *section = wctx->section[wctx->level];
650  int ret = 0;
651 
652  if ((flags & PRINT_STRING_OPT)
654  return 0;
655 
656  if (section->show_all_entries || av_dict_get(section->entries_to_show, key, NULL, 0)) {
657  if (flags & PRINT_STRING_VALIDATE) {
658  char *key1 = NULL, *val1 = NULL;
659  ret = validate_string(wctx, &key1, key);
660  if (ret < 0) goto end;
661  ret = validate_string(wctx, &val1, val);
662  if (ret < 0) goto end;
663  wctx->writer->print_string(wctx, key1, val1);
664  end:
665  if (ret < 0) {
666  av_log(wctx, AV_LOG_ERROR,
667  "Invalid key=value string combination %s=%s in section %s\n",
668  key, val, section->unique_name);
669  }
670  av_free(key1);
671  av_free(val1);
672  } else {
673  wctx->writer->print_string(wctx, key, val);
674  }
675 
676  wctx->nb_item[wctx->level]++;
677  }
678 
679  return ret;
680 }
681 
682 static inline void writer_print_rational(WriterContext *wctx,
683  const char *key, AVRational q, char sep)
684 {
685  AVBPrint buf;
687  av_bprintf(&buf, "%d%c%d", q.num, sep, q.den);
688  writer_print_string(wctx, key, buf.str, 0);
689 }
690 
691 static void writer_print_time(WriterContext *wctx, const char *key,
692  int64_t ts, const AVRational *time_base, int is_duration)
693 {
694  char buf[128];
695 
696  if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
697  writer_print_string(wctx, key, "N/A", PRINT_STRING_OPT);
698  } else {
699  double d = ts * av_q2d(*time_base);
700  struct unit_value uv;
701  uv.val.d = d;
702  uv.unit = unit_second_str;
703  value_string(buf, sizeof(buf), uv);
704  writer_print_string(wctx, key, buf, 0);
705  }
706 }
707 
708 static void writer_print_ts(WriterContext *wctx, const char *key, int64_t ts, int is_duration)
709 {
710  if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
711  writer_print_string(wctx, key, "N/A", PRINT_STRING_OPT);
712  } else {
713  writer_print_integer(wctx, key, ts);
714  }
715 }
716 
717 static void writer_print_data(WriterContext *wctx, const char *name,
718  uint8_t *data, int size)
719 {
720  AVBPrint bp;
721  int offset = 0, l, i;
722 
724  av_bprintf(&bp, "\n");
725  while (size) {
726  av_bprintf(&bp, "%08x: ", offset);
727  l = FFMIN(size, 16);
728  for (i = 0; i < l; i++) {
729  av_bprintf(&bp, "%02x", data[i]);
730  if (i & 1)
731  av_bprintf(&bp, " ");
732  }
733  av_bprint_chars(&bp, ' ', 41 - 2 * i - i / 2);
734  for (i = 0; i < l; i++)
735  av_bprint_chars(&bp, data[i] - 32U < 95 ? data[i] : '.', 1);
736  av_bprintf(&bp, "\n");
737  offset += l;
738  data += l;
739  size -= l;
740  }
741  writer_print_string(wctx, name, bp.str, 0);
742  av_bprint_finalize(&bp, NULL);
743 }
744 
745 static void writer_print_data_hash(WriterContext *wctx, const char *name,
746  uint8_t *data, int size)
747 {
748  char *p, buf[AV_HASH_MAX_SIZE * 2 + 64] = { 0 };
749 
750  if (!hash)
751  return;
752  av_hash_init(hash);
753  av_hash_update(hash, data, size);
754  snprintf(buf, sizeof(buf), "%s:", av_hash_get_name(hash));
755  p = buf + strlen(buf);
756  av_hash_final_hex(hash, p, buf + sizeof(buf) - p);
757  writer_print_string(wctx, name, buf, 0);
758 }
759 
760 static void writer_print_integers(WriterContext *wctx, const char *name,
761  uint8_t *data, int size, const char *format,
762  int columns, int bytes, int offset_add)
763 {
764  AVBPrint bp;
765  int offset = 0, l, i;
766 
768  av_bprintf(&bp, "\n");
769  while (size) {
770  av_bprintf(&bp, "%08x: ", offset);
771  l = FFMIN(size, columns);
772  for (i = 0; i < l; i++) {
773  if (bytes == 1) av_bprintf(&bp, format, *data);
774  else if (bytes == 2) av_bprintf(&bp, format, AV_RN16(data));
775  else if (bytes == 4) av_bprintf(&bp, format, AV_RN32(data));
776  data += bytes;
777  size --;
778  }
779  av_bprintf(&bp, "\n");
780  offset += offset_add;
781  }
782  writer_print_string(wctx, name, bp.str, 0);
783  av_bprint_finalize(&bp, NULL);
784 }
785 
786 #define MAX_REGISTERED_WRITERS_NB 64
787 
789 
790 static int writer_register(const Writer *writer)
791 {
792  static int next_registered_writer_idx = 0;
793 
794  if (next_registered_writer_idx == MAX_REGISTERED_WRITERS_NB)
795  return AVERROR(ENOMEM);
796 
797  registered_writers[next_registered_writer_idx++] = writer;
798  return 0;
799 }
800 
801 static const Writer *writer_get_by_name(const char *name)
802 {
803  int i;
804 
805  for (i = 0; registered_writers[i]; i++)
806  if (!strcmp(registered_writers[i]->name, name))
807  return registered_writers[i];
808 
809  return NULL;
810 }
811 
812 
813 /* WRITERS */
814 
815 #define DEFINE_WRITER_CLASS(name) \
816 static const char *name##_get_name(void *ctx) \
817 { \
818  return #name ; \
819 } \
820 static const AVClass name##_class = { \
821  .class_name = #name, \
822  .item_name = name##_get_name, \
823  .option = name##_options \
824 }
825 
826 /* Default output */
827 
828 typedef struct DefaultContext {
829  const AVClass *class;
830  int nokey;
834 
835 #undef OFFSET
836 #define OFFSET(x) offsetof(DefaultContext, x)
837 
838 static const AVOption default_options[] = {
839  { "noprint_wrappers", "do not print headers and footers", OFFSET(noprint_wrappers), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
840  { "nw", "do not print headers and footers", OFFSET(noprint_wrappers), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
841  { "nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
842  { "nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
843  {NULL},
844 };
845 
846 DEFINE_WRITER_CLASS(default);
847 
848 /* lame uppercasing routine, assumes the string is lower case ASCII */
849 static inline char *upcase_string(char *dst, size_t dst_size, const char *src)
850 {
851  int i;
852  for (i = 0; src[i] && i < dst_size-1; i++)
853  dst[i] = av_toupper(src[i]);
854  dst[i] = 0;
855  return dst;
856 }
857 
859 {
860  DefaultContext *def = wctx->priv;
861  char buf[32];
862  const struct section *section = wctx->section[wctx->level];
863  const struct section *parent_section = wctx->level ?
864  wctx->section[wctx->level-1] : NULL;
865 
866  av_bprint_clear(&wctx->section_pbuf[wctx->level]);
867  if (parent_section &&
868  !(parent_section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY))) {
869  def->nested_section[wctx->level] = 1;
870  av_bprintf(&wctx->section_pbuf[wctx->level], "%s%s:",
871  wctx->section_pbuf[wctx->level-1].str,
872  upcase_string(buf, sizeof(buf),
873  av_x_if_null(section->element_name, section->name)));
874  }
875 
876  if (def->noprint_wrappers || def->nested_section[wctx->level])
877  return;
878 
880  printf("[%s]\n", upcase_string(buf, sizeof(buf), section->name));
881 }
882 
884 {
885  DefaultContext *def = wctx->priv;
886  const struct section *section = wctx->section[wctx->level];
887  char buf[32];
888 
889  if (def->noprint_wrappers || def->nested_section[wctx->level])
890  return;
891 
893  printf("[/%s]\n", upcase_string(buf, sizeof(buf), section->name));
894 }
895 
896 static void default_print_str(WriterContext *wctx, const char *key, const char *value)
897 {
898  DefaultContext *def = wctx->priv;
899 
900  if (!def->nokey)
901  printf("%s%s=", wctx->section_pbuf[wctx->level].str, key);
902  printf("%s\n", value);
903 }
904 
905 static void default_print_int(WriterContext *wctx, const char *key, long long int value)
906 {
907  DefaultContext *def = wctx->priv;
908 
909  if (!def->nokey)
910  printf("%s%s=", wctx->section_pbuf[wctx->level].str, key);
911  printf("%lld\n", value);
912 }
913 
914 static const Writer default_writer = {
915  .name = "default",
916  .priv_size = sizeof(DefaultContext),
919  .print_integer = default_print_int,
920  .print_string = default_print_str,
922  .priv_class = &default_class,
923 };
924 
925 /* Compact output */
926 
927 /**
928  * Apply C-language-like string escaping.
929  */
930 static const char *c_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
931 {
932  const char *p;
933 
934  for (p = src; *p; p++) {
935  switch (*p) {
936  case '\b': av_bprintf(dst, "%s", "\\b"); break;
937  case '\f': av_bprintf(dst, "%s", "\\f"); break;
938  case '\n': av_bprintf(dst, "%s", "\\n"); break;
939  case '\r': av_bprintf(dst, "%s", "\\r"); break;
940  case '\\': av_bprintf(dst, "%s", "\\\\"); break;
941  default:
942  if (*p == sep)
943  av_bprint_chars(dst, '\\', 1);
944  av_bprint_chars(dst, *p, 1);
945  }
946  }
947  return dst->str;
948 }
949 
950 /**
951  * Quote fields containing special characters, check RFC4180.
952  */
953 static const char *csv_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
954 {
955  char meta_chars[] = { sep, '"', '\n', '\r', '\0' };
956  int needs_quoting = !!src[strcspn(src, meta_chars)];
957 
958  if (needs_quoting)
959  av_bprint_chars(dst, '"', 1);
960 
961  for (; *src; src++) {
962  if (*src == '"')
963  av_bprint_chars(dst, '"', 1);
964  av_bprint_chars(dst, *src, 1);
965  }
966  if (needs_quoting)
967  av_bprint_chars(dst, '"', 1);
968  return dst->str;
969 }
970 
971 static const char *none_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
972 {
973  return src;
974 }
975 
976 typedef struct CompactContext {
977  const AVClass *class;
979  char item_sep;
980  int nokey;
983  const char * (*escape_str)(AVBPrint *dst, const char *src, const char sep, void *log_ctx);
988 
989 #undef OFFSET
990 #define OFFSET(x) offsetof(CompactContext, x)
991 
992 static const AVOption compact_options[]= {
993  {"item_sep", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str="|"}, CHAR_MIN, CHAR_MAX },
994  {"s", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str="|"}, CHAR_MIN, CHAR_MAX },
995  {"nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
996  {"nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
997  {"escape", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="c"}, CHAR_MIN, CHAR_MAX },
998  {"e", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="c"}, CHAR_MIN, CHAR_MAX },
999  {"print_section", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1000  {"p", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1001  {NULL},
1002 };
1003 
1004 DEFINE_WRITER_CLASS(compact);
1005 
1007 {
1008  CompactContext *compact = wctx->priv;
1009 
1010  if (strlen(compact->item_sep_str) != 1) {
1011  av_log(wctx, AV_LOG_ERROR, "Item separator '%s' specified, but must contain a single character\n",
1012  compact->item_sep_str);
1013  return AVERROR(EINVAL);
1014  }
1015  compact->item_sep = compact->item_sep_str[0];
1016 
1017  if (!strcmp(compact->escape_mode_str, "none")) compact->escape_str = none_escape_str;
1018  else if (!strcmp(compact->escape_mode_str, "c" )) compact->escape_str = c_escape_str;
1019  else if (!strcmp(compact->escape_mode_str, "csv" )) compact->escape_str = csv_escape_str;
1020  else {
1021  av_log(wctx, AV_LOG_ERROR, "Unknown escape mode '%s'\n", compact->escape_mode_str);
1022  return AVERROR(EINVAL);
1023  }
1024 
1025  return 0;
1026 }
1027 
1029 {
1030  CompactContext *compact = wctx->priv;
1031  const struct section *section = wctx->section[wctx->level];
1032  const struct section *parent_section = wctx->level ?
1033  wctx->section[wctx->level-1] : NULL;
1034  compact->terminate_line[wctx->level] = 1;
1035  compact->has_nested_elems[wctx->level] = 0;
1036 
1037  av_bprint_clear(&wctx->section_pbuf[wctx->level]);
1038  if (!(section->flags & SECTION_FLAG_IS_ARRAY) && parent_section &&
1039  !(parent_section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY))) {
1040  compact->nested_section[wctx->level] = 1;
1041  compact->has_nested_elems[wctx->level-1] = 1;
1042  av_bprintf(&wctx->section_pbuf[wctx->level], "%s%s:",
1043  wctx->section_pbuf[wctx->level-1].str,
1044  (char *)av_x_if_null(section->element_name, section->name));
1045  wctx->nb_item[wctx->level] = wctx->nb_item[wctx->level-1];
1046  } else {
1047  if (parent_section && compact->has_nested_elems[wctx->level-1] &&
1048  (section->flags & SECTION_FLAG_IS_ARRAY)) {
1049  compact->terminate_line[wctx->level-1] = 0;
1050  printf("\n");
1051  }
1052  if (compact->print_section &&
1054  printf("%s%c", section->name, compact->item_sep);
1055  }
1056 }
1057 
1059 {
1060  CompactContext *compact = wctx->priv;
1061 
1062  if (!compact->nested_section[wctx->level] &&
1063  compact->terminate_line[wctx->level] &&
1065  printf("\n");
1066 }
1067 
1068 static void compact_print_str(WriterContext *wctx, const char *key, const char *value)
1069 {
1070  CompactContext *compact = wctx->priv;
1071  AVBPrint buf;
1072 
1073  if (wctx->nb_item[wctx->level]) printf("%c", compact->item_sep);
1074  if (!compact->nokey)
1075  printf("%s%s=", wctx->section_pbuf[wctx->level].str, key);
1077  printf("%s", compact->escape_str(&buf, value, compact->item_sep, wctx));
1078  av_bprint_finalize(&buf, NULL);
1079 }
1080 
1081 static void compact_print_int(WriterContext *wctx, const char *key, long long int value)
1082 {
1083  CompactContext *compact = wctx->priv;
1084 
1085  if (wctx->nb_item[wctx->level]) printf("%c", compact->item_sep);
1086  if (!compact->nokey)
1087  printf("%s%s=", wctx->section_pbuf[wctx->level].str, key);
1088  printf("%lld", value);
1089 }
1090 
1091 static const Writer compact_writer = {
1092  .name = "compact",
1093  .priv_size = sizeof(CompactContext),
1094  .init = compact_init,
1097  .print_integer = compact_print_int,
1098  .print_string = compact_print_str,
1100  .priv_class = &compact_class,
1101 };
1102 
1103 /* CSV output */
1104 
1105 #undef OFFSET
1106 #define OFFSET(x) offsetof(CompactContext, x)
1107 
1108 static const AVOption csv_options[] = {
1109  {"item_sep", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=","}, CHAR_MIN, CHAR_MAX },
1110  {"s", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=","}, CHAR_MIN, CHAR_MAX },
1111  {"nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1112  {"nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1113  {"escape", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="csv"}, CHAR_MIN, CHAR_MAX },
1114  {"e", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="csv"}, CHAR_MIN, CHAR_MAX },
1115  {"print_section", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1116  {"p", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1117  {NULL},
1118 };
1119 
1120 DEFINE_WRITER_CLASS(csv);
1121 
1122 static const Writer csv_writer = {
1123  .name = "csv",
1124  .priv_size = sizeof(CompactContext),
1125  .init = compact_init,
1128  .print_integer = compact_print_int,
1129  .print_string = compact_print_str,
1131  .priv_class = &csv_class,
1132 };
1133 
1134 /* Flat output */
1135 
1136 typedef struct FlatContext {
1137  const AVClass *class;
1138  const char *sep_str;
1139  char sep;
1141 } FlatContext;
1142 
1143 #undef OFFSET
1144 #define OFFSET(x) offsetof(FlatContext, x)
1145 
1146 static const AVOption flat_options[]= {
1147  {"sep_char", "set separator", OFFSET(sep_str), AV_OPT_TYPE_STRING, {.str="."}, CHAR_MIN, CHAR_MAX },
1148  {"s", "set separator", OFFSET(sep_str), AV_OPT_TYPE_STRING, {.str="."}, CHAR_MIN, CHAR_MAX },
1149  {"hierarchical", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1150  {"h", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1151  {NULL},
1152 };
1153 
1155 
1157 {
1158  FlatContext *flat = wctx->priv;
1159 
1160  if (strlen(flat->sep_str) != 1) {
1161  av_log(wctx, AV_LOG_ERROR, "Item separator '%s' specified, but must contain a single character\n",
1162  flat->sep_str);
1163  return AVERROR(EINVAL);
1164  }
1165  flat->sep = flat->sep_str[0];
1166 
1167  return 0;
1168 }
1169 
1170 static const char *flat_escape_key_str(AVBPrint *dst, const char *src, const char sep)
1171 {
1172  const char *p;
1173 
1174  for (p = src; *p; p++) {
1175  if (!((*p >= '0' && *p <= '9') ||
1176  (*p >= 'a' && *p <= 'z') ||
1177  (*p >= 'A' && *p <= 'Z')))
1178  av_bprint_chars(dst, '_', 1);
1179  else
1180  av_bprint_chars(dst, *p, 1);
1181  }
1182  return dst->str;
1183 }
1184 
1185 static const char *flat_escape_value_str(AVBPrint *dst, const char *src)
1186 {
1187  const char *p;
1188 
1189  for (p = src; *p; p++) {
1190  switch (*p) {
1191  case '\n': av_bprintf(dst, "%s", "\\n"); break;
1192  case '\r': av_bprintf(dst, "%s", "\\r"); break;
1193  case '\\': av_bprintf(dst, "%s", "\\\\"); break;
1194  case '"': av_bprintf(dst, "%s", "\\\""); break;
1195  case '`': av_bprintf(dst, "%s", "\\`"); break;
1196  case '$': av_bprintf(dst, "%s", "\\$"); break;
1197  default: av_bprint_chars(dst, *p, 1); break;
1198  }
1199  }
1200  return dst->str;
1201 }
1202 
1204 {
1205  FlatContext *flat = wctx->priv;
1206  AVBPrint *buf = &wctx->section_pbuf[wctx->level];
1207  const struct section *section = wctx->section[wctx->level];
1208  const struct section *parent_section = wctx->level ?
1209  wctx->section[wctx->level-1] : NULL;
1210 
1211  /* build section header */
1212  av_bprint_clear(buf);
1213  if (!parent_section)
1214  return;
1215  av_bprintf(buf, "%s", wctx->section_pbuf[wctx->level-1].str);
1216 
1217  if (flat->hierarchical ||
1219  av_bprintf(buf, "%s%s", wctx->section[wctx->level]->name, flat->sep_str);
1220 
1221  if (parent_section->flags & SECTION_FLAG_IS_ARRAY) {
1222  int n = parent_section->id == SECTION_ID_PACKETS_AND_FRAMES ?
1223  wctx->nb_section_packet_frame : wctx->nb_item[wctx->level-1];
1224  av_bprintf(buf, "%d%s", n, flat->sep_str);
1225  }
1226  }
1227 }
1228 
1229 static void flat_print_int(WriterContext *wctx, const char *key, long long int value)
1230 {
1231  printf("%s%s=%lld\n", wctx->section_pbuf[wctx->level].str, key, value);
1232 }
1233 
1234 static void flat_print_str(WriterContext *wctx, const char *key, const char *value)
1235 {
1236  FlatContext *flat = wctx->priv;
1237  AVBPrint buf;
1238 
1239  printf("%s", wctx->section_pbuf[wctx->level].str);
1241  printf("%s=", flat_escape_key_str(&buf, key, flat->sep));
1242  av_bprint_clear(&buf);
1243  printf("\"%s\"\n", flat_escape_value_str(&buf, value));
1244  av_bprint_finalize(&buf, NULL);
1245 }
1246 
1247 static const Writer flat_writer = {
1248  .name = "flat",
1249  .priv_size = sizeof(FlatContext),
1250  .init = flat_init,
1252  .print_integer = flat_print_int,
1253  .print_string = flat_print_str,
1255  .priv_class = &flat_class,
1256 };
1257 
1258 /* INI format output */
1259 
1260 typedef struct INIContext {
1261  const AVClass *class;
1263 } INIContext;
1264 
1265 #undef OFFSET
1266 #define OFFSET(x) offsetof(INIContext, x)
1267 
1268 static const AVOption ini_options[] = {
1269  {"hierarchical", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1270  {"h", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1271  {NULL},
1272 };
1273 
1274 DEFINE_WRITER_CLASS(ini);
1275 
1276 static char *ini_escape_str(AVBPrint *dst, const char *src)
1277 {
1278  int i = 0;
1279  char c = 0;
1280 
1281  while (c = src[i++]) {
1282  switch (c) {
1283  case '\b': av_bprintf(dst, "%s", "\\b"); break;
1284  case '\f': av_bprintf(dst, "%s", "\\f"); break;
1285  case '\n': av_bprintf(dst, "%s", "\\n"); break;
1286  case '\r': av_bprintf(dst, "%s", "\\r"); break;
1287  case '\t': av_bprintf(dst, "%s", "\\t"); break;
1288  case '\\':
1289  case '#' :
1290  case '=' :
1291  case ':' : av_bprint_chars(dst, '\\', 1);
1292  default:
1293  if ((unsigned char)c < 32)
1294  av_bprintf(dst, "\\x00%02x", c & 0xff);
1295  else
1296  av_bprint_chars(dst, c, 1);
1297  break;
1298  }
1299  }
1300  return dst->str;
1301 }
1302 
1304 {
1305  INIContext *ini = wctx->priv;
1306  AVBPrint *buf = &wctx->section_pbuf[wctx->level];
1307  const struct section *section = wctx->section[wctx->level];
1308  const struct section *parent_section = wctx->level ?
1309  wctx->section[wctx->level-1] : NULL;
1310 
1311  av_bprint_clear(buf);
1312  if (!parent_section) {
1313  printf("# ffprobe output\n\n");
1314  return;
1315  }
1316 
1317  if (wctx->nb_item[wctx->level-1])
1318  printf("\n");
1319 
1320  av_bprintf(buf, "%s", wctx->section_pbuf[wctx->level-1].str);
1321  if (ini->hierarchical ||
1323  av_bprintf(buf, "%s%s", buf->str[0] ? "." : "", wctx->section[wctx->level]->name);
1324 
1325  if (parent_section->flags & SECTION_FLAG_IS_ARRAY) {
1326  int n = parent_section->id == SECTION_ID_PACKETS_AND_FRAMES ?
1327  wctx->nb_section_packet_frame : wctx->nb_item[wctx->level-1];
1328  av_bprintf(buf, ".%d", n);
1329  }
1330  }
1331 
1333  printf("[%s]\n", buf->str);
1334 }
1335 
1336 static void ini_print_str(WriterContext *wctx, const char *key, const char *value)
1337 {
1338  AVBPrint buf;
1339 
1341  printf("%s=", ini_escape_str(&buf, key));
1342  av_bprint_clear(&buf);
1343  printf("%s\n", ini_escape_str(&buf, value));
1344  av_bprint_finalize(&buf, NULL);
1345 }
1346 
1347 static void ini_print_int(WriterContext *wctx, const char *key, long long int value)
1348 {
1349  printf("%s=%lld\n", key, value);
1350 }
1351 
1352 static const Writer ini_writer = {
1353  .name = "ini",
1354  .priv_size = sizeof(INIContext),
1356  .print_integer = ini_print_int,
1357  .print_string = ini_print_str,
1359  .priv_class = &ini_class,
1360 };
1361 
1362 /* JSON output */
1363 
1364 typedef struct JSONContext {
1365  const AVClass *class;
1367  int compact;
1368  const char *item_sep, *item_start_end;
1369 } JSONContext;
1370 
1371 #undef OFFSET
1372 #define OFFSET(x) offsetof(JSONContext, x)
1373 
1374 static const AVOption json_options[]= {
1375  { "compact", "enable compact output", OFFSET(compact), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1376  { "c", "enable compact output", OFFSET(compact), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1377  { NULL }
1378 };
1379 
1380 DEFINE_WRITER_CLASS(json);
1381 
1383 {
1384  JSONContext *json = wctx->priv;
1385 
1386  json->item_sep = json->compact ? ", " : ",\n";
1387  json->item_start_end = json->compact ? " " : "\n";
1388 
1389  return 0;
1390 }
1391 
1392 static const char *json_escape_str(AVBPrint *dst, const char *src, void *log_ctx)
1393 {
1394  static const char json_escape[] = {'"', '\\', '\b', '\f', '\n', '\r', '\t', 0};
1395  static const char json_subst[] = {'"', '\\', 'b', 'f', 'n', 'r', 't', 0};
1396  const char *p;
1397 
1398  for (p = src; *p; p++) {
1399  char *s = strchr(json_escape, *p);
1400  if (s) {
1401  av_bprint_chars(dst, '\\', 1);
1402  av_bprint_chars(dst, json_subst[s - json_escape], 1);
1403  } else if ((unsigned char)*p < 32) {
1404  av_bprintf(dst, "\\u00%02x", *p & 0xff);
1405  } else {
1406  av_bprint_chars(dst, *p, 1);
1407  }
1408  }
1409  return dst->str;
1410 }
1411 
1412 #define JSON_INDENT() printf("%*c", json->indent_level * 4, ' ')
1413 
1415 {
1416  JSONContext *json = wctx->priv;
1417  AVBPrint buf;
1418  const struct section *section = wctx->section[wctx->level];
1419  const struct section *parent_section = wctx->level ?
1420  wctx->section[wctx->level-1] : NULL;
1421 
1422  if (wctx->level && wctx->nb_item[wctx->level-1])
1423  printf(",\n");
1424 
1425  if (section->flags & SECTION_FLAG_IS_WRAPPER) {
1426  printf("{\n");
1427  json->indent_level++;
1428  } else {
1430  json_escape_str(&buf, section->name, wctx);
1431  JSON_INDENT();
1432 
1433  json->indent_level++;
1434  if (section->flags & SECTION_FLAG_IS_ARRAY) {
1435  printf("\"%s\": [\n", buf.str);
1436  } else if (parent_section && !(parent_section->flags & SECTION_FLAG_IS_ARRAY)) {
1437  printf("\"%s\": {%s", buf.str, json->item_start_end);
1438  } else {
1439  printf("{%s", json->item_start_end);
1440 
1441  /* this is required so the parser can distinguish between packets and frames */
1442  if (parent_section && parent_section->id == SECTION_ID_PACKETS_AND_FRAMES) {
1443  if (!json->compact)
1444  JSON_INDENT();
1445  printf("\"type\": \"%s\"%s", section->name, json->item_sep);
1446  }
1447  }
1448  av_bprint_finalize(&buf, NULL);
1449  }
1450 }
1451 
1453 {
1454  JSONContext *json = wctx->priv;
1455  const struct section *section = wctx->section[wctx->level];
1456 
1457  if (wctx->level == 0) {
1458  json->indent_level--;
1459  printf("\n}\n");
1460  } else if (section->flags & SECTION_FLAG_IS_ARRAY) {
1461  printf("\n");
1462  json->indent_level--;
1463  JSON_INDENT();
1464  printf("]");
1465  } else {
1466  printf("%s", json->item_start_end);
1467  json->indent_level--;
1468  if (!json->compact)
1469  JSON_INDENT();
1470  printf("}");
1471  }
1472 }
1473 
1474 static inline void json_print_item_str(WriterContext *wctx,
1475  const char *key, const char *value)
1476 {
1477  AVBPrint buf;
1478 
1480  printf("\"%s\":", json_escape_str(&buf, key, wctx));
1481  av_bprint_clear(&buf);
1482  printf(" \"%s\"", json_escape_str(&buf, value, wctx));
1483  av_bprint_finalize(&buf, NULL);
1484 }
1485 
1486 static void json_print_str(WriterContext *wctx, const char *key, const char *value)
1487 {
1488  JSONContext *json = wctx->priv;
1489 
1490  if (wctx->nb_item[wctx->level])
1491  printf("%s", json->item_sep);
1492  if (!json->compact)
1493  JSON_INDENT();
1494  json_print_item_str(wctx, key, value);
1495 }
1496 
1497 static void json_print_int(WriterContext *wctx, const char *key, long long int value)
1498 {
1499  JSONContext *json = wctx->priv;
1500  AVBPrint buf;
1501 
1502  if (wctx->nb_item[wctx->level])
1503  printf("%s", json->item_sep);
1504  if (!json->compact)
1505  JSON_INDENT();
1506 
1508  printf("\"%s\": %lld", json_escape_str(&buf, key, wctx), value);
1509  av_bprint_finalize(&buf, NULL);
1510 }
1511 
1512 static const Writer json_writer = {
1513  .name = "json",
1514  .priv_size = sizeof(JSONContext),
1515  .init = json_init,
1518  .print_integer = json_print_int,
1519  .print_string = json_print_str,
1521  .priv_class = &json_class,
1522 };
1523 
1524 /* XML output */
1525 
1526 typedef struct XMLContext {
1527  const AVClass *class;
1532 } XMLContext;
1533 
1534 #undef OFFSET
1535 #define OFFSET(x) offsetof(XMLContext, x)
1536 
1537 static const AVOption xml_options[] = {
1538  {"fully_qualified", "specify if the output should be fully qualified", OFFSET(fully_qualified), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1539  {"q", "specify if the output should be fully qualified", OFFSET(fully_qualified), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1540  {"xsd_strict", "ensure that the output is XSD compliant", OFFSET(xsd_strict), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1541  {"x", "ensure that the output is XSD compliant", OFFSET(xsd_strict), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1542  {NULL},
1543 };
1544 
1545 DEFINE_WRITER_CLASS(xml);
1546 
1547 static av_cold int xml_init(WriterContext *wctx)
1548 {
1549  XMLContext *xml = wctx->priv;
1550 
1551  if (xml->xsd_strict) {
1552  xml->fully_qualified = 1;
1553 #define CHECK_COMPLIANCE(opt, opt_name) \
1554  if (opt) { \
1555  av_log(wctx, AV_LOG_ERROR, \
1556  "XSD-compliant output selected but option '%s' was selected, XML output may be non-compliant.\n" \
1557  "You need to disable such option with '-no%s'\n", opt_name, opt_name); \
1558  return AVERROR(EINVAL); \
1559  }
1560  CHECK_COMPLIANCE(show_private_data, "private");
1563 
1565  av_log(wctx, AV_LOG_ERROR,
1566  "Interleaved frames and packets are not allowed in XSD. "
1567  "Select only one between the -show_frames and the -show_packets options.\n");
1568  return AVERROR(EINVAL);
1569  }
1570  }
1571 
1572  return 0;
1573 }
1574 
1575 static const char *xml_escape_str(AVBPrint *dst, const char *src, void *log_ctx)
1576 {
1577  const char *p;
1578 
1579  for (p = src; *p; p++) {
1580  switch (*p) {
1581  case '&' : av_bprintf(dst, "%s", "&amp;"); break;
1582  case '<' : av_bprintf(dst, "%s", "&lt;"); break;
1583  case '>' : av_bprintf(dst, "%s", "&gt;"); break;
1584  case '"' : av_bprintf(dst, "%s", "&quot;"); break;
1585  case '\'': av_bprintf(dst, "%s", "&apos;"); break;
1586  default: av_bprint_chars(dst, *p, 1);
1587  }
1588  }
1589 
1590  return dst->str;
1591 }
1592 
1593 #define XML_INDENT() printf("%*c", xml->indent_level * 4, ' ')
1594 
1596 {
1597  XMLContext *xml = wctx->priv;
1598  const struct section *section = wctx->section[wctx->level];
1599  const struct section *parent_section = wctx->level ?
1600  wctx->section[wctx->level-1] : NULL;
1601 
1602  if (wctx->level == 0) {
1603  const char *qual = " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' "
1604  "xmlns:ffprobe='http://www.ffmpeg.org/schema/ffprobe' "
1605  "xsi:schemaLocation='http://www.ffmpeg.org/schema/ffprobe ffprobe.xsd'";
1606 
1607  printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
1608  printf("<%sffprobe%s>\n",
1609  xml->fully_qualified ? "ffprobe:" : "",
1610  xml->fully_qualified ? qual : "");
1611  return;
1612  }
1613 
1614  if (xml->within_tag) {
1615  xml->within_tag = 0;
1616  printf(">\n");
1617  }
1618  if (section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS) {
1619  xml->indent_level++;
1620  } else {
1621  if (parent_section && (parent_section->flags & SECTION_FLAG_IS_WRAPPER) &&
1622  wctx->level && wctx->nb_item[wctx->level-1])
1623  printf("\n");
1624  xml->indent_level++;
1625 
1626  if (section->flags & SECTION_FLAG_IS_ARRAY) {
1627  XML_INDENT(); printf("<%s>\n", section->name);
1628  } else {
1629  XML_INDENT(); printf("<%s ", section->name);
1630  xml->within_tag = 1;
1631  }
1632  }
1633 }
1634 
1636 {
1637  XMLContext *xml = wctx->priv;
1638  const struct section *section = wctx->section[wctx->level];
1639 
1640  if (wctx->level == 0) {
1641  printf("</%sffprobe>\n", xml->fully_qualified ? "ffprobe:" : "");
1642  } else if (xml->within_tag) {
1643  xml->within_tag = 0;
1644  printf("/>\n");
1645  xml->indent_level--;
1646  } else if (section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS) {
1647  xml->indent_level--;
1648  } else {
1649  XML_INDENT(); printf("</%s>\n", section->name);
1650  xml->indent_level--;
1651  }
1652 }
1653 
1654 static void xml_print_str(WriterContext *wctx, const char *key, const char *value)
1655 {
1656  AVBPrint buf;
1657  XMLContext *xml = wctx->priv;
1658  const struct section *section = wctx->section[wctx->level];
1659 
1661 
1662  if (section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS) {
1663  XML_INDENT();
1664  printf("<%s key=\"%s\"",
1665  section->element_name, xml_escape_str(&buf, key, wctx));
1666  av_bprint_clear(&buf);
1667  printf(" value=\"%s\"/>\n", xml_escape_str(&buf, value, wctx));
1668  } else {
1669  if (wctx->nb_item[wctx->level])
1670  printf(" ");
1671  printf("%s=\"%s\"", key, xml_escape_str(&buf, value, wctx));
1672  }
1673 
1674  av_bprint_finalize(&buf, NULL);
1675 }
1676 
1677 static void xml_print_int(WriterContext *wctx, const char *key, long long int value)
1678 {
1679  if (wctx->nb_item[wctx->level])
1680  printf(" ");
1681  printf("%s=\"%lld\"", key, value);
1682 }
1683 
1684 static Writer xml_writer = {
1685  .name = "xml",
1686  .priv_size = sizeof(XMLContext),
1687  .init = xml_init,
1690  .print_integer = xml_print_int,
1691  .print_string = xml_print_str,
1693  .priv_class = &xml_class,
1694 };
1695 
1696 static void writer_register_all(void)
1697 {
1698  static int initialized;
1699 
1700  if (initialized)
1701  return;
1702  initialized = 1;
1703 
1704  writer_register(&default_writer);
1705  writer_register(&compact_writer);
1706  writer_register(&csv_writer);
1707  writer_register(&flat_writer);
1708  writer_register(&ini_writer);
1709  writer_register(&json_writer);
1710  writer_register(&xml_writer);
1711 }
1712 
1713 #define print_fmt(k, f, ...) do { \
1714  av_bprint_clear(&pbuf); \
1715  av_bprintf(&pbuf, f, __VA_ARGS__); \
1716  writer_print_string(w, k, pbuf.str, 0); \
1717 } while (0)
1718 
1719 #define print_int(k, v) writer_print_integer(w, k, v)
1720 #define print_q(k, v, s) writer_print_rational(w, k, v, s)
1721 #define print_str(k, v) writer_print_string(w, k, v, 0)
1722 #define print_str_opt(k, v) writer_print_string(w, k, v, PRINT_STRING_OPT)
1723 #define print_str_validate(k, v) writer_print_string(w, k, v, PRINT_STRING_VALIDATE)
1724 #define print_time(k, v, tb) writer_print_time(w, k, v, tb, 0)
1725 #define print_ts(k, v) writer_print_ts(w, k, v, 0)
1726 #define print_duration_time(k, v, tb) writer_print_time(w, k, v, tb, 1)
1727 #define print_duration_ts(k, v) writer_print_ts(w, k, v, 1)
1728 #define print_val(k, v, u) do { \
1729  struct unit_value uv; \
1730  uv.val.i = v; \
1731  uv.unit = u; \
1732  writer_print_string(w, k, value_string(val_str, sizeof(val_str), uv), 0); \
1733 } while (0)
1734 
1735 #define print_section_header(s) writer_print_section_header(w, s)
1736 #define print_section_footer(s) writer_print_section_footer(w, s)
1737 
1738 #define REALLOCZ_ARRAY_STREAM(ptr, cur_n, new_n) \
1739 { \
1740  ret = av_reallocp_array(&(ptr), (new_n), sizeof(*(ptr))); \
1741  if (ret < 0) \
1742  goto end; \
1743  memset( (ptr) + (cur_n), 0, ((new_n) - (cur_n)) * sizeof(*(ptr)) ); \
1744 }
1745 
1746 static inline int show_tags(WriterContext *w, AVDictionary *tags, int section_id)
1747 {
1749  int ret = 0;
1750 
1751  if (!tags)
1752  return 0;
1753  writer_print_section_header(w, section_id);
1754 
1755  while ((tag = av_dict_get(tags, "", tag, AV_DICT_IGNORE_SUFFIX))) {
1756  if ((ret = print_str_validate(tag->key, tag->value)) < 0)
1757  break;
1758  }
1760 
1761  return ret;
1762 }
1763 
1765  AVCodecParameters *par,
1766  const AVPacketSideData *side_data,
1767  int nb_side_data,
1768  SectionID id_data_list,
1769  SectionID id_data)
1770 {
1771  int i;
1772 
1774  for (i = 0; i < nb_side_data; i++) {
1775  const AVPacketSideData *sd = &side_data[i];
1776  const char *name = av_packet_side_data_name(sd->type);
1777 
1779  print_str("side_data_type", name ? name : "unknown");
1780  if (sd->type == AV_PKT_DATA_DISPLAYMATRIX && sd->size >= 9*4) {
1781  writer_print_integers(w, "displaymatrix", sd->data, 9, " %11d", 3, 4, 1);
1782  print_int("rotation", av_display_rotation_get((int32_t *)sd->data));
1783  } else if (sd->type == AV_PKT_DATA_STEREO3D) {
1784  const AVStereo3D *stereo = (AVStereo3D *)sd->data;
1785  print_str("type", av_stereo3d_type_name(stereo->type));
1786  print_int("inverted", !!(stereo->flags & AV_STEREO3D_FLAG_INVERT));
1787  } else if (sd->type == AV_PKT_DATA_SPHERICAL) {
1788  const AVSphericalMapping *spherical = (AVSphericalMapping *)sd->data;
1790  print_str("projection", "equirectangular");
1791  else if (spherical->projection == AV_SPHERICAL_CUBEMAP) {
1792  print_str("projection", "cubemap");
1793  print_int("padding", spherical->padding);
1794  } else if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR_TILE) {
1795  size_t l, t, r, b;
1796  av_spherical_tile_bounds(spherical, par->width, par->height,
1797  &l, &t, &r, &b);
1798  print_str("projection", "tiled equirectangular");
1799  print_int("bound_left", l);
1800  print_int("bound_top", t);
1801  print_int("bound_right", r);
1802  print_int("bound_bottom", b);
1803  } else
1804  print_str("projection", "unknown");
1805 
1806  print_int("yaw", (double) spherical->yaw / (1 << 16));
1807  print_int("pitch", (double) spherical->pitch / (1 << 16));
1808  print_int("roll", (double) spherical->roll / (1 << 16));
1809  }
1811  }
1813 }
1814 
1815 static void show_packet(WriterContext *w, InputFile *ifile, AVPacket *pkt, int packet_idx)
1816 {
1817  char val_str[128];
1818  AVStream *st = ifile->streams[pkt->stream_index].st;
1819  AVBPrint pbuf;
1820  const char *s;
1821 
1823 
1825 
1827  if (s) print_str ("codec_type", s);
1828  else print_str_opt("codec_type", "unknown");
1829  print_int("stream_index", pkt->stream_index);
1830  print_ts ("pts", pkt->pts);
1831  print_time("pts_time", pkt->pts, &st->time_base);
1832  print_ts ("dts", pkt->dts);
1833  print_time("dts_time", pkt->dts, &st->time_base);
1834  print_duration_ts("duration", pkt->duration);
1835  print_duration_time("duration_time", pkt->duration, &st->time_base);
1836  print_duration_ts("convergence_duration", pkt->convergence_duration);
1837  print_duration_time("convergence_duration_time", pkt->convergence_duration, &st->time_base);
1838  print_val("size", pkt->size, unit_byte_str);
1839  if (pkt->pos != -1) print_fmt ("pos", "%"PRId64, pkt->pos);
1840  else print_str_opt("pos", "N/A");
1841  print_fmt("flags", "%c%c", pkt->flags & AV_PKT_FLAG_KEY ? 'K' : '_',
1842  pkt->flags & AV_PKT_FLAG_DISCARD ? 'D' : '_');
1843 
1844  if (pkt->side_data_elems) {
1845  int size;
1846  const uint8_t *side_metadata;
1847 
1848  side_metadata = av_packet_get_side_data(pkt, AV_PKT_DATA_STRINGS_METADATA, &size);
1849  if (side_metadata && size && do_show_packet_tags) {
1850  AVDictionary *dict = NULL;
1851  if (av_packet_unpack_dictionary(side_metadata, size, &dict) >= 0)
1853  av_dict_free(&dict);
1854  }
1855 
1859  }
1860 
1861  if (do_show_data)
1862  writer_print_data(w, "data", pkt->data, pkt->size);
1863  writer_print_data_hash(w, "data_hash", pkt->data, pkt->size);
1865 
1866  av_bprint_finalize(&pbuf, NULL);
1867  fflush(stdout);
1868 }
1869 
1870 static void show_subtitle(WriterContext *w, AVSubtitle *sub, AVStream *stream,
1872 {
1873  AVBPrint pbuf;
1874 
1876 
1878 
1879  print_str ("media_type", "subtitle");
1880  print_ts ("pts", sub->pts);
1881  print_time("pts_time", sub->pts, &AV_TIME_BASE_Q);
1882  print_int ("format", sub->format);
1883  print_int ("start_display_time", sub->start_display_time);
1884  print_int ("end_display_time", sub->end_display_time);
1885  print_int ("num_rects", sub->num_rects);
1886 
1888 
1889  av_bprint_finalize(&pbuf, NULL);
1890  fflush(stdout);
1891 }
1892 
1893 static void show_frame(WriterContext *w, AVFrame *frame, AVStream *stream,
1895 {
1896  AVBPrint pbuf;
1897  char val_str[128];
1898  const char *s;
1899  int i;
1900 
1902 
1904 
1906  if (s) print_str ("media_type", s);
1907  else print_str_opt("media_type", "unknown");
1908  print_int("stream_index", stream->index);
1909  print_int("key_frame", frame->key_frame);
1910  print_ts ("pkt_pts", frame->pts);
1911  print_time("pkt_pts_time", frame->pts, &stream->time_base);
1912  print_ts ("pkt_dts", frame->pkt_dts);
1913  print_time("pkt_dts_time", frame->pkt_dts, &stream->time_base);
1914  print_ts ("best_effort_timestamp", av_frame_get_best_effort_timestamp(frame));
1915  print_time("best_effort_timestamp_time", av_frame_get_best_effort_timestamp(frame), &stream->time_base);
1916  print_duration_ts ("pkt_duration", av_frame_get_pkt_duration(frame));
1917  print_duration_time("pkt_duration_time", av_frame_get_pkt_duration(frame), &stream->time_base);
1918  if (av_frame_get_pkt_pos (frame) != -1) print_fmt ("pkt_pos", "%"PRId64, av_frame_get_pkt_pos(frame));
1919  else print_str_opt("pkt_pos", "N/A");
1920  if (av_frame_get_pkt_size(frame) != -1) print_val ("pkt_size", av_frame_get_pkt_size(frame), unit_byte_str);
1921  else print_str_opt("pkt_size", "N/A");
1922 
1923  switch (stream->codecpar->codec_type) {
1924  AVRational sar;
1925 
1926  case AVMEDIA_TYPE_VIDEO:
1927  print_int("width", frame->width);
1928  print_int("height", frame->height);
1929  s = av_get_pix_fmt_name(frame->format);
1930  if (s) print_str ("pix_fmt", s);
1931  else print_str_opt("pix_fmt", "unknown");
1932  sar = av_guess_sample_aspect_ratio(fmt_ctx, stream, frame);
1933  if (sar.num) {
1934  print_q("sample_aspect_ratio", sar, ':');
1935  } else {
1936  print_str_opt("sample_aspect_ratio", "N/A");
1937  }
1938  print_fmt("pict_type", "%c", av_get_picture_type_char(frame->pict_type));
1939  print_int("coded_picture_number", frame->coded_picture_number);
1940  print_int("display_picture_number", frame->display_picture_number);
1941  print_int("interlaced_frame", frame->interlaced_frame);
1942  print_int("top_field_first", frame->top_field_first);
1943  print_int("repeat_pict", frame->repeat_pict);
1944  break;
1945 
1946  case AVMEDIA_TYPE_AUDIO:
1947  s = av_get_sample_fmt_name(frame->format);
1948  if (s) print_str ("sample_fmt", s);
1949  else print_str_opt("sample_fmt", "unknown");
1950  print_int("nb_samples", frame->nb_samples);
1951  print_int("channels", av_frame_get_channels(frame));
1952  if (av_frame_get_channel_layout(frame)) {
1953  av_bprint_clear(&pbuf);
1956  print_str ("channel_layout", pbuf.str);
1957  } else
1958  print_str_opt("channel_layout", "unknown");
1959  break;
1960  }
1961  if (do_show_frame_tags)
1963  if (frame->nb_side_data) {
1965  for (i = 0; i < frame->nb_side_data; i++) {
1966  AVFrameSideData *sd = frame->side_data[i];
1967  const char *name;
1968 
1970  name = av_frame_side_data_name(sd->type);
1971  print_str("side_data_type", name ? name : "unknown");
1972  if (sd->type == AV_FRAME_DATA_DISPLAYMATRIX && sd->size >= 9*4) {
1973  writer_print_integers(w, "displaymatrix", sd->data, 9, " %11d", 3, 4, 1);
1974  print_int("rotation", av_display_rotation_get((int32_t *)sd->data));
1975  } else if (sd->type == AV_FRAME_DATA_GOP_TIMECODE && sd->size >= 8) {
1976  char tcbuf[AV_TIMECODE_STR_SIZE];
1977  av_timecode_make_mpeg_tc_string(tcbuf, *(int64_t *)(sd->data));
1978  print_str("timecode", tcbuf);
1979  }
1981  }
1983  }
1984 
1986 
1987  av_bprint_finalize(&pbuf, NULL);
1988  fflush(stdout);
1989 }
1990 
1992  InputFile *ifile,
1994 {
1995  AVFormatContext *fmt_ctx = ifile->fmt_ctx;
1997  AVCodecParameters *par = ifile->streams[pkt->stream_index].st->codecpar;
1998  AVSubtitle sub;
1999  int ret = 0, got_frame = 0;
2000 
2001  if (dec_ctx && dec_ctx->codec) {
2002  switch (par->codec_type) {
2003  case AVMEDIA_TYPE_VIDEO:
2004  ret = avcodec_decode_video2(dec_ctx, frame, &got_frame, pkt);
2005  break;
2006 
2007  case AVMEDIA_TYPE_AUDIO:
2008  ret = avcodec_decode_audio4(dec_ctx, frame, &got_frame, pkt);
2009  break;
2010 
2011  case AVMEDIA_TYPE_SUBTITLE:
2012  ret = avcodec_decode_subtitle2(dec_ctx, &sub, &got_frame, pkt);
2013  break;
2014  }
2015  }
2016 
2017  if (ret < 0)
2018  return ret;
2019  ret = FFMIN(ret, pkt->size); /* guard against bogus return values */
2020  pkt->data += ret;
2021  pkt->size -= ret;
2022  if (got_frame) {
2023  int is_sub = (par->codec_type == AVMEDIA_TYPE_SUBTITLE);
2025  if (do_show_frames)
2026  if (is_sub)
2027  show_subtitle(w, &sub, ifile->streams[pkt->stream_index].st, fmt_ctx);
2028  else
2029  show_frame(w, frame, ifile->streams[pkt->stream_index].st, fmt_ctx);
2030  if (is_sub)
2031  avsubtitle_free(&sub);
2032  }
2033  return got_frame;
2034 }
2035 
2036 static void log_read_interval(const ReadInterval *interval, void *log_ctx, int log_level)
2037 {
2038  av_log(log_ctx, log_level, "id:%d", interval->id);
2039 
2040  if (interval->has_start) {
2041  av_log(log_ctx, log_level, " start:%s%s", interval->start_is_offset ? "+" : "",
2042  av_ts2timestr(interval->start, &AV_TIME_BASE_Q));
2043  } else {
2044  av_log(log_ctx, log_level, " start:N/A");
2045  }
2046 
2047  if (interval->has_end) {
2048  av_log(log_ctx, log_level, " end:%s", interval->end_is_offset ? "+" : "");
2049  if (interval->duration_frames)
2050  av_log(log_ctx, log_level, "#%"PRId64, interval->end);
2051  else
2052  av_log(log_ctx, log_level, "%s", av_ts2timestr(interval->end, &AV_TIME_BASE_Q));
2053  } else {
2054  av_log(log_ctx, log_level, " end:N/A");
2055  }
2056 
2057  av_log(log_ctx, log_level, "\n");
2058 }
2059 
2061  const ReadInterval *interval, int64_t *cur_ts)
2062 {
2063  AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2064  AVPacket pkt, pkt1;
2065  AVFrame *frame = NULL;
2066  int ret = 0, i = 0, frame_count = 0;
2067  int64_t start = -INT64_MAX, end = interval->end;
2068  int has_start = 0, has_end = interval->has_end && !interval->end_is_offset;
2069 
2070  av_init_packet(&pkt);
2071 
2072  av_log(NULL, AV_LOG_VERBOSE, "Processing read interval ");
2074 
2075  if (interval->has_start) {
2076  int64_t target;
2077  if (interval->start_is_offset) {
2078  if (*cur_ts == AV_NOPTS_VALUE) {
2080  "Could not seek to relative position since current "
2081  "timestamp is not defined\n");
2082  ret = AVERROR(EINVAL);
2083  goto end;
2084  }
2085  target = *cur_ts + interval->start;
2086  } else {
2087  target = interval->start;
2088  }
2089 
2090  av_log(NULL, AV_LOG_VERBOSE, "Seeking to read interval start point %s\n",
2091  av_ts2timestr(target, &AV_TIME_BASE_Q));
2092  if ((ret = avformat_seek_file(fmt_ctx, -1, -INT64_MAX, target, INT64_MAX, 0)) < 0) {
2093  av_log(NULL, AV_LOG_ERROR, "Could not seek to position %"PRId64": %s\n",
2094  interval->start, av_err2str(ret));
2095  goto end;
2096  }
2097  }
2098 
2099  frame = av_frame_alloc();
2100  if (!frame) {
2101  ret = AVERROR(ENOMEM);
2102  goto end;
2103  }
2104  while (!av_read_frame(fmt_ctx, &pkt)) {
2105  if (ifile->nb_streams > nb_streams) {
2109  nb_streams = ifile->nb_streams;
2110  }
2111  if (selected_streams[pkt.stream_index]) {
2112  AVRational tb = ifile->streams[pkt.stream_index].st->time_base;
2113 
2114  if (pkt.pts != AV_NOPTS_VALUE)
2115  *cur_ts = av_rescale_q(pkt.pts, tb, AV_TIME_BASE_Q);
2116 
2117  if (!has_start && *cur_ts != AV_NOPTS_VALUE) {
2118  start = *cur_ts;
2119  has_start = 1;
2120  }
2121 
2122  if (has_start && !has_end && interval->end_is_offset) {
2123  end = start + interval->end;
2124  has_end = 1;
2125  }
2126 
2127  if (interval->end_is_offset && interval->duration_frames) {
2128  if (frame_count >= interval->end)
2129  break;
2130  } else if (has_end && *cur_ts != AV_NOPTS_VALUE && *cur_ts >= end) {
2131  break;
2132  }
2133 
2134  frame_count++;
2135  if (do_read_packets) {
2136  if (do_show_packets)
2137  show_packet(w, ifile, &pkt, i++);
2139  }
2140  if (do_read_frames) {
2141  pkt1 = pkt;
2142  while (pkt1.size && process_frame(w, ifile, frame, &pkt1) > 0);
2143  }
2144  }
2145  av_packet_unref(&pkt);
2146  }
2147  av_init_packet(&pkt);
2148  pkt.data = NULL;
2149  pkt.size = 0;
2150  //Flush remaining frames that are cached in the decoder
2151  for (i = 0; i < fmt_ctx->nb_streams; i++) {
2152  pkt.stream_index = i;
2153  if (do_read_frames)
2154  while (process_frame(w, ifile, frame, &pkt) > 0);
2155  }
2156 
2157 end:
2158  av_frame_free(&frame);
2159  if (ret < 0) {
2160  av_log(NULL, AV_LOG_ERROR, "Could not read packets in interval ");
2161  log_read_interval(interval, NULL, AV_LOG_ERROR);
2162  }
2163  return ret;
2164 }
2165 
2167 {
2168  AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2169  int i, ret = 0;
2170  int64_t cur_ts = fmt_ctx->start_time;
2171 
2172  if (read_intervals_nb == 0) {
2173  ReadInterval interval = (ReadInterval) { .has_start = 0, .has_end = 0 };
2174  ret = read_interval_packets(w, ifile, &interval, &cur_ts);
2175  } else {
2176  for (i = 0; i < read_intervals_nb; i++) {
2177  ret = read_interval_packets(w, ifile, &read_intervals[i], &cur_ts);
2178  if (ret < 0)
2179  break;
2180  }
2181  }
2182 
2183  return ret;
2184 }
2185 
2186 static int show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_idx, InputStream *ist, int in_program)
2187 {
2188  AVStream *stream = ist->st;
2189  AVCodecParameters *par;
2191  char val_str[128];
2192  const char *s;
2193  AVRational sar, dar;
2194  AVBPrint pbuf;
2195  const AVCodecDescriptor *cd;
2196  int ret = 0;
2197  const char *profile = NULL;
2198 
2200 
2202 
2203  print_int("index", stream->index);
2204 
2205  par = stream->codecpar;
2206  dec_ctx = ist->dec_ctx;
2207  if (cd = avcodec_descriptor_get(par->codec_id)) {
2208  print_str("codec_name", cd->name);
2209  if (!do_bitexact) {
2210  print_str("codec_long_name",
2211  cd->long_name ? cd->long_name : "unknown");
2212  }
2213  } else {
2214  print_str_opt("codec_name", "unknown");
2215  if (!do_bitexact) {
2216  print_str_opt("codec_long_name", "unknown");
2217  }
2218  }
2219 
2220  if (!do_bitexact && (profile = avcodec_profile_name(par->codec_id, par->profile)))
2221  print_str("profile", profile);
2222  else {
2223  if (par->profile != FF_PROFILE_UNKNOWN) {
2224  char profile_num[12];
2225  snprintf(profile_num, sizeof(profile_num), "%d", par->profile);
2226  print_str("profile", profile_num);
2227  } else
2228  print_str_opt("profile", "unknown");
2229  }
2230 
2232  if (s) print_str ("codec_type", s);
2233  else print_str_opt("codec_type", "unknown");
2234 #if FF_API_LAVF_AVCTX
2235  if (dec_ctx)
2236  print_q("codec_time_base", dec_ctx->time_base, '/');
2237 #endif
2238 
2239  /* print AVI/FourCC tag */
2240  av_get_codec_tag_string(val_str, sizeof(val_str), par->codec_tag);
2241  print_str("codec_tag_string", val_str);
2242  print_fmt("codec_tag", "0x%04x", par->codec_tag);
2243 
2244  switch (par->codec_type) {
2245  case AVMEDIA_TYPE_VIDEO:
2246  print_int("width", par->width);
2247  print_int("height", par->height);
2248  if (dec_ctx) {
2249  print_int("coded_width", dec_ctx->coded_width);
2250  print_int("coded_height", dec_ctx->coded_height);
2251  }
2252  print_int("has_b_frames", par->video_delay);
2253  sar = av_guess_sample_aspect_ratio(fmt_ctx, stream, NULL);
2254  if (sar.den) {
2255  print_q("sample_aspect_ratio", sar, ':');
2256  av_reduce(&dar.num, &dar.den,
2257  par->width * sar.num,
2258  par->height * sar.den,
2259  1024*1024);
2260  print_q("display_aspect_ratio", dar, ':');
2261  } else {
2262  print_str_opt("sample_aspect_ratio", "N/A");
2263  print_str_opt("display_aspect_ratio", "N/A");
2264  }
2265  s = av_get_pix_fmt_name(par->format);
2266  if (s) print_str ("pix_fmt", s);
2267  else print_str_opt("pix_fmt", "unknown");
2268  print_int("level", par->level);
2270  print_str ("color_range", av_color_range_name(par->color_range));
2271  else
2272  print_str_opt("color_range", "N/A");
2273 
2275  if (s) print_str ("color_space", s);
2276  else print_str_opt("color_space", "unknown");
2277 
2278  if (par->color_trc != AVCOL_TRC_UNSPECIFIED)
2279  print_str("color_transfer", av_color_transfer_name(par->color_trc));
2280  else
2281  print_str_opt("color_transfer", av_color_transfer_name(par->color_trc));
2282 
2284  print_str("color_primaries", av_color_primaries_name(par->color_primaries));
2285  else
2286  print_str_opt("color_primaries", av_color_primaries_name(par->color_primaries));
2287 
2289  print_str("chroma_location", av_chroma_location_name(par->chroma_location));
2290  else
2291  print_str_opt("chroma_location", av_chroma_location_name(par->chroma_location));
2292 
2293  if (par->field_order == AV_FIELD_PROGRESSIVE)
2294  print_str("field_order", "progressive");
2295  else if (par->field_order == AV_FIELD_TT)
2296  print_str("field_order", "tt");
2297  else if (par->field_order == AV_FIELD_BB)
2298  print_str("field_order", "bb");
2299  else if (par->field_order == AV_FIELD_TB)
2300  print_str("field_order", "tb");
2301  else if (par->field_order == AV_FIELD_BT)
2302  print_str("field_order", "bt");
2303  else
2304  print_str_opt("field_order", "unknown");
2305 
2306 #if FF_API_PRIVATE_OPT
2307  if (dec_ctx && dec_ctx->timecode_frame_start >= 0) {
2308  char tcbuf[AV_TIMECODE_STR_SIZE];
2310  print_str("timecode", tcbuf);
2311  } else {
2312  print_str_opt("timecode", "N/A");
2313  }
2314 #endif
2315  if (dec_ctx)
2316  print_int("refs", dec_ctx->refs);
2317  break;
2318 
2319  case AVMEDIA_TYPE_AUDIO:
2320  s = av_get_sample_fmt_name(par->format);
2321  if (s) print_str ("sample_fmt", s);
2322  else print_str_opt("sample_fmt", "unknown");
2323  print_val("sample_rate", par->sample_rate, unit_hertz_str);
2324  print_int("channels", par->channels);
2325 
2326  if (par->channel_layout) {
2327  av_bprint_clear(&pbuf);
2329  print_str ("channel_layout", pbuf.str);
2330  } else {
2331  print_str_opt("channel_layout", "unknown");
2332  }
2333 
2334  print_int("bits_per_sample", av_get_bits_per_sample(par->codec_id));
2335  break;
2336 
2337  case AVMEDIA_TYPE_SUBTITLE:
2338  if (par->width)
2339  print_int("width", par->width);
2340  else
2341  print_str_opt("width", "N/A");
2342  if (par->height)
2343  print_int("height", par->height);
2344  else
2345  print_str_opt("height", "N/A");
2346  break;
2347  }
2348 
2349  if (dec_ctx && dec_ctx->codec && dec_ctx->codec->priv_class && show_private_data) {
2350  const AVOption *opt = NULL;
2351  while (opt = av_opt_next(dec_ctx->priv_data,opt)) {
2352  uint8_t *str;
2353  if (opt->flags) continue;
2354  if (av_opt_get(dec_ctx->priv_data, opt->name, 0, &str) >= 0) {
2355  print_str(opt->name, str);
2356  av_free(str);
2357  }
2358  }
2359  }
2360 
2361  if (fmt_ctx->iformat->flags & AVFMT_SHOW_IDS) print_fmt ("id", "0x%x", stream->id);
2362  else print_str_opt("id", "N/A");
2363  print_q("r_frame_rate", stream->r_frame_rate, '/');
2364  print_q("avg_frame_rate", stream->avg_frame_rate, '/');
2365  print_q("time_base", stream->time_base, '/');
2366  print_ts ("start_pts", stream->start_time);
2367  print_time("start_time", stream->start_time, &stream->time_base);
2368  print_ts ("duration_ts", stream->duration);
2369  print_time("duration", stream->duration, &stream->time_base);
2370  if (par->bit_rate > 0) print_val ("bit_rate", par->bit_rate, unit_bit_per_second_str);
2371  else print_str_opt("bit_rate", "N/A");
2372 #if FF_API_LAVF_AVCTX
2373  if (stream->codec->rc_max_rate > 0) print_val ("max_bit_rate", stream->codec->rc_max_rate, unit_bit_per_second_str);
2374  else print_str_opt("max_bit_rate", "N/A");
2375 #endif
2376  if (dec_ctx && dec_ctx->bits_per_raw_sample > 0) print_fmt("bits_per_raw_sample", "%d", dec_ctx->bits_per_raw_sample);
2377  else print_str_opt("bits_per_raw_sample", "N/A");
2378  if (stream->nb_frames) print_fmt ("nb_frames", "%"PRId64, stream->nb_frames);
2379  else print_str_opt("nb_frames", "N/A");
2380  if (nb_streams_frames[stream_idx]) print_fmt ("nb_read_frames", "%"PRIu64, nb_streams_frames[stream_idx]);
2381  else print_str_opt("nb_read_frames", "N/A");
2382  if (nb_streams_packets[stream_idx]) print_fmt ("nb_read_packets", "%"PRIu64, nb_streams_packets[stream_idx]);
2383  else print_str_opt("nb_read_packets", "N/A");
2384  if (do_show_data)
2385  writer_print_data(w, "extradata", par->extradata,
2386  par->extradata_size);
2387  writer_print_data_hash(w, "extradata_hash", par->extradata,
2388  par->extradata_size);
2389 
2390  /* Print disposition information */
2391 #define PRINT_DISPOSITION(flagname, name) do { \
2392  print_int(name, !!(stream->disposition & AV_DISPOSITION_##flagname)); \
2393  } while (0)
2394 
2397  PRINT_DISPOSITION(DEFAULT, "default");
2398  PRINT_DISPOSITION(DUB, "dub");
2399  PRINT_DISPOSITION(ORIGINAL, "original");
2400  PRINT_DISPOSITION(COMMENT, "comment");
2401  PRINT_DISPOSITION(LYRICS, "lyrics");
2402  PRINT_DISPOSITION(KARAOKE, "karaoke");
2403  PRINT_DISPOSITION(FORCED, "forced");
2404  PRINT_DISPOSITION(HEARING_IMPAIRED, "hearing_impaired");
2405  PRINT_DISPOSITION(VISUAL_IMPAIRED, "visual_impaired");
2406  PRINT_DISPOSITION(CLEAN_EFFECTS, "clean_effects");
2407  PRINT_DISPOSITION(ATTACHED_PIC, "attached_pic");
2408  PRINT_DISPOSITION(TIMED_THUMBNAILS, "timed_thumbnails");
2410  }
2411 
2412  if (do_show_stream_tags)
2413  ret = show_tags(w, stream->metadata, in_program ? SECTION_ID_PROGRAM_STREAM_TAGS : SECTION_ID_STREAM_TAGS);
2414 
2415  if (stream->nb_side_data) {
2416  print_pkt_side_data(w, stream->codecpar, stream->side_data, stream->nb_side_data,
2419  }
2420 
2422  av_bprint_finalize(&pbuf, NULL);
2423  fflush(stdout);
2424 
2425  return ret;
2426 }
2427 
2429 {
2430  AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2431  int i, ret = 0;
2432 
2434  for (i = 0; i < ifile->nb_streams; i++)
2435  if (selected_streams[i]) {
2436  ret = show_stream(w, fmt_ctx, i, &ifile->streams[i], 0);
2437  if (ret < 0)
2438  break;
2439  }
2441 
2442  return ret;
2443 }
2444 
2446 {
2447  AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2448  int i, ret = 0;
2449 
2451  print_int("program_id", program->id);
2452  print_int("program_num", program->program_num);
2453  print_int("nb_streams", program->nb_stream_indexes);
2454  print_int("pmt_pid", program->pmt_pid);
2455  print_int("pcr_pid", program->pcr_pid);
2456  print_ts("start_pts", program->start_time);
2457  print_time("start_time", program->start_time, &AV_TIME_BASE_Q);
2458  print_ts("end_pts", program->end_time);
2459  print_time("end_time", program->end_time, &AV_TIME_BASE_Q);
2461  ret = show_tags(w, program->metadata, SECTION_ID_PROGRAM_TAGS);
2462  if (ret < 0)
2463  goto end;
2464 
2466  for (i = 0; i < program->nb_stream_indexes; i++) {
2467  if (selected_streams[program->stream_index[i]]) {
2468  ret = show_stream(w, fmt_ctx, program->stream_index[i], &ifile->streams[program->stream_index[i]], 1);
2469  if (ret < 0)
2470  break;
2471  }
2472  }
2474 
2475 end:
2477  return ret;
2478 }
2479 
2481 {
2482  AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2483  int i, ret = 0;
2484 
2486  for (i = 0; i < fmt_ctx->nb_programs; i++) {
2487  AVProgram *program = fmt_ctx->programs[i];
2488  if (!program)
2489  continue;
2490  ret = show_program(w, ifile, program);
2491  if (ret < 0)
2492  break;
2493  }
2495  return ret;
2496 }
2497 
2499 {
2500  AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2501  int i, ret = 0;
2502 
2504  for (i = 0; i < fmt_ctx->nb_chapters; i++) {
2505  AVChapter *chapter = fmt_ctx->chapters[i];
2506 
2508  print_int("id", chapter->id);
2509  print_q ("time_base", chapter->time_base, '/');
2510  print_int("start", chapter->start);
2511  print_time("start_time", chapter->start, &chapter->time_base);
2512  print_int("end", chapter->end);
2513  print_time("end_time", chapter->end, &chapter->time_base);
2515  ret = show_tags(w, chapter->metadata, SECTION_ID_CHAPTER_TAGS);
2517  }
2519 
2520  return ret;
2521 }
2522 
2524 {
2525  AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2526  char val_str[128];
2527  int64_t size = fmt_ctx->pb ? avio_size(fmt_ctx->pb) : -1;
2528  int ret = 0;
2529 
2531  print_str_validate("filename", fmt_ctx->filename);
2532  print_int("nb_streams", fmt_ctx->nb_streams);
2533  print_int("nb_programs", fmt_ctx->nb_programs);
2534  print_str("format_name", fmt_ctx->iformat->name);
2535  if (!do_bitexact) {
2536  if (fmt_ctx->iformat->long_name) print_str ("format_long_name", fmt_ctx->iformat->long_name);
2537  else print_str_opt("format_long_name", "unknown");
2538  }
2539  print_time("start_time", fmt_ctx->start_time, &AV_TIME_BASE_Q);
2540  print_time("duration", fmt_ctx->duration, &AV_TIME_BASE_Q);
2541  if (size >= 0) print_val ("size", size, unit_byte_str);
2542  else print_str_opt("size", "N/A");
2543  if (fmt_ctx->bit_rate > 0) print_val ("bit_rate", fmt_ctx->bit_rate, unit_bit_per_second_str);
2544  else print_str_opt("bit_rate", "N/A");
2545  print_int("probe_score", av_format_get_probe_score(fmt_ctx));
2546  if (do_show_format_tags)
2547  ret = show_tags(w, fmt_ctx->metadata, SECTION_ID_FORMAT_TAGS);
2548 
2550  fflush(stdout);
2551  return ret;
2552 }
2553 
2554 static void show_error(WriterContext *w, int err)
2555 {
2556  char errbuf[128];
2557  const char *errbuf_ptr = errbuf;
2558 
2559  if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)
2560  errbuf_ptr = strerror(AVUNERROR(err));
2561 
2563  print_int("code", err);
2564  print_str("string", errbuf_ptr);
2566 }
2567 
2568 static int open_input_file(InputFile *ifile, const char *filename)
2569 {
2570  int err, i, orig_nb_streams;
2572  AVDictionaryEntry *t;
2573  AVDictionary **opts;
2574  int scan_all_pmts_set = 0;
2575 
2576  fmt_ctx = avformat_alloc_context();
2577  if (!fmt_ctx) {
2578  print_error(filename, AVERROR(ENOMEM));
2579  exit_program(1);
2580  }
2581 
2582  fmt_ctx->flags |= AVFMT_FLAG_KEEP_SIDE_DATA;
2583 
2584  if (!av_dict_get(format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
2585  av_dict_set(&format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE);
2586  scan_all_pmts_set = 1;
2587  }
2588  if ((err = avformat_open_input(&fmt_ctx, filename,
2589  iformat, &format_opts)) < 0) {
2590  print_error(filename, err);
2591  return err;
2592  }
2593  ifile->fmt_ctx = fmt_ctx;
2594  if (scan_all_pmts_set)
2595  av_dict_set(&format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
2597  av_log(NULL, AV_LOG_ERROR, "Option %s not found.\n", t->key);
2598  return AVERROR_OPTION_NOT_FOUND;
2599  }
2600 
2601  /* fill the streams in the format context */
2602  opts = setup_find_stream_info_opts(fmt_ctx, codec_opts);
2603  orig_nb_streams = fmt_ctx->nb_streams;
2604 
2605  err = avformat_find_stream_info(fmt_ctx, opts);
2606 
2607  for (i = 0; i < orig_nb_streams; i++)
2608  av_dict_free(&opts[i]);
2609  av_freep(&opts);
2610 
2611  if (err < 0) {
2612  print_error(filename, err);
2613  return err;
2614  }
2615 
2616  av_dump_format(fmt_ctx, 0, filename, 0);
2617 
2618  ifile->streams = av_mallocz_array(fmt_ctx->nb_streams,
2619  sizeof(*ifile->streams));
2620  if (!ifile->streams)
2621  exit(1);
2622  ifile->nb_streams = fmt_ctx->nb_streams;
2623 
2624  /* bind a decoder to each input stream */
2625  for (i = 0; i < fmt_ctx->nb_streams; i++) {
2626  InputStream *ist = &ifile->streams[i];
2627  AVStream *stream = fmt_ctx->streams[i];
2628  AVCodec *codec;
2629 
2630  ist->st = stream;
2631 
2632  if (stream->codecpar->codec_id == AV_CODEC_ID_PROBE) {
2634  "Failed to probe codec for input stream %d\n",
2635  stream->index);
2636  continue;
2637  }
2638 
2639  codec = avcodec_find_decoder(stream->codecpar->codec_id);
2640  if (!codec) {
2642  "Unsupported codec with id %d for input stream %d\n",
2643  stream->codecpar->codec_id, stream->index);
2644  continue;
2645  }
2646  {
2648  fmt_ctx, stream, codec);
2649 
2650  ist->dec_ctx = avcodec_alloc_context3(codec);
2651  if (!ist->dec_ctx)
2652  exit(1);
2653 
2654  err = avcodec_parameters_to_context(ist->dec_ctx, stream->codecpar);
2655  if (err < 0)
2656  exit(1);
2657 
2659  ist->dec_ctx->framerate = stream->avg_frame_rate;
2660 
2661  if (avcodec_open2(ist->dec_ctx, codec, &opts) < 0) {
2662  av_log(NULL, AV_LOG_WARNING, "Could not open codec for input stream %d\n",
2663  stream->index);
2664  exit(1);
2665  }
2666 
2667  if ((t = av_dict_get(opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
2668  av_log(NULL, AV_LOG_ERROR, "Option %s for input stream %d not found\n",
2669  t->key, stream->index);
2670  return AVERROR_OPTION_NOT_FOUND;
2671  }
2672  }
2673  }
2674 
2675  ifile->fmt_ctx = fmt_ctx;
2676  return 0;
2677 }
2678 
2680 {
2681  int i;
2682 
2683  /* close decoder for each stream */
2684  for (i = 0; i < ifile->nb_streams; i++)
2685  if (ifile->streams[i].st->codecpar->codec_id != AV_CODEC_ID_NONE)
2686  avcodec_free_context(&ifile->streams[i].dec_ctx);
2687 
2688  av_freep(&ifile->streams);
2689  ifile->nb_streams = 0;
2690 
2691  avformat_close_input(&ifile->fmt_ctx);
2692 }
2693 
2694 static int probe_file(WriterContext *wctx, const char *filename)
2695 {
2696  InputFile ifile = { 0 };
2697  int ret, i;
2698  int section_id;
2699 
2702 
2703  ret = open_input_file(&ifile, filename);
2704  if (ret < 0)
2705  goto end;
2706 
2707 #define CHECK_END if (ret < 0) goto end
2708 
2709  nb_streams = ifile.fmt_ctx->nb_streams;
2713 
2714  for (i = 0; i < ifile.fmt_ctx->nb_streams; i++) {
2715  if (stream_specifier) {
2717  ifile.fmt_ctx->streams[i],
2719  CHECK_END;
2720  else
2721  selected_streams[i] = ret;
2722  ret = 0;
2723  } else {
2724  selected_streams[i] = 1;
2725  }
2726  }
2727 
2731  section_id = SECTION_ID_PACKETS_AND_FRAMES;
2732  else if (do_show_packets && !do_show_frames)
2733  section_id = SECTION_ID_PACKETS;
2734  else // (!do_show_packets && do_show_frames)
2735  section_id = SECTION_ID_FRAMES;
2737  writer_print_section_header(wctx, section_id);
2738  ret = read_packets(wctx, &ifile);
2741  CHECK_END;
2742  }
2743 
2744  if (do_show_programs) {
2745  ret = show_programs(wctx, &ifile);
2746  CHECK_END;
2747  }
2748 
2749  if (do_show_streams) {
2750  ret = show_streams(wctx, &ifile);
2751  CHECK_END;
2752  }
2753  if (do_show_chapters) {
2754  ret = show_chapters(wctx, &ifile);
2755  CHECK_END;
2756  }
2757  if (do_show_format) {
2758  ret = show_format(wctx, &ifile);
2759  CHECK_END;
2760  }
2761 
2762 end:
2763  if (ifile.fmt_ctx)
2764  close_input_file(&ifile);
2768 
2769  return ret;
2770 }
2771 
2772 static void show_usage(void)
2773 {
2774  av_log(NULL, AV_LOG_INFO, "Simple multimedia streams analyzer\n");
2775  av_log(NULL, AV_LOG_INFO, "usage: %s [OPTIONS] [INPUT_FILE]\n", program_name);
2776  av_log(NULL, AV_LOG_INFO, "\n");
2777 }
2778 
2780 {
2781  AVBPrint pbuf;
2783 
2785  print_str("version", FFMPEG_VERSION);
2786  print_fmt("copyright", "Copyright (c) %d-%d the FFmpeg developers",
2787  program_birth_year, CONFIG_THIS_YEAR);
2788  print_str("compiler_ident", CC_IDENT);
2789  print_str("configuration", FFMPEG_CONFIGURATION);
2791 
2792  av_bprint_finalize(&pbuf, NULL);
2793 }
2794 
2795 #define SHOW_LIB_VERSION(libname, LIBNAME) \
2796  do { \
2797  if (CONFIG_##LIBNAME) { \
2798  unsigned int version = libname##_version(); \
2799  writer_print_section_header(w, SECTION_ID_LIBRARY_VERSION); \
2800  print_str("name", "lib" #libname); \
2801  print_int("major", LIB##LIBNAME##_VERSION_MAJOR); \
2802  print_int("minor", LIB##LIBNAME##_VERSION_MINOR); \
2803  print_int("micro", LIB##LIBNAME##_VERSION_MICRO); \
2804  print_int("version", version); \
2805  print_str("ident", LIB##LIBNAME##_IDENT); \
2806  writer_print_section_footer(w); \
2807  } \
2808  } while (0)
2809 
2811 {
2813  SHOW_LIB_VERSION(avutil, AVUTIL);
2814  SHOW_LIB_VERSION(avcodec, AVCODEC);
2815  SHOW_LIB_VERSION(avformat, AVFORMAT);
2816  SHOW_LIB_VERSION(avdevice, AVDEVICE);
2817  SHOW_LIB_VERSION(avfilter, AVFILTER);
2818  SHOW_LIB_VERSION(swscale, SWSCALE);
2819  SHOW_LIB_VERSION(swresample, SWRESAMPLE);
2820  SHOW_LIB_VERSION(postproc, POSTPROC);
2822 }
2823 
2824 #define PRINT_PIX_FMT_FLAG(flagname, name) \
2825  do { \
2826  print_int(name, !!(pixdesc->flags & AV_PIX_FMT_FLAG_##flagname)); \
2827  } while (0)
2828 
2830 {
2831  const AVPixFmtDescriptor *pixdesc = NULL;
2832  int i, n;
2833 
2835  while (pixdesc = av_pix_fmt_desc_next(pixdesc)) {
2837  print_str("name", pixdesc->name);
2838  print_int("nb_components", pixdesc->nb_components);
2839  if ((pixdesc->nb_components >= 3) && !(pixdesc->flags & AV_PIX_FMT_FLAG_RGB)) {
2840  print_int ("log2_chroma_w", pixdesc->log2_chroma_w);
2841  print_int ("log2_chroma_h", pixdesc->log2_chroma_h);
2842  } else {
2843  print_str_opt("log2_chroma_w", "N/A");
2844  print_str_opt("log2_chroma_h", "N/A");
2845  }
2846  n = av_get_bits_per_pixel(pixdesc);
2847  if (n) print_int ("bits_per_pixel", n);
2848  else print_str_opt("bits_per_pixel", "N/A");
2851  PRINT_PIX_FMT_FLAG(BE, "big_endian");
2852  PRINT_PIX_FMT_FLAG(PAL, "palette");
2853  PRINT_PIX_FMT_FLAG(BITSTREAM, "bitstream");
2854  PRINT_PIX_FMT_FLAG(HWACCEL, "hwaccel");
2855  PRINT_PIX_FMT_FLAG(PLANAR, "planar");
2856  PRINT_PIX_FMT_FLAG(RGB, "rgb");
2857  PRINT_PIX_FMT_FLAG(PSEUDOPAL, "pseudopal");
2858  PRINT_PIX_FMT_FLAG(ALPHA, "alpha");
2860  }
2861  if (do_show_pixel_format_components && (pixdesc->nb_components > 0)) {
2863  for (i = 0; i < pixdesc->nb_components; i++) {
2865  print_int("index", i + 1);
2866  print_int("bit_depth", pixdesc->comp[i].depth);
2868  }
2870  }
2872  }
2874 }
2875 
2876 static int opt_format(void *optctx, const char *opt, const char *arg)
2877 {
2878  iformat = av_find_input_format(arg);
2879  if (!iformat) {
2880  av_log(NULL, AV_LOG_ERROR, "Unknown input format: %s\n", arg);
2881  return AVERROR(EINVAL);
2882  }
2883  return 0;
2884 }
2885 
2886 static inline void mark_section_show_entries(SectionID section_id,
2887  int show_all_entries, AVDictionary *entries)
2888 {
2889  struct section *section = &sections[section_id];
2890 
2892  if (show_all_entries) {
2893  SectionID *id;
2894  for (id = section->children_ids; *id != -1; id++)
2895  mark_section_show_entries(*id, show_all_entries, entries);
2896  } else {
2897  av_dict_copy(&section->entries_to_show, entries, 0);
2898  }
2899 }
2900 
2901 static int match_section(const char *section_name,
2902  int show_all_entries, AVDictionary *entries)
2903 {
2904  int i, ret = 0;
2905 
2906  for (i = 0; i < FF_ARRAY_ELEMS(sections); i++) {
2907  const struct section *section = &sections[i];
2908  if (!strcmp(section_name, section->name) ||
2909  (section->unique_name && !strcmp(section_name, section->unique_name))) {
2911  "'%s' matches section with unique name '%s'\n", section_name,
2912  (char *)av_x_if_null(section->unique_name, section->name));
2913  ret++;
2914  mark_section_show_entries(section->id, show_all_entries, entries);
2915  }
2916  }
2917  return ret;
2918 }
2919 
2920 static int opt_show_entries(void *optctx, const char *opt, const char *arg)
2921 {
2922  const char *p = arg;
2923  int ret = 0;
2924 
2925  while (*p) {
2926  AVDictionary *entries = NULL;
2927  char *section_name = av_get_token(&p, "=:");
2928  int show_all_entries = 0;
2929 
2930  if (!section_name) {
2932  "Missing section name for option '%s'\n", opt);
2933  return AVERROR(EINVAL);
2934  }
2935 
2936  if (*p == '=') {
2937  p++;
2938  while (*p && *p != ':') {
2939  char *entry = av_get_token(&p, ",:");
2940  if (!entry)
2941  break;
2943  "Adding '%s' to the entries to show in section '%s'\n",
2944  entry, section_name);
2945  av_dict_set(&entries, entry, "", AV_DICT_DONT_STRDUP_KEY);
2946  if (*p == ',')
2947  p++;
2948  }
2949  } else {
2950  show_all_entries = 1;
2951  }
2952 
2953  ret = match_section(section_name, show_all_entries, entries);
2954  if (ret == 0) {
2955  av_log(NULL, AV_LOG_ERROR, "No match for section '%s'\n", section_name);
2956  ret = AVERROR(EINVAL);
2957  }
2958  av_dict_free(&entries);
2959  av_free(section_name);
2960 
2961  if (ret <= 0)
2962  break;
2963  if (*p)
2964  p++;
2965  }
2966 
2967  return ret;
2968 }
2969 
2970 static int opt_show_format_entry(void *optctx, const char *opt, const char *arg)
2971 {
2972  char *buf = av_asprintf("format=%s", arg);
2973  int ret;
2974 
2975  if (!buf)
2976  return AVERROR(ENOMEM);
2977 
2979  "Option '%s' is deprecated, use '-show_entries format=%s' instead\n",
2980  opt, arg);
2981  ret = opt_show_entries(optctx, opt, buf);
2982  av_free(buf);
2983  return ret;
2984 }
2985 
2986 static void opt_input_file(void *optctx, const char *arg)
2987 {
2988  if (input_filename) {
2990  "Argument '%s' provided as input filename, but '%s' was already specified.\n",
2991  arg, input_filename);
2992  exit_program(1);
2993  }
2994  if (!strcmp(arg, "-"))
2995  arg = "pipe:";
2996  input_filename = arg;
2997 }
2998 
2999 static int opt_input_file_i(void *optctx, const char *opt, const char *arg)
3000 {
3001  opt_input_file(optctx, arg);
3002  return 0;
3003 }
3004 
3005 void show_help_default(const char *opt, const char *arg)
3006 {
3008  show_usage();
3009  show_help_options(options, "Main options:", 0, 0, 0);
3010  printf("\n");
3011 
3014 }
3015 
3016 /**
3017  * Parse interval specification, according to the format:
3018  * INTERVAL ::= [START|+START_OFFSET][%[END|+END_OFFSET]]
3019  * INTERVALS ::= INTERVAL[,INTERVALS]
3020 */
3021 static int parse_read_interval(const char *interval_spec,
3022  ReadInterval *interval)
3023 {
3024  int ret = 0;
3025  char *next, *p, *spec = av_strdup(interval_spec);
3026  if (!spec)
3027  return AVERROR(ENOMEM);
3028 
3029  if (!*spec) {
3030  av_log(NULL, AV_LOG_ERROR, "Invalid empty interval specification\n");
3031  ret = AVERROR(EINVAL);
3032  goto end;
3033  }
3034 
3035  p = spec;
3036  next = strchr(spec, '%');
3037  if (next)
3038  *next++ = 0;
3039 
3040  /* parse first part */
3041  if (*p) {
3042  interval->has_start = 1;
3043 
3044  if (*p == '+') {
3045  interval->start_is_offset = 1;
3046  p++;
3047  } else {
3048  interval->start_is_offset = 0;
3049  }
3050 
3051  ret = av_parse_time(&interval->start, p, 1);
3052  if (ret < 0) {
3053  av_log(NULL, AV_LOG_ERROR, "Invalid interval start specification '%s'\n", p);
3054  goto end;
3055  }
3056  } else {
3057  interval->has_start = 0;
3058  }
3059 
3060  /* parse second part */
3061  p = next;
3062  if (p && *p) {
3063  int64_t us;
3064  interval->has_end = 1;
3065 
3066  if (*p == '+') {
3067  interval->end_is_offset = 1;
3068  p++;
3069  } else {
3070  interval->end_is_offset = 0;
3071  }
3072 
3073  if (interval->end_is_offset && *p == '#') {
3074  long long int lli;
3075  char *tail;
3076  interval->duration_frames = 1;
3077  p++;
3078  lli = strtoll(p, &tail, 10);
3079  if (*tail || lli < 0) {
3081  "Invalid or negative value '%s' for duration number of frames\n", p);
3082  goto end;
3083  }
3084  interval->end = lli;
3085  } else {
3086  ret = av_parse_time(&us, p, 1);
3087  if (ret < 0) {
3088  av_log(NULL, AV_LOG_ERROR, "Invalid interval end/duration specification '%s'\n", p);
3089  goto end;
3090  }
3091  interval->end = us;
3092  }
3093  } else {
3094  interval->has_end = 0;
3095  }
3096 
3097 end:
3098  av_free(spec);
3099  return ret;
3100 }
3101 
3102 static int parse_read_intervals(const char *intervals_spec)
3103 {
3104  int ret, n, i;
3105  char *p, *spec = av_strdup(intervals_spec);
3106  if (!spec)
3107  return AVERROR(ENOMEM);
3108 
3109  /* preparse specification, get number of intervals */
3110  for (n = 0, p = spec; *p; p++)
3111  if (*p == ',')
3112  n++;
3113  n++;
3114 
3115  read_intervals = av_malloc_array(n, sizeof(*read_intervals));
3116  if (!read_intervals) {
3117  ret = AVERROR(ENOMEM);
3118  goto end;
3119  }
3120  read_intervals_nb = n;
3121 
3122  /* parse intervals */
3123  p = spec;
3124  for (i = 0; p; i++) {
3125  char *next;
3126 
3128  next = strchr(p, ',');
3129  if (next)
3130  *next++ = 0;
3131 
3132  read_intervals[i].id = i;
3133  ret = parse_read_interval(p, &read_intervals[i]);
3134  if (ret < 0) {
3135  av_log(NULL, AV_LOG_ERROR, "Error parsing read interval #%d '%s'\n",
3136  i, p);
3137  goto end;
3138  }
3139  av_log(NULL, AV_LOG_VERBOSE, "Parsed log interval ");
3140  log_read_interval(&read_intervals[i], NULL, AV_LOG_VERBOSE);
3141  p = next;
3142  }
3144 
3145 end:
3146  av_free(spec);
3147  return ret;
3148 }
3149 
3150 static int opt_read_intervals(void *optctx, const char *opt, const char *arg)
3151 {
3152  return parse_read_intervals(arg);
3153 }
3154 
3155 static int opt_pretty(void *optctx, const char *opt, const char *arg)
3156 {
3157  show_value_unit = 1;
3158  use_value_prefix = 1;
3161  return 0;
3162 }
3163 
3164 static void print_section(SectionID id, int level)
3165 {
3166  const SectionID *pid;
3167  const struct section *section = &sections[id];
3168  printf("%c%c%c",
3169  section->flags & SECTION_FLAG_IS_WRAPPER ? 'W' : '.',
3170  section->flags & SECTION_FLAG_IS_ARRAY ? 'A' : '.',
3171  section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS ? 'V' : '.');
3172  printf("%*c %s", level * 4, ' ', section->name);
3173  if (section->unique_name)
3174  printf("/%s", section->unique_name);
3175  printf("\n");
3176 
3177  for (pid = section->children_ids; *pid != -1; pid++)
3178  print_section(*pid, level+1);
3179 }
3180 
3181 static int opt_sections(void *optctx, const char *opt, const char *arg)
3182 {
3183  printf("Sections:\n"
3184  "W.. = Section is a wrapper (contains other sections, no local entries)\n"
3185  ".A. = Section contains an array of elements of the same type\n"
3186  "..V = Section may contain a variable number of fields with variable keys\n"
3187  "FLAGS NAME/UNIQUE_NAME\n"
3188  "---\n");
3190  return 0;
3191 }
3192 
3193 static int opt_show_versions(const char *opt, const char *arg)
3194 {
3197  return 0;
3198 }
3199 
3200 #define DEFINE_OPT_SHOW_SECTION(section, target_section_id) \
3201  static int opt_show_##section(const char *opt, const char *arg) \
3202  { \
3203  mark_section_show_entries(SECTION_ID_##target_section_id, 1, NULL); \
3204  return 0; \
3205  }
3206 
3207 DEFINE_OPT_SHOW_SECTION(chapters, CHAPTERS)
3211 DEFINE_OPT_SHOW_SECTION(library_versions, LIBRARY_VERSIONS)
3212 DEFINE_OPT_SHOW_SECTION(packets, PACKETS)
3213 DEFINE_OPT_SHOW_SECTION(pixel_formats, PIXEL_FORMATS)
3214 DEFINE_OPT_SHOW_SECTION(program_version, PROGRAM_VERSION)
3215 DEFINE_OPT_SHOW_SECTION(streams, STREAMS)
3216 DEFINE_OPT_SHOW_SECTION(programs, PROGRAMS)
3217 
3218 static const OptionDef real_options[] = {
3219 #include "cmdutils_common_opts.h"
3220  { "f", HAS_ARG, {.func_arg = opt_format}, "force format", "format" },
3221  { "unit", OPT_BOOL, {&show_value_unit}, "show unit of the displayed values" },
3222  { "prefix", OPT_BOOL, {&use_value_prefix}, "use SI prefixes for the displayed values" },
3223  { "byte_binary_prefix", OPT_BOOL, {&use_byte_value_binary_prefix},
3224  "use binary prefixes for byte units" },
3225  { "sexagesimal", OPT_BOOL, {&use_value_sexagesimal_format},
3226  "use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units" },
3227  { "pretty", 0, {.func_arg = opt_pretty},
3228  "prettify the format of displayed values, make it more human readable" },
3229  { "print_format", OPT_STRING | HAS_ARG, {(void*)&print_format},
3230  "set the output printing format (available formats are: default, compact, csv, flat, ini, json, xml)", "format" },
3231  { "of", OPT_STRING | HAS_ARG, {(void*)&print_format}, "alias for -print_format", "format" },
3232  { "select_streams", OPT_STRING | HAS_ARG, {(void*)&stream_specifier}, "select the specified streams", "stream_specifier" },
3233  { "sections", OPT_EXIT, {.func_arg = opt_sections}, "print sections structure and section information, and exit" },
3234  { "show_data", OPT_BOOL, {(void*)&do_show_data}, "show packets data" },
3235  { "show_data_hash", OPT_STRING | HAS_ARG, {(void*)&show_data_hash}, "show packets data hash" },
3236  { "show_error", 0, {(void*)&opt_show_error}, "show probing error" },
3237  { "show_format", 0, {(void*)&opt_show_format}, "show format/container info" },
3238  { "show_frames", 0, {(void*)&opt_show_frames}, "show frames info" },
3239  { "show_format_entry", HAS_ARG, {.func_arg = opt_show_format_entry},
3240  "show a particular entry from the format/container info", "entry" },
3241  { "show_entries", HAS_ARG, {.func_arg = opt_show_entries},
3242  "show a set of specified entries", "entry_list" },
3243  { "show_packets", 0, {(void*)&opt_show_packets}, "show packets info" },
3244  { "show_programs", 0, {(void*)&opt_show_programs}, "show programs info" },
3245  { "show_streams", 0, {(void*)&opt_show_streams}, "show streams info" },
3246  { "show_chapters", 0, {(void*)&opt_show_chapters}, "show chapters info" },
3247  { "count_frames", OPT_BOOL, {(void*)&do_count_frames}, "count the number of frames per stream" },
3248  { "count_packets", OPT_BOOL, {(void*)&do_count_packets}, "count the number of packets per stream" },
3249  { "show_program_version", 0, {(void*)&opt_show_program_version}, "show ffprobe version" },
3250  { "show_library_versions", 0, {(void*)&opt_show_library_versions}, "show library versions" },
3251  { "show_versions", 0, {(void*)&opt_show_versions}, "show program and library versions" },
3252  { "show_pixel_formats", 0, {(void*)&opt_show_pixel_formats}, "show pixel format descriptions" },
3253  { "show_private_data", OPT_BOOL, {(void*)&show_private_data}, "show private data" },
3254  { "private", OPT_BOOL, {(void*)&show_private_data}, "same as show_private_data" },
3255  { "bitexact", OPT_BOOL, {&do_bitexact}, "force bitexact output" },
3256  { "read_intervals", HAS_ARG, {.func_arg = opt_read_intervals}, "set read intervals", "read_intervals" },
3257  { "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {.func_arg = opt_default}, "generic catch all option", "" },
3258  { "i", HAS_ARG, {.func_arg = opt_input_file_i}, "read specified file", "input_file"},
3259  { NULL, },
3260 };
3261 
3262 static inline int check_section_show_entries(int section_id)
3263 {
3264  int *id;
3265  struct section *section = &sections[section_id];
3266  if (sections[section_id].show_all_entries || sections[section_id].entries_to_show)
3267  return 1;
3268  for (id = section->children_ids; *id != -1; id++)
3269  if (check_section_show_entries(*id))
3270  return 1;
3271  return 0;
3272 }
3273 
3274 #define SET_DO_SHOW(id, varname) do { \
3275  if (check_section_show_entries(SECTION_ID_##id)) \
3276  do_show_##varname = 1; \
3277  } while (0)
3278 
3279 int main(int argc, char **argv)
3280 {
3281  const Writer *w;
3282  WriterContext *wctx;
3283  char *buf;
3284  char *w_name = NULL, *w_args = NULL;
3285  int ret, i;
3286 
3287  init_dynload();
3288 
3291 
3292  options = real_options;
3293  parse_loglevel(argc, argv, options);
3294  av_register_all();
3296  init_opts();
3297 #if CONFIG_AVDEVICE
3299 #endif
3300 
3301  show_banner(argc, argv, options);
3302  parse_options(NULL, argc, argv, options, opt_input_file);
3303 
3304  /* mark things to show, based on -show_entries */
3305  SET_DO_SHOW(CHAPTERS, chapters);
3306  SET_DO_SHOW(ERROR, error);
3307  SET_DO_SHOW(FORMAT, format);
3308  SET_DO_SHOW(FRAMES, frames);
3309  SET_DO_SHOW(LIBRARY_VERSIONS, library_versions);
3310  SET_DO_SHOW(PACKETS, packets);
3311  SET_DO_SHOW(PIXEL_FORMATS, pixel_formats);
3312  SET_DO_SHOW(PIXEL_FORMAT_FLAGS, pixel_format_flags);
3313  SET_DO_SHOW(PIXEL_FORMAT_COMPONENTS, pixel_format_components);
3314  SET_DO_SHOW(PROGRAM_VERSION, program_version);
3315  SET_DO_SHOW(PROGRAMS, programs);
3316  SET_DO_SHOW(STREAMS, streams);
3317  SET_DO_SHOW(STREAM_DISPOSITION, stream_disposition);
3318  SET_DO_SHOW(PROGRAM_STREAM_DISPOSITION, stream_disposition);
3319 
3320  SET_DO_SHOW(CHAPTER_TAGS, chapter_tags);
3321  SET_DO_SHOW(FORMAT_TAGS, format_tags);
3322  SET_DO_SHOW(FRAME_TAGS, frame_tags);
3323  SET_DO_SHOW(PROGRAM_TAGS, program_tags);
3324  SET_DO_SHOW(STREAM_TAGS, stream_tags);
3325  SET_DO_SHOW(PROGRAM_STREAM_TAGS, stream_tags);
3326  SET_DO_SHOW(PACKET_TAGS, packet_tags);
3327 
3330  "-bitexact and -show_program_version or -show_library_versions "
3331  "options are incompatible\n");
3332  ret = AVERROR(EINVAL);
3333  goto end;
3334  }
3335 
3337 
3338  if (!print_format)
3339  print_format = av_strdup("default");
3340  if (!print_format) {
3341  ret = AVERROR(ENOMEM);
3342  goto end;
3343  }
3344  w_name = av_strtok(print_format, "=", &buf);
3345  if (!w_name) {
3347  "No name specified for the output format\n");
3348  ret = AVERROR(EINVAL);
3349  goto end;
3350  }
3351  w_args = buf;
3352 
3353  if (show_data_hash) {
3354  if ((ret = av_hash_alloc(&hash, show_data_hash)) < 0) {
3355  if (ret == AVERROR(EINVAL)) {
3356  const char *n;
3358  "Unknown hash algorithm '%s'\nKnown algorithms:",
3359  show_data_hash);
3360  for (i = 0; (n = av_hash_names(i)); i++)
3361  av_log(NULL, AV_LOG_ERROR, " %s", n);
3362  av_log(NULL, AV_LOG_ERROR, "\n");
3363  }
3364  goto end;
3365  }
3366  }
3367 
3368  w = writer_get_by_name(w_name);
3369  if (!w) {
3370  av_log(NULL, AV_LOG_ERROR, "Unknown output format with name '%s'\n", w_name);
3371  ret = AVERROR(EINVAL);
3372  goto end;
3373  }
3374 
3375  if ((ret = writer_open(&wctx, w, w_args,
3376  sections, FF_ARRAY_ELEMS(sections))) >= 0) {
3377  if (w == &xml_writer)
3379 
3381 
3388 
3389  if (!input_filename &&
3392  show_usage();
3393  av_log(NULL, AV_LOG_ERROR, "You have to specify one input file.\n");
3394  av_log(NULL, AV_LOG_ERROR, "Use -h to get full help or, even better, run 'man %s'.\n", program_name);
3395  ret = AVERROR(EINVAL);
3396  } else if (input_filename) {
3397  ret = probe_file(wctx, input_filename);
3398  if (ret < 0 && do_show_error)
3399  show_error(wctx, ret);
3400  }
3401 
3403  writer_close(&wctx);
3404  }
3405 
3406 end:
3408  av_freep(&read_intervals);
3409  av_hash_freep(&hash);
3410 
3411  uninit_opts();
3412  for (i = 0; i < FF_ARRAY_ELEMS(sections); i++)
3413  av_dict_free(&(sections[i].entries_to_show));
3414 
3416 
3417  return ret < 0;
3418 }
unsigned int nb_chapters
Number of chapters in AVChapter array.
Definition: avformat.h:1556
int32_t pitch
Rotation around the right vector [-90, 90].
Definition: spherical.h:127
void init_dynload(void)
Initialize dynamic library loading.
Definition: cmdutils.c:119
int(* init)(WriterContext *wctx)
Definition: ffprobe.c:344
codec_id is not known (like AV_CODEC_ID_NONE) but lavf should attempt to identify it ...
Definition: avcodec.h:680
enum AVChromaLocation chroma_location
Definition: avcodec.h:4146
const struct section * section[SECTION_MAX_NB_LEVELS]
section per each level
Definition: ffprobe.c:372
#define NULL
Definition: coverity.c:32
const struct AVCodec * codec
Definition: avcodec.h:1731
AVRational framerate
Definition: avcodec.h:3419
const char const char void * val
Definition: avisynth_c.h:771
static char * value_string(char *buf, int buf_size, struct unit_value uv)
Definition: ffprobe.c:272
static int do_show_program_tags
Definition: ffprobe.c:93
enum AVFieldOrder field_order
Video only.
Definition: avcodec.h:4137
static const struct @38 si_prefixes[]
const char * s
Definition: avisynth_c.h:768
unsigned int nb_item[SECTION_MAX_NB_LEVELS]
number of the item printed in the given section, starting from 0
Definition: ffprobe.c:369
enum AVColorTransferCharacteristic color_trc
Definition: avcodec.h:4144
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
double dec_val
Definition: ffprobe.c:238
static int show_tags(WriterContext *w, AVDictionary *tags, int section_id)
Definition: ffprobe.c:1746
#define OPT_EXPERT
Definition: cmdutils.h:168
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:319
int av_utf8_decode(int32_t *codep, const uint8_t **bufp, const uint8_t *buf_end, unsigned int flags)
Read and decode a single UTF-8 code point (character) from the buffer in *buf, and update *buf to poi...
Definition: avstring.c:343
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:94
int64_t av_frame_get_pkt_duration(const AVFrame *frame)
int nested_section[SECTION_MAX_NB_LEVELS]
Definition: ffprobe.c:832
double bin_val
Definition: ffprobe.c:237
int av_frame_get_pkt_size(const AVFrame *frame)
This structure describes decoded (raw) audio or video data.
Definition: frame.h:187
static void json_print_int(WriterContext *wctx, const char *key, long long int value)
Definition: ffprobe.c:1497
static void default_print_section_header(WriterContext *wctx)
Definition: ffprobe.c:858
static int writer_register(const Writer *writer)
Definition: ffprobe.c:790
AVOption.
Definition: opt.h:246
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
#define print_ts(k, v)
Definition: ffprobe.c:1725
static int opt_input_file_i(void *optctx, const char *opt, const char *arg)
Definition: ffprobe.c:2999
static int opt_format(void *optctx, const char *opt, const char *arg)
Definition: ffprobe.c:2876
int within_tag
Definition: ffprobe.c:1528
#define SHOW_LIB_VERSION(libname, LIBNAME)
Definition: ffprobe.c:2795
enum AVCodecID id
Definition: mxfenc.c:104
#define OPT_VIDEO
Definition: cmdutils.h:170
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:1924
static void writer_print_rational(WriterContext *wctx, const char *key, AVRational q, char sep)
Definition: ffprobe.c:682
void(* print_string)(WriterContext *wctx, const char *, const char *)
Definition: ffprobe.c:351
static int opt_show_format_entry(void *optctx, const char *opt, const char *arg)
Definition: ffprobe.c:2970
static const char unit_hertz_str[]
Definition: ffprobe.c:251
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
const char * sep_str
Definition: ffprobe.c:1138
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
#define PLANAR
Definition: flacdsp.c:43
int64_t pos
byte position in stream, -1 if unknown
Definition: avcodec.h:1667
static const char * xml_escape_str(AVBPrint *dst, const char *src, void *log_ctx)
Definition: ffprobe.c:1575
#define AV_DICT_DONT_OVERWRITE
Don't overwrite existing entries.
Definition: dict.h:79
int av_parse_time(int64_t *timeval, const char *timestr, int duration)
Parse timestr and return in *time a corresponding number of microseconds.
Definition: parseutils.c:587
static void json_print_section_footer(WriterContext *wctx)
Definition: ffprobe.c:1452
static void writer_close(WriterContext **wctx)
Definition: ffprobe.c:422
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
static int do_show_data
Definition: ffprobe.c:83
static int read_intervals_nb
Definition: ffprobe.c:116
int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel used by the pixel format described by pixdesc.
Definition: pixdesc.c:2284
static void writer_print_integer(WriterContext *wctx, const char *key, long long int val)
Definition: ffprobe.c:577
static int do_show_stream_tags
Definition: ffprobe.c:94
static char * ini_escape_str(AVBPrint *dst, const char *src)
Definition: ffprobe.c:1276
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...
Definition: utils.c:4783
This side data should be associated with a video stream and contains Stereoscopic 3D information in f...
Definition: avcodec.h:1471
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition: opt.c:1293
#define OPT_AUDIO
Definition: cmdutils.h:171
static AVFormatContext * fmt_ctx
static int show_streams(WriterContext *w, InputFile *ifile)
Definition: ffprobe.c:2428
static char * print_format
Definition: ffprobe.c:103
Video represents a portion of a sphere mapped on a flat surface using equirectangular projection...
Definition: spherical.h:72
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:4056
static const Writer json_writer
Definition: ffprobe.c:1512
void av_codec_set_pkt_timebase(AVCodecContext *avctx, AVRational val)
int num
Numerator.
Definition: rational.h:59
int repeat_pict
When decoding, this signals how much the picture must be delayed.
Definition: frame.h:320
int index
stream index in AVFormatContext
Definition: avformat.h:890
int size
Definition: avcodec.h:1648
static const AVOption writer_options[]
Definition: ffprobe.c:393
const char * b
Definition: vf_curves.c:113
static void writer_print_integers(WriterContext *wctx, const char *name, uint8_t *data, int size, const char *format, int columns, int bytes, int offset_add)
Definition: ffprobe.c:760
static int show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_idx, InputStream *ist, int in_program)
Definition: ffprobe.c:2186
#define print_str_opt(k, v)
Definition: ffprobe.c:1722
void(* print_integer)(WriterContext *wctx, const char *, long long int)
Definition: ffprobe.c:349
static int read_packets(WriterContext *w, InputFile *ifile)
Definition: ffprobe.c:2166
int64_t bit_rate
Total stream bitrate in bit/s, 0 if not available.
Definition: avformat.h:1451
int show_all_entries
Definition: ffprobe.c:135
void show_banner(int argc, char **argv, const OptionDef *options)
Print the program banner to stderr.
Definition: cmdutils.c:1150
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).
Definition: timecode.c:130
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:217
attribute_deprecated 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.
Definition: utils.c:2336
static const AVClass writer_class
Definition: ffprobe.c:414
static int do_show_packets
Definition: ffprobe.c:79
unsigned num_rects
Definition: avcodec.h:4036
Video represents a sphere mapped on a flat surface using equirectangular projection.
Definition: spherical.h:56
static int do_show_format_tags
Definition: ffprobe.c:91
static int writer_open(WriterContext **wctx, const Writer *writer, const char *args, const struct section *sections, int nb_sections)
Definition: ffprobe.c:449
void(* uninit)(WriterContext *wctx)
Definition: ffprobe.c:345
static void bprint_bytes(AVBPrint *bp, const uint8_t *ubuf, size_t ubuf_size)
Definition: ffprobe.c:440
size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag)
Put a string representing the codec tag codec_tag in buf.
Definition: utils.c:3207
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:222
static void json_print_item_str(WriterContext *wctx, const char *key, const char *value)
Definition: ffprobe.c:1474
char * escape_mode_str
Definition: ffprobe.c:982
static const Writer default_writer
Definition: ffprobe.c:914
AVPacketSideData * side_data
An array of side data that applies to the whole stream (i.e.
Definition: avformat.h:999
static void show_frame(WriterContext *w, AVFrame *frame, AVStream *stream, AVFormatContext *fmt_ctx)
Definition: ffprobe.c:1893
static const char * json_escape_str(AVBPrint *dst, const char *src, void *log_ctx)
Definition: ffprobe.c:1392
static AVPacket pkt
static void xml_print_section_footer(WriterContext *wctx)
Definition: ffprobe.c:1635
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:3123
static void mark_section_show_entries(SectionID section_id, int show_all_entries, AVDictionary *entries)
Definition: ffprobe.c:2886
static int do_show_error
Definition: ffprobe.c:76
static av_always_inline int process_frame(WriterContext *w, InputFile *ifile, AVFrame *frame, AVPacket *pkt)
Definition: ffprobe.c:1991
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt)
Decode a subtitle message.
Definition: utils.c:2669
AVDictionary * metadata
Definition: avformat.h:1310
#define src
Definition: vp8dsp.c:254
static uint64_t * nb_streams_frames
Definition: ffprobe.c:257
int has_nested_elems[SECTION_MAX_NB_LEVELS]
Definition: ffprobe.c:985
static int validate_string(WriterContext *wctx, char **dstp, const char *src)
Definition: ffprobe.c:588
AVCodec.
Definition: avcodec.h:3671
static int open_input_file(InputFile *ifile, const char *filename)
Definition: ffprobe.c:2568
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
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:2002
This struct describes the properties of an encoded stream.
Definition: avcodec.h:4048
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:235
static int do_count_frames
Definition: ffprobe.c:71
#define SECTION_MAX_NB_LEVELS
Definition: ffprobe.c:355
enum AVColorSpace color_space
Definition: avcodec.h:4145
static void * writer_child_next(void *obj, void *prev)
Definition: ffprobe.c:406
int indent_level
Definition: ffprobe.c:1529
int end_is_offset
Definition: ffprobe.c:111
#define log2(x)
Definition: libm.h:404
static const AVOption default_options[]
Definition: ffprobe.c:838
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1859
#define AV_DICT_DONT_STRDUP_KEY
Take ownership of a key that's been allocated with av_malloc() or another memory allocation function...
Definition: dict.h:73
#define AVFMT_SHOW_IDS
Show format stream IDs numbers.
Definition: avformat.h:480
const char *(* escape_str)(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
Definition: ffprobe.c:983
Format I/O context.
Definition: avformat.h:1349
#define OFFSET(x)
Definition: ffprobe.c:1535
#define AV_HASH_MAX_SIZE
Maximum value that av_hash_get_size() will currently return.
Definition: hash.h:155
const AVClass * avcodec_get_class(void)
Get the AVClass for AVCodecContext.
Definition: options.c:280
unsigned int nb_stream_indexes
Definition: avformat.h:1281
const char * element_name
name of the contained element, if provided
Definition: ffprobe.c:132
static void writer_print_section_header(WriterContext *wctx, int section_id)
Definition: ffprobe.c:536
static void compact_print_section_footer(WriterContext *wctx)
Definition: ffprobe.c:1058
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
Public dictionary API.
const char * name
Definition: opt.h:247
unsigned int nb_section_packet
number of the packet section in case we are in "packets_and_frames" section
Definition: ffprobe.c:376
static void ini_print_section_header(WriterContext *wctx)
Definition: ffprobe.c:1303
#define print_duration_ts(k, v)
Definition: ffprobe.c:1727
#define DEFAULT
Definition: avdct.c:28
void register_exit(void(*cb)(int ret))
Register a program-specific cleanup routine.
Definition: cmdutils.c:130
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
void log_callback_help(void *ptr, int level, const char *fmt, va_list vl)
Trivial log callback.
Definition: cmdutils.c:98
uint8_t
static int nb_streams
Definition: ffprobe.c:255
#define av_cold
Definition: attributes.h:82
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:150
static int do_read_packets
Definition: ffprobe.c:74
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:544
static int opt_read_intervals(void *optctx, const char *opt, const char *arg)
Definition: ffprobe.c:3150
int av_packet_unpack_dictionary(const uint8_t *data, int size, AVDictionary **dict)
Unpack a dictionary from side_data.
Definition: avpacket.c:502
int width
Video only.
Definition: avcodec.h:4122
Generic hashing API.
static int do_show_pixel_format_components
Definition: ffprobe.c:88
static int * selected_streams
Definition: ffprobe.c:258
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:678
#define HAS_ARG
Definition: cmdutils.h:166
const char * av_stereo3d_type_name(unsigned int type)
Provide a human-readable name of a given stereo3d type.
Definition: stereo3d.c:57
static void close_input_file(InputFile *ifile)
Definition: ffprobe.c:2679
timestamp utils, mostly useful for debugging/logging purposes
Stereo 3D type: this structure describes how two videos are packed within a single video surface...
Definition: stereo3d.h:123
static const char * flat_escape_value_str(AVBPrint *dst, const char *src)
Definition: ffprobe.c:1185
static void writer_print_time(WriterContext *wctx, const char *key, int64_t ts, const AVRational *time_base, int is_duration)
Definition: ffprobe.c:691
const char * av_color_range_name(enum AVColorRange range)
Definition: pixdesc.c:2645
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
int id
unique ID to identify the chapter
Definition: avformat.h:1307
static int show_chapters(WriterContext *w, InputFile *ifile)
Definition: ffprobe.c:2498
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: avcodec.h:1665
static av_cold int compact_init(WriterContext *wctx)
Definition: ffprobe.c:1006
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition: avcodec.h:1465
#define CHECK_END
int id
Format-specific stream ID.
Definition: avformat.h:896
static int do_show_library_versions
Definition: ffprobe.c:85
static void compact_print_section_header(WriterContext *wctx)
Definition: ffprobe.c:1028
#define ERROR(...)
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.
Definition: utils.c:4827
void av_spherical_tile_bounds(const AVSphericalMapping *map, size_t width, size_t height, size_t *left, size_t *top, size_t *right, size_t *bottom)
Convert the bounding fields from an AVSphericalVideo from 0.32 fixed point to pixels.
Definition: spherical.c:36
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:271
int nb_side_data
The number of elements in the AVStream.side_data array.
Definition: avformat.h:1003
static int match_section(const char *section_name, int show_all_entries, AVDictionary *entries)
Definition: ffprobe.c:2901
int pmt_pid
Definition: avformat.h:1285
void init_opts(void)
Initialize the cmdutils option system, in particular allocate the *_opts contexts.
Definition: cmdutils.c:84
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1417
int avcodec_parameters_to_context(AVCodecContext *codec, const AVCodecParameters *par)
Fill the codec context based on the values from the supplied codec parameters.
Definition: utils.c:4266
void av_bprint_append_data(AVBPrint *buf, const char *data, unsigned size)
Append data to a print buffer.
Definition: bprint.c:158
static AVFrame * frame
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
Definition: options.c:132
static void writer_print_data_hash(WriterContext *wctx, const char *name, uint8_t *data, int size)
Definition: ffprobe.c:745
const char * name
Definition: ffprobe.c:124
Structure to hold side data for an AVFrame.
Definition: frame.h:149
static const AVOption json_options[]
Definition: ffprobe.c:1374
static void log_read_interval(const ReadInterval *interval, void *log_ctx, int log_level)
Definition: ffprobe.c:2036
static const char * writer_get_name(void *p)
Definition: ffprobe.c:385
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:40
int nb_streams
Definition: ffmpeg.h:405
int flags
Flags modifying the (de)muxer behaviour.
Definition: avformat.h:1460
#define PRINT_DISPOSITION(flagname, name)
uint8_t * data
Definition: avcodec.h:1647
StringValidation
Definition: ffprobe.c:332
void parse_options(void *optctx, int argc, char **argv, const OptionDef *options, void(*parse_arg_function)(void *, const char *))
Definition: cmdutils.c:382
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
#define SECTION_MAX_NB_CHILDREN
Definition: ffprobe.c:120
static int show_program(WriterContext *w, InputFile *ifile, AVProgram *program)
Definition: ffprobe.c:2445
static int flags
Definition: log.c:57
list ifile
Definition: normalize.py:6
uint32_t tag
Definition: movenc.c:1412
int avformat_network_init(void)
Do global initialization of network components.
Definition: utils.c:4718
char av_get_picture_type_char(enum AVPictureType pict_type)
Return a single letter to describe the given picture type pict_type.
Definition: utils.c:91
const AVClass * priv_class
private class of the writer, if any
Definition: ffprobe.c:340
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
int has_end
Definition: ffprobe.c:110
uint8_t * data
Definition: avcodec.h:1591
static int check_section_show_entries(int section_id)
Definition: ffprobe.c:3262
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:325
const AVClass * avformat_get_class(void)
Get the AVClass for AVFormatContext.
Definition: options.c:156
static void print_section(SectionID id, int level)
Definition: ffprobe.c:3164
void parse_loglevel(int argc, char **argv, const OptionDef *options)
Find the '-loglevel' option in the command line args and apply it.
Definition: cmdutils.c:505
external API header
void(* print_section_footer)(WriterContext *wctx)
Definition: ffprobe.c:348
int64_t av_frame_get_best_effort_timestamp(const AVFrame *frame)
Accessors for some AVFrame fields.
ptrdiff_t size
Definition: opengl_enc.c:101
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
void show_help_default(const char *opt, const char *arg)
Per-fftool specific help handler.
Definition: ffprobe.c:3005
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:176
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:930
static void writer_register_all(void)
Definition: ffprobe.c:1696
static void xml_print_str(WriterContext *wctx, const char *key, const char *value)
Definition: ffprobe.c:1654
int children_ids[SECTION_MAX_NB_CHILDREN+1]
list of children section IDS, terminated by -1
Definition: ffprobe.c:131
static void print_pkt_side_data(WriterContext *w, AVCodecParameters *par, const AVPacketSideData *side_data, int nb_side_data, SectionID id_data_list, SectionID id_data)
Definition: ffprobe.c:1764
int nb_side_data
Definition: frame.h:391
static const char * input_filename
Definition: ffprobe.c:231
unsigned int * stream_index
Definition: avformat.h:1280
static void json_print_section_header(WriterContext *wctx)
Definition: ffprobe.c:1414
AVFrameSideData ** side_data
Definition: frame.h:390
uint64_t channel_layout
Audio only.
Definition: avcodec.h:4158
#define av_log(a,...)
int print_section
Definition: ffprobe.c:981
static void ffprobe_show_program_version(WriterContext *w)
Definition: ffprobe.c:2779
static int do_show_chapter_tags
Definition: ffprobe.c:90
const char * name
Definition: pixdesc.h:82
int64_t start_time
Definition: avformat.h:1295
AVDictionary ** setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *codec_opts)
Setup AVCodecContext options for avformat_find_stream_info().
Definition: cmdutils.c:2059
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: avcodec.h:4085
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1679
AVDictionary * format_opts
Definition: cmdutils.c:72
int hierarchical
Definition: ffprobe.c:1262
static int do_show_frames
Definition: ffprobe.c:78
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
Definition: avutil.h:308
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
int id
identifier
Definition: ffprobe.c:108
void av_dump_format(AVFormatContext *ic, int index, const char *url, int is_output)
Print detailed information about the input or output format, such as duration, bitrate, streams, container, programs, metadata, side data, codec and time base.
Definition: dump.c:552
Main libavdevice API header.
#define U(x)
Definition: vp56_arith.h:37
static int read_interval_packets(WriterContext *w, InputFile *ifile, const ReadInterval *interval, int64_t *cur_ts)
Definition: ffprobe.c:2060
static int do_show_chapters
Definition: ffprobe.c:75
char * string_validation_replacement
Definition: ffprobe.c:381
double d
Definition: ffprobe.c:268
libswresample public header
static int opt_show_versions(const char *opt, const char *arg)
Definition: ffprobe.c:3193
const char * av_chroma_location_name(enum AVChromaLocation location)
Definition: pixdesc.c:2669
static const char unit_byte_str[]
Definition: ffprobe.c:252
void av_hash_init(AVHashContext *ctx)
Initialize or reset a hash context.
Definition: hash.c:137
const int program_birth_year
program birth year, defined by the program for show_banner()
Definition: ffprobe.c:68
int level
current level, starting from 0
Definition: ffprobe.c:366
int width
width and height of the video frame
Definition: frame.h:239
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
AVDictionary * entries_to_show
Definition: ffprobe.c:134
static int do_show_pixel_format_flags
Definition: ffprobe.c:87
#define AV_DICT_MATCH_CASE
Only get an entry with exact-case key match.
Definition: dict.h:69
AVDictionary * metadata
Metadata that applies to the whole file.
Definition: avformat.h:1567
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
Definition: utils.c:3578
int flags
Additional information about the frame packing.
Definition: stereo3d.h:132
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
#define AV_BPRINT_SIZE_UNLIMITED
int xsd_strict
Definition: ffprobe.c:1531
#define print_int(k, v)
Definition: ffprobe.c:1719
static void opt_input_file(void *optctx, const char *arg)
Definition: ffprobe.c:2986
static int opt_pretty(void *optctx, const char *opt, const char *arg)
Definition: ffprobe.c:3155
BYTE * dstp
Definition: avisynth_c.h:813
#define AVERROR(e)
Definition: error.h:43
#define SET_DO_SHOW(id, varname)
Definition: ffprobe.c:3274
int priv_size
private size for the writer context
Definition: ffprobe.c:341
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition: pixdesc.h:148
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, int *size)
Get side information from packet.
Definition: avpacket.c:339
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:163
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:76
static const AVOption xml_options[]
Definition: ffprobe.c:1537
enum AVColorPrimaries color_primaries
Definition: avcodec.h:4143
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
int video_delay
Video only.
Definition: avcodec.h:4151
#define SECTION_FLAG_HAS_VARIABLE_FIELDS
the section may contain a variable number of fields with variable keys.
Definition: ffprobe.c:128
const char * r
Definition: vf_curves.c:111
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
unsigned int nb_programs
Definition: avformat.h:1506
int start_is_offset
Definition: ffprobe.c:111
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:203
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:4052
const char * arg
Definition: jacosubdec.c:66
int nested_section[SECTION_MAX_NB_LEVELS]
Definition: ffprobe.c:984
AVChapter ** chapters
Definition: avformat.h:1557
#define print_q(k, v, s)
Definition: ffprobe.c:1720
static void default_print_int(WriterContext *wctx, const char *key, long long int value)
Definition: ffprobe.c:905
#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:359
static av_cold int json_init(WriterContext *wctx)
Definition: ffprobe.c:1382
simple assert() macros that are a bit more flexible than ISO C assert().
const AVOption * av_opt_next(const void *obj, const AVOption *last)
Iterate over all AVOptions belonging to obj.
Definition: opt.c:45
enum AVPacketSideDataType type
Definition: avcodec.h:1593
#define JSON_INDENT()
Definition: ffprobe.c:1412
int side_data_elems
Definition: avcodec.h:1659
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:49
static void flat_print_str(WriterContext *wctx, const char *key, const char *value)
Definition: ffprobe.c:1234
int av_hash_alloc(AVHashContext **ctx, const char *name)
Allocate a hash context for the algorithm specified by name.
Definition: hash.c:100
int id
unique id identifying a section
Definition: ffprobe.c:123
const char * long_name
A more descriptive name for this codec.
Definition: avcodec.h:707
The GOP timecode in 25 bit timecode format.
Definition: frame.h:123
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:970
New fields can be added to the end with minor version bumps.
Definition: avformat.h:1276
static void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.h:226
attribute_deprecated int64_t timecode_frame_start
Definition: avcodec.h:2834
static int parse_read_intervals(const char *intervals_spec)
Definition: ffprobe.c:3102
#define fail()
Definition: checkasm.h:88
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:149
static av_always_inline void flat(WaveformContext *s, AVFrame *in, AVFrame *out, int component, int intensity, int offset_y, int offset_x, int column, int mirror)
Definition: vf_waveform.c:899
int program_num
Definition: avformat.h:1284
const char * unit
Definition: ffprobe.c:269
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1653
const char * av_color_primaries_name(enum AVColorPrimaries primaries)
Definition: pixdesc.c:2651
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:3063
void * priv
private data for use by the filter
Definition: ffprobe.c:361
int extradata_size
Size of the extradata content in bytes.
Definition: avcodec.h:4074
uint32_t end_display_time
Definition: avcodec.h:4035
char * name
name of this writer instance
Definition: ffprobe.c:360
int64_t pts
Same as packet pts, in AV_TIME_BASE.
Definition: avcodec.h:4038
char * av_asprintf(const char *fmt,...)
Definition: avstring.c:113
#define SECTION_FLAG_IS_WRAPPER
the section only contains other sections, but has no data at its own level
Definition: ffprobe.c:126
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:106
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1405
static void writer_print_data(WriterContext *wctx, const char *name, uint8_t *data, int size)
Definition: ffprobe.c:717
static int show_format(WriterContext *w, InputFile *ifile)
Definition: ffprobe.c:2523
int refs
number of reference frames
Definition: avcodec.h:2403
AVDictionary * opts
Definition: movenc.c:50
static ReadInterval * read_intervals
Definition: ffprobe.c:115
AVInputFormat * av_find_input_format(const char *short_name)
Find AVInputFormat based on the short name of the input format.
Definition: format.c:164
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:83
AVBPrint section_pbuf[SECTION_MAX_NB_LEVELS]
generic print buffer dedicated to each section, used by various writers
Definition: ffprobe.c:373
Video frame is split into 6 faces of a cube, and arranged on a 3x2 layout.
Definition: spherical.h:65
#define print_section_footer(s)
Definition: ffprobe.c:1736
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:953
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:261
char filename[1024]
input or output filename
Definition: avformat.h:1425
static const char unit_bit_per_second_str[]
Definition: ffprobe.c:253
Spherical video.
static const Writer * registered_writers[MAX_REGISTERED_WRITERS_NB+1]
Definition: ffprobe.c:788
#define AV_UTF8_FLAG_EXCLUDE_XML_INVALID_CONTROL_CODES
exclude control codes not accepted by XML
Definition: avstring.h:354
#define FFMIN(a, b)
Definition: common.h:96
const char * av_hash_names(int i)
Get the names of available hash algorithms.
Definition: hash.c:84
int display_picture_number
picture number in display order
Definition: frame.h:296
static struct section sections[]
Definition: ffprobe.c:182
void av_log_set_callback(void(*callback)(void *, int, const char *, va_list))
Set the logging callback.
Definition: log.c:406
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition: options.c:157
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:557
static int do_read_frames
Definition: ffprobe.c:73
#define PRINT_PIX_FMT_FLAG(flagname, name)
Definition: ffprobe.c:2824
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
GLsizei GLboolean const GLfloat * value
Definition: opengl_enc.c:109
#define print_fmt(k, f,...)
Definition: ffprobe.c:1713
#define FF_PROFILE_UNKNOWN
Definition: avcodec.h:3226
int string_validation
Definition: ffprobe.c:380
This side data should be associated with a video stream and corresponds to the AVSphericalMapping str...
Definition: avcodec.h:1585
static void ffprobe_show_pixel_formats(WriterContext *w)
Definition: ffprobe.c:2829
static void show_usage(void)
Definition: ffprobe.c:2772
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:119
int32_t
AVFormatContext * ctx
Definition: movenc.c:48
char sep
Definition: ffprobe.c:1139
const char * av_hash_get_name(const AVHashContext *ctx)
Definition: hash.c:90
static int show_private_data
Definition: ffprobe.c:101
static int probe_file(WriterContext *wctx, const char *filename)
Definition: ffprobe.c:2694
#define OPT_EXIT
Definition: cmdutils.h:176
static av_cold int xml_init(WriterContext *wctx)
Definition: ffprobe.c:1547
uint16_t format
Definition: avcodec.h:4033
int nb_sections
number of sections
Definition: ffprobe.c:364
const struct section * sections
array containing all sections
Definition: ffprobe.c:363
static const Writer flat_writer
Definition: ffprobe.c:1247
static void flat_print_int(WriterContext *wctx, const char *key, long long int value)
Definition: ffprobe.c:1229
int32_t yaw
Rotation around the up vector [-180, 180].
Definition: spherical.h:126
static int opt_sections(void *optctx, const char *opt, const char *arg)
Definition: ffprobe.c:3181
int n
Definition: avisynth_c.h:684
AVDictionary * metadata
Definition: avformat.h:961
static int do_show_programs
Definition: ffprobe.c:80
static const OptionDef real_options[]
Definition: ffprobe.c:3218
const char * bin_str
Definition: ffprobe.c:239
enum AVColorRange color_range
Video only.
Definition: avcodec.h:4142
#define WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS
Definition: ffprobe.c:329
const char * av_get_colorspace_name(enum AVColorSpace val)
Get the name of a colorspace.
Definition: frame.c:83
int frames
Definition: movenc.c:65
const char * dec_str
Definition: ffprobe.c:240
static int do_show_format
Definition: ffprobe.c:77
#define AV_STEREO3D_FLAG_INVERT
Inverted views, Right/Bottom represents the left view.
Definition: stereo3d.h:114
static void error(const char *err)
const char * item_start_end
Definition: ffprobe.c:1368
#define FF_ARRAY_ELEMS(a)
static const Writer ini_writer
Definition: ffprobe.c:1352
int flags
Definition: opt.h:275
void exit_program(int ret)
Wraps exit with a program-specific cleanup routine.
Definition: cmdutils.c:135
static void compact_print_str(WriterContext *wctx, const char *key, const char *value)
Definition: ffprobe.c:1068
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.
uint32_t padding
Number of pixels to pad from the edge of each cube face.
Definition: spherical.h:182
const char * long_name
Descriptive name for the format, meant to be more human-readable than name.
Definition: avformat.h:671
int av_format_get_probe_score(const AVFormatContext *s)
Accessors for some AVFormatContext fields.
Definition: utils.c:218
Stream structure.
Definition: avformat.h:889
const char program_name[]
program name, defined by the program for show_version().
Definition: ffprobe.c:67
static const Writer compact_writer
Definition: ffprobe.c:1091
static void compact_print_int(WriterContext *wctx, const char *key, long long int value)
Definition: ffprobe.c:1081
int64_t end
chapter start/end time in time_base units
Definition: avformat.h:1309
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:251
int av_dict_parse_string(AVDictionary **pm, const char *str, const char *key_val_sep, const char *pairs_sep, int flags)
Parse the key/value pairs list and add the parsed entries to a dictionary.
Definition: dict.c:180
const char * name
Definition: ffprobe.c:342
int has_start
Definition: ffprobe.c:110
int avformat_network_deinit(void)
Undo the initialization done by avformat_network_init.
Definition: utils.c:4731
static int do_show_packet_tags
Definition: ffprobe.c:95
external API header
static struct AVHashContext * hash
Definition: ffprobe.c:234
AVStream * st
Definition: ffmpeg.h:293
int coded_picture_number
picture number in bitstream order
Definition: frame.h:292
enum AVStereo3DType type
How views are packed within the video.
Definition: stereo3d.h:127
static AVInputFormat * iformat
Definition: ffprobe.c:232
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
unsigned int nb_section_frame
number of the frame section in case we are in "packets_and_frames" section
Definition: ffprobe.c:377
#define AV_BPRINT_SIZE_AUTOMATIC
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:237
int64_t end_time
Definition: avformat.h:1296
Libavcodec external API header.
A list of zero terminated key/value strings.
Definition: avcodec.h:1529
attribute_deprecated 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.
Definition: utils.c:2227
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition: frame.h:83
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer...
Definition: options.c:172
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:260
Timecode helpers header.
AVIOContext * pb
I/O context.
Definition: avformat.h:1391
#define XML_INDENT()
Definition: ffprobe.c:1593
static void xml_print_int(WriterContext *wctx, const char *key, long long int value)
Definition: ffprobe.c:1677
static int do_bitexact
Definition: ffprobe.c:70
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
#define AV_RN16(p)
Definition: intreadwrite.h:365
main external API structure.
Definition: avcodec.h:1722
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: utils.c:3168
static Writer xml_writer
Definition: ffprobe.c:1684
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:575
static const Writer csv_writer
Definition: ffprobe.c:1122
static void show_error(WriterContext *w, int err)
Definition: ffprobe.c:2554
const char * item_sep
Definition: ffprobe.c:1368
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
Definition: utils.c:2782
static void ini_print_str(WriterContext *wctx, const char *key, const char *value)
Definition: ffprobe.c:1336
#define WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER
Definition: ffprobe.c:330
uint8_t * data
Definition: frame.h:151
void av_hash_update(AVHashContext *ctx, const uint8_t *src, int len)
Update a hash context with additional data.
Definition: hash.c:158
void * buf
Definition: avisynth_c.h:690
InputStream * streams
Definition: ffprobe.c:63
unsigned int nb_section_packet_frame
nb_section_packet or nb_section_frame according if is_packets_and_frames
Definition: ffprobe.c:378
int terminate_line[SECTION_MAX_NB_LEVELS]
Definition: ffprobe.c:986
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:70
Replacements for frequently missing libm functions.
static int show_value_unit
Definition: ffprobe.c:97
static int use_value_sexagesimal_format
Definition: ffprobe.c:100
#define print_duration_time(k, v, tb)
Definition: ffprobe.c:1726
AVDictionary * av_frame_get_metadata(const AVFrame *frame)
int coded_height
Definition: avcodec.h:1924
static const char * format
Definition: movenc.c:47
Describe the class of an AVClass context structure.
Definition: log.h:67
void av_hash_freep(AVHashContext **ctx)
Free hash context and set hash context pointer to NULL.
Definition: hash.c:234
int av_frame_get_channels(const AVFrame *frame)
void av_hash_final_hex(struct AVHashContext *ctx, uint8_t *dst, int size)
Finalize a hash context and store the hexadecimal representation of the actual hash value as a string...
Definition: hash.c:211
static av_const int av_toupper(int c)
Locale-independent conversion of ASCII characters to uppercase.
Definition: avstring.h:231
int index
Definition: gxfenc.c:89
char * item_sep_str
Definition: ffprobe.c:978
int32_t roll
Rotation around the forward vector [-180, 180].
Definition: spherical.h:128
#define DEFINE_WRITER_CLASS(name)
Definition: ffprobe.c:815
Rational number (pair of numerator and denominator).
Definition: rational.h:58
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
Definition: opt.h:277
AVCodecContext * dec_ctx
Definition: ffmpeg.h:300
#define OPT_STRING
Definition: cmdutils.h:169
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition: avstring.c:101
const char * name
Name of the codec described by this descriptor.
Definition: avcodec.h:703
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
Definition: utils.c:1242
#define snprintf
Definition: snprintf.h:34
static void ffprobe_cleanup(int ret)
Definition: ffprobe.c:260
#define SECTION_FLAG_IS_ARRAY
the section contains an array of elements of the same type
Definition: ffprobe.c:127
SectionID
Definition: ffprobe.c:138
This structure describes how to handle spherical videos, outlining information about projection...
Definition: spherical.h:82
static const AVOption compact_options[]
Definition: ffprobe.c:992
#define REALLOCZ_ARRAY_STREAM(ptr, cur_n, new_n)
Definition: ffprobe.c:1738
int64_t end
start, end in second/AV_TIME_BASE units
Definition: ffprobe.c:109
#define AV_RN32(p)
Definition: intreadwrite.h:369
misc parsing utilities
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
Definition: utils.c:1710
int64_t av_frame_get_channel_layout(const AVFrame *frame)
int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
Seek to timestamp ts.
Definition: utils.c:2469
mfxU16 profile
Definition: qsvenc.c:44
const char * av_frame_side_data_name(enum AVFrameSideDataType type)
Definition: frame.c:760
This struct describes the properties of a single codec described by an AVCodecID. ...
Definition: avcodec.h:695
unsigned int string_validation_utf8_flags
Definition: ffprobe.c:382
int64_t start
Definition: ffprobe.c:109
static void writer_print_ts(WriterContext *wctx, const char *key, int64_t ts, int is_duration)
Definition: ffprobe.c:708
AVDictionary * metadata
Definition: avformat.h:1282
static uint64_t * nb_streams_packets
Definition: ffprobe.c:256
enum AVFrameSideDataType type
Definition: frame.h:150
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.
Definition: utils.c:79
static void ffprobe_show_library_versions(WriterContext *w)
Definition: ffprobe.c:2810
static int use_value_prefix
Definition: ffprobe.c:98
int64_t start_time
Position of the first frame of the component, in AV_TIME_BASE fractional seconds. ...
Definition: avformat.h:1434
const AVClass * priv_class
AVClass for the private context.
Definition: avcodec.h:3697
uint8_t level
Definition: svq3.c:207
static int swscale(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
Definition: swscale.c:231
static void flat_print_section_header(WriterContext *wctx)
Definition: ffprobe.c:1203
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
Put a description of the AVERROR code errnum in errbuf.
Definition: error.c:105
static char * upcase_string(char *dst, size_t dst_size, const char *src)
Definition: ffprobe.c:849
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
Definition: bprint.c:227
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:184
int64_t start
Definition: avformat.h:1309
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:946
static char * show_data_hash
Definition: ffprobe.c:105
static const OptionDef * options
Definition: ffprobe.c:228
int sample_rate
Audio only.
Definition: avcodec.h:4166
#define OPT_BOOL
Definition: cmdutils.h:167
static int do_show_pixel_formats
Definition: ffprobe.c:86
int64_t pkt_dts
DTS copied from the AVPacket that triggered returning this frame.
Definition: frame.h:287