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