FFmpeg
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"
37 #include "libavutil/display.h"
38 #include "libavutil/hash.h"
41 #include "libavutil/dovi_meta.h"
42 #include "libavutil/opt.h"
43 #include "libavutil/pixdesc.h"
44 #include "libavutil/spherical.h"
45 #include "libavutil/stereo3d.h"
46 #include "libavutil/dict.h"
47 #include "libavutil/intreadwrite.h"
48 #include "libavutil/libm.h"
49 #include "libavutil/parseutils.h"
50 #include "libavutil/timecode.h"
51 #include "libavutil/timestamp.h"
52 #include "libavdevice/avdevice.h"
53 #include "libswscale/swscale.h"
56 #include "cmdutils.h"
57 
58 #include "libavutil/thread.h"
59 
60 #if !HAVE_THREADS
61 # ifdef pthread_mutex_lock
62 # undef pthread_mutex_lock
63 # endif
64 # define pthread_mutex_lock(a) do{}while(0)
65 # ifdef pthread_mutex_unlock
66 # undef pthread_mutex_unlock
67 # endif
68 # define pthread_mutex_unlock(a) do{}while(0)
69 #endif
70 
71 typedef struct InputStream {
72  AVStream *st;
73 
75 } InputStream;
76 
77 typedef struct InputFile {
79 
81  int nb_streams;
82 } InputFile;
83 
84 const char program_name[] = "ffprobe";
85 const int program_birth_year = 2007;
86 
87 static int do_bitexact = 0;
88 static int do_count_frames = 0;
89 static int do_count_packets = 0;
90 static int do_read_frames = 0;
91 static int do_read_packets = 0;
92 static int do_show_chapters = 0;
93 static int do_show_error = 0;
94 static int do_show_format = 0;
95 static int do_show_frames = 0;
96 static int do_show_packets = 0;
97 static int do_show_programs = 0;
98 static int do_show_streams = 0;
100 static int do_show_data = 0;
101 static int do_show_program_version = 0;
103 static int do_show_pixel_formats = 0;
106 static int do_show_log = 0;
107 
108 static int do_show_chapter_tags = 0;
109 static int do_show_format_tags = 0;
110 static int do_show_frame_tags = 0;
111 static int do_show_program_tags = 0;
112 static int do_show_stream_tags = 0;
113 static int do_show_packet_tags = 0;
114 
115 static int show_value_unit = 0;
116 static int use_value_prefix = 0;
119 static int show_private_data = 1;
120 
121 #define SHOW_OPTIONAL_FIELDS_AUTO -1
122 #define SHOW_OPTIONAL_FIELDS_NEVER 0
123 #define SHOW_OPTIONAL_FIELDS_ALWAYS 1
125 
126 static char *print_format;
127 static char *stream_specifier;
128 static char *show_data_hash;
129 
130 typedef struct ReadInterval {
131  int id; ///< identifier
132  int64_t start, end; ///< start, end in second/AV_TIME_BASE units
136 } ReadInterval;
137 
139 static int read_intervals_nb = 0;
140 
141 static int find_stream_info = 1;
142 
143 /* section structure definition */
144 
145 #define SECTION_MAX_NB_CHILDREN 10
146 
147 struct section {
148  int id; ///< unique id identifying a section
149  const char *name;
150 
151 #define SECTION_FLAG_IS_WRAPPER 1 ///< the section only contains other sections, but has no data at its own level
152 #define SECTION_FLAG_IS_ARRAY 2 ///< the section contains an array of elements of the same type
153 #define SECTION_FLAG_HAS_VARIABLE_FIELDS 4 ///< the section may contain a variable number of fields with variable keys.
154  /// For these sections the element_name field is mandatory.
155  int flags;
156  int children_ids[SECTION_MAX_NB_CHILDREN+1]; ///< list of children section IDS, terminated by -1
157  const char *element_name; ///< name of the contained element, if provided
158  const char *unique_name; ///< unique section name, in case the name is ambiguous
161 };
162 
163 typedef enum {
213 } SectionID;
214 
215 static struct section sections[] = {
217  [SECTION_ID_CHAPTER] = { SECTION_ID_CHAPTER, "chapter", 0, { SECTION_ID_CHAPTER_TAGS, -1 } },
218  [SECTION_ID_CHAPTER_TAGS] = { SECTION_ID_CHAPTER_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "chapter_tags" },
219  [SECTION_ID_ERROR] = { SECTION_ID_ERROR, "error", 0, { -1 } },
220  [SECTION_ID_FORMAT] = { SECTION_ID_FORMAT, "format", 0, { SECTION_ID_FORMAT_TAGS, -1 } },
221  [SECTION_ID_FORMAT_TAGS] = { SECTION_ID_FORMAT_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "format_tags" },
224  [SECTION_ID_FRAME_TAGS] = { SECTION_ID_FRAME_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "frame_tags" },
225  [SECTION_ID_FRAME_SIDE_DATA_LIST] ={ SECTION_ID_FRAME_SIDE_DATA_LIST, "side_data_list", SECTION_FLAG_IS_ARRAY, { SECTION_ID_FRAME_SIDE_DATA, -1 }, .element_name = "side_data", .unique_name = "frame_side_data_list" },
234  [SECTION_ID_FRAME_LOG] = { SECTION_ID_FRAME_LOG, "log", 0, { -1 }, },
236  [SECTION_ID_LIBRARY_VERSION] = { SECTION_ID_LIBRARY_VERSION, "library_version", 0, { -1 } },
240  [SECTION_ID_PACKET_TAGS] = { SECTION_ID_PACKET_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "packet_tags" },
241  [SECTION_ID_PACKET_SIDE_DATA_LIST] ={ SECTION_ID_PACKET_SIDE_DATA_LIST, "side_data_list", SECTION_FLAG_IS_ARRAY, { SECTION_ID_PACKET_SIDE_DATA, -1 }, .element_name = "side_data", .unique_name = "packet_side_data_list" },
242  [SECTION_ID_PACKET_SIDE_DATA] = { SECTION_ID_PACKET_SIDE_DATA, "side_data", 0, { -1 } },
245  [SECTION_ID_PIXEL_FORMAT_FLAGS] = { SECTION_ID_PIXEL_FORMAT_FLAGS, "flags", 0, { -1 }, .unique_name = "pixel_format_flags" },
246  [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" },
248  [SECTION_ID_PROGRAM_STREAM_DISPOSITION] = { SECTION_ID_PROGRAM_STREAM_DISPOSITION, "disposition", 0, { -1 }, .unique_name = "program_stream_disposition" },
249  [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" },
251  [SECTION_ID_PROGRAM_STREAMS] = { SECTION_ID_PROGRAM_STREAMS, "streams", SECTION_FLAG_IS_ARRAY, { SECTION_ID_PROGRAM_STREAM, -1 }, .unique_name = "program_streams" },
253  [SECTION_ID_PROGRAM_TAGS] = { SECTION_ID_PROGRAM_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "program_tags" },
254  [SECTION_ID_PROGRAM_VERSION] = { SECTION_ID_PROGRAM_VERSION, "program_version", 0, { -1 } },
262  [SECTION_ID_STREAM_DISPOSITION] = { SECTION_ID_STREAM_DISPOSITION, "disposition", 0, { -1 }, .unique_name = "stream_disposition" },
263  [SECTION_ID_STREAM_TAGS] = { SECTION_ID_STREAM_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "stream_tags" },
264  [SECTION_ID_STREAM_SIDE_DATA_LIST] ={ SECTION_ID_STREAM_SIDE_DATA_LIST, "side_data_list", SECTION_FLAG_IS_ARRAY, { SECTION_ID_STREAM_SIDE_DATA, -1 }, .element_name = "side_data", .unique_name = "stream_side_data_list" },
265  [SECTION_ID_STREAM_SIDE_DATA] = { SECTION_ID_STREAM_SIDE_DATA, "side_data", 0, { -1 } },
266  [SECTION_ID_SUBTITLE] = { SECTION_ID_SUBTITLE, "subtitle", 0, { -1 } },
267 };
268 
269 static const OptionDef *options;
270 
271 /* FFprobe context */
272 static const char *input_filename;
273 static const char *print_input_filename;
274 static const AVInputFormat *iformat = NULL;
275 
276 static struct AVHashContext *hash;
277 
278 static const struct {
279  double bin_val;
280  double dec_val;
281  const char *bin_str;
282  const char *dec_str;
283 } si_prefixes[] = {
284  { 1.0, 1.0, "", "" },
285  { 1.024e3, 1e3, "Ki", "K" },
286  { 1.048576e6, 1e6, "Mi", "M" },
287  { 1.073741824e9, 1e9, "Gi", "G" },
288  { 1.099511627776e12, 1e12, "Ti", "T" },
289  { 1.125899906842624e15, 1e15, "Pi", "P" },
290 };
291 
292 static const char unit_second_str[] = "s" ;
293 static const char unit_hertz_str[] = "Hz" ;
294 static const char unit_byte_str[] = "byte" ;
295 static const char unit_bit_per_second_str[] = "bit/s";
296 
297 static int nb_streams;
298 static uint64_t *nb_streams_packets;
299 static uint64_t *nb_streams_frames;
300 static int *selected_streams;
301 
302 #if HAVE_THREADS
303 pthread_mutex_t log_mutex;
304 #endif
305 typedef struct LogBuffer {
308  char *log_message;
310  char *parent_name;
312 }LogBuffer;
313 
315 static int log_buffer_size;
316 
317 static void log_callback(void *ptr, int level, const char *fmt, va_list vl)
318 {
319  AVClass* avc = ptr ? *(AVClass **) ptr : NULL;
320  va_list vl2;
321  char line[1024];
322  static int print_prefix = 1;
323  void *new_log_buffer;
324 
325  va_copy(vl2, vl);
326  av_log_default_callback(ptr, level, fmt, vl);
327  av_log_format_line(ptr, level, fmt, vl2, line, sizeof(line), &print_prefix);
328  va_end(vl2);
329 
330 #if HAVE_THREADS
331  pthread_mutex_lock(&log_mutex);
332 
333  new_log_buffer = av_realloc_array(log_buffer, log_buffer_size + 1, sizeof(*log_buffer));
334  if (new_log_buffer) {
335  char *msg;
336  int i;
337 
338  log_buffer = new_log_buffer;
339  memset(&log_buffer[log_buffer_size], 0, sizeof(log_buffer[log_buffer_size]));
341  if (avc) {
344  }
347  for (i=strlen(msg) - 1; i>=0 && msg[i] == '\n'; i--) {
348  msg[i] = 0;
349  }
350  if (avc && avc->parent_log_context_offset) {
351  AVClass** parent = *(AVClass ***) (((uint8_t *) ptr) +
353  if (parent && *parent) {
354  log_buffer[log_buffer_size].parent_name = av_strdup((*parent)->item_name(parent));
356  (*parent)->get_category ? (*parent)->get_category(parent) :(*parent)->category;
357  }
358  }
359  log_buffer_size ++;
360  }
361 
362  pthread_mutex_unlock(&log_mutex);
363 #endif
364 }
365 
366 static void ffprobe_cleanup(int ret)
367 {
368  int i;
369  for (i = 0; i < FF_ARRAY_ELEMS(sections); i++)
370  av_dict_free(&(sections[i].entries_to_show));
371 
372 #if HAVE_THREADS
373  pthread_mutex_destroy(&log_mutex);
374 #endif
375 }
376 
377 struct unit_value {
378  union { double d; long long int i; } val;
379  const char *unit;
380 };
381 
382 static char *value_string(char *buf, int buf_size, struct unit_value uv)
383 {
384  double vald;
385  long long int vali;
386  int show_float = 0;
387 
388  if (uv.unit == unit_second_str) {
389  vald = uv.val.d;
390  show_float = 1;
391  } else {
392  vald = vali = uv.val.i;
393  }
394 
396  double secs;
397  int hours, mins;
398  secs = vald;
399  mins = (int)secs / 60;
400  secs = secs - mins * 60;
401  hours = mins / 60;
402  mins %= 60;
403  snprintf(buf, buf_size, "%d:%02d:%09.6f", hours, mins, secs);
404  } else {
405  const char *prefix_string = "";
406 
407  if (use_value_prefix && vald > 1) {
408  long long int index;
409 
411  index = (long long int) (log2(vald)) / 10;
413  vald /= si_prefixes[index].bin_val;
414  prefix_string = si_prefixes[index].bin_str;
415  } else {
416  index = (long long int) (log10(vald)) / 3;
418  vald /= si_prefixes[index].dec_val;
419  prefix_string = si_prefixes[index].dec_str;
420  }
421  vali = vald;
422  }
423 
424  if (show_float || (use_value_prefix && vald != (long long int)vald))
425  snprintf(buf, buf_size, "%f", vald);
426  else
427  snprintf(buf, buf_size, "%lld", vali);
428  av_strlcatf(buf, buf_size, "%s%s%s", *prefix_string || show_value_unit ? " " : "",
429  prefix_string, show_value_unit ? uv.unit : "");
430  }
431 
432  return buf;
433 }
434 
435 /* WRITERS API */
436 
437 typedef struct WriterContext WriterContext;
438 
439 #define WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS 1
440 #define WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER 2
441 
442 typedef enum {
448 
449 typedef struct Writer {
450  const AVClass *priv_class; ///< private class of the writer, if any
451  int priv_size; ///< private size for the writer context
452  const char *name;
453 
454  int (*init) (WriterContext *wctx);
455  void (*uninit)(WriterContext *wctx);
456 
459  void (*print_integer) (WriterContext *wctx, const char *, long long int);
460  void (*print_rational) (WriterContext *wctx, AVRational *q, char *sep);
461  void (*print_string) (WriterContext *wctx, const char *, const char *);
462  int flags; ///< a combination or WRITER_FLAG_*
463 } Writer;
464 
465 #define SECTION_MAX_NB_LEVELS 10
466 
468  const AVClass *class; ///< class of the writer
469  const Writer *writer; ///< the Writer of which this is an instance
470  char *name; ///< name of this writer instance
471  void *priv; ///< private data for use by the filter
472 
473  const struct section *sections; ///< array containing all sections
474  int nb_sections; ///< number of sections
475 
476  int level; ///< current level, starting from 0
477 
478  /** number of the item printed in the given section, starting from 0 */
480 
481  /** section per each level */
483  AVBPrint section_pbuf[SECTION_MAX_NB_LEVELS]; ///< generic print buffer dedicated to each section,
484  /// used by various writers
485 
486  unsigned int nb_section_packet; ///< number of the packet section in case we are in "packets_and_frames" section
487  unsigned int nb_section_frame; ///< number of the frame section in case we are in "packets_and_frames" section
488  unsigned int nb_section_packet_frame; ///< nb_section_packet or nb_section_frame according if is_packets_and_frames
489 
493 };
494 
495 static const char *writer_get_name(void *p)
496 {
497  WriterContext *wctx = p;
498  return wctx->writer->name;
499 }
500 
501 #define OFFSET(x) offsetof(WriterContext, x)
502 
503 static const AVOption writer_options[] = {
504  { "string_validation", "set string validation mode",
505  OFFSET(string_validation), AV_OPT_TYPE_INT, {.i64=WRITER_STRING_VALIDATION_REPLACE}, 0, WRITER_STRING_VALIDATION_NB-1, .unit = "sv" },
506  { "sv", "set string validation mode",
507  OFFSET(string_validation), AV_OPT_TYPE_INT, {.i64=WRITER_STRING_VALIDATION_REPLACE}, 0, WRITER_STRING_VALIDATION_NB-1, .unit = "sv" },
508  { "ignore", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = WRITER_STRING_VALIDATION_IGNORE}, .unit = "sv" },
509  { "replace", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = WRITER_STRING_VALIDATION_REPLACE}, .unit = "sv" },
510  { "fail", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = WRITER_STRING_VALIDATION_FAIL}, .unit = "sv" },
511  { "string_validation_replacement", "set string validation replacement string", OFFSET(string_validation_replacement), AV_OPT_TYPE_STRING, {.str=""}},
512  { "svr", "set string validation replacement string", OFFSET(string_validation_replacement), AV_OPT_TYPE_STRING, {.str="\xEF\xBF\xBD"}},
513  { NULL }
514 };
515 
516 static void *writer_child_next(void *obj, void *prev)
517 {
518  WriterContext *ctx = obj;
519  if (!prev && ctx->writer && ctx->writer->priv_class && ctx->priv)
520  return ctx->priv;
521  return NULL;
522 }
523 
524 static const AVClass writer_class = {
525  .class_name = "Writer",
526  .item_name = writer_get_name,
527  .option = writer_options,
528  .version = LIBAVUTIL_VERSION_INT,
529  .child_next = writer_child_next,
530 };
531 
532 static void writer_close(WriterContext **wctx)
533 {
534  int i;
535 
536  if (!*wctx)
537  return;
538 
539  if ((*wctx)->writer->uninit)
540  (*wctx)->writer->uninit(*wctx);
541  for (i = 0; i < SECTION_MAX_NB_LEVELS; i++)
542  av_bprint_finalize(&(*wctx)->section_pbuf[i], NULL);
543  if ((*wctx)->writer->priv_class)
544  av_opt_free((*wctx)->priv);
545  av_freep(&((*wctx)->priv));
546  av_opt_free(*wctx);
547  av_freep(wctx);
548 }
549 
550 static void bprint_bytes(AVBPrint *bp, const uint8_t *ubuf, size_t ubuf_size)
551 {
552  int i;
553  av_bprintf(bp, "0X");
554  for (i = 0; i < ubuf_size; i++)
555  av_bprintf(bp, "%02X", ubuf[i]);
556 }
557 
558 
559 static int writer_open(WriterContext **wctx, const Writer *writer, const char *args,
560  const struct section *sections, int nb_sections)
561 {
562  int i, ret = 0;
563 
564  if (!(*wctx = av_mallocz(sizeof(WriterContext)))) {
565  ret = AVERROR(ENOMEM);
566  goto fail;
567  }
568 
569  if (!((*wctx)->priv = av_mallocz(writer->priv_size))) {
570  ret = AVERROR(ENOMEM);
571  goto fail;
572  }
573 
574  (*wctx)->class = &writer_class;
575  (*wctx)->writer = writer;
576  (*wctx)->level = -1;
577  (*wctx)->sections = sections;
578  (*wctx)->nb_sections = nb_sections;
579 
580  av_opt_set_defaults(*wctx);
581 
582  if (writer->priv_class) {
583  void *priv_ctx = (*wctx)->priv;
584  *((const AVClass **)priv_ctx) = writer->priv_class;
585  av_opt_set_defaults(priv_ctx);
586  }
587 
588  /* convert options to dictionary */
589  if (args) {
591  const AVDictionaryEntry *opt = NULL;
592 
593  if ((ret = av_dict_parse_string(&opts, args, "=", ":", 0)) < 0) {
594  av_log(*wctx, AV_LOG_ERROR, "Failed to parse option string '%s' provided to writer context\n", args);
595  av_dict_free(&opts);
596  goto fail;
597  }
598 
599  while ((opt = av_dict_get(opts, "", opt, AV_DICT_IGNORE_SUFFIX))) {
600  if ((ret = av_opt_set(*wctx, opt->key, opt->value, AV_OPT_SEARCH_CHILDREN)) < 0) {
601  av_log(*wctx, AV_LOG_ERROR, "Failed to set option '%s' with value '%s' provided to writer context\n",
602  opt->key, opt->value);
603  av_dict_free(&opts);
604  goto fail;
605  }
606  }
607 
608  av_dict_free(&opts);
609  }
610 
611  /* validate replace string */
612  {
613  const uint8_t *p = (*wctx)->string_validation_replacement;
614  const uint8_t *endp = p + strlen(p);
615  while (*p) {
616  const uint8_t *p0 = p;
617  int32_t code;
618  ret = av_utf8_decode(&code, &p, endp, (*wctx)->string_validation_utf8_flags);
619  if (ret < 0) {
620  AVBPrint bp;
622  bprint_bytes(&bp, p0, p-p0),
623  av_log(wctx, AV_LOG_ERROR,
624  "Invalid UTF8 sequence %s found in string validation replace '%s'\n",
625  bp.str, (*wctx)->string_validation_replacement);
626  return ret;
627  }
628  }
629  }
630 
631  for (i = 0; i < SECTION_MAX_NB_LEVELS; i++)
632  av_bprint_init(&(*wctx)->section_pbuf[i], 1, AV_BPRINT_SIZE_UNLIMITED);
633 
634  if ((*wctx)->writer->init)
635  ret = (*wctx)->writer->init(*wctx);
636  if (ret < 0)
637  goto fail;
638 
639  return 0;
640 
641 fail:
642  writer_close(wctx);
643  return ret;
644 }
645 
647  int section_id)
648 {
649  int parent_section_id;
650  wctx->level++;
652  parent_section_id = wctx->level ?
653  (wctx->section[wctx->level-1])->id : SECTION_ID_NONE;
654 
655  wctx->nb_item[wctx->level] = 0;
656  wctx->section[wctx->level] = &wctx->sections[section_id];
657 
658  if (section_id == SECTION_ID_PACKETS_AND_FRAMES) {
659  wctx->nb_section_packet = wctx->nb_section_frame =
660  wctx->nb_section_packet_frame = 0;
661  } else if (parent_section_id == SECTION_ID_PACKETS_AND_FRAMES) {
662  wctx->nb_section_packet_frame = section_id == SECTION_ID_PACKET ?
663  wctx->nb_section_packet : wctx->nb_section_frame;
664  }
665 
666  if (wctx->writer->print_section_header)
667  wctx->writer->print_section_header(wctx);
668 }
669 
671 {
672  int section_id = wctx->section[wctx->level]->id;
673  int parent_section_id = wctx->level ?
674  wctx->section[wctx->level-1]->id : SECTION_ID_NONE;
675 
676  if (parent_section_id != SECTION_ID_NONE)
677  wctx->nb_item[wctx->level-1]++;
678  if (parent_section_id == SECTION_ID_PACKETS_AND_FRAMES) {
679  if (section_id == SECTION_ID_PACKET) wctx->nb_section_packet++;
680  else wctx->nb_section_frame++;
681  }
682  if (wctx->writer->print_section_footer)
683  wctx->writer->print_section_footer(wctx);
684  wctx->level--;
685 }
686 
687 static inline void writer_print_integer(WriterContext *wctx,
688  const char *key, long long int val)
689 {
690  const struct section *section = wctx->section[wctx->level];
691 
693  wctx->writer->print_integer(wctx, key, val);
694  wctx->nb_item[wctx->level]++;
695  }
696 }
697 
698 static inline int validate_string(WriterContext *wctx, char **dstp, const char *src)
699 {
700  const uint8_t *p, *endp;
701  AVBPrint dstbuf;
702  int invalid_chars_nb = 0, ret = 0;
703 
705 
706  endp = src + strlen(src);
707  for (p = (uint8_t *)src; *p;) {
708  uint32_t code;
709  int invalid = 0;
710  const uint8_t *p0 = p;
711 
712  if (av_utf8_decode(&code, &p, endp, wctx->string_validation_utf8_flags) < 0) {
713  AVBPrint bp;
715  bprint_bytes(&bp, p0, p-p0);
716  av_log(wctx, AV_LOG_DEBUG,
717  "Invalid UTF-8 sequence %s found in string '%s'\n", bp.str, src);
718  invalid = 1;
719  }
720 
721  if (invalid) {
722  invalid_chars_nb++;
723 
724  switch (wctx->string_validation) {
726  av_log(wctx, AV_LOG_ERROR,
727  "Invalid UTF-8 sequence found in string '%s'\n", src);
729  goto end;
730  break;
731 
733  av_bprintf(&dstbuf, "%s", wctx->string_validation_replacement);
734  break;
735  }
736  }
737 
738  if (!invalid || wctx->string_validation == WRITER_STRING_VALIDATION_IGNORE)
739  av_bprint_append_data(&dstbuf, p0, p-p0);
740  }
741 
742  if (invalid_chars_nb && wctx->string_validation == WRITER_STRING_VALIDATION_REPLACE) {
743  av_log(wctx, AV_LOG_WARNING,
744  "%d invalid UTF-8 sequence(s) found in string '%s', replaced with '%s'\n",
745  invalid_chars_nb, src, wctx->string_validation_replacement);
746  }
747 
748 end:
749  av_bprint_finalize(&dstbuf, dstp);
750  return ret;
751 }
752 
753 #define PRINT_STRING_OPT 1
754 #define PRINT_STRING_VALIDATE 2
755 
756 static inline int writer_print_string(WriterContext *wctx,
757  const char *key, const char *val, int flags)
758 {
759  const struct section *section = wctx->section[wctx->level];
760  int ret = 0;
761 
764  && (flags & PRINT_STRING_OPT)
766  return 0;
767 
770  char *key1 = NULL, *val1 = NULL;
771  ret = validate_string(wctx, &key1, key);
772  if (ret < 0) goto end;
773  ret = validate_string(wctx, &val1, val);
774  if (ret < 0) goto end;
775  wctx->writer->print_string(wctx, key1, val1);
776  end:
777  if (ret < 0) {
778  av_log(wctx, AV_LOG_ERROR,
779  "Invalid key=value string combination %s=%s in section %s\n",
781  }
782  av_free(key1);
783  av_free(val1);
784  } else {
785  wctx->writer->print_string(wctx, key, val);
786  }
787 
788  wctx->nb_item[wctx->level]++;
789  }
790 
791  return ret;
792 }
793 
794 static inline void writer_print_rational(WriterContext *wctx,
795  const char *key, AVRational q, char sep)
796 {
797  AVBPrint buf;
799  av_bprintf(&buf, "%d%c%d", q.num, sep, q.den);
800  writer_print_string(wctx, key, buf.str, 0);
801 }
802 
803 static void writer_print_time(WriterContext *wctx, const char *key,
804  int64_t ts, const AVRational *time_base, int is_duration)
805 {
806  char buf[128];
807 
808  if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
810  } else {
811  double d = ts * av_q2d(*time_base);
812  struct unit_value uv;
813  uv.val.d = d;
814  uv.unit = unit_second_str;
815  value_string(buf, sizeof(buf), uv);
816  writer_print_string(wctx, key, buf, 0);
817  }
818 }
819 
820 static void writer_print_ts(WriterContext *wctx, const char *key, int64_t ts, int is_duration)
821 {
822  if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
824  } else {
825  writer_print_integer(wctx, key, ts);
826  }
827 }
828 
829 static void writer_print_data(WriterContext *wctx, const char *name,
830  uint8_t *data, int size)
831 {
832  AVBPrint bp;
833  int offset = 0, l, i;
834 
836  av_bprintf(&bp, "\n");
837  while (size) {
838  av_bprintf(&bp, "%08x: ", offset);
839  l = FFMIN(size, 16);
840  for (i = 0; i < l; i++) {
841  av_bprintf(&bp, "%02x", data[i]);
842  if (i & 1)
843  av_bprintf(&bp, " ");
844  }
845  av_bprint_chars(&bp, ' ', 41 - 2 * i - i / 2);
846  for (i = 0; i < l; i++)
847  av_bprint_chars(&bp, data[i] - 32U < 95 ? data[i] : '.', 1);
848  av_bprintf(&bp, "\n");
849  offset += l;
850  data += l;
851  size -= l;
852  }
853  writer_print_string(wctx, name, bp.str, 0);
854  av_bprint_finalize(&bp, NULL);
855 }
856 
857 static void writer_print_data_hash(WriterContext *wctx, const char *name,
858  uint8_t *data, int size)
859 {
860  char *p, buf[AV_HASH_MAX_SIZE * 2 + 64] = { 0 };
861 
862  if (!hash)
863  return;
866  snprintf(buf, sizeof(buf), "%s:", av_hash_get_name(hash));
867  p = buf + strlen(buf);
868  av_hash_final_hex(hash, p, buf + sizeof(buf) - p);
869  writer_print_string(wctx, name, buf, 0);
870 }
871 
872 static void writer_print_integers(WriterContext *wctx, const char *name,
873  uint8_t *data, int size, const char *format,
874  int columns, int bytes, int offset_add)
875 {
876  AVBPrint bp;
877  int offset = 0, l, i;
878 
880  av_bprintf(&bp, "\n");
881  while (size) {
882  av_bprintf(&bp, "%08x: ", offset);
883  l = FFMIN(size, columns);
884  for (i = 0; i < l; i++) {
885  if (bytes == 1) av_bprintf(&bp, format, *data);
886  else if (bytes == 2) av_bprintf(&bp, format, AV_RN16(data));
887  else if (bytes == 4) av_bprintf(&bp, format, AV_RN32(data));
888  data += bytes;
889  size --;
890  }
891  av_bprintf(&bp, "\n");
892  offset += offset_add;
893  }
894  writer_print_string(wctx, name, bp.str, 0);
895  av_bprint_finalize(&bp, NULL);
896 }
897 
898 #define MAX_REGISTERED_WRITERS_NB 64
899 
901 
902 static int writer_register(const Writer *writer)
903 {
904  static int next_registered_writer_idx = 0;
905 
906  if (next_registered_writer_idx == MAX_REGISTERED_WRITERS_NB)
907  return AVERROR(ENOMEM);
908 
909  registered_writers[next_registered_writer_idx++] = writer;
910  return 0;
911 }
912 
913 static const Writer *writer_get_by_name(const char *name)
914 {
915  int i;
916 
917  for (i = 0; registered_writers[i]; i++)
918  if (!strcmp(registered_writers[i]->name, name))
919  return registered_writers[i];
920 
921  return NULL;
922 }
923 
924 
925 /* WRITERS */
926 
927 #define DEFINE_WRITER_CLASS(name) \
928 static const char *name##_get_name(void *ctx) \
929 { \
930  return #name ; \
931 } \
932 static const AVClass name##_class = { \
933  .class_name = #name, \
934  .item_name = name##_get_name, \
935  .option = name##_options \
936 }
937 
938 /* Default output */
939 
940 typedef struct DefaultContext {
941  const AVClass *class;
942  int nokey;
946 
947 #undef OFFSET
948 #define OFFSET(x) offsetof(DefaultContext, x)
949 
950 static const AVOption default_options[] = {
951  { "noprint_wrappers", "do not print headers and footers", OFFSET(noprint_wrappers), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
952  { "nw", "do not print headers and footers", OFFSET(noprint_wrappers), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
953  { "nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
954  { "nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
955  {NULL},
956 };
957 
958 DEFINE_WRITER_CLASS(default);
959 
960 /* lame uppercasing routine, assumes the string is lower case ASCII */
961 static inline char *upcase_string(char *dst, size_t dst_size, const char *src)
962 {
963  int i;
964  for (i = 0; src[i] && i < dst_size-1; i++)
965  dst[i] = av_toupper(src[i]);
966  dst[i] = 0;
967  return dst;
968 }
969 
971 {
972  DefaultContext *def = wctx->priv;
973  char buf[32];
974  const struct section *section = wctx->section[wctx->level];
975  const struct section *parent_section = wctx->level ?
976  wctx->section[wctx->level-1] : NULL;
977 
978  av_bprint_clear(&wctx->section_pbuf[wctx->level]);
979  if (parent_section &&
980  !(parent_section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY))) {
981  def->nested_section[wctx->level] = 1;
982  av_bprintf(&wctx->section_pbuf[wctx->level], "%s%s:",
983  wctx->section_pbuf[wctx->level-1].str,
984  upcase_string(buf, sizeof(buf),
986  }
987 
988  if (def->noprint_wrappers || def->nested_section[wctx->level])
989  return;
990 
992  printf("[%s]\n", upcase_string(buf, sizeof(buf), section->name));
993 }
994 
996 {
997  DefaultContext *def = wctx->priv;
998  const struct section *section = wctx->section[wctx->level];
999  char buf[32];
1000 
1001  if (def->noprint_wrappers || def->nested_section[wctx->level])
1002  return;
1003 
1005  printf("[/%s]\n", upcase_string(buf, sizeof(buf), section->name));
1006 }
1007 
1008 static void default_print_str(WriterContext *wctx, const char *key, const char *value)
1009 {
1010  DefaultContext *def = wctx->priv;
1011 
1012  if (!def->nokey)
1013  printf("%s%s=", wctx->section_pbuf[wctx->level].str, key);
1014  printf("%s\n", value);
1015 }
1016 
1017 static void default_print_int(WriterContext *wctx, const char *key, long long int value)
1018 {
1019  DefaultContext *def = wctx->priv;
1020 
1021  if (!def->nokey)
1022  printf("%s%s=", wctx->section_pbuf[wctx->level].str, key);
1023  printf("%lld\n", value);
1024 }
1025 
1026 static const Writer default_writer = {
1027  .name = "default",
1028  .priv_size = sizeof(DefaultContext),
1031  .print_integer = default_print_int,
1032  .print_string = default_print_str,
1034  .priv_class = &default_class,
1035 };
1036 
1037 /* Compact output */
1038 
1039 /**
1040  * Apply C-language-like string escaping.
1041  */
1042 static const char *c_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
1043 {
1044  const char *p;
1045 
1046  for (p = src; *p; p++) {
1047  switch (*p) {
1048  case '\b': av_bprintf(dst, "%s", "\\b"); break;
1049  case '\f': av_bprintf(dst, "%s", "\\f"); break;
1050  case '\n': av_bprintf(dst, "%s", "\\n"); break;
1051  case '\r': av_bprintf(dst, "%s", "\\r"); break;
1052  case '\\': av_bprintf(dst, "%s", "\\\\"); break;
1053  default:
1054  if (*p == sep)
1055  av_bprint_chars(dst, '\\', 1);
1056  av_bprint_chars(dst, *p, 1);
1057  }
1058  }
1059  return dst->str;
1060 }
1061 
1062 /**
1063  * Quote fields containing special characters, check RFC4180.
1064  */
1065 static const char *csv_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
1066 {
1067  char meta_chars[] = { sep, '"', '\n', '\r', '\0' };
1068  int needs_quoting = !!src[strcspn(src, meta_chars)];
1069 
1070  if (needs_quoting)
1071  av_bprint_chars(dst, '"', 1);
1072 
1073  for (; *src; src++) {
1074  if (*src == '"')
1075  av_bprint_chars(dst, '"', 1);
1076  av_bprint_chars(dst, *src, 1);
1077  }
1078  if (needs_quoting)
1079  av_bprint_chars(dst, '"', 1);
1080  return dst->str;
1081 }
1082 
1083 static const char *none_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
1084 {
1085  return src;
1086 }
1087 
1088 typedef struct CompactContext {
1089  const AVClass *class;
1091  char item_sep;
1092  int nokey;
1095  const char * (*escape_str)(AVBPrint *dst, const char *src, const char sep, void *log_ctx);
1099 } CompactContext;
1100 
1101 #undef OFFSET
1102 #define OFFSET(x) offsetof(CompactContext, x)
1103 
1104 static const AVOption compact_options[]= {
1105  {"item_sep", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str="|"}, 0, 0 },
1106  {"s", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str="|"}, 0, 0 },
1107  {"nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1108  {"nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1109  {"escape", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="c"}, 0, 0 },
1110  {"e", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="c"}, 0, 0 },
1111  {"print_section", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1112  {"p", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1113  {NULL},
1114 };
1115 
1116 DEFINE_WRITER_CLASS(compact);
1117 
1119 {
1120  CompactContext *compact = wctx->priv;
1121 
1122  if (strlen(compact->item_sep_str) != 1) {
1123  av_log(wctx, AV_LOG_ERROR, "Item separator '%s' specified, but must contain a single character\n",
1124  compact->item_sep_str);
1125  return AVERROR(EINVAL);
1126  }
1127  compact->item_sep = compact->item_sep_str[0];
1128 
1129  if (!strcmp(compact->escape_mode_str, "none")) compact->escape_str = none_escape_str;
1130  else if (!strcmp(compact->escape_mode_str, "c" )) compact->escape_str = c_escape_str;
1131  else if (!strcmp(compact->escape_mode_str, "csv" )) compact->escape_str = csv_escape_str;
1132  else {
1133  av_log(wctx, AV_LOG_ERROR, "Unknown escape mode '%s'\n", compact->escape_mode_str);
1134  return AVERROR(EINVAL);
1135  }
1136 
1137  return 0;
1138 }
1139 
1141 {
1142  CompactContext *compact = wctx->priv;
1143  const struct section *section = wctx->section[wctx->level];
1144  const struct section *parent_section = wctx->level ?
1145  wctx->section[wctx->level-1] : NULL;
1146  compact->terminate_line[wctx->level] = 1;
1147  compact->has_nested_elems[wctx->level] = 0;
1148 
1149  av_bprint_clear(&wctx->section_pbuf[wctx->level]);
1150  if (!(section->flags & SECTION_FLAG_IS_ARRAY) && parent_section &&
1151  !(parent_section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY))) {
1152  compact->nested_section[wctx->level] = 1;
1153  compact->has_nested_elems[wctx->level-1] = 1;
1154  av_bprintf(&wctx->section_pbuf[wctx->level], "%s%s:",
1155  wctx->section_pbuf[wctx->level-1].str,
1157  wctx->nb_item[wctx->level] = wctx->nb_item[wctx->level-1];
1158  } else {
1159  if (parent_section && compact->has_nested_elems[wctx->level-1] &&
1161  compact->terminate_line[wctx->level-1] = 0;
1162  }
1163  if (parent_section && !(parent_section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY)) &&
1164  wctx->level && wctx->nb_item[wctx->level-1])
1165  printf("%c", compact->item_sep);
1166  if (compact->print_section &&
1168  printf("%s%c", section->name, compact->item_sep);
1169  }
1170 }
1171 
1173 {
1174  CompactContext *compact = wctx->priv;
1175 
1176  if (!compact->nested_section[wctx->level] &&
1177  compact->terminate_line[wctx->level] &&
1179  printf("\n");
1180 }
1181 
1182 static void compact_print_str(WriterContext *wctx, const char *key, const char *value)
1183 {
1184  CompactContext *compact = wctx->priv;
1185  AVBPrint buf;
1186 
1187  if (wctx->nb_item[wctx->level]) printf("%c", compact->item_sep);
1188  if (!compact->nokey)
1189  printf("%s%s=", wctx->section_pbuf[wctx->level].str, key);
1191  printf("%s", compact->escape_str(&buf, value, compact->item_sep, wctx));
1192  av_bprint_finalize(&buf, NULL);
1193 }
1194 
1195 static void compact_print_int(WriterContext *wctx, const char *key, long long int value)
1196 {
1197  CompactContext *compact = wctx->priv;
1198 
1199  if (wctx->nb_item[wctx->level]) printf("%c", compact->item_sep);
1200  if (!compact->nokey)
1201  printf("%s%s=", wctx->section_pbuf[wctx->level].str, key);
1202  printf("%lld", value);
1203 }
1204 
1205 static const Writer compact_writer = {
1206  .name = "compact",
1207  .priv_size = sizeof(CompactContext),
1208  .init = compact_init,
1211  .print_integer = compact_print_int,
1212  .print_string = compact_print_str,
1214  .priv_class = &compact_class,
1215 };
1216 
1217 /* CSV output */
1218 
1219 #undef OFFSET
1220 #define OFFSET(x) offsetof(CompactContext, x)
1221 
1222 static const AVOption csv_options[] = {
1223  {"item_sep", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=","}, 0, 0 },
1224  {"s", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=","}, 0, 0 },
1225  {"nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1226  {"nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1227  {"escape", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="csv"}, 0, 0 },
1228  {"e", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="csv"}, 0, 0 },
1229  {"print_section", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1230  {"p", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1231  {NULL},
1232 };
1233 
1234 DEFINE_WRITER_CLASS(csv);
1235 
1236 static const Writer csv_writer = {
1237  .name = "csv",
1238  .priv_size = sizeof(CompactContext),
1239  .init = compact_init,
1242  .print_integer = compact_print_int,
1243  .print_string = compact_print_str,
1245  .priv_class = &csv_class,
1246 };
1247 
1248 /* Flat output */
1249 
1250 typedef struct FlatContext {
1251  const AVClass *class;
1252  const char *sep_str;
1253  char sep;
1255 } FlatContext;
1256 
1257 #undef OFFSET
1258 #define OFFSET(x) offsetof(FlatContext, x)
1259 
1260 static const AVOption flat_options[]= {
1261  {"sep_char", "set separator", OFFSET(sep_str), AV_OPT_TYPE_STRING, {.str="."}, 0, 0 },
1262  {"s", "set separator", OFFSET(sep_str), AV_OPT_TYPE_STRING, {.str="."}, 0, 0 },
1263  {"hierarchical", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1264  {"h", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1265  {NULL},
1266 };
1267 
1269 
1271 {
1272  FlatContext *flat = wctx->priv;
1273 
1274  if (strlen(flat->sep_str) != 1) {
1275  av_log(wctx, AV_LOG_ERROR, "Item separator '%s' specified, but must contain a single character\n",
1276  flat->sep_str);
1277  return AVERROR(EINVAL);
1278  }
1279  flat->sep = flat->sep_str[0];
1280 
1281  return 0;
1282 }
1283 
1284 static const char *flat_escape_key_str(AVBPrint *dst, const char *src, const char sep)
1285 {
1286  const char *p;
1287 
1288  for (p = src; *p; p++) {
1289  if (!((*p >= '0' && *p <= '9') ||
1290  (*p >= 'a' && *p <= 'z') ||
1291  (*p >= 'A' && *p <= 'Z')))
1292  av_bprint_chars(dst, '_', 1);
1293  else
1294  av_bprint_chars(dst, *p, 1);
1295  }
1296  return dst->str;
1297 }
1298 
1299 static const char *flat_escape_value_str(AVBPrint *dst, const char *src)
1300 {
1301  const char *p;
1302 
1303  for (p = src; *p; p++) {
1304  switch (*p) {
1305  case '\n': av_bprintf(dst, "%s", "\\n"); break;
1306  case '\r': av_bprintf(dst, "%s", "\\r"); break;
1307  case '\\': av_bprintf(dst, "%s", "\\\\"); break;
1308  case '"': av_bprintf(dst, "%s", "\\\""); break;
1309  case '`': av_bprintf(dst, "%s", "\\`"); break;
1310  case '$': av_bprintf(dst, "%s", "\\$"); break;
1311  default: av_bprint_chars(dst, *p, 1); break;
1312  }
1313  }
1314  return dst->str;
1315 }
1316 
1318 {
1319  FlatContext *flat = wctx->priv;
1320  AVBPrint *buf = &wctx->section_pbuf[wctx->level];
1321  const struct section *section = wctx->section[wctx->level];
1322  const struct section *parent_section = wctx->level ?
1323  wctx->section[wctx->level-1] : NULL;
1324 
1325  /* build section header */
1326  av_bprint_clear(buf);
1327  if (!parent_section)
1328  return;
1329  av_bprintf(buf, "%s", wctx->section_pbuf[wctx->level-1].str);
1330 
1331  if (flat->hierarchical ||
1333  av_bprintf(buf, "%s%s", wctx->section[wctx->level]->name, flat->sep_str);
1334 
1335  if (parent_section->flags & SECTION_FLAG_IS_ARRAY) {
1336  int n = parent_section->id == SECTION_ID_PACKETS_AND_FRAMES ?
1337  wctx->nb_section_packet_frame : wctx->nb_item[wctx->level-1];
1338  av_bprintf(buf, "%d%s", n, flat->sep_str);
1339  }
1340  }
1341 }
1342 
1343 static void flat_print_int(WriterContext *wctx, const char *key, long long int value)
1344 {
1345  printf("%s%s=%lld\n", wctx->section_pbuf[wctx->level].str, key, value);
1346 }
1347 
1348 static void flat_print_str(WriterContext *wctx, const char *key, const char *value)
1349 {
1350  FlatContext *flat = wctx->priv;
1351  AVBPrint buf;
1352 
1353  printf("%s", wctx->section_pbuf[wctx->level].str);
1355  printf("%s=", flat_escape_key_str(&buf, key, flat->sep));
1356  av_bprint_clear(&buf);
1357  printf("\"%s\"\n", flat_escape_value_str(&buf, value));
1358  av_bprint_finalize(&buf, NULL);
1359 }
1360 
1361 static const Writer flat_writer = {
1362  .name = "flat",
1363  .priv_size = sizeof(FlatContext),
1364  .init = flat_init,
1366  .print_integer = flat_print_int,
1367  .print_string = flat_print_str,
1369  .priv_class = &flat_class,
1370 };
1371 
1372 /* INI format output */
1373 
1374 typedef struct INIContext {
1375  const AVClass *class;
1377 } INIContext;
1378 
1379 #undef OFFSET
1380 #define OFFSET(x) offsetof(INIContext, x)
1381 
1382 static const AVOption ini_options[] = {
1383  {"hierarchical", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1384  {"h", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1385  {NULL},
1386 };
1387 
1388 DEFINE_WRITER_CLASS(ini);
1389 
1390 static char *ini_escape_str(AVBPrint *dst, const char *src)
1391 {
1392  int i = 0;
1393  char c = 0;
1394 
1395  while (c = src[i++]) {
1396  switch (c) {
1397  case '\b': av_bprintf(dst, "%s", "\\b"); break;
1398  case '\f': av_bprintf(dst, "%s", "\\f"); break;
1399  case '\n': av_bprintf(dst, "%s", "\\n"); break;
1400  case '\r': av_bprintf(dst, "%s", "\\r"); break;
1401  case '\t': av_bprintf(dst, "%s", "\\t"); break;
1402  case '\\':
1403  case '#' :
1404  case '=' :
1405  case ':' : av_bprint_chars(dst, '\\', 1);
1406  default:
1407  if ((unsigned char)c < 32)
1408  av_bprintf(dst, "\\x00%02x", c & 0xff);
1409  else
1410  av_bprint_chars(dst, c, 1);
1411  break;
1412  }
1413  }
1414  return dst->str;
1415 }
1416 
1418 {
1419  INIContext *ini = wctx->priv;
1420  AVBPrint *buf = &wctx->section_pbuf[wctx->level];
1421  const struct section *section = wctx->section[wctx->level];
1422  const struct section *parent_section = wctx->level ?
1423  wctx->section[wctx->level-1] : NULL;
1424 
1425  av_bprint_clear(buf);
1426  if (!parent_section) {
1427  printf("# ffprobe output\n\n");
1428  return;
1429  }
1430 
1431  if (wctx->nb_item[wctx->level-1])
1432  printf("\n");
1433 
1434  av_bprintf(buf, "%s", wctx->section_pbuf[wctx->level-1].str);
1435  if (ini->hierarchical ||
1437  av_bprintf(buf, "%s%s", buf->str[0] ? "." : "", wctx->section[wctx->level]->name);
1438 
1439  if (parent_section->flags & SECTION_FLAG_IS_ARRAY) {
1440  int n = parent_section->id == SECTION_ID_PACKETS_AND_FRAMES ?
1441  wctx->nb_section_packet_frame : wctx->nb_item[wctx->level-1];
1442  av_bprintf(buf, ".%d", n);
1443  }
1444  }
1445 
1447  printf("[%s]\n", buf->str);
1448 }
1449 
1450 static void ini_print_str(WriterContext *wctx, const char *key, const char *value)
1451 {
1452  AVBPrint buf;
1453 
1455  printf("%s=", ini_escape_str(&buf, key));
1456  av_bprint_clear(&buf);
1457  printf("%s\n", ini_escape_str(&buf, value));
1458  av_bprint_finalize(&buf, NULL);
1459 }
1460 
1461 static void ini_print_int(WriterContext *wctx, const char *key, long long int value)
1462 {
1463  printf("%s=%lld\n", key, value);
1464 }
1465 
1466 static const Writer ini_writer = {
1467  .name = "ini",
1468  .priv_size = sizeof(INIContext),
1470  .print_integer = ini_print_int,
1471  .print_string = ini_print_str,
1473  .priv_class = &ini_class,
1474 };
1475 
1476 /* JSON output */
1477 
1478 typedef struct JSONContext {
1479  const AVClass *class;
1481  int compact;
1482  const char *item_sep, *item_start_end;
1483 } JSONContext;
1484 
1485 #undef OFFSET
1486 #define OFFSET(x) offsetof(JSONContext, x)
1487 
1488 static const AVOption json_options[]= {
1489  { "compact", "enable compact output", OFFSET(compact), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1490  { "c", "enable compact output", OFFSET(compact), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1491  { NULL }
1492 };
1493 
1494 DEFINE_WRITER_CLASS(json);
1495 
1497 {
1498  JSONContext *json = wctx->priv;
1499 
1500  json->item_sep = json->compact ? ", " : ",\n";
1501  json->item_start_end = json->compact ? " " : "\n";
1502 
1503  return 0;
1504 }
1505 
1506 static const char *json_escape_str(AVBPrint *dst, const char *src, void *log_ctx)
1507 {
1508  static const char json_escape[] = {'"', '\\', '\b', '\f', '\n', '\r', '\t', 0};
1509  static const char json_subst[] = {'"', '\\', 'b', 'f', 'n', 'r', 't', 0};
1510  const char *p;
1511 
1512  for (p = src; *p; p++) {
1513  char *s = strchr(json_escape, *p);
1514  if (s) {
1515  av_bprint_chars(dst, '\\', 1);
1516  av_bprint_chars(dst, json_subst[s - json_escape], 1);
1517  } else if ((unsigned char)*p < 32) {
1518  av_bprintf(dst, "\\u00%02x", *p & 0xff);
1519  } else {
1520  av_bprint_chars(dst, *p, 1);
1521  }
1522  }
1523  return dst->str;
1524 }
1525 
1526 #define JSON_INDENT() printf("%*c", json->indent_level * 4, ' ')
1527 
1529 {
1530  JSONContext *json = wctx->priv;
1531  AVBPrint buf;
1532  const struct section *section = wctx->section[wctx->level];
1533  const struct section *parent_section = wctx->level ?
1534  wctx->section[wctx->level-1] : NULL;
1535 
1536  if (wctx->level && wctx->nb_item[wctx->level-1])
1537  printf(",\n");
1538 
1540  printf("{\n");
1541  json->indent_level++;
1542  } else {
1544  json_escape_str(&buf, section->name, wctx);
1545  JSON_INDENT();
1546 
1547  json->indent_level++;
1549  printf("\"%s\": [\n", buf.str);
1550  } else if (parent_section && !(parent_section->flags & SECTION_FLAG_IS_ARRAY)) {
1551  printf("\"%s\": {%s", buf.str, json->item_start_end);
1552  } else {
1553  printf("{%s", json->item_start_end);
1554 
1555  /* this is required so the parser can distinguish between packets and frames */
1556  if (parent_section && parent_section->id == SECTION_ID_PACKETS_AND_FRAMES) {
1557  if (!json->compact)
1558  JSON_INDENT();
1559  printf("\"type\": \"%s\"", section->name);
1560  }
1561  }
1562  av_bprint_finalize(&buf, NULL);
1563  }
1564 }
1565 
1567 {
1568  JSONContext *json = wctx->priv;
1569  const struct section *section = wctx->section[wctx->level];
1570 
1571  if (wctx->level == 0) {
1572  json->indent_level--;
1573  printf("\n}\n");
1574  } else if (section->flags & SECTION_FLAG_IS_ARRAY) {
1575  printf("\n");
1576  json->indent_level--;
1577  JSON_INDENT();
1578  printf("]");
1579  } else {
1580  printf("%s", json->item_start_end);
1581  json->indent_level--;
1582  if (!json->compact)
1583  JSON_INDENT();
1584  printf("}");
1585  }
1586 }
1587 
1588 static inline void json_print_item_str(WriterContext *wctx,
1589  const char *key, const char *value)
1590 {
1591  AVBPrint buf;
1592 
1594  printf("\"%s\":", json_escape_str(&buf, key, wctx));
1595  av_bprint_clear(&buf);
1596  printf(" \"%s\"", json_escape_str(&buf, value, wctx));
1597  av_bprint_finalize(&buf, NULL);
1598 }
1599 
1600 static void json_print_str(WriterContext *wctx, const char *key, const char *value)
1601 {
1602  JSONContext *json = wctx->priv;
1603  const struct section *parent_section = wctx->level ?
1604  wctx->section[wctx->level-1] : NULL;
1605 
1606  if (wctx->nb_item[wctx->level] || (parent_section && parent_section->id == SECTION_ID_PACKETS_AND_FRAMES))
1607  printf("%s", json->item_sep);
1608  if (!json->compact)
1609  JSON_INDENT();
1610  json_print_item_str(wctx, key, value);
1611 }
1612 
1613 static void json_print_int(WriterContext *wctx, const char *key, long long int value)
1614 {
1615  JSONContext *json = wctx->priv;
1616  const struct section *parent_section = wctx->level ?
1617  wctx->section[wctx->level-1] : NULL;
1618  AVBPrint buf;
1619 
1620  if (wctx->nb_item[wctx->level] || (parent_section && parent_section->id == SECTION_ID_PACKETS_AND_FRAMES))
1621  printf("%s", json->item_sep);
1622  if (!json->compact)
1623  JSON_INDENT();
1624 
1626  printf("\"%s\": %lld", json_escape_str(&buf, key, wctx), value);
1627  av_bprint_finalize(&buf, NULL);
1628 }
1629 
1630 static const Writer json_writer = {
1631  .name = "json",
1632  .priv_size = sizeof(JSONContext),
1633  .init = json_init,
1636  .print_integer = json_print_int,
1637  .print_string = json_print_str,
1639  .priv_class = &json_class,
1640 };
1641 
1642 /* XML output */
1643 
1644 typedef struct XMLContext {
1645  const AVClass *class;
1650 } XMLContext;
1651 
1652 #undef OFFSET
1653 #define OFFSET(x) offsetof(XMLContext, x)
1654 
1655 static const AVOption xml_options[] = {
1656  {"fully_qualified", "specify if the output should be fully qualified", OFFSET(fully_qualified), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1657  {"q", "specify if the output should be fully qualified", OFFSET(fully_qualified), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1658  {"xsd_strict", "ensure that the output is XSD compliant", OFFSET(xsd_strict), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1659  {"x", "ensure that the output is XSD compliant", OFFSET(xsd_strict), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1660  {NULL},
1661 };
1662 
1663 DEFINE_WRITER_CLASS(xml);
1664 
1665 static av_cold int xml_init(WriterContext *wctx)
1666 {
1667  XMLContext *xml = wctx->priv;
1668 
1669  if (xml->xsd_strict) {
1670  xml->fully_qualified = 1;
1671 #define CHECK_COMPLIANCE(opt, opt_name) \
1672  if (opt) { \
1673  av_log(wctx, AV_LOG_ERROR, \
1674  "XSD-compliant output selected but option '%s' was selected, XML output may be non-compliant.\n" \
1675  "You need to disable such option with '-no%s'\n", opt_name, opt_name); \
1676  return AVERROR(EINVAL); \
1677  }
1678  CHECK_COMPLIANCE(show_private_data, "private");
1681  }
1682 
1683  return 0;
1684 }
1685 
1686 #define XML_INDENT() printf("%*c", xml->indent_level * 4, ' ')
1687 
1689 {
1690  XMLContext *xml = wctx->priv;
1691  const struct section *section = wctx->section[wctx->level];
1692  const struct section *parent_section = wctx->level ?
1693  wctx->section[wctx->level-1] : NULL;
1694 
1695  if (wctx->level == 0) {
1696  const char *qual = " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
1697  "xmlns:ffprobe=\"http://www.ffmpeg.org/schema/ffprobe\" "
1698  "xsi:schemaLocation=\"http://www.ffmpeg.org/schema/ffprobe ffprobe.xsd\"";
1699 
1700  printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
1701  printf("<%sffprobe%s>\n",
1702  xml->fully_qualified ? "ffprobe:" : "",
1703  xml->fully_qualified ? qual : "");
1704  return;
1705  }
1706 
1707  if (xml->within_tag) {
1708  xml->within_tag = 0;
1709  printf(">\n");
1710  }
1712  xml->indent_level++;
1713  } else {
1714  if (parent_section && (parent_section->flags & SECTION_FLAG_IS_WRAPPER) &&
1715  wctx->level && wctx->nb_item[wctx->level-1])
1716  printf("\n");
1717  xml->indent_level++;
1718 
1720  XML_INDENT(); printf("<%s>\n", section->name);
1721  } else {
1722  XML_INDENT(); printf("<%s ", section->name);
1723  xml->within_tag = 1;
1724  }
1725  }
1726 }
1727 
1729 {
1730  XMLContext *xml = wctx->priv;
1731  const struct section *section = wctx->section[wctx->level];
1732 
1733  if (wctx->level == 0) {
1734  printf("</%sffprobe>\n", xml->fully_qualified ? "ffprobe:" : "");
1735  } else if (xml->within_tag) {
1736  xml->within_tag = 0;
1737  printf("/>\n");
1738  xml->indent_level--;
1740  xml->indent_level--;
1741  } else {
1742  XML_INDENT(); printf("</%s>\n", section->name);
1743  xml->indent_level--;
1744  }
1745 }
1746 
1747 static void xml_print_str(WriterContext *wctx, const char *key, const char *value)
1748 {
1749  AVBPrint buf;
1750  XMLContext *xml = wctx->priv;
1751  const struct section *section = wctx->section[wctx->level];
1752 
1754 
1756  XML_INDENT();
1757  av_bprint_escape(&buf, key, NULL,
1759  printf("<%s key=\"%s\"",
1760  section->element_name, buf.str);
1761  av_bprint_clear(&buf);
1762 
1763  av_bprint_escape(&buf, value, NULL,
1765  printf(" value=\"%s\"/>\n", buf.str);
1766  } else {
1767  if (wctx->nb_item[wctx->level])
1768  printf(" ");
1769 
1770  av_bprint_escape(&buf, value, NULL,
1772  printf("%s=\"%s\"", key, buf.str);
1773  }
1774 
1775  av_bprint_finalize(&buf, NULL);
1776 }
1777 
1778 static void xml_print_int(WriterContext *wctx, const char *key, long long int value)
1779 {
1780  if (wctx->nb_item[wctx->level])
1781  printf(" ");
1782  printf("%s=\"%lld\"", key, value);
1783 }
1784 
1785 static Writer xml_writer = {
1786  .name = "xml",
1787  .priv_size = sizeof(XMLContext),
1788  .init = xml_init,
1791  .print_integer = xml_print_int,
1792  .print_string = xml_print_str,
1794  .priv_class = &xml_class,
1795 };
1796 
1797 static void writer_register_all(void)
1798 {
1799  static int initialized;
1800 
1801  if (initialized)
1802  return;
1803  initialized = 1;
1804 
1812 }
1813 
1814 #define print_fmt(k, f, ...) do { \
1815  av_bprint_clear(&pbuf); \
1816  av_bprintf(&pbuf, f, __VA_ARGS__); \
1817  writer_print_string(w, k, pbuf.str, 0); \
1818 } while (0)
1819 
1820 #define print_list_fmt(k, f, n, ...) do { \
1821  av_bprint_clear(&pbuf); \
1822  for (int idx = 0; idx < n; idx++) { \
1823  if (idx > 0) \
1824  av_bprint_chars(&pbuf, ' ', 1); \
1825  av_bprintf(&pbuf, f, __VA_ARGS__); \
1826  } \
1827  writer_print_string(w, k, pbuf.str, 0); \
1828 } while (0)
1829 
1830 #define print_int(k, v) writer_print_integer(w, k, v)
1831 #define print_q(k, v, s) writer_print_rational(w, k, v, s)
1832 #define print_str(k, v) writer_print_string(w, k, v, 0)
1833 #define print_str_opt(k, v) writer_print_string(w, k, v, PRINT_STRING_OPT)
1834 #define print_str_validate(k, v) writer_print_string(w, k, v, PRINT_STRING_VALIDATE)
1835 #define print_time(k, v, tb) writer_print_time(w, k, v, tb, 0)
1836 #define print_ts(k, v) writer_print_ts(w, k, v, 0)
1837 #define print_duration_time(k, v, tb) writer_print_time(w, k, v, tb, 1)
1838 #define print_duration_ts(k, v) writer_print_ts(w, k, v, 1)
1839 #define print_val(k, v, u) do { \
1840  struct unit_value uv; \
1841  uv.val.i = v; \
1842  uv.unit = u; \
1843  writer_print_string(w, k, value_string(val_str, sizeof(val_str), uv), 0); \
1844 } while (0)
1845 
1846 #define print_section_header(s) writer_print_section_header(w, s)
1847 #define print_section_footer(s) writer_print_section_footer(w, s)
1848 
1849 #define REALLOCZ_ARRAY_STREAM(ptr, cur_n, new_n) \
1850 { \
1851  ret = av_reallocp_array(&(ptr), (new_n), sizeof(*(ptr))); \
1852  if (ret < 0) \
1853  goto end; \
1854  memset( (ptr) + (cur_n), 0, ((new_n) - (cur_n)) * sizeof(*(ptr)) ); \
1855 }
1856 
1857 static inline int show_tags(WriterContext *w, AVDictionary *tags, int section_id)
1858 {
1859  const AVDictionaryEntry *tag = NULL;
1860  int ret = 0;
1861 
1862  if (!tags)
1863  return 0;
1864  writer_print_section_header(w, section_id);
1865 
1866  while ((tag = av_dict_get(tags, "", tag, AV_DICT_IGNORE_SUFFIX))) {
1867  if ((ret = print_str_validate(tag->key, tag->value)) < 0)
1868  break;
1869  }
1871 
1872  return ret;
1873 }
1874 
1876 {
1877  if (!dovi)
1878  return;
1879 
1880  {
1881  const AVDOVIRpuDataHeader *hdr = av_dovi_get_header(dovi);
1882  const AVDOVIDataMapping *mapping = av_dovi_get_mapping(dovi);
1884  AVBPrint pbuf;
1885 
1887 
1888  // header
1889  print_int("rpu_type", hdr->rpu_type);
1890  print_int("rpu_format", hdr->rpu_format);
1891  print_int("vdr_rpu_profile", hdr->vdr_rpu_profile);
1892  print_int("vdr_rpu_level", hdr->vdr_rpu_level);
1893  print_int("chroma_resampling_explicit_filter_flag",
1895  print_int("coef_data_type", hdr->coef_data_type);
1896  print_int("coef_log2_denom", hdr->coef_log2_denom);
1897  print_int("vdr_rpu_normalized_idc", hdr->vdr_rpu_normalized_idc);
1898  print_int("bl_video_full_range_flag", hdr->bl_video_full_range_flag);
1899  print_int("bl_bit_depth", hdr->bl_bit_depth);
1900  print_int("el_bit_depth", hdr->el_bit_depth);
1901  print_int("vdr_bit_depth", hdr->vdr_bit_depth);
1902  print_int("spatial_resampling_filter_flag",
1904  print_int("el_spatial_resampling_filter_flag",
1906  print_int("disable_residual_flag", hdr->disable_residual_flag);
1907 
1908  // data mapping values
1909  print_int("vdr_rpu_id", mapping->vdr_rpu_id);
1910  print_int("mapping_color_space", mapping->mapping_color_space);
1911  print_int("mapping_chroma_format_idc",
1912  mapping->mapping_chroma_format_idc);
1913 
1914  print_int("nlq_method_idc", mapping->nlq_method_idc);
1915  switch (mapping->nlq_method_idc) {
1916  case AV_DOVI_NLQ_NONE:
1917  print_str("nlq_method_idc_name", "none");
1918  break;
1919  case AV_DOVI_NLQ_LINEAR_DZ:
1920  print_str("nlq_method_idc_name", "linear_dz");
1921  break;
1922  default:
1923  print_str("nlq_method_idc_name", "unknown");
1924  break;
1925  }
1926 
1927  print_int("num_x_partitions", mapping->num_x_partitions);
1928  print_int("num_y_partitions", mapping->num_y_partitions);
1929 
1931 
1932  for (int c = 0; c < 3; c++) {
1933  const AVDOVIReshapingCurve *curve = &mapping->curves[c];
1935 
1936  print_list_fmt("pivots", "%"PRIu16, curve->num_pivots, curve->pivots[idx]);
1937 
1939  for (int i = 0; i < curve->num_pivots - 1; i++) {
1940 
1942  print_int("mapping_idc", curve->mapping_idc[i]);
1943  switch (curve->mapping_idc[i]) {
1945  print_str("mapping_idc_name", "polynomial");
1946  print_int("poly_order", curve->poly_order[i]);
1947  print_list_fmt("poly_coef", "%"PRIi64,
1948  curve->poly_order[i] + 1,
1949  curve->poly_coef[i][idx]);
1950  break;
1951  case AV_DOVI_MAPPING_MMR:
1952  print_str("mapping_idc_name", "mmr");
1953  print_int("mmr_order", curve->mmr_order[i]);
1954  print_int("mmr_constant", curve->mmr_constant[i]);
1955  print_list_fmt("mmr_coef", "%"PRIi64,
1956  curve->mmr_order[i] * 7,
1957  curve->mmr_coef[i][0][idx]);
1958  break;
1959  default:
1960  print_str("mapping_idc_name", "unknown");
1961  break;
1962  }
1963 
1964  // SECTION_ID_FRAME_SIDE_DATA_PIECE
1966  }
1967 
1968  // SECTION_ID_FRAME_SIDE_DATA_PIECE_LIST
1970 
1971  if (mapping->nlq_method_idc != AV_DOVI_NLQ_NONE) {
1972  const AVDOVINLQParams *nlq = &mapping->nlq[c];
1973  print_int("nlq_offset", nlq->nlq_offset);
1974  print_int("vdr_in_max", nlq->vdr_in_max);
1975 
1976  switch (mapping->nlq_method_idc) {
1977  case AV_DOVI_NLQ_LINEAR_DZ:
1978  print_int("linear_deadzone_slope", nlq->linear_deadzone_slope);
1979  print_int("linear_deadzone_threshold", nlq->linear_deadzone_threshold);
1980  break;
1981  }
1982  }
1983 
1984  // SECTION_ID_FRAME_SIDE_DATA_COMPONENT
1986  }
1987 
1988  // SECTION_ID_FRAME_SIDE_DATA_COMPONENT_LIST
1990 
1991  // color metadata
1992  print_int("dm_metadata_id", color->dm_metadata_id);
1993  print_int("scene_refresh_flag", color->scene_refresh_flag);
1994  print_list_fmt("ycc_to_rgb_matrix", "%d/%d",
1995  FF_ARRAY_ELEMS(color->ycc_to_rgb_matrix),
1996  color->ycc_to_rgb_matrix[idx].num,
1997  color->ycc_to_rgb_matrix[idx].den);
1998  print_list_fmt("ycc_to_rgb_offset", "%d/%d",
1999  FF_ARRAY_ELEMS(color->ycc_to_rgb_offset),
2000  color->ycc_to_rgb_offset[idx].num,
2001  color->ycc_to_rgb_offset[idx].den);
2002  print_list_fmt("rgb_to_lms_matrix", "%d/%d",
2003  FF_ARRAY_ELEMS(color->rgb_to_lms_matrix),
2004  color->rgb_to_lms_matrix[idx].num,
2005  color->rgb_to_lms_matrix[idx].den);
2006  print_int("signal_eotf", color->signal_eotf);
2007  print_int("signal_eotf_param0", color->signal_eotf_param0);
2008  print_int("signal_eotf_param1", color->signal_eotf_param1);
2009  print_int("signal_eotf_param2", color->signal_eotf_param2);
2010  print_int("signal_bit_depth", color->signal_bit_depth);
2011  print_int("signal_color_space", color->signal_color_space);
2012  print_int("signal_chroma_format", color->signal_chroma_format);
2013  print_int("signal_full_range_flag", color->signal_full_range_flag);
2014  print_int("source_min_pq", color->source_min_pq);
2015  print_int("source_max_pq", color->source_max_pq);
2016  print_int("source_diagonal", color->source_diagonal);
2017 
2018  av_bprint_finalize(&pbuf, NULL);
2019  }
2020 }
2021 
2023 {
2024  if (!metadata)
2025  return;
2026  print_int("application version", metadata->application_version);
2027  print_int("num_windows", metadata->num_windows);
2028  for (int n = 1; n < metadata->num_windows; n++) {
2029  const AVHDRPlusColorTransformParams *params = &metadata->params[n];
2030  print_q("window_upper_left_corner_x",
2031  params->window_upper_left_corner_x,'/');
2032  print_q("window_upper_left_corner_y",
2033  params->window_upper_left_corner_y,'/');
2034  print_q("window_lower_right_corner_x",
2035  params->window_lower_right_corner_x,'/');
2036  print_q("window_lower_right_corner_y",
2037  params->window_lower_right_corner_y,'/');
2038  print_q("window_upper_left_corner_x",
2039  params->window_upper_left_corner_x,'/');
2040  print_q("window_upper_left_corner_y",
2041  params->window_upper_left_corner_y,'/');
2042  print_int("center_of_ellipse_x",
2043  params->center_of_ellipse_x ) ;
2044  print_int("center_of_ellipse_y",
2045  params->center_of_ellipse_y );
2046  print_int("rotation_angle",
2047  params->rotation_angle);
2048  print_int("semimajor_axis_internal_ellipse",
2050  print_int("semimajor_axis_external_ellipse",
2052  print_int("semiminor_axis_external_ellipse",
2054  print_int("overlap_process_option",
2055  params->overlap_process_option);
2056  }
2057  print_q("targeted_system_display_maximum_luminance",
2060  print_int("num_rows_targeted_system_display_actual_peak_luminance",
2062  print_int("num_cols_targeted_system_display_actual_peak_luminance",
2064  for (int i = 0; i < metadata->num_rows_targeted_system_display_actual_peak_luminance; i++) {
2065  for (int j = 0; j < metadata->num_cols_targeted_system_display_actual_peak_luminance; j++) {
2066  print_q("targeted_system_display_actual_peak_luminance",
2068  }
2069  }
2070  }
2071  for (int n = 0; n < metadata->num_windows; n++) {
2072  const AVHDRPlusColorTransformParams *params = &metadata->params[n];
2073  for (int i = 0; i < 3; i++) {
2074  print_q("maxscl",params->maxscl[i],'/');
2075  }
2076  print_q("average_maxrgb",
2077  params->average_maxrgb,'/');
2078  print_int("num_distribution_maxrgb_percentiles",
2080  for (int i = 0; i < params->num_distribution_maxrgb_percentiles; i++) {
2081  print_int("distribution_maxrgb_percentage",
2082  params->distribution_maxrgb[i].percentage);
2083  print_q("distribution_maxrgb_percentile",
2084  params->distribution_maxrgb[i].percentile,'/');
2085  }
2086  print_q("fraction_bright_pixels",
2087  params->fraction_bright_pixels,'/');
2088  }
2090  print_int("num_rows_mastering_display_actual_peak_luminance",
2092  print_int("num_cols_mastering_display_actual_peak_luminance",
2094  for (int i = 0; i < metadata->num_rows_mastering_display_actual_peak_luminance; i++) {
2095  for (int j = 0; j < metadata->num_cols_mastering_display_actual_peak_luminance; j++) {
2096  print_q("mastering_display_actual_peak_luminance",
2097  metadata->mastering_display_actual_peak_luminance[i][j],'/');
2098  }
2099  }
2100  }
2101 
2102  for (int n = 0; n < metadata->num_windows; n++) {
2103  const AVHDRPlusColorTransformParams *params = &metadata->params[n];
2104  if (params->tone_mapping_flag) {
2105  print_q("knee_point_x", params->knee_point_x,'/');
2106  print_q("knee_point_y", params->knee_point_y,'/');
2107  print_int("num_bezier_curve_anchors",
2108  params->num_bezier_curve_anchors );
2109  for (int i = 0; i < params->num_bezier_curve_anchors; i++) {
2110  print_q("bezier_curve_anchors",
2111  params->bezier_curve_anchors[i],'/');
2112  }
2113  }
2114  if (params->color_saturation_mapping_flag) {
2115  print_q("color_saturation_weight",
2116  params->color_saturation_weight,'/');
2117  }
2118  }
2119 }
2120 
2122  AVCodecParameters *par,
2123  const AVPacketSideData *side_data,
2124  int nb_side_data,
2125  SectionID id_data_list,
2126  SectionID id_data)
2127 {
2128  int i;
2129 
2130  writer_print_section_header(w, id_data_list);
2131  for (i = 0; i < nb_side_data; i++) {
2132  const AVPacketSideData *sd = &side_data[i];
2133  const char *name = av_packet_side_data_name(sd->type);
2134 
2135  writer_print_section_header(w, id_data);
2136  print_str("side_data_type", name ? name : "unknown");
2137  if (sd->type == AV_PKT_DATA_DISPLAYMATRIX && sd->size >= 9*4) {
2138  writer_print_integers(w, "displaymatrix", sd->data, 9, " %11d", 3, 4, 1);
2139  print_int("rotation", av_display_rotation_get((int32_t *)sd->data));
2140  } else if (sd->type == AV_PKT_DATA_STEREO3D) {
2141  const AVStereo3D *stereo = (AVStereo3D *)sd->data;
2142  print_str("type", av_stereo3d_type_name(stereo->type));
2143  print_int("inverted", !!(stereo->flags & AV_STEREO3D_FLAG_INVERT));
2144  } else if (sd->type == AV_PKT_DATA_SPHERICAL) {
2145  const AVSphericalMapping *spherical = (AVSphericalMapping *)sd->data;
2146  print_str("projection", av_spherical_projection_name(spherical->projection));
2147  if (spherical->projection == AV_SPHERICAL_CUBEMAP) {
2148  print_int("padding", spherical->padding);
2149  } else if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR_TILE) {
2150  size_t l, t, r, b;
2151  av_spherical_tile_bounds(spherical, par->width, par->height,
2152  &l, &t, &r, &b);
2153  print_int("bound_left", l);
2154  print_int("bound_top", t);
2155  print_int("bound_right", r);
2156  print_int("bound_bottom", b);
2157  }
2158 
2159  print_int("yaw", (double) spherical->yaw / (1 << 16));
2160  print_int("pitch", (double) spherical->pitch / (1 << 16));
2161  print_int("roll", (double) spherical->roll / (1 << 16));
2162  } else if (sd->type == AV_PKT_DATA_SKIP_SAMPLES && sd->size == 10) {
2163  print_int("skip_samples", AV_RL32(sd->data));
2164  print_int("discard_padding", AV_RL32(sd->data + 4));
2165  print_int("skip_reason", AV_RL8(sd->data + 8));
2166  print_int("discard_reason", AV_RL8(sd->data + 9));
2167  } else if (sd->type == AV_PKT_DATA_MASTERING_DISPLAY_METADATA) {
2169 
2170  if (metadata->has_primaries) {
2171  print_q("red_x", metadata->display_primaries[0][0], '/');
2172  print_q("red_y", metadata->display_primaries[0][1], '/');
2173  print_q("green_x", metadata->display_primaries[1][0], '/');
2174  print_q("green_y", metadata->display_primaries[1][1], '/');
2175  print_q("blue_x", metadata->display_primaries[2][0], '/');
2176  print_q("blue_y", metadata->display_primaries[2][1], '/');
2177 
2178  print_q("white_point_x", metadata->white_point[0], '/');
2179  print_q("white_point_y", metadata->white_point[1], '/');
2180  }
2181 
2182  if (metadata->has_luminance) {
2183  print_q("min_luminance", metadata->min_luminance, '/');
2184  print_q("max_luminance", metadata->max_luminance, '/');
2185  }
2186  } else if (sd->type == AV_PKT_DATA_CONTENT_LIGHT_LEVEL) {
2188  print_int("max_content", metadata->MaxCLL);
2189  print_int("max_average", metadata->MaxFALL);
2190  } else if (sd->type == AV_PKT_DATA_DOVI_CONF) {
2192  print_int("dv_version_major", dovi->dv_version_major);
2193  print_int("dv_version_minor", dovi->dv_version_minor);
2194  print_int("dv_profile", dovi->dv_profile);
2195  print_int("dv_level", dovi->dv_level);
2196  print_int("rpu_present_flag", dovi->rpu_present_flag);
2197  print_int("el_present_flag", dovi->el_present_flag);
2198  print_int("bl_present_flag", dovi->bl_present_flag);
2199  print_int("dv_bl_signal_compatibility_id", dovi->dv_bl_signal_compatibility_id);
2200  } else if (sd->type == AV_PKT_DATA_AUDIO_SERVICE_TYPE) {
2201  enum AVAudioServiceType *t = (enum AVAudioServiceType *)sd->data;
2202  print_int("service_type", *t);
2203  } else if (sd->type == AV_PKT_DATA_MPEGTS_STREAM_ID) {
2204  print_int("id", *sd->data);
2205  } else if (sd->type == AV_PKT_DATA_CPB_PROPERTIES) {
2206  const AVCPBProperties *prop = (AVCPBProperties *)sd->data;
2207  print_int("max_bitrate", prop->max_bitrate);
2208  print_int("min_bitrate", prop->min_bitrate);
2209  print_int("avg_bitrate", prop->avg_bitrate);
2210  print_int("buffer_size", prop->buffer_size);
2211  print_int("vbv_delay", prop->vbv_delay);
2212  } else if (sd->type == AV_PKT_DATA_WEBVTT_IDENTIFIER ||
2214  if (do_show_data)
2215  writer_print_data(w, "data", sd->data, sd->size);
2216  writer_print_data_hash(w, "data_hash", sd->data, sd->size);
2217  }
2219  }
2221 }
2222 
2224 {
2225  const char *val = av_color_range_name(color_range);
2227  print_str_opt("color_range", "unknown");
2228  } else {
2229  print_str("color_range", val);
2230  }
2231 }
2232 
2233 static void print_color_space(WriterContext *w, enum AVColorSpace color_space)
2234 {
2235  const char *val = av_color_space_name(color_space);
2236  if (!val || color_space == AVCOL_SPC_UNSPECIFIED) {
2237  print_str_opt("color_space", "unknown");
2238  } else {
2239  print_str("color_space", val);
2240  }
2241 }
2242 
2244 {
2247  print_str_opt("color_primaries", "unknown");
2248  } else {
2249  print_str("color_primaries", val);
2250  }
2251 }
2252 
2254 {
2255  const char *val = av_color_transfer_name(color_trc);
2256  if (!val || color_trc == AVCOL_TRC_UNSPECIFIED) {
2257  print_str_opt("color_transfer", "unknown");
2258  } else {
2259  print_str("color_transfer", val);
2260  }
2261 }
2262 
2263 static void print_chroma_location(WriterContext *w, enum AVChromaLocation chroma_location)
2264 {
2265  const char *val = av_chroma_location_name(chroma_location);
2266  if (!val || chroma_location == AVCHROMA_LOC_UNSPECIFIED) {
2267  print_str_opt("chroma_location", "unspecified");
2268  } else {
2269  print_str("chroma_location", val);
2270  }
2271 }
2272 
2273 
2274 static void clear_log(int need_lock)
2275 {
2276  int i;
2277 
2278  if (need_lock)
2279  pthread_mutex_lock(&log_mutex);
2280  for (i=0; i<log_buffer_size; i++) {
2281  av_freep(&log_buffer[i].context_name);
2282  av_freep(&log_buffer[i].parent_name);
2283  av_freep(&log_buffer[i].log_message);
2284  }
2285  log_buffer_size = 0;
2286  if(need_lock)
2287  pthread_mutex_unlock(&log_mutex);
2288 }
2289 
2290 static int show_log(WriterContext *w, int section_ids, int section_id, int log_level)
2291 {
2292  int i;
2293  pthread_mutex_lock(&log_mutex);
2294  if (!log_buffer_size) {
2295  pthread_mutex_unlock(&log_mutex);
2296  return 0;
2297  }
2298  writer_print_section_header(w, section_ids);
2299 
2300  for (i=0; i<log_buffer_size; i++) {
2301  if (log_buffer[i].log_level <= log_level) {
2302  writer_print_section_header(w, section_id);
2303  print_str("context", log_buffer[i].context_name);
2304  print_int("level", log_buffer[i].log_level);
2305  print_int("category", log_buffer[i].category);
2306  if (log_buffer[i].parent_name) {
2307  print_str("parent_context", log_buffer[i].parent_name);
2308  print_int("parent_category", log_buffer[i].parent_category);
2309  } else {
2310  print_str_opt("parent_context", "N/A");
2311  print_str_opt("parent_category", "N/A");
2312  }
2313  print_str("message", log_buffer[i].log_message);
2315  }
2316  }
2317  clear_log(0);
2318  pthread_mutex_unlock(&log_mutex);
2319 
2321 
2322  return 0;
2323 }
2324 
2325 static void show_packet(WriterContext *w, InputFile *ifile, AVPacket *pkt, int packet_idx)
2326 {
2327  char val_str[128];
2328  AVStream *st = ifile->streams[pkt->stream_index].st;
2329  AVBPrint pbuf;
2330  const char *s;
2331 
2333 
2335 
2337  if (s) print_str ("codec_type", s);
2338  else print_str_opt("codec_type", "unknown");
2339  print_int("stream_index", pkt->stream_index);
2340  print_ts ("pts", pkt->pts);
2341  print_time("pts_time", pkt->pts, &st->time_base);
2342  print_ts ("dts", pkt->dts);
2343  print_time("dts_time", pkt->dts, &st->time_base);
2344  print_duration_ts("duration", pkt->duration);
2345  print_duration_time("duration_time", pkt->duration, &st->time_base);
2346  print_val("size", pkt->size, unit_byte_str);
2347  if (pkt->pos != -1) print_fmt ("pos", "%"PRId64, pkt->pos);
2348  else print_str_opt("pos", "N/A");
2349  print_fmt("flags", "%c%c", pkt->flags & AV_PKT_FLAG_KEY ? 'K' : '_',
2350  pkt->flags & AV_PKT_FLAG_DISCARD ? 'D' : '_');
2351 
2352  if (pkt->side_data_elems) {
2353  size_t size;
2354  const uint8_t *side_metadata;
2355 
2357  if (side_metadata && size && do_show_packet_tags) {
2358  AVDictionary *dict = NULL;
2359  if (av_packet_unpack_dictionary(side_metadata, size, &dict) >= 0)
2361  av_dict_free(&dict);
2362  }
2363 
2367  }
2368 
2369  if (do_show_data)
2370  writer_print_data(w, "data", pkt->data, pkt->size);
2371  writer_print_data_hash(w, "data_hash", pkt->data, pkt->size);
2373 
2374  av_bprint_finalize(&pbuf, NULL);
2375  fflush(stdout);
2376 }
2377 
2380 {
2381  AVBPrint pbuf;
2382 
2384 
2386 
2387  print_str ("media_type", "subtitle");
2388  print_ts ("pts", sub->pts);
2389  print_time("pts_time", sub->pts, &AV_TIME_BASE_Q);
2390  print_int ("format", sub->format);
2391  print_int ("start_display_time", sub->start_display_time);
2392  print_int ("end_display_time", sub->end_display_time);
2393  print_int ("num_rects", sub->num_rects);
2394 
2396 
2397  av_bprint_finalize(&pbuf, NULL);
2398  fflush(stdout);
2399 }
2400 
2403 {
2404  AVBPrint pbuf;
2405  char val_str[128];
2406  const char *s;
2407  int i;
2408 
2410 
2412 
2414  if (s) print_str ("media_type", s);
2415  else print_str_opt("media_type", "unknown");
2416  print_int("stream_index", stream->index);
2417  print_int("key_frame", frame->key_frame);
2418  print_ts ("pts", frame->pts);
2419  print_time("pts_time", frame->pts, &stream->time_base);
2420  print_ts ("pkt_dts", frame->pkt_dts);
2421  print_time("pkt_dts_time", frame->pkt_dts, &stream->time_base);
2422  print_ts ("best_effort_timestamp", frame->best_effort_timestamp);
2423  print_time("best_effort_timestamp_time", frame->best_effort_timestamp, &stream->time_base);
2424  print_duration_ts ("pkt_duration", frame->pkt_duration);
2425  print_duration_time("pkt_duration_time", frame->pkt_duration, &stream->time_base);
2426  if (frame->pkt_pos != -1) print_fmt ("pkt_pos", "%"PRId64, frame->pkt_pos);
2427  else print_str_opt("pkt_pos", "N/A");
2428  if (frame->pkt_size != -1) print_val ("pkt_size", frame->pkt_size, unit_byte_str);
2429  else print_str_opt("pkt_size", "N/A");
2430 
2431  switch (stream->codecpar->codec_type) {
2432  AVRational sar;
2433 
2434  case AVMEDIA_TYPE_VIDEO:
2435  print_int("width", frame->width);
2436  print_int("height", frame->height);
2437  s = av_get_pix_fmt_name(frame->format);
2438  if (s) print_str ("pix_fmt", s);
2439  else print_str_opt("pix_fmt", "unknown");
2440  sar = av_guess_sample_aspect_ratio(fmt_ctx, stream, frame);
2441  if (sar.num) {
2442  print_q("sample_aspect_ratio", sar, ':');
2443  } else {
2444  print_str_opt("sample_aspect_ratio", "N/A");
2445  }
2446  print_fmt("pict_type", "%c", av_get_picture_type_char(frame->pict_type));
2447  print_int("coded_picture_number", frame->coded_picture_number);
2448  print_int("display_picture_number", frame->display_picture_number);
2449  print_int("interlaced_frame", frame->interlaced_frame);
2450  print_int("top_field_first", frame->top_field_first);
2451  print_int("repeat_pict", frame->repeat_pict);
2452 
2453  print_color_range(w, frame->color_range);
2454  print_color_space(w, frame->colorspace);
2455  print_primaries(w, frame->color_primaries);
2456  print_color_trc(w, frame->color_trc);
2457  print_chroma_location(w, frame->chroma_location);
2458  break;
2459 
2460  case AVMEDIA_TYPE_AUDIO:
2461  s = av_get_sample_fmt_name(frame->format);
2462  if (s) print_str ("sample_fmt", s);
2463  else print_str_opt("sample_fmt", "unknown");
2464  print_int("nb_samples", frame->nb_samples);
2465  print_int("channels", frame->channels);
2466  if (frame->channel_layout) {
2467  av_bprint_clear(&pbuf);
2468  av_bprint_channel_layout(&pbuf, frame->channels,
2469  frame->channel_layout);
2470  print_str ("channel_layout", pbuf.str);
2471  } else
2472  print_str_opt("channel_layout", "unknown");
2473  break;
2474  }
2475  if (do_show_frame_tags)
2476  show_tags(w, frame->metadata, SECTION_ID_FRAME_TAGS);
2477  if (do_show_log)
2479  if (frame->nb_side_data) {
2481  for (i = 0; i < frame->nb_side_data; i++) {
2482  AVFrameSideData *sd = frame->side_data[i];
2483  const char *name;
2484 
2487  print_str("side_data_type", name ? name : "unknown");
2488  if (sd->type == AV_FRAME_DATA_DISPLAYMATRIX && sd->size >= 9*4) {
2489  writer_print_integers(w, "displaymatrix", sd->data, 9, " %11d", 3, 4, 1);
2490  print_int("rotation", av_display_rotation_get((int32_t *)sd->data));
2491  } else if (sd->type == AV_FRAME_DATA_GOP_TIMECODE && sd->size >= 8) {
2492  char tcbuf[AV_TIMECODE_STR_SIZE];
2493  av_timecode_make_mpeg_tc_string(tcbuf, *(int64_t *)(sd->data));
2494  print_str("timecode", tcbuf);
2495  } else if (sd->type == AV_FRAME_DATA_S12M_TIMECODE && sd->size == 16) {
2496  uint32_t *tc = (uint32_t*)sd->data;
2497  int m = FFMIN(tc[0],3);
2499  for (int j = 1; j <= m ; j++) {
2500  char tcbuf[AV_TIMECODE_STR_SIZE];
2501  av_timecode_make_smpte_tc_string2(tcbuf, stream->avg_frame_rate, tc[j], 0, 0);
2503  print_str("value", tcbuf);
2505  }
2507  } else if (sd->type == AV_FRAME_DATA_MASTERING_DISPLAY_METADATA) {
2509 
2510  if (metadata->has_primaries) {
2511  print_q("red_x", metadata->display_primaries[0][0], '/');
2512  print_q("red_y", metadata->display_primaries[0][1], '/');
2513  print_q("green_x", metadata->display_primaries[1][0], '/');
2514  print_q("green_y", metadata->display_primaries[1][1], '/');
2515  print_q("blue_x", metadata->display_primaries[2][0], '/');
2516  print_q("blue_y", metadata->display_primaries[2][1], '/');
2517 
2518  print_q("white_point_x", metadata->white_point[0], '/');
2519  print_q("white_point_y", metadata->white_point[1], '/');
2520  }
2521 
2522  if (metadata->has_luminance) {
2523  print_q("min_luminance", metadata->min_luminance, '/');
2524  print_q("max_luminance", metadata->max_luminance, '/');
2525  }
2526  } else if (sd->type == AV_FRAME_DATA_DYNAMIC_HDR_PLUS) {
2527  AVDynamicHDRPlus *metadata = (AVDynamicHDRPlus *)sd->data;
2528  print_dynamic_hdr10_plus(w, metadata);
2529  } else if (sd->type == AV_FRAME_DATA_CONTENT_LIGHT_LEVEL) {
2531  print_int("max_content", metadata->MaxCLL);
2532  print_int("max_average", metadata->MaxFALL);
2533  } else if (sd->type == AV_FRAME_DATA_ICC_PROFILE) {
2535  if (tag)
2536  print_str(tag->key, tag->value);
2537  print_int("size", sd->size);
2538  } else if (sd->type == AV_FRAME_DATA_DOVI_METADATA) {
2539  print_dovi_metadata(w, (const AVDOVIMetadata *)sd->data);
2540  }
2542  }
2544  }
2545 
2547 
2548  av_bprint_finalize(&pbuf, NULL);
2549  fflush(stdout);
2550 }
2551 
2553  InputFile *ifile,
2555  int *packet_new)
2556 {
2557  AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2558  AVCodecContext *dec_ctx = ifile->streams[pkt->stream_index].dec_ctx;
2559  AVCodecParameters *par = ifile->streams[pkt->stream_index].st->codecpar;
2560  AVSubtitle sub;
2561  int ret = 0, got_frame = 0;
2562 
2563  clear_log(1);
2564  if (dec_ctx && dec_ctx->codec) {
2565  switch (par->codec_type) {
2566  case AVMEDIA_TYPE_VIDEO:
2567  case AVMEDIA_TYPE_AUDIO:
2568  if (*packet_new) {
2570  if (ret == AVERROR(EAGAIN)) {
2571  ret = 0;
2572  } else if (ret >= 0 || ret == AVERROR_EOF) {
2573  ret = 0;
2574  *packet_new = 0;
2575  }
2576  }
2577  if (ret >= 0) {
2579  if (ret >= 0) {
2580  got_frame = 1;
2581  } else if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
2582  ret = 0;
2583  }
2584  }
2585  break;
2586 
2587  case AVMEDIA_TYPE_SUBTITLE:
2588  if (*packet_new)
2589  ret = avcodec_decode_subtitle2(dec_ctx, &sub, &got_frame, pkt);
2590  *packet_new = 0;
2591  break;
2592  default:
2593  *packet_new = 0;
2594  }
2595  } else {
2596  *packet_new = 0;
2597  }
2598 
2599  if (ret < 0)
2600  return ret;
2601  if (got_frame) {
2602  int is_sub = (par->codec_type == AVMEDIA_TYPE_SUBTITLE);
2604  if (do_show_frames)
2605  if (is_sub)
2606  show_subtitle(w, &sub, ifile->streams[pkt->stream_index].st, fmt_ctx);
2607  else
2608  show_frame(w, frame, ifile->streams[pkt->stream_index].st, fmt_ctx);
2609  if (is_sub)
2610  avsubtitle_free(&sub);
2611  }
2612  return got_frame || *packet_new;
2613 }
2614 
2615 static void log_read_interval(const ReadInterval *interval, void *log_ctx, int log_level)
2616 {
2617  av_log(log_ctx, log_level, "id:%d", interval->id);
2618 
2619  if (interval->has_start) {
2620  av_log(log_ctx, log_level, " start:%s%s", interval->start_is_offset ? "+" : "",
2621  av_ts2timestr(interval->start, &AV_TIME_BASE_Q));
2622  } else {
2623  av_log(log_ctx, log_level, " start:N/A");
2624  }
2625 
2626  if (interval->has_end) {
2627  av_log(log_ctx, log_level, " end:%s", interval->end_is_offset ? "+" : "");
2628  if (interval->duration_frames)
2629  av_log(log_ctx, log_level, "#%"PRId64, interval->end);
2630  else
2631  av_log(log_ctx, log_level, "%s", av_ts2timestr(interval->end, &AV_TIME_BASE_Q));
2632  } else {
2633  av_log(log_ctx, log_level, " end:N/A");
2634  }
2635 
2636  av_log(log_ctx, log_level, "\n");
2637 }
2638 
2640  const ReadInterval *interval, int64_t *cur_ts)
2641 {
2642  AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2643  AVPacket *pkt = NULL;
2644  AVFrame *frame = NULL;
2645  int ret = 0, i = 0, frame_count = 0;
2646  int64_t start = -INT64_MAX, end = interval->end;
2647  int has_start = 0, has_end = interval->has_end && !interval->end_is_offset;
2648 
2649  av_log(NULL, AV_LOG_VERBOSE, "Processing read interval ");
2651 
2652  if (interval->has_start) {
2653  int64_t target;
2654  if (interval->start_is_offset) {
2655  if (*cur_ts == AV_NOPTS_VALUE) {
2657  "Could not seek to relative position since current "
2658  "timestamp is not defined\n");
2659  ret = AVERROR(EINVAL);
2660  goto end;
2661  }
2662  target = *cur_ts + interval->start;
2663  } else {
2664  target = interval->start;
2665  }
2666 
2667  av_log(NULL, AV_LOG_VERBOSE, "Seeking to read interval start point %s\n",
2668  av_ts2timestr(target, &AV_TIME_BASE_Q));
2669  if ((ret = avformat_seek_file(fmt_ctx, -1, -INT64_MAX, target, INT64_MAX, 0)) < 0) {
2670  av_log(NULL, AV_LOG_ERROR, "Could not seek to position %"PRId64": %s\n",
2671  interval->start, av_err2str(ret));
2672  goto end;
2673  }
2674  }
2675 
2676  frame = av_frame_alloc();
2677  if (!frame) {
2678  ret = AVERROR(ENOMEM);
2679  goto end;
2680  }
2681  pkt = av_packet_alloc();
2682  if (!pkt) {
2683  ret = AVERROR(ENOMEM);
2684  goto end;
2685  }
2686  while (!av_read_frame(fmt_ctx, pkt)) {
2687  if (fmt_ctx->nb_streams > nb_streams) {
2692  }
2694  AVRational tb = ifile->streams[pkt->stream_index].st->time_base;
2695 
2696  if (pkt->pts != AV_NOPTS_VALUE)
2697  *cur_ts = av_rescale_q(pkt->pts, tb, AV_TIME_BASE_Q);
2698 
2699  if (!has_start && *cur_ts != AV_NOPTS_VALUE) {
2700  start = *cur_ts;
2701  has_start = 1;
2702  }
2703 
2704  if (has_start && !has_end && interval->end_is_offset) {
2705  end = start + interval->end;
2706  has_end = 1;
2707  }
2708 
2709  if (interval->end_is_offset && interval->duration_frames) {
2710  if (frame_count >= interval->end)
2711  break;
2712  } else if (has_end && *cur_ts != AV_NOPTS_VALUE && *cur_ts >= end) {
2713  break;
2714  }
2715 
2716  frame_count++;
2717  if (do_read_packets) {
2718  if (do_show_packets)
2719  show_packet(w, ifile, pkt, i++);
2721  }
2722  if (do_read_frames) {
2723  int packet_new = 1;
2724  while (process_frame(w, ifile, frame, pkt, &packet_new) > 0);
2725  }
2726  }
2728  }
2730  //Flush remaining frames that are cached in the decoder
2731  for (i = 0; i < fmt_ctx->nb_streams; i++) {
2732  pkt->stream_index = i;
2733  if (do_read_frames)
2734  while (process_frame(w, ifile, frame, pkt, &(int){1}) > 0);
2735  }
2736 
2737 end:
2738  av_frame_free(&frame);
2739  av_packet_free(&pkt);
2740  if (ret < 0) {
2741  av_log(NULL, AV_LOG_ERROR, "Could not read packets in interval ");
2742  log_read_interval(interval, NULL, AV_LOG_ERROR);
2743  }
2744  return ret;
2745 }
2746 
2748 {
2749  AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2750  int i, ret = 0;
2751  int64_t cur_ts = fmt_ctx->start_time;
2752 
2753  if (read_intervals_nb == 0) {
2754  ReadInterval interval = (ReadInterval) { .has_start = 0, .has_end = 0 };
2755  ret = read_interval_packets(w, ifile, &interval, &cur_ts);
2756  } else {
2757  for (i = 0; i < read_intervals_nb; i++) {
2758  ret = read_interval_packets(w, ifile, &read_intervals[i], &cur_ts);
2759  if (ret < 0)
2760  break;
2761  }
2762  }
2763 
2764  return ret;
2765 }
2766 
2767 static int show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_idx, InputStream *ist, int in_program)
2768 {
2769  AVStream *stream = ist->st;
2770  AVCodecParameters *par;
2772  char val_str[128];
2773  const char *s;
2774  AVRational sar, dar;
2775  AVBPrint pbuf;
2776  const AVCodecDescriptor *cd;
2777  int ret = 0;
2778  const char *profile = NULL;
2779 
2781 
2783 
2784  print_int("index", stream->index);
2785 
2786  par = stream->codecpar;
2787  dec_ctx = ist->dec_ctx;
2788  if (cd = avcodec_descriptor_get(par->codec_id)) {
2789  print_str("codec_name", cd->name);
2790  if (!do_bitexact) {
2791  print_str("codec_long_name",
2792  cd->long_name ? cd->long_name : "unknown");
2793  }
2794  } else {
2795  print_str_opt("codec_name", "unknown");
2796  if (!do_bitexact) {
2797  print_str_opt("codec_long_name", "unknown");
2798  }
2799  }
2800 
2801  if (!do_bitexact && (profile = avcodec_profile_name(par->codec_id, par->profile)))
2802  print_str("profile", profile);
2803  else {
2804  if (par->profile != FF_PROFILE_UNKNOWN) {
2805  char profile_num[12];
2806  snprintf(profile_num, sizeof(profile_num), "%d", par->profile);
2807  print_str("profile", profile_num);
2808  } else
2809  print_str_opt("profile", "unknown");
2810  }
2811 
2813  if (s) print_str ("codec_type", s);
2814  else print_str_opt("codec_type", "unknown");
2815 
2816  /* print AVI/FourCC tag */
2817  print_str("codec_tag_string", av_fourcc2str(par->codec_tag));
2818  print_fmt("codec_tag", "0x%04"PRIx32, par->codec_tag);
2819 
2820  switch (par->codec_type) {
2821  case AVMEDIA_TYPE_VIDEO:
2822  print_int("width", par->width);
2823  print_int("height", par->height);
2824  if (dec_ctx) {
2825  print_int("coded_width", dec_ctx->coded_width);
2826  print_int("coded_height", dec_ctx->coded_height);
2829  }
2830  print_int("has_b_frames", par->video_delay);
2831  sar = av_guess_sample_aspect_ratio(fmt_ctx, stream, NULL);
2832  if (sar.num) {
2833  print_q("sample_aspect_ratio", sar, ':');
2834  av_reduce(&dar.num, &dar.den,
2835  par->width * sar.num,
2836  par->height * sar.den,
2837  1024*1024);
2838  print_q("display_aspect_ratio", dar, ':');
2839  } else {
2840  print_str_opt("sample_aspect_ratio", "N/A");
2841  print_str_opt("display_aspect_ratio", "N/A");
2842  }
2843  s = av_get_pix_fmt_name(par->format);
2844  if (s) print_str ("pix_fmt", s);
2845  else print_str_opt("pix_fmt", "unknown");
2846  print_int("level", par->level);
2847 
2850  print_color_trc(w, par->color_trc);
2853 
2854  if (par->field_order == AV_FIELD_PROGRESSIVE)
2855  print_str("field_order", "progressive");
2856  else if (par->field_order == AV_FIELD_TT)
2857  print_str("field_order", "tt");
2858  else if (par->field_order == AV_FIELD_BB)
2859  print_str("field_order", "bb");
2860  else if (par->field_order == AV_FIELD_TB)
2861  print_str("field_order", "tb");
2862  else if (par->field_order == AV_FIELD_BT)
2863  print_str("field_order", "bt");
2864  else
2865  print_str_opt("field_order", "unknown");
2866 
2867  if (dec_ctx)
2868  print_int("refs", dec_ctx->refs);
2869  break;
2870 
2871  case AVMEDIA_TYPE_AUDIO:
2873  if (s) print_str ("sample_fmt", s);
2874  else print_str_opt("sample_fmt", "unknown");
2875  print_val("sample_rate", par->sample_rate, unit_hertz_str);
2876  print_int("channels", par->channels);
2877 
2878  if (par->channel_layout) {
2879  av_bprint_clear(&pbuf);
2881  print_str ("channel_layout", pbuf.str);
2882  } else {
2883  print_str_opt("channel_layout", "unknown");
2884  }
2885 
2886  print_int("bits_per_sample", av_get_bits_per_sample(par->codec_id));
2887  break;
2888 
2889  case AVMEDIA_TYPE_SUBTITLE:
2890  if (par->width)
2891  print_int("width", par->width);
2892  else
2893  print_str_opt("width", "N/A");
2894  if (par->height)
2895  print_int("height", par->height);
2896  else
2897  print_str_opt("height", "N/A");
2898  break;
2899  }
2900 
2902  const AVOption *opt = NULL;
2903  while (opt = av_opt_next(dec_ctx->priv_data,opt)) {
2904  uint8_t *str;
2905  if (!(opt->flags & AV_OPT_FLAG_EXPORT)) continue;
2906  if (av_opt_get(dec_ctx->priv_data, opt->name, 0, &str) >= 0) {
2907  print_str(opt->name, str);
2908  av_free(str);
2909  }
2910  }
2911  }
2912 
2913  if (fmt_ctx->iformat->flags & AVFMT_SHOW_IDS) print_fmt ("id", "0x%x", stream->id);
2914  else print_str_opt("id", "N/A");
2915  print_q("r_frame_rate", stream->r_frame_rate, '/');
2916  print_q("avg_frame_rate", stream->avg_frame_rate, '/');
2917  print_q("time_base", stream->time_base, '/');
2918  print_ts ("start_pts", stream->start_time);
2919  print_time("start_time", stream->start_time, &stream->time_base);
2920  print_ts ("duration_ts", stream->duration);
2921  print_time("duration", stream->duration, &stream->time_base);
2922  if (par->bit_rate > 0) print_val ("bit_rate", par->bit_rate, unit_bit_per_second_str);
2923  else print_str_opt("bit_rate", "N/A");
2924  if (dec_ctx && dec_ctx->rc_max_rate > 0)
2926  else
2927  print_str_opt("max_bit_rate", "N/A");
2928  if (dec_ctx && dec_ctx->bits_per_raw_sample > 0) print_fmt("bits_per_raw_sample", "%d", dec_ctx->bits_per_raw_sample);
2929  else print_str_opt("bits_per_raw_sample", "N/A");
2930  if (stream->nb_frames) print_fmt ("nb_frames", "%"PRId64, stream->nb_frames);
2931  else print_str_opt("nb_frames", "N/A");
2932  if (nb_streams_frames[stream_idx]) print_fmt ("nb_read_frames", "%"PRIu64, nb_streams_frames[stream_idx]);
2933  else print_str_opt("nb_read_frames", "N/A");
2934  if (nb_streams_packets[stream_idx]) print_fmt ("nb_read_packets", "%"PRIu64, nb_streams_packets[stream_idx]);
2935  else print_str_opt("nb_read_packets", "N/A");
2936  if (do_show_data)
2937  writer_print_data(w, "extradata", par->extradata,
2938  par->extradata_size);
2939 
2940  if (par->extradata_size > 0) {
2941  print_int("extradata_size", par->extradata_size);
2942  writer_print_data_hash(w, "extradata_hash", par->extradata,
2943  par->extradata_size);
2944  }
2945 
2946  /* Print disposition information */
2947 #define PRINT_DISPOSITION(flagname, name) do { \
2948  print_int(name, !!(stream->disposition & AV_DISPOSITION_##flagname)); \
2949  } while (0)
2950 
2953  PRINT_DISPOSITION(DEFAULT, "default");
2954  PRINT_DISPOSITION(DUB, "dub");
2955  PRINT_DISPOSITION(ORIGINAL, "original");
2956  PRINT_DISPOSITION(COMMENT, "comment");
2957  PRINT_DISPOSITION(LYRICS, "lyrics");
2958  PRINT_DISPOSITION(KARAOKE, "karaoke");
2959  PRINT_DISPOSITION(FORCED, "forced");
2960  PRINT_DISPOSITION(HEARING_IMPAIRED, "hearing_impaired");
2961  PRINT_DISPOSITION(VISUAL_IMPAIRED, "visual_impaired");
2962  PRINT_DISPOSITION(CLEAN_EFFECTS, "clean_effects");
2963  PRINT_DISPOSITION(ATTACHED_PIC, "attached_pic");
2964  PRINT_DISPOSITION(TIMED_THUMBNAILS, "timed_thumbnails");
2965  PRINT_DISPOSITION(CAPTIONS, "captions");
2966  PRINT_DISPOSITION(DESCRIPTIONS, "descriptions");
2967  PRINT_DISPOSITION(METADATA, "metadata");
2968  PRINT_DISPOSITION(DEPENDENT, "dependent");
2969  PRINT_DISPOSITION(STILL_IMAGE, "still_image");
2971  }
2972 
2973  if (do_show_stream_tags)
2975 
2976  if (stream->nb_side_data) {
2977  print_pkt_side_data(w, stream->codecpar, stream->side_data, stream->nb_side_data,
2980  }
2981 
2983  av_bprint_finalize(&pbuf, NULL);
2984  fflush(stdout);
2985 
2986  return ret;
2987 }
2988 
2990 {
2991  AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2992  int i, ret = 0;
2993 
2995  for (i = 0; i < ifile->nb_streams; i++)
2996  if (selected_streams[i]) {
2997  ret = show_stream(w, fmt_ctx, i, &ifile->streams[i], 0);
2998  if (ret < 0)
2999  break;
3000  }
3002 
3003  return ret;
3004 }
3005 
3007 {
3008  AVFormatContext *fmt_ctx = ifile->fmt_ctx;
3009  int i, ret = 0;
3010 
3012  print_int("program_id", program->id);
3013  print_int("program_num", program->program_num);
3014  print_int("nb_streams", program->nb_stream_indexes);
3015  print_int("pmt_pid", program->pmt_pid);
3016  print_int("pcr_pid", program->pcr_pid);
3019  if (ret < 0)
3020  goto end;
3021 
3023  for (i = 0; i < program->nb_stream_indexes; i++) {
3024  if (selected_streams[program->stream_index[i]]) {
3025  ret = show_stream(w, fmt_ctx, program->stream_index[i], &ifile->streams[program->stream_index[i]], 1);
3026  if (ret < 0)
3027  break;
3028  }
3029  }
3031 
3032 end:
3034  return ret;
3035 }
3036 
3038 {
3039  AVFormatContext *fmt_ctx = ifile->fmt_ctx;
3040  int i, ret = 0;
3041 
3043  for (i = 0; i < fmt_ctx->nb_programs; i++) {
3045  if (!program)
3046  continue;
3048  if (ret < 0)
3049  break;
3050  }
3052  return ret;
3053 }
3054 
3056 {
3057  AVFormatContext *fmt_ctx = ifile->fmt_ctx;
3058  int i, ret = 0;
3059 
3061  for (i = 0; i < fmt_ctx->nb_chapters; i++) {
3062  AVChapter *chapter = fmt_ctx->chapters[i];
3063 
3065  print_int("id", chapter->id);
3066  print_q ("time_base", chapter->time_base, '/');
3067  print_int("start", chapter->start);
3068  print_time("start_time", chapter->start, &chapter->time_base);
3069  print_int("end", chapter->end);
3070  print_time("end_time", chapter->end, &chapter->time_base);
3074  }
3076 
3077  return ret;
3078 }
3079 
3081 {
3082  AVFormatContext *fmt_ctx = ifile->fmt_ctx;
3083  char val_str[128];
3084  int64_t size = fmt_ctx->pb ? avio_size(fmt_ctx->pb) : -1;
3085  int ret = 0;
3086 
3088  print_str_validate("filename", fmt_ctx->url);
3089  print_int("nb_streams", fmt_ctx->nb_streams);
3090  print_int("nb_programs", fmt_ctx->nb_programs);
3091  print_str("format_name", fmt_ctx->iformat->name);
3092  if (!do_bitexact) {
3093  if (fmt_ctx->iformat->long_name) print_str ("format_long_name", fmt_ctx->iformat->long_name);
3094  else print_str_opt("format_long_name", "unknown");
3095  }
3096  print_time("start_time", fmt_ctx->start_time, &AV_TIME_BASE_Q);
3097  print_time("duration", fmt_ctx->duration, &AV_TIME_BASE_Q);
3098  if (size >= 0) print_val ("size", size, unit_byte_str);
3099  else print_str_opt("size", "N/A");
3101  else print_str_opt("bit_rate", "N/A");
3102  print_int("probe_score", fmt_ctx->probe_score);
3103  if (do_show_format_tags)
3105 
3107  fflush(stdout);
3108  return ret;
3109 }
3110 
3111 static void show_error(WriterContext *w, int err)
3112 {
3113  char errbuf[128];
3114  const char *errbuf_ptr = errbuf;
3115 
3116  if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)
3117  errbuf_ptr = strerror(AVUNERROR(err));
3118 
3120  print_int("code", err);
3121  print_str("string", errbuf_ptr);
3123 }
3124 
3125 static int open_input_file(InputFile *ifile, const char *filename,
3126  const char *print_filename)
3127 {
3128  int err, i;
3130  const AVDictionaryEntry *t = NULL;
3131  int scan_all_pmts_set = 0;
3132 
3134  if (!fmt_ctx) {
3135  print_error(filename, AVERROR(ENOMEM));
3136  exit_program(1);
3137  }
3138 
3139  if (!av_dict_get(format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
3140  av_dict_set(&format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE);
3141  scan_all_pmts_set = 1;
3142  }
3143  if ((err = avformat_open_input(&fmt_ctx, filename,
3144  iformat, &format_opts)) < 0) {
3145  print_error(filename, err);
3146  return err;
3147  }
3148  if (print_filename) {
3149  av_freep(&fmt_ctx->url);
3150  fmt_ctx->url = av_strdup(print_filename);
3151  }
3152  ifile->fmt_ctx = fmt_ctx;
3153  if (scan_all_pmts_set)
3154  av_dict_set(&format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
3155  while ((t = av_dict_get(format_opts, "", t, AV_DICT_IGNORE_SUFFIX)))
3156  av_log(NULL, AV_LOG_WARNING, "Option %s skipped - not known to demuxer.\n", t->key);
3157 
3158  if (find_stream_info) {
3160  int orig_nb_streams = fmt_ctx->nb_streams;
3161 
3163 
3164  for (i = 0; i < orig_nb_streams; i++)
3165  av_dict_free(&opts[i]);
3166  av_freep(&opts);
3167 
3168  if (err < 0) {
3169  print_error(filename, err);
3170  return err;
3171  }
3172  }
3173 
3174  av_dump_format(fmt_ctx, 0, filename, 0);
3175 
3176  ifile->streams = av_calloc(fmt_ctx->nb_streams, sizeof(*ifile->streams));
3177  if (!ifile->streams)
3178  exit(1);
3179  ifile->nb_streams = fmt_ctx->nb_streams;
3180 
3181  /* bind a decoder to each input stream */
3182  for (i = 0; i < fmt_ctx->nb_streams; i++) {
3183  InputStream *ist = &ifile->streams[i];
3184  AVStream *stream = fmt_ctx->streams[i];
3185  const AVCodec *codec;
3186 
3187  ist->st = stream;
3188 
3189  if (stream->codecpar->codec_id == AV_CODEC_ID_PROBE) {
3191  "Failed to probe codec for input stream %d\n",
3192  stream->index);
3193  continue;
3194  }
3195 
3196  codec = avcodec_find_decoder(stream->codecpar->codec_id);
3197  if (!codec) {
3199  "Unsupported codec with id %d for input stream %d\n",
3200  stream->codecpar->codec_id, stream->index);
3201  continue;
3202  }
3203  {
3205  fmt_ctx, stream, codec);
3206 
3207  ist->dec_ctx = avcodec_alloc_context3(codec);
3208  if (!ist->dec_ctx)
3209  exit(1);
3210 
3211  err = avcodec_parameters_to_context(ist->dec_ctx, stream->codecpar);
3212  if (err < 0)
3213  exit(1);
3214 
3215  if (do_show_log) {
3216  // For loging it is needed to disable at least frame threads as otherwise
3217  // the log information would need to be reordered and matches up to contexts and frames
3218  // That is in fact possible but not trivial
3219  av_dict_set(&codec_opts, "threads", "1", 0);
3220  }
3221 
3222  ist->dec_ctx->pkt_timebase = stream->time_base;
3223 
3224  if (avcodec_open2(ist->dec_ctx, codec, &opts) < 0) {
3225  av_log(NULL, AV_LOG_WARNING, "Could not open codec for input stream %d\n",
3226  stream->index);
3227  exit(1);
3228  }
3229 
3230  if ((t = av_dict_get(opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
3231  av_log(NULL, AV_LOG_ERROR, "Option %s for input stream %d not found\n",
3232  t->key, stream->index);
3233  return AVERROR_OPTION_NOT_FOUND;
3234  }
3235  }
3236  }
3237 
3238  ifile->fmt_ctx = fmt_ctx;
3239  return 0;
3240 }
3241 
3243 {
3244  int i;
3245 
3246  /* close decoder for each stream */
3247  for (i = 0; i < ifile->nb_streams; i++)
3248  avcodec_free_context(&ifile->streams[i].dec_ctx);
3249 
3250  av_freep(&ifile->streams);
3251  ifile->nb_streams = 0;
3252 
3253  avformat_close_input(&ifile->fmt_ctx);
3254 }
3255 
3256 static int probe_file(WriterContext *wctx, const char *filename,
3257  const char *print_filename)
3258 {
3259  InputFile ifile = { 0 };
3260  int ret, i;
3261  int section_id;
3262 
3265 
3266  ret = open_input_file(&ifile, filename, print_filename);
3267  if (ret < 0)
3268  goto end;
3269 
3270 #define CHECK_END if (ret < 0) goto end
3271 
3272  nb_streams = ifile.fmt_ctx->nb_streams;
3273  REALLOCZ_ARRAY_STREAM(nb_streams_frames,0,ifile.fmt_ctx->nb_streams);
3274  REALLOCZ_ARRAY_STREAM(nb_streams_packets,0,ifile.fmt_ctx->nb_streams);
3275  REALLOCZ_ARRAY_STREAM(selected_streams,0,ifile.fmt_ctx->nb_streams);
3276 
3277  for (i = 0; i < ifile.fmt_ctx->nb_streams; i++) {
3278  if (stream_specifier) {
3280  ifile.fmt_ctx->streams[i],
3282  CHECK_END;
3283  else
3284  selected_streams[i] = ret;
3285  ret = 0;
3286  } else {
3287  selected_streams[i] = 1;
3288  }
3289  if (!selected_streams[i])
3290  ifile.fmt_ctx->streams[i]->discard = AVDISCARD_ALL;
3291  }
3292 
3296  section_id = SECTION_ID_PACKETS_AND_FRAMES;
3297  else if (do_show_packets && !do_show_frames)
3298  section_id = SECTION_ID_PACKETS;
3299  else // (!do_show_packets && do_show_frames)
3300  section_id = SECTION_ID_FRAMES;
3302  writer_print_section_header(wctx, section_id);
3303  ret = read_packets(wctx, &ifile);
3306  CHECK_END;
3307  }
3308 
3309  if (do_show_programs) {
3310  ret = show_programs(wctx, &ifile);
3311  CHECK_END;
3312  }
3313 
3314  if (do_show_streams) {
3315  ret = show_streams(wctx, &ifile);
3316  CHECK_END;
3317  }
3318  if (do_show_chapters) {
3319  ret = show_chapters(wctx, &ifile);
3320  CHECK_END;
3321  }
3322  if (do_show_format) {
3323  ret = show_format(wctx, &ifile);
3324  CHECK_END;
3325  }
3326 
3327 end:
3328  if (ifile.fmt_ctx)
3333 
3334  return ret;
3335 }
3336 
3337 static void show_usage(void)
3338 {
3339  av_log(NULL, AV_LOG_INFO, "Simple multimedia streams analyzer\n");
3340  av_log(NULL, AV_LOG_INFO, "usage: %s [OPTIONS] [INPUT_FILE]\n", program_name);
3341  av_log(NULL, AV_LOG_INFO, "\n");
3342 }
3343 
3345 {
3346  AVBPrint pbuf;
3348 
3350  print_str("version", FFMPEG_VERSION);
3351  print_fmt("copyright", "Copyright (c) %d-%d the FFmpeg developers",
3352  program_birth_year, CONFIG_THIS_YEAR);
3353  print_str("compiler_ident", CC_IDENT);
3354  print_str("configuration", FFMPEG_CONFIGURATION);
3356 
3357  av_bprint_finalize(&pbuf, NULL);
3358 }
3359 
3360 #define SHOW_LIB_VERSION(libname, LIBNAME) \
3361  do { \
3362  if (CONFIG_##LIBNAME) { \
3363  unsigned int version = libname##_version(); \
3364  writer_print_section_header(w, SECTION_ID_LIBRARY_VERSION); \
3365  print_str("name", "lib" #libname); \
3366  print_int("major", LIB##LIBNAME##_VERSION_MAJOR); \
3367  print_int("minor", LIB##LIBNAME##_VERSION_MINOR); \
3368  print_int("micro", LIB##LIBNAME##_VERSION_MICRO); \
3369  print_int("version", version); \
3370  print_str("ident", LIB##LIBNAME##_IDENT); \
3371  writer_print_section_footer(w); \
3372  } \
3373  } while (0)
3374 
3376 {
3378  SHOW_LIB_VERSION(avutil, AVUTIL);
3379  SHOW_LIB_VERSION(avcodec, AVCODEC);
3380  SHOW_LIB_VERSION(avformat, AVFORMAT);
3381  SHOW_LIB_VERSION(avdevice, AVDEVICE);
3382  SHOW_LIB_VERSION(avfilter, AVFILTER);
3383  SHOW_LIB_VERSION(swscale, SWSCALE);
3384  SHOW_LIB_VERSION(swresample, SWRESAMPLE);
3385  SHOW_LIB_VERSION(postproc, POSTPROC);
3387 }
3388 
3389 #define PRINT_PIX_FMT_FLAG(flagname, name) \
3390  do { \
3391  print_int(name, !!(pixdesc->flags & AV_PIX_FMT_FLAG_##flagname)); \
3392  } while (0)
3393 
3395 {
3396  const AVPixFmtDescriptor *pixdesc = NULL;
3397  int i, n;
3398 
3400  while (pixdesc = av_pix_fmt_desc_next(pixdesc)) {
3402  print_str("name", pixdesc->name);
3403  print_int("nb_components", pixdesc->nb_components);
3404  if ((pixdesc->nb_components >= 3) && !(pixdesc->flags & AV_PIX_FMT_FLAG_RGB)) {
3405  print_int ("log2_chroma_w", pixdesc->log2_chroma_w);
3406  print_int ("log2_chroma_h", pixdesc->log2_chroma_h);
3407  } else {
3408  print_str_opt("log2_chroma_w", "N/A");
3409  print_str_opt("log2_chroma_h", "N/A");
3410  }
3411  n = av_get_bits_per_pixel(pixdesc);
3412  if (n) print_int ("bits_per_pixel", n);
3413  else print_str_opt("bits_per_pixel", "N/A");
3416  PRINT_PIX_FMT_FLAG(BE, "big_endian");
3417  PRINT_PIX_FMT_FLAG(PAL, "palette");
3418  PRINT_PIX_FMT_FLAG(BITSTREAM, "bitstream");
3419  PRINT_PIX_FMT_FLAG(HWACCEL, "hwaccel");
3420  PRINT_PIX_FMT_FLAG(PLANAR, "planar");
3421  PRINT_PIX_FMT_FLAG(RGB, "rgb");
3422  PRINT_PIX_FMT_FLAG(ALPHA, "alpha");
3424  }
3425  if (do_show_pixel_format_components && (pixdesc->nb_components > 0)) {
3427  for (i = 0; i < pixdesc->nb_components; i++) {
3429  print_int("index", i + 1);
3430  print_int("bit_depth", pixdesc->comp[i].depth);
3432  }
3434  }
3436  }
3438 }
3439 
3440 static int opt_show_optional_fields(void *optctx, const char *opt, const char *arg)
3441 {
3445 
3448  return 0;
3449 }
3450 
3451 static int opt_format(void *optctx, const char *opt, const char *arg)
3452 {
3454  if (!iformat) {
3455  av_log(NULL, AV_LOG_ERROR, "Unknown input format: %s\n", arg);
3456  return AVERROR(EINVAL);
3457  }
3458  return 0;
3459 }
3460 
3461 static inline void mark_section_show_entries(SectionID section_id,
3462  int show_all_entries, AVDictionary *entries)
3463 {
3464  struct section *section = &sections[section_id];
3465 
3467  if (show_all_entries) {
3468  SectionID *id;
3469  for (id = section->children_ids; *id != -1; id++)
3471  } else {
3472  av_dict_copy(&section->entries_to_show, entries, 0);
3473  }
3474 }
3475 
3476 static int match_section(const char *section_name,
3477  int show_all_entries, AVDictionary *entries)
3478 {
3479  int i, ret = 0;
3480 
3481  for (i = 0; i < FF_ARRAY_ELEMS(sections); i++) {
3482  const struct section *section = &sections[i];
3483  if (!strcmp(section_name, section->name) ||
3484  (section->unique_name && !strcmp(section_name, section->unique_name))) {
3486  "'%s' matches section with unique name '%s'\n", section_name,
3488  ret++;
3490  }
3491  }
3492  return ret;
3493 }
3494 
3495 static int opt_show_entries(void *optctx, const char *opt, const char *arg)
3496 {
3497  const char *p = arg;
3498  int ret = 0;
3499 
3500  while (*p) {
3501  AVDictionary *entries = NULL;
3502  char *section_name = av_get_token(&p, "=:");
3503  int show_all_entries = 0;
3504 
3505  if (!section_name) {
3507  "Missing section name for option '%s'\n", opt);
3508  return AVERROR(EINVAL);
3509  }
3510 
3511  if (*p == '=') {
3512  p++;
3513  while (*p && *p != ':') {
3514  char *entry = av_get_token(&p, ",:");
3515  if (!entry)
3516  break;
3518  "Adding '%s' to the entries to show in section '%s'\n",
3519  entry, section_name);
3520  av_dict_set(&entries, entry, "", AV_DICT_DONT_STRDUP_KEY);
3521  if (*p == ',')
3522  p++;
3523  }
3524  } else {
3525  show_all_entries = 1;
3526  }
3527 
3528  ret = match_section(section_name, show_all_entries, entries);
3529  if (ret == 0) {
3530  av_log(NULL, AV_LOG_ERROR, "No match for section '%s'\n", section_name);
3531  ret = AVERROR(EINVAL);
3532  }
3533  av_dict_free(&entries);
3534  av_free(section_name);
3535 
3536  if (ret <= 0)
3537  break;
3538  if (*p)
3539  p++;
3540  }
3541 
3542  return ret;
3543 }
3544 
3545 static int opt_show_format_entry(void *optctx, const char *opt, const char *arg)
3546 {
3547  char *buf = av_asprintf("format=%s", arg);
3548  int ret;
3549 
3550  if (!buf)
3551  return AVERROR(ENOMEM);
3552 
3554  "Option '%s' is deprecated, use '-show_entries format=%s' instead\n",
3555  opt, arg);
3556  ret = opt_show_entries(optctx, opt, buf);
3557  av_free(buf);
3558  return ret;
3559 }
3560 
3561 static void opt_input_file(void *optctx, const char *arg)
3562 {
3563  if (input_filename) {
3565  "Argument '%s' provided as input filename, but '%s' was already specified.\n",
3566  arg, input_filename);
3567  exit_program(1);
3568  }
3569  if (!strcmp(arg, "-"))
3570  arg = "pipe:";
3571  input_filename = arg;
3572 }
3573 
3574 static int opt_input_file_i(void *optctx, const char *opt, const char *arg)
3575 {
3576  opt_input_file(optctx, arg);
3577  return 0;
3578 }
3579 
3580 static int opt_print_filename(void *optctx, const char *opt, const char *arg)
3581 {
3583  return 0;
3584 }
3585 
3586 void show_help_default(const char *opt, const char *arg)
3587 {
3589  show_usage();
3590  show_help_options(options, "Main options:", 0, 0, 0);
3591  printf("\n");
3592 
3595 }
3596 
3597 /**
3598  * Parse interval specification, according to the format:
3599  * INTERVAL ::= [START|+START_OFFSET][%[END|+END_OFFSET]]
3600  * INTERVALS ::= INTERVAL[,INTERVALS]
3601 */
3602 static int parse_read_interval(const char *interval_spec,
3603  ReadInterval *interval)
3604 {
3605  int ret = 0;
3606  char *next, *p, *spec = av_strdup(interval_spec);
3607  if (!spec)
3608  return AVERROR(ENOMEM);
3609 
3610  if (!*spec) {
3611  av_log(NULL, AV_LOG_ERROR, "Invalid empty interval specification\n");
3612  ret = AVERROR(EINVAL);
3613  goto end;
3614  }
3615 
3616  p = spec;
3617  next = strchr(spec, '%');
3618  if (next)
3619  *next++ = 0;
3620 
3621  /* parse first part */
3622  if (*p) {
3623  interval->has_start = 1;
3624 
3625  if (*p == '+') {
3626  interval->start_is_offset = 1;
3627  p++;
3628  } else {
3629  interval->start_is_offset = 0;
3630  }
3631 
3632  ret = av_parse_time(&interval->start, p, 1);
3633  if (ret < 0) {
3634  av_log(NULL, AV_LOG_ERROR, "Invalid interval start specification '%s'\n", p);
3635  goto end;
3636  }
3637  } else {
3638  interval->has_start = 0;
3639  }
3640 
3641  /* parse second part */
3642  p = next;
3643  if (p && *p) {
3644  int64_t us;
3645  interval->has_end = 1;
3646 
3647  if (*p == '+') {
3648  interval->end_is_offset = 1;
3649  p++;
3650  } else {
3651  interval->end_is_offset = 0;
3652  }
3653 
3654  if (interval->end_is_offset && *p == '#') {
3655  long long int lli;
3656  char *tail;
3657  interval->duration_frames = 1;
3658  p++;
3659  lli = strtoll(p, &tail, 10);
3660  if (*tail || lli < 0) {
3662  "Invalid or negative value '%s' for duration number of frames\n", p);
3663  goto end;
3664  }
3665  interval->end = lli;
3666  } else {
3667  interval->duration_frames = 0;
3668  ret = av_parse_time(&us, p, 1);
3669  if (ret < 0) {
3670  av_log(NULL, AV_LOG_ERROR, "Invalid interval end/duration specification '%s'\n", p);
3671  goto end;
3672  }
3673  interval->end = us;
3674  }
3675  } else {
3676  interval->has_end = 0;
3677  }
3678 
3679 end:
3680  av_free(spec);
3681  return ret;
3682 }
3683 
3684 static int parse_read_intervals(const char *intervals_spec)
3685 {
3686  int ret, n, i;
3687  char *p, *spec = av_strdup(intervals_spec);
3688  if (!spec)
3689  return AVERROR(ENOMEM);
3690 
3691  /* preparse specification, get number of intervals */
3692  for (n = 0, p = spec; *p; p++)
3693  if (*p == ',')
3694  n++;
3695  n++;
3696 
3698  if (!read_intervals) {
3699  ret = AVERROR(ENOMEM);
3700  goto end;
3701  }
3702  read_intervals_nb = n;
3703 
3704  /* parse intervals */
3705  p = spec;
3706  for (i = 0; p; i++) {
3707  char *next;
3708 
3710  next = strchr(p, ',');
3711  if (next)
3712  *next++ = 0;
3713 
3714  read_intervals[i].id = i;
3716  if (ret < 0) {
3717  av_log(NULL, AV_LOG_ERROR, "Error parsing read interval #%d '%s'\n",
3718  i, p);
3719  goto end;
3720  }
3721  av_log(NULL, AV_LOG_VERBOSE, "Parsed log interval ");
3723  p = next;
3724  }
3726 
3727 end:
3728  av_free(spec);
3729  return ret;
3730 }
3731 
3732 static int opt_read_intervals(void *optctx, const char *opt, const char *arg)
3733 {
3734  return parse_read_intervals(arg);
3735 }
3736 
3737 static int opt_pretty(void *optctx, const char *opt, const char *arg)
3738 {
3739  show_value_unit = 1;
3740  use_value_prefix = 1;
3743  return 0;
3744 }
3745 
3746 static void print_section(SectionID id, int level)
3747 {
3748  const SectionID *pid;
3749  const struct section *section = &sections[id];
3750  printf("%c%c%c",
3751  section->flags & SECTION_FLAG_IS_WRAPPER ? 'W' : '.',
3752  section->flags & SECTION_FLAG_IS_ARRAY ? 'A' : '.',
3754  printf("%*c %s", level * 4, ' ', section->name);
3755  if (section->unique_name)
3756  printf("/%s", section->unique_name);
3757  printf("\n");
3758 
3759  for (pid = section->children_ids; *pid != -1; pid++)
3760  print_section(*pid, level+1);
3761 }
3762 
3763 static int opt_sections(void *optctx, const char *opt, const char *arg)
3764 {
3765  printf("Sections:\n"
3766  "W.. = Section is a wrapper (contains other sections, no local entries)\n"
3767  ".A. = Section contains an array of elements of the same type\n"
3768  "..V = Section may contain a variable number of fields with variable keys\n"
3769  "FLAGS NAME/UNIQUE_NAME\n"
3770  "---\n");
3772  return 0;
3773 }
3774 
3775 static int opt_show_versions(void *optctx, const char *opt, const char *arg)
3776 {
3779  return 0;
3780 }
3781 
3782 #define DEFINE_OPT_SHOW_SECTION(section, target_section_id) \
3783  static int opt_show_##section(void *optctx, const char *opt, const char *arg) \
3784  { \
3785  mark_section_show_entries(SECTION_ID_##target_section_id, 1, NULL); \
3786  return 0; \
3787  }
3788 
3789 DEFINE_OPT_SHOW_SECTION(chapters, CHAPTERS)
3793 DEFINE_OPT_SHOW_SECTION(library_versions, LIBRARY_VERSIONS)
3794 DEFINE_OPT_SHOW_SECTION(packets, PACKETS)
3795 DEFINE_OPT_SHOW_SECTION(pixel_formats, PIXEL_FORMATS)
3796 DEFINE_OPT_SHOW_SECTION(program_version, PROGRAM_VERSION)
3797 DEFINE_OPT_SHOW_SECTION(streams, STREAMS)
3798 DEFINE_OPT_SHOW_SECTION(programs, PROGRAMS)
3799 
3800 static const OptionDef real_options[] = {
3802  { "f", HAS_ARG, {.func_arg = opt_format}, "force format", "format" },
3803  { "unit", OPT_BOOL, {&show_value_unit}, "show unit of the displayed values" },
3804  { "prefix", OPT_BOOL, {&use_value_prefix}, "use SI prefixes for the displayed values" },
3805  { "byte_binary_prefix", OPT_BOOL, {&use_byte_value_binary_prefix},
3806  "use binary prefixes for byte units" },
3807  { "sexagesimal", OPT_BOOL, {&use_value_sexagesimal_format},
3808  "use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units" },
3809  { "pretty", 0, {.func_arg = opt_pretty},
3810  "prettify the format of displayed values, make it more human readable" },
3811  { "print_format", OPT_STRING | HAS_ARG, { &print_format },
3812  "set the output printing format (available formats are: default, compact, csv, flat, ini, json, xml)", "format" },
3813  { "of", OPT_STRING | HAS_ARG, { &print_format }, "alias for -print_format", "format" },
3814  { "select_streams", OPT_STRING | HAS_ARG, { &stream_specifier }, "select the specified streams", "stream_specifier" },
3815  { "sections", OPT_EXIT, {.func_arg = opt_sections}, "print sections structure and section information, and exit" },
3816  { "show_data", OPT_BOOL, { &do_show_data }, "show packets data" },
3817  { "show_data_hash", OPT_STRING | HAS_ARG, { &show_data_hash }, "show packets data hash" },
3818  { "show_error", 0, { .func_arg = &opt_show_error }, "show probing error" },
3819  { "show_format", 0, { .func_arg = &opt_show_format }, "show format/container info" },
3820  { "show_frames", 0, { .func_arg = &opt_show_frames }, "show frames info" },
3821  { "show_format_entry", HAS_ARG, {.func_arg = opt_show_format_entry},
3822  "show a particular entry from the format/container info", "entry" },
3823  { "show_entries", HAS_ARG, {.func_arg = opt_show_entries},
3824  "show a set of specified entries", "entry_list" },
3825 #if HAVE_THREADS
3826  { "show_log", OPT_INT|HAS_ARG, { &do_show_log }, "show log" },
3827 #endif
3828  { "show_packets", 0, { .func_arg = &opt_show_packets }, "show packets info" },
3829  { "show_programs", 0, { .func_arg = &opt_show_programs }, "show programs info" },
3830  { "show_streams", 0, { .func_arg = &opt_show_streams }, "show streams info" },
3831  { "show_chapters", 0, { .func_arg = &opt_show_chapters }, "show chapters info" },
3832  { "count_frames", OPT_BOOL, { &do_count_frames }, "count the number of frames per stream" },
3833  { "count_packets", OPT_BOOL, { &do_count_packets }, "count the number of packets per stream" },
3834  { "show_program_version", 0, { .func_arg = &opt_show_program_version }, "show ffprobe version" },
3835  { "show_library_versions", 0, { .func_arg = &opt_show_library_versions }, "show library versions" },
3836  { "show_versions", 0, { .func_arg = &opt_show_versions }, "show program and library versions" },
3837  { "show_pixel_formats", 0, { .func_arg = &opt_show_pixel_formats }, "show pixel format descriptions" },
3838  { "show_optional_fields", HAS_ARG, { .func_arg = &opt_show_optional_fields }, "show optional fields" },
3839  { "show_private_data", OPT_BOOL, { &show_private_data }, "show private data" },
3840  { "private", OPT_BOOL, { &show_private_data }, "same as show_private_data" },
3841  { "bitexact", OPT_BOOL, {&do_bitexact}, "force bitexact output" },
3842  { "read_intervals", HAS_ARG, {.func_arg = opt_read_intervals}, "set read intervals", "read_intervals" },
3843  { "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {.func_arg = opt_default}, "generic catch all option", "" },
3844  { "i", HAS_ARG, {.func_arg = opt_input_file_i}, "read specified file", "input_file"},
3845  { "print_filename", HAS_ARG, {.func_arg = opt_print_filename}, "override the printed input filename", "print_file"},
3846  { "find_stream_info", OPT_BOOL | OPT_INPUT | OPT_EXPERT, { &find_stream_info },
3847  "read and decode the streams to fill missing information with heuristics" },
3848  { NULL, },
3849 };
3850 
3851 static inline int check_section_show_entries(int section_id)
3852 {
3853  int *id;
3854  struct section *section = &sections[section_id];
3855  if (sections[section_id].show_all_entries || sections[section_id].entries_to_show)
3856  return 1;
3857  for (id = section->children_ids; *id != -1; id++)
3858  if (check_section_show_entries(*id))
3859  return 1;
3860  return 0;
3861 }
3862 
3863 #define SET_DO_SHOW(id, varname) do { \
3864  if (check_section_show_entries(SECTION_ID_##id)) \
3865  do_show_##varname = 1; \
3866  } while (0)
3867 
3868 int main(int argc, char **argv)
3869 {
3870  const Writer *w;
3871  WriterContext *wctx;
3872  char *buf;
3873  char *w_name = NULL, *w_args = NULL;
3874  int ret, i;
3875 
3876  init_dynload();
3877 
3878 #if HAVE_THREADS
3879  ret = pthread_mutex_init(&log_mutex, NULL);
3880  if (ret != 0) {
3881  goto end;
3882  }
3883 #endif
3886 
3888  parse_loglevel(argc, argv, options);
3890 #if CONFIG_AVDEVICE
3892 #endif
3893 
3894  show_banner(argc, argv, options);
3895  parse_options(NULL, argc, argv, options, opt_input_file);
3896 
3897  if (do_show_log)
3899 
3900  /* mark things to show, based on -show_entries */
3901  SET_DO_SHOW(CHAPTERS, chapters);
3903  SET_DO_SHOW(FORMAT, format);
3904  SET_DO_SHOW(FRAMES, frames);
3905  SET_DO_SHOW(LIBRARY_VERSIONS, library_versions);
3906  SET_DO_SHOW(PACKETS, packets);
3907  SET_DO_SHOW(PIXEL_FORMATS, pixel_formats);
3908  SET_DO_SHOW(PIXEL_FORMAT_FLAGS, pixel_format_flags);
3909  SET_DO_SHOW(PIXEL_FORMAT_COMPONENTS, pixel_format_components);
3910  SET_DO_SHOW(PROGRAM_VERSION, program_version);
3911  SET_DO_SHOW(PROGRAMS, programs);
3912  SET_DO_SHOW(STREAMS, streams);
3913  SET_DO_SHOW(STREAM_DISPOSITION, stream_disposition);
3914  SET_DO_SHOW(PROGRAM_STREAM_DISPOSITION, stream_disposition);
3915 
3916  SET_DO_SHOW(CHAPTER_TAGS, chapter_tags);
3917  SET_DO_SHOW(FORMAT_TAGS, format_tags);
3918  SET_DO_SHOW(FRAME_TAGS, frame_tags);
3919  SET_DO_SHOW(PROGRAM_TAGS, program_tags);
3920  SET_DO_SHOW(STREAM_TAGS, stream_tags);
3921  SET_DO_SHOW(PROGRAM_STREAM_TAGS, stream_tags);
3922  SET_DO_SHOW(PACKET_TAGS, packet_tags);
3923 
3926  "-bitexact and -show_program_version or -show_library_versions "
3927  "options are incompatible\n");
3928  ret = AVERROR(EINVAL);
3929  goto end;
3930  }
3931 
3933 
3934  if (!print_format)
3935  print_format = av_strdup("default");
3936  if (!print_format) {
3937  ret = AVERROR(ENOMEM);
3938  goto end;
3939  }
3940  w_name = av_strtok(print_format, "=", &buf);
3941  if (!w_name) {
3943  "No name specified for the output format\n");
3944  ret = AVERROR(EINVAL);
3945  goto end;
3946  }
3947  w_args = buf;
3948 
3949  if (show_data_hash) {
3950  if ((ret = av_hash_alloc(&hash, show_data_hash)) < 0) {
3951  if (ret == AVERROR(EINVAL)) {
3952  const char *n;
3954  "Unknown hash algorithm '%s'\nKnown algorithms:",
3955  show_data_hash);
3956  for (i = 0; (n = av_hash_names(i)); i++)
3957  av_log(NULL, AV_LOG_ERROR, " %s", n);
3958  av_log(NULL, AV_LOG_ERROR, "\n");
3959  }
3960  goto end;
3961  }
3962  }
3963 
3964  w = writer_get_by_name(w_name);
3965  if (!w) {
3966  av_log(NULL, AV_LOG_ERROR, "Unknown output format with name '%s'\n", w_name);
3967  ret = AVERROR(EINVAL);
3968  goto end;
3969  }
3970 
3971  if ((ret = writer_open(&wctx, w, w_args,
3972  sections, FF_ARRAY_ELEMS(sections))) >= 0) {
3973  if (w == &xml_writer)
3975 
3977 
3984 
3985  if (!input_filename &&
3988  show_usage();
3989  av_log(NULL, AV_LOG_ERROR, "You have to specify one input file.\n");
3990  av_log(NULL, AV_LOG_ERROR, "Use -h to get full help or, even better, run 'man %s'.\n", program_name);
3991  ret = AVERROR(EINVAL);
3992  } else if (input_filename) {
3994  if (ret < 0 && do_show_error)
3995  show_error(wctx, ret);
3996  }
3997 
3999  writer_close(&wctx);
4000  }
4001 
4002 end:
4005  av_hash_freep(&hash);
4006 
4007  uninit_opts();
4008  for (i = 0; i < FF_ARRAY_ELEMS(sections); i++)
4010 
4012 
4013  return ret < 0;
4014 }
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:31
flat_escape_key_str
static const char * flat_escape_key_str(AVBPrint *dst, const char *src, const char sep)
Definition: ffprobe.c:1284
main
int main(int argc, char **argv)
Definition: ffprobe.c:3868
AVSubtitle
Definition: avcodec.h:2289
SECTION_ID_STREAM_SIDE_DATA_LIST
@ SECTION_ID_STREAM_SIDE_DATA_LIST
Definition: ffprobe.c:210
opt_format
static int opt_format(void *optctx, const char *opt, const char *arg)
Definition: ffprobe.c:3451
pthread_mutex_t
_fmutex pthread_mutex_t
Definition: os2threads.h:53
clear_log
static void clear_log(int need_lock)
Definition: ffprobe.c:2274
AVMasteringDisplayMetadata::has_primaries
int has_primaries
Flag indicating whether the display primaries (and white point) are set.
Definition: mastering_display_metadata.h:62
AVHDRPlusColorTransformParams::average_maxrgb
AVRational average_maxrgb
The average of linearized maxRGB values in the processing window in the scene.
Definition: hdr_dynamic_metadata.h:164
mark_section_show_entries
static void mark_section_show_entries(SectionID section_id, int show_all_entries, AVDictionary *entries)
Definition: ffprobe.c:3461
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:424
OPT_EXIT
#define OPT_EXIT
Definition: cmdutils.h:176
AVCodec
AVCodec.
Definition: codec.h:202
writer_get_by_name
static const Writer * writer_get_by_name(const char *name)
Definition: ffprobe.c:913
av_utf8_decode
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:376
AVDynamicHDRPlus::params
AVHDRPlusColorTransformParams params[3]
The color transform parameters for every processing window.
Definition: hdr_dynamic_metadata.h:264
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
flat_options
static const AVOption flat_options[]
Definition: ffprobe.c:1260
WriterContext::section_pbuf
AVBPrint section_pbuf[SECTION_MAX_NB_LEVELS]
generic print buffer dedicated to each section, used by various writers
Definition:</