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