MobileFFmpeg iOS / tvOS API  4.4
fftools_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 
26 /*
27  * CHANGES 01.2020
28  * - ffprobe support changes
29  * - Concurrent execution support
30  * - main() function renamed as ffprobe_execute()
31  */
32 
33 #include "config.h"
34 #include "libavutil/ffversion.h"
35 
36 #include <string.h>
37 
38 #include "libavformat/avformat.h"
39 #include "libavcodec/avcodec.h"
40 #include "libavutil/avassert.h"
41 #include "libavutil/avstring.h"
42 #include "libavutil/bprint.h"
43 #include "libavutil/display.h"
44 #include "libavutil/hash.h"
45 #include "libavutil/mastering_display_metadata.h"
46 #include "libavutil/opt.h"
47 #include "libavutil/pixdesc.h"
48 #include "libavutil/spherical.h"
49 #include "libavutil/stereo3d.h"
50 #include "libavutil/dict.h"
51 #include "libavutil/intreadwrite.h"
52 #include "libavutil/libm.h"
53 #include "libavutil/parseutils.h"
54 #include "libavutil/timecode.h"
55 #include "libavutil/timestamp.h"
56 #include "libavdevice/avdevice.h"
57 #include "libswscale/swscale.h"
58 #include "libswresample/swresample.h"
59 #include "fftools_cmdutils.h"
60 
61 #include "libavutil/thread.h"
62 
63 #include "mobileffmpeg_exception.h"
64 
65 #if !HAVE_THREADS
66 # ifdef pthread_mutex_lock
67 # undef pthread_mutex_lock
68 # endif
69 # define pthread_mutex_lock(a) do{}while(0)
70 # ifdef pthread_mutex_unlock
71 # undef pthread_mutex_unlock
72 # endif
73 # define pthread_mutex_unlock(a) do{}while(0)
74 #endif
75 
76 typedef struct InputStream {
77  AVStream *st;
78 
79  AVCodecContext *dec_ctx;
81 
82 typedef struct InputFile {
83  AVFormatContext *fmt_ctx;
84 
86  int nb_streams;
88 
89 __thread int do_bitexact = 0;
90 __thread int do_count_frames = 0;
91 __thread int do_count_packets = 0;
92 __thread int do_read_frames = 0;
93 __thread int do_read_packets = 0;
94 __thread int do_show_chapters = 0;
95 __thread int do_show_error = 0;
96 __thread int do_show_format = 0;
97 __thread int do_show_frames = 0;
98 __thread int do_show_packets = 0;
99 __thread int do_show_programs = 0;
100 __thread int do_show_streams = 0;
101 __thread int do_show_stream_disposition = 0;
102 __thread int do_show_data = 0;
103 __thread int do_show_program_version = 0;
104 __thread int do_show_library_versions = 0;
105 __thread int do_show_pixel_formats = 0;
106 __thread int do_show_pixel_format_flags = 0;
108 __thread int do_show_log = 0;
109 
110 __thread int do_show_chapter_tags = 0;
111 __thread int do_show_format_tags = 0;
112 __thread int do_show_frame_tags = 0;
113 __thread int do_show_program_tags = 0;
114 __thread int do_show_stream_tags = 0;
115 __thread int do_show_packet_tags = 0;
116 
117 __thread int show_value_unit = 0;
118 __thread int use_value_prefix = 0;
121 __thread int show_private_data = 1;
122 
123 __thread char *print_format;
124 __thread char *stream_specifier;
125 __thread char *show_data_hash;
126 
127 typedef struct ReadInterval {
128  int id;
129  int64_t start, end;
134 
136 __thread int read_intervals_nb = 0;
137 
138 /* section structure definition */
139 
140 #define SECTION_MAX_NB_CHILDREN 10
141 
142 struct section {
143  int id;
144  const char *name;
145 
146 #define SECTION_FLAG_IS_WRAPPER 1
147 #define SECTION_FLAG_IS_ARRAY 2
148 #define SECTION_FLAG_HAS_VARIABLE_FIELDS 4
149  int flags;
152  const char *element_name;
153  const char *unique_name;
154  AVDictionary *entries_to_show;
156 };
157 
158 typedef enum {
204 } SectionID;
205 
206 static struct section sections[] = {
208  [SECTION_ID_CHAPTER] = { SECTION_ID_CHAPTER, "chapter", 0, { SECTION_ID_CHAPTER_TAGS, -1 } },
209  [SECTION_ID_CHAPTER_TAGS] = { SECTION_ID_CHAPTER_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "chapter_tags" },
210  [SECTION_ID_ERROR] = { SECTION_ID_ERROR, "error", 0, { -1 } },
211  [SECTION_ID_FORMAT] = { SECTION_ID_FORMAT, "format", 0, { SECTION_ID_FORMAT_TAGS, -1 } },
212  [SECTION_ID_FORMAT_TAGS] = { SECTION_ID_FORMAT_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "format_tags" },
215  [SECTION_ID_FRAME_TAGS] = { SECTION_ID_FRAME_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "frame_tags" },
216  [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" },
221  [SECTION_ID_FRAME_LOG] = { SECTION_ID_FRAME_LOG, "log", 0, { -1 }, },
223  [SECTION_ID_LIBRARY_VERSION] = { SECTION_ID_LIBRARY_VERSION, "library_version", 0, { -1 } },
227  [SECTION_ID_PACKET_TAGS] = { SECTION_ID_PACKET_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "packet_tags" },
228  [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" },
229  [SECTION_ID_PACKET_SIDE_DATA] = { SECTION_ID_PACKET_SIDE_DATA, "side_data", 0, { -1 } },
232  [SECTION_ID_PIXEL_FORMAT_FLAGS] = { SECTION_ID_PIXEL_FORMAT_FLAGS, "flags", 0, { -1 }, .unique_name = "pixel_format_flags" },
233  [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" },
235  [SECTION_ID_PROGRAM_STREAM_DISPOSITION] = { SECTION_ID_PROGRAM_STREAM_DISPOSITION, "disposition", 0, { -1 }, .unique_name = "program_stream_disposition" },
236  [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" },
238  [SECTION_ID_PROGRAM_STREAMS] = { SECTION_ID_PROGRAM_STREAMS, "streams", SECTION_FLAG_IS_ARRAY, { SECTION_ID_PROGRAM_STREAM, -1 }, .unique_name = "program_streams" },
240  [SECTION_ID_PROGRAM_TAGS] = { SECTION_ID_PROGRAM_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "program_tags" },
241  [SECTION_ID_PROGRAM_VERSION] = { SECTION_ID_PROGRAM_VERSION, "program_version", 0, { -1 } },
249  [SECTION_ID_STREAM_DISPOSITION] = { SECTION_ID_STREAM_DISPOSITION, "disposition", 0, { -1 }, .unique_name = "stream_disposition" },
250  [SECTION_ID_STREAM_TAGS] = { SECTION_ID_STREAM_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "stream_tags" },
251  [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" },
252  [SECTION_ID_STREAM_SIDE_DATA] = { SECTION_ID_STREAM_SIDE_DATA, "side_data", 0, { -1 } },
253  [SECTION_ID_SUBTITLE] = { SECTION_ID_SUBTITLE, "subtitle", 0, { -1 } },
254 };
255 
256 __thread OptionDef *ffprobe_options = NULL;
257 
258 /* FFprobe context */
259 __thread const char *input_filename;
260 __thread AVInputFormat *iformat = NULL;
261 
262 __thread struct AVHashContext *hash;
263 
264 __thread volatile int main_ffprobe_return_code = 0;
265 extern __thread volatile int longjmp_value;
266 
267 static const struct {
268  double bin_val;
269  double dec_val;
270  const char *bin_str;
271  const char *dec_str;
272 } si_prefixes[] = {
273  { 1.0, 1.0, "", "" },
274  { 1.024e3, 1e3, "Ki", "K" },
275  { 1.048576e6, 1e6, "Mi", "M" },
276  { 1.073741824e9, 1e9, "Gi", "G" },
277  { 1.099511627776e12, 1e12, "Ti", "T" },
278  { 1.125899906842624e15, 1e15, "Pi", "P" },
279 };
280 
281 static const char unit_second_str[] = "s" ;
282 static const char unit_hertz_str[] = "Hz" ;
283 static const char unit_byte_str[] = "byte" ;
284 static const char unit_bit_per_second_str[] = "bit/s";
285 
286 __thread int nb_streams;
287 __thread uint64_t *nb_streams_packets;
288 __thread uint64_t *nb_streams_frames;
289 __thread int *selected_streams;
290 
291 #if HAVE_THREADS
292 __thread pthread_mutex_t log_mutex;
293 #endif
294 typedef struct LogBuffer {
297  char *log_message;
298  AVClassCategory category;
299  char *parent_name;
300  AVClassCategory parent_category;
302 
304 __thread int log_buffer_size;
305 
306 static void log_callback(void *ptr, int level, const char *fmt, va_list vl)
307 {
308  AVClass* avc = ptr ? *(AVClass **) ptr : NULL;
309  va_list vl2;
310  char line[1024];
311  static int print_prefix = 1;
312  void *new_log_buffer;
313 
314  va_copy(vl2, vl);
315  av_log_default_callback(ptr, level, fmt, vl);
316  av_log_format_line(ptr, level, fmt, vl2, line, sizeof(line), &print_prefix);
317  va_end(vl2);
318 
319 #if HAVE_THREADS
320  pthread_mutex_lock(&log_mutex);
321 
322  new_log_buffer = av_realloc_array(log_buffer, log_buffer_size + 1, sizeof(*log_buffer));
323  if (new_log_buffer) {
324  char *msg;
325  int i;
326 
327  log_buffer = new_log_buffer;
328  memset(&log_buffer[log_buffer_size], 0, sizeof(log_buffer[log_buffer_size]));
329  log_buffer[log_buffer_size].context_name= avc ? av_strdup(avc->item_name(ptr)) : NULL;
330  if (avc) {
331  if (avc->get_category) log_buffer[log_buffer_size].category = avc->get_category(ptr);
332  else log_buffer[log_buffer_size].category = avc->category;
333  }
335  msg = log_buffer[log_buffer_size].log_message = av_strdup(line);
336  for (i=strlen(msg) - 1; i>=0 && msg[i] == '\n'; i--) {
337  msg[i] = 0;
338  }
339  if (avc && avc->parent_log_context_offset) {
340  AVClass** parent = *(AVClass ***) (((uint8_t *) ptr) +
341  avc->parent_log_context_offset);
342  if (parent && *parent) {
343  log_buffer[log_buffer_size].parent_name = av_strdup((*parent)->item_name(parent));
345  (*parent)->get_category ? (*parent)->get_category(parent) :(*parent)->category;
346  }
347  }
348  log_buffer_size ++;
349  }
350 
351  pthread_mutex_unlock(&log_mutex);
352 #endif
353 }
354 
355 static void ffprobe_cleanup(int ret)
356 {
357  int i;
358  for (i = 0; i < FF_ARRAY_ELEMS(sections); i++)
359  av_dict_free(&(sections[i].entries_to_show));
360 
361 #if HAVE_THREADS
362  pthread_mutex_destroy(&log_mutex);
363 #endif
364 }
365 
366 struct unit_value {
367  union { double d; long long int i; } val;
368  const char *unit;
369 };
370 
371 static char *value_string(char *buf, int buf_size, struct unit_value uv)
372 {
373  double vald;
374  long long int vali;
375  int show_float = 0;
376 
377  if (uv.unit == unit_second_str) {
378  vald = uv.val.d;
379  show_float = 1;
380  } else {
381  vald = vali = uv.val.i;
382  }
383 
385  double secs;
386  int hours, mins;
387  secs = vald;
388  mins = (int)secs / 60;
389  secs = secs - mins * 60;
390  hours = mins / 60;
391  mins %= 60;
392  snprintf(buf, buf_size, "%d:%02d:%09.6f", hours, mins, secs);
393  } else {
394  const char *prefix_string = "";
395 
396  if (use_value_prefix && vald > 1) {
397  long long int index;
398 
400  index = (long long int) (log2(vald)) / 10;
401  index = av_clip(index, 0, FF_ARRAY_ELEMS(si_prefixes) - 1);
402  vald /= si_prefixes[index].bin_val;
403  prefix_string = si_prefixes[index].bin_str;
404  } else {
405  index = (long long int) (log10(vald)) / 3;
406  index = av_clip(index, 0, FF_ARRAY_ELEMS(si_prefixes) - 1);
407  vald /= si_prefixes[index].dec_val;
408  prefix_string = si_prefixes[index].dec_str;
409  }
410  vali = vald;
411  }
412 
413  if (show_float || (use_value_prefix && vald != (long long int)vald))
414  snprintf(buf, buf_size, "%f", vald);
415  else
416  snprintf(buf, buf_size, "%lld", vali);
417  av_strlcatf(buf, buf_size, "%s%s%s", *prefix_string || show_value_unit ? " " : "",
418  prefix_string, show_value_unit ? uv.unit : "");
419  }
420 
421  return buf;
422 }
423 
424 /* WRITERS API */
425 
426 typedef struct WriterContext WriterContext;
427 
428 #define WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS 1
429 #define WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER 2
430 
431 typedef enum {
437 
438 typedef struct Writer {
439  const AVClass *priv_class;
440  int priv_size;
441  const char *name;
442 
443  int (*init) (WriterContext *wctx);
444  void (*uninit)(WriterContext *wctx);
445 
448  void (*print_integer) (WriterContext *wctx, const char *, long long int);
449  void (*print_rational) (WriterContext *wctx, AVRational *q, char *sep);
450  void (*print_string) (WriterContext *wctx, const char *, const char *);
451  int flags;
453 
454 #define SECTION_MAX_NB_LEVELS 10
455 
457  const AVClass *class;
458  const Writer *writer;
459  char *name;
460  void *priv;
461 
462  const struct section *sections;
464 
465  int level;
466 
469 
473 
475  unsigned int nb_section_packet;
476  unsigned int nb_section_frame;
477  unsigned int nb_section_packet_frame;
478 
482 };
483 
484 static const char *writer_get_name(void *p)
485 {
486  WriterContext *wctx = p;
487  return wctx->writer->name;
488 }
489 
490 #define OFFSET(x) offsetof(WriterContext, x)
491 
492 static const AVOption writer_options[] = {
493  { "string_validation", "set string validation mode",
494  OFFSET(string_validation), AV_OPT_TYPE_INT, {.i64=WRITER_STRING_VALIDATION_REPLACE}, 0, WRITER_STRING_VALIDATION_NB-1, .unit = "sv" },
495  { "sv", "set string validation mode",
496  OFFSET(string_validation), AV_OPT_TYPE_INT, {.i64=WRITER_STRING_VALIDATION_REPLACE}, 0, WRITER_STRING_VALIDATION_NB-1, .unit = "sv" },
497  { "ignore", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = WRITER_STRING_VALIDATION_IGNORE}, .unit = "sv" },
498  { "replace", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = WRITER_STRING_VALIDATION_REPLACE}, .unit = "sv" },
499  { "fail", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = WRITER_STRING_VALIDATION_FAIL}, .unit = "sv" },
500  { "string_validation_replacement", "set string validation replacement string", OFFSET(string_validation_replacement), AV_OPT_TYPE_STRING, {.str=""}},
501  { "svr", "set string validation replacement string", OFFSET(string_validation_replacement), AV_OPT_TYPE_STRING, {.str="\xEF\xBF\xBD"}},
502  { NULL }
503 };
504 
505 static void *writer_child_next(void *obj, void *prev)
506 {
507  WriterContext *ctx = obj;
508  if (!prev && ctx->writer && ctx->writer->priv_class && ctx->priv)
509  return ctx->priv;
510  return NULL;
511 }
512 
513 static const AVClass writer_class = {
514  .class_name = "Writer",
515  .item_name = writer_get_name,
516  .option = writer_options,
517  .version = LIBAVUTIL_VERSION_INT,
518  .child_next = writer_child_next,
519 };
520 
521 static void writer_close(WriterContext **wctx)
522 {
523  int i;
524 
525  if (!*wctx)
526  return;
527 
528  if ((*wctx)->writer->uninit)
529  (*wctx)->writer->uninit(*wctx);
530  for (i = 0; i < SECTION_MAX_NB_LEVELS; i++)
531  av_bprint_finalize(&(*wctx)->section_pbuf[i], NULL);
532  if ((*wctx)->writer->priv_class)
533  av_opt_free((*wctx)->priv);
534  av_freep(&((*wctx)->priv));
535  av_opt_free(*wctx);
536  av_freep(wctx);
537 }
538 
539 static void bprint_bytes(AVBPrint *bp, const uint8_t *ubuf, size_t ubuf_size)
540 {
541  int i;
542  av_bprintf(bp, "0X");
543  for (i = 0; i < ubuf_size; i++)
544  av_bprintf(bp, "%02X", ubuf[i]);
545 }
546 
547 
548 static int writer_open(WriterContext **wctx, const Writer *writer, const char *args,
549  const struct section *sections, int nb_sections)
550 {
551  int i, ret = 0;
552 
553  if (!(*wctx = av_mallocz(sizeof(WriterContext)))) {
554  ret = AVERROR(ENOMEM);
555  goto fail;
556  }
557 
558  if (!((*wctx)->priv = av_mallocz(writer->priv_size))) {
559  ret = AVERROR(ENOMEM);
560  goto fail;
561  }
562 
563  (*wctx)->class = &writer_class;
564  (*wctx)->writer = writer;
565  (*wctx)->level = -1;
566  (*wctx)->sections = sections;
567  (*wctx)->nb_sections = nb_sections;
568 
569  av_opt_set_defaults(*wctx);
570 
571  if (writer->priv_class) {
572  void *priv_ctx = (*wctx)->priv;
573  *((const AVClass **)priv_ctx) = writer->priv_class;
574  av_opt_set_defaults(priv_ctx);
575  }
576 
577  /* convert options to dictionary */
578  if (args) {
579  AVDictionary *opts = NULL;
580  AVDictionaryEntry *opt = NULL;
581 
582  if ((ret = av_dict_parse_string(&opts, args, "=", ":", 0)) < 0) {
583  av_log(*wctx, AV_LOG_ERROR, "Failed to parse option string '%s' provided to writer context\n", args);
584  av_dict_free(&opts);
585  goto fail;
586  }
587 
588  while ((opt = av_dict_get(opts, "", opt, AV_DICT_IGNORE_SUFFIX))) {
589  if ((ret = av_opt_set(*wctx, opt->key, opt->value, AV_OPT_SEARCH_CHILDREN)) < 0) {
590  av_log(*wctx, AV_LOG_ERROR, "Failed to set option '%s' with value '%s' provided to writer context\n",
591  opt->key, opt->value);
592  av_dict_free(&opts);
593  goto fail;
594  }
595  }
596 
597  av_dict_free(&opts);
598  }
599 
600  /* validate replace string */
601  {
602  const uint8_t *p = (*wctx)->string_validation_replacement;
603  const uint8_t *endp = p + strlen(p);
604  while (*p) {
605  const uint8_t *p0 = p;
606  int32_t code;
607  ret = av_utf8_decode(&code, &p, endp, (*wctx)->string_validation_utf8_flags);
608  if (ret < 0) {
609  AVBPrint bp;
610  av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
611  bprint_bytes(&bp, p0, p-p0),
612  av_log(wctx, AV_LOG_ERROR,
613  "Invalid UTF8 sequence %s found in string validation replace '%s'\n",
614  bp.str, (*wctx)->string_validation_replacement);
615  return ret;
616  }
617  }
618  }
619 
620  for (i = 0; i < SECTION_MAX_NB_LEVELS; i++)
621  av_bprint_init(&(*wctx)->section_pbuf[i], 1, AV_BPRINT_SIZE_UNLIMITED);
622 
623  if ((*wctx)->writer->init)
624  ret = (*wctx)->writer->init(*wctx);
625  if (ret < 0)
626  goto fail;
627 
628  return 0;
629 
630 fail:
631  writer_close(wctx);
632  return ret;
633 }
634 
636  int section_id)
637 {
638  int parent_section_id;
639  wctx->level++;
640  av_assert0(wctx->level < SECTION_MAX_NB_LEVELS);
641  parent_section_id = wctx->level ?
642  (wctx->section[wctx->level-1])->id : SECTION_ID_NONE;
643 
644  wctx->nb_item[wctx->level] = 0;
645  wctx->section[wctx->level] = &wctx->sections[section_id];
646 
647  if (section_id == SECTION_ID_PACKETS_AND_FRAMES) {
648  wctx->nb_section_packet = wctx->nb_section_frame =
649  wctx->nb_section_packet_frame = 0;
650  } else if (parent_section_id == SECTION_ID_PACKETS_AND_FRAMES) {
651  wctx->nb_section_packet_frame = section_id == SECTION_ID_PACKET ?
652  wctx->nb_section_packet : wctx->nb_section_frame;
653  }
654 
655  if (wctx->writer->print_section_header)
656  wctx->writer->print_section_header(wctx);
657 }
658 
660 {
661  int section_id = wctx->section[wctx->level]->id;
662  int parent_section_id = wctx->level ?
663  wctx->section[wctx->level-1]->id : SECTION_ID_NONE;
664 
665  if (parent_section_id != SECTION_ID_NONE)
666  wctx->nb_item[wctx->level-1]++;
667  if (parent_section_id == SECTION_ID_PACKETS_AND_FRAMES) {
668  if (section_id == SECTION_ID_PACKET) wctx->nb_section_packet++;
669  else wctx->nb_section_frame++;
670  }
671  if (wctx->writer->print_section_footer)
672  wctx->writer->print_section_footer(wctx);
673  wctx->level--;
674 }
675 
676 static inline void writer_print_integer(WriterContext *wctx,
677  const char *key, long long int val)
678 {
679  const struct section *section = wctx->section[wctx->level];
680 
681  if (section->show_all_entries || av_dict_get(section->entries_to_show, key, NULL, 0)) {
682  wctx->writer->print_integer(wctx, key, val);
683  wctx->nb_item[wctx->level]++;
684  }
685 }
686 
687 static inline int validate_string(WriterContext *wctx, char **dstp, const char *src)
688 {
689  const uint8_t *p, *endp;
690  AVBPrint dstbuf;
691  int invalid_chars_nb = 0, ret = 0;
692 
693  av_bprint_init(&dstbuf, 0, AV_BPRINT_SIZE_UNLIMITED);
694 
695  endp = src + strlen(src);
696  for (p = (uint8_t *)src; *p;) {
697  uint32_t code;
698  int invalid = 0;
699  const uint8_t *p0 = p;
700 
701  if (av_utf8_decode(&code, &p, endp, wctx->string_validation_utf8_flags) < 0) {
702  AVBPrint bp;
703  av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
704  bprint_bytes(&bp, p0, p-p0);
705  av_log(wctx, AV_LOG_DEBUG,
706  "Invalid UTF-8 sequence %s found in string '%s'\n", bp.str, src);
707  invalid = 1;
708  }
709 
710  if (invalid) {
711  invalid_chars_nb++;
712 
713  switch (wctx->string_validation) {
715  av_log(wctx, AV_LOG_ERROR,
716  "Invalid UTF-8 sequence found in string '%s'\n", src);
717  ret = AVERROR_INVALIDDATA;
718  goto end;
719  break;
720 
722  av_bprintf(&dstbuf, "%s", wctx->string_validation_replacement);
723  break;
724  }
725  }
726 
727  if (!invalid || wctx->string_validation == WRITER_STRING_VALIDATION_IGNORE)
728  av_bprint_append_data(&dstbuf, p0, p-p0);
729  }
730 
731  if (invalid_chars_nb && wctx->string_validation == WRITER_STRING_VALIDATION_REPLACE) {
732  av_log(wctx, AV_LOG_WARNING,
733  "%d invalid UTF-8 sequence(s) found in string '%s', replaced with '%s'\n",
734  invalid_chars_nb, src, wctx->string_validation_replacement);
735  }
736 
737 end:
738  av_bprint_finalize(&dstbuf, dstp);
739  return ret;
740 }
741 
742 #define PRINT_STRING_OPT 1
743 #define PRINT_STRING_VALIDATE 2
744 
745 static inline int writer_print_string(WriterContext *wctx,
746  const char *key, const char *val, int flags)
747 {
748  const struct section *section = wctx->section[wctx->level];
749  int ret = 0;
750 
751  if ((flags & PRINT_STRING_OPT)
753  return 0;
754 
755  if (section->show_all_entries || av_dict_get(section->entries_to_show, key, NULL, 0)) {
757  char *key1 = NULL, *val1 = NULL;
758  ret = validate_string(wctx, &key1, key);
759  if (ret < 0) goto end;
760  ret = validate_string(wctx, &val1, val);
761  if (ret < 0) goto end;
762  wctx->writer->print_string(wctx, key1, val1);
763  end:
764  if (ret < 0) {
765  av_log(wctx, AV_LOG_ERROR,
766  "Invalid key=value string combination %s=%s in section %s\n",
767  key, val, section->unique_name);
768  }
769  av_free(key1);
770  av_free(val1);
771  } else {
772  wctx->writer->print_string(wctx, key, val);
773  }
774 
775  wctx->nb_item[wctx->level]++;
776  }
777 
778  return ret;
779 }
780 
781 static inline void writer_print_rational(WriterContext *wctx,
782  const char *key, AVRational q, char sep)
783 {
784  AVBPrint buf;
785  av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC);
786  av_bprintf(&buf, "%d%c%d", q.num, sep, q.den);
787  writer_print_string(wctx, key, buf.str, 0);
788 }
789 
790 static void writer_print_time(WriterContext *wctx, const char *key,
791  int64_t ts, const AVRational *time_base, int is_duration)
792 {
793  char buf[128];
794 
795  if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
796  writer_print_string(wctx, key, "N/A", PRINT_STRING_OPT);
797  } else {
798  double d = ts * av_q2d(*time_base);
799  struct unit_value uv;
800  uv.val.d = d;
801  uv.unit = unit_second_str;
802  value_string(buf, sizeof(buf), uv);
803  writer_print_string(wctx, key, buf, 0);
804  }
805 }
806 
807 static void writer_print_ts(WriterContext *wctx, const char *key, int64_t ts, int is_duration)
808 {
809  if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
810  writer_print_string(wctx, key, "N/A", PRINT_STRING_OPT);
811  } else {
812  writer_print_integer(wctx, key, ts);
813  }
814 }
815 
816 static void writer_print_data(WriterContext *wctx, const char *name,
817  uint8_t *data, int size)
818 {
819  AVBPrint bp;
820  int offset = 0, l, i;
821 
822  av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
823  av_bprintf(&bp, "\n");
824  while (size) {
825  av_bprintf(&bp, "%08x: ", offset);
826  l = FFMIN(size, 16);
827  for (i = 0; i < l; i++) {
828  av_bprintf(&bp, "%02x", data[i]);
829  if (i & 1)
830  av_bprintf(&bp, " ");
831  }
832  av_bprint_chars(&bp, ' ', 41 - 2 * i - i / 2);
833  for (i = 0; i < l; i++)
834  av_bprint_chars(&bp, data[i] - 32U < 95 ? data[i] : '.', 1);
835  av_bprintf(&bp, "\n");
836  offset += l;
837  data += l;
838  size -= l;
839  }
840  writer_print_string(wctx, name, bp.str, 0);
841  av_bprint_finalize(&bp, NULL);
842 }
843 
844 static void writer_print_data_hash(WriterContext *wctx, const char *name,
845  uint8_t *data, int size)
846 {
847  char *p, buf[AV_HASH_MAX_SIZE * 2 + 64] = { 0 };
848 
849  if (!hash)
850  return;
851  av_hash_init(hash);
852  av_hash_update(hash, data, size);
853  snprintf(buf, sizeof(buf), "%s:", av_hash_get_name(hash));
854  p = buf + strlen(buf);
855  av_hash_final_hex(hash, p, buf + sizeof(buf) - p);
856  writer_print_string(wctx, name, buf, 0);
857 }
858 
859 static void writer_print_integers(WriterContext *wctx, const char *name,
860  uint8_t *data, int size, const char *format,
861  int columns, int bytes, int offset_add)
862 {
863  AVBPrint bp;
864  int offset = 0, l, i;
865 
866  av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
867  av_bprintf(&bp, "\n");
868  while (size) {
869  av_bprintf(&bp, "%08x: ", offset);
870  l = FFMIN(size, columns);
871  for (i = 0; i < l; i++) {
872  if (bytes == 1) av_bprintf(&bp, format, *data);
873  else if (bytes == 2) av_bprintf(&bp, format, AV_RN16(data));
874  else if (bytes == 4) av_bprintf(&bp, format, AV_RN32(data));
875  data += bytes;
876  size --;
877  }
878  av_bprintf(&bp, "\n");
879  offset += offset_add;
880  }
881  writer_print_string(wctx, name, bp.str, 0);
882  av_bprint_finalize(&bp, NULL);
883 }
884 
885 #define MAX_REGISTERED_WRITERS_NB 64
886 
888 
889 __thread int next_registered_writer_idx = 0;
890 
891 static int writer_register(const Writer *writer)
892 {
894  return AVERROR(ENOMEM);
895 
897  return 0;
898 }
899 
900 static const Writer *writer_get_by_name(const char *name)
901 {
902  int i;
903 
904  for (i = 0; registered_writers[i]; i++)
905  if (!strcmp(registered_writers[i]->name, name))
906  return registered_writers[i];
907 
908  return NULL;
909 }
910 
911 
912 /* WRITERS */
913 
914 #define DEFINE_WRITER_CLASS(name) \
915 static const char *name##_get_name(void *ctx) \
916 { \
917  return #name ; \
918 } \
919 static const AVClass name##_class = { \
920  .class_name = #name, \
921  .item_name = name##_get_name, \
922  .option = name##_options \
923 }
924 
925 /* Default output */
926 
927 typedef struct DefaultContext {
928  const AVClass *class;
929  int nokey;
933 
934 #undef OFFSET
935 #define OFFSET(x) offsetof(DefaultContext, x)
936 
937 static const AVOption default_options[] = {
938  { "noprint_wrappers", "do not print headers and footers", OFFSET(noprint_wrappers), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
939  { "nw", "do not print headers and footers", OFFSET(noprint_wrappers), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
940  { "nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
941  { "nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
942  {NULL},
943 };
944 
946 
947 /* lame uppercasing routine, assumes the string is lower case ASCII */
948 static inline char *upcase_string(char *dst, size_t dst_size, const char *src)
949 {
950  int i;
951  for (i = 0; src[i] && i < dst_size-1; i++)
952  dst[i] = av_toupper(src[i]);
953  dst[i] = 0;
954  return dst;
955 }
956 
958 {
959  DefaultContext *def = wctx->priv;
960  char buf[32];
961  const struct section *section = wctx->section[wctx->level];
962  const struct section *parent_section = wctx->level ?
963  wctx->section[wctx->level-1] : NULL;
964 
965  av_bprint_clear(&wctx->section_pbuf[wctx->level]);
966  if (parent_section &&
967  !(parent_section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY))) {
968  def->nested_section[wctx->level] = 1;
969  av_bprintf(&wctx->section_pbuf[wctx->level], "%s%s:",
970  wctx->section_pbuf[wctx->level-1].str,
971  upcase_string(buf, sizeof(buf),
972  av_x_if_null(section->element_name, section->name)));
973  }
974 
975  if (def->noprint_wrappers || def->nested_section[wctx->level])
976  return;
977 
979  av_log(NULL, AV_LOG_STDERR, "[%s]\n", upcase_string(buf, sizeof(buf), section->name));
980 }
981 
983 {
984  DefaultContext *def = wctx->priv;
985  const struct section *section = wctx->section[wctx->level];
986  char buf[32];
987 
988  if (def->noprint_wrappers || def->nested_section[wctx->level])
989  return;
990 
992  av_log(NULL, AV_LOG_STDERR, "[/%s]\n", upcase_string(buf, sizeof(buf), section->name));
993 }
994 
995 static void default_print_str(WriterContext *wctx, const char *key, const char *value)
996 {
997  DefaultContext *def = wctx->priv;
998 
999  if (!def->nokey)
1000  av_log(NULL, AV_LOG_STDERR, "%s%s=", wctx->section_pbuf[wctx->level].str, key);
1001  av_log(NULL, AV_LOG_STDERR, "%s\n", value);
1002 }
1003 
1004 static void default_print_int(WriterContext *wctx, const char *key, long long int value)
1005 {
1006  DefaultContext *def = wctx->priv;
1007 
1008  if (!def->nokey)
1009  av_log(NULL, AV_LOG_STDERR, "%s%s=", wctx->section_pbuf[wctx->level].str, key);
1010  av_log(NULL, AV_LOG_STDERR, "%lld\n", value);
1011 }
1012 
1013 static const Writer default_writer = {
1014  .name = "default",
1015  .priv_size = sizeof(DefaultContext),
1018  .print_integer = default_print_int,
1019  .print_string = default_print_str,
1021  .priv_class = &default_class,
1022 };
1023 
1024 /* Compact output */
1025 
1029 static const char *c_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
1030 {
1031  const char *p;
1032 
1033  for (p = src; *p; p++) {
1034  switch (*p) {
1035  case '\b': av_bprintf(dst, "%s", "\\b"); break;
1036  case '\f': av_bprintf(dst, "%s", "\\f"); break;
1037  case '\n': av_bprintf(dst, "%s", "\\n"); break;
1038  case '\r': av_bprintf(dst, "%s", "\\r"); break;
1039  case '\\': av_bprintf(dst, "%s", "\\\\"); break;
1040  default:
1041  if (*p == sep)
1042  av_bprint_chars(dst, '\\', 1);
1043  av_bprint_chars(dst, *p, 1);
1044  }
1045  }
1046  return dst->str;
1047 }
1048 
1052 static const char *csv_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
1053 {
1054  char meta_chars[] = { sep, '"', '\n', '\r', '\0' };
1055  int needs_quoting = !!src[strcspn(src, meta_chars)];
1056 
1057  if (needs_quoting)
1058  av_bprint_chars(dst, '"', 1);
1059 
1060  for (; *src; src++) {
1061  if (*src == '"')
1062  av_bprint_chars(dst, '"', 1);
1063  av_bprint_chars(dst, *src, 1);
1064  }
1065  if (needs_quoting)
1066  av_bprint_chars(dst, '"', 1);
1067  return dst->str;
1068 }
1069 
1070 static const char *none_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
1071 {
1072  return src;
1073 }
1074 
1075 typedef struct CompactContext {
1076  const AVClass *class;
1078  char item_sep;
1079  int nokey;
1082  const char * (*escape_str)(AVBPrint *dst, const char *src, const char sep, void *log_ctx);
1087 
1088 #undef OFFSET
1089 #define OFFSET(x) offsetof(CompactContext, x)
1090 
1091 static const AVOption compact_options[]= {
1092  {"item_sep", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str="|"}, CHAR_MIN, CHAR_MAX },
1093  {"s", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str="|"}, CHAR_MIN, CHAR_MAX },
1094  {"nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1095  {"nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1096  {"escape", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="c"}, CHAR_MIN, CHAR_MAX },
1097  {"e", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="c"}, CHAR_MIN, CHAR_MAX },
1098  {"print_section", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1099  {"p", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1100  {NULL},
1101 };
1102 
1104 
1105 static av_cold int compact_init(WriterContext *wctx)
1106 {
1107  CompactContext *compact = wctx->priv;
1108 
1109  if (strlen(compact->item_sep_str) != 1) {
1110  av_log(wctx, AV_LOG_ERROR, "Item separator '%s' specified, but must contain a single character\n",
1111  compact->item_sep_str);
1112  return AVERROR(EINVAL);
1113  }
1114  compact->item_sep = compact->item_sep_str[0];
1115 
1116  if (!strcmp(compact->escape_mode_str, "none")) compact->escape_str = none_escape_str;
1117  else if (!strcmp(compact->escape_mode_str, "c" )) compact->escape_str = c_escape_str;
1118  else if (!strcmp(compact->escape_mode_str, "csv" )) compact->escape_str = csv_escape_str;
1119  else {
1120  av_log(wctx, AV_LOG_ERROR, "Unknown escape mode '%s'\n", compact->escape_mode_str);
1121  return AVERROR(EINVAL);
1122  }
1123 
1124  return 0;
1125 }
1126 
1128 {
1129  CompactContext *compact = wctx->priv;
1130  const struct section *section = wctx->section[wctx->level];
1131  const struct section *parent_section = wctx->level ?
1132  wctx->section[wctx->level-1] : NULL;
1133  compact->terminate_line[wctx->level] = 1;
1134  compact->has_nested_elems[wctx->level] = 0;
1135 
1136  av_bprint_clear(&wctx->section_pbuf[wctx->level]);
1137  if (!(section->flags & SECTION_FLAG_IS_ARRAY) && parent_section &&
1138  !(parent_section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY))) {
1139  compact->nested_section[wctx->level] = 1;
1140  compact->has_nested_elems[wctx->level-1] = 1;
1141  av_bprintf(&wctx->section_pbuf[wctx->level], "%s%s:",
1142  wctx->section_pbuf[wctx->level-1].str,
1143  (char *)av_x_if_null(section->element_name, section->name));
1144  wctx->nb_item[wctx->level] = wctx->nb_item[wctx->level-1];
1145  } else {
1146  if (parent_section && compact->has_nested_elems[wctx->level-1] &&
1148  compact->terminate_line[wctx->level-1] = 0;
1149  av_log(NULL, AV_LOG_STDERR, "\n");
1150  }
1151  if (compact->print_section &&
1153  av_log(NULL, AV_LOG_STDERR, "%s%c", section->name, compact->item_sep);
1154  }
1155 }
1156 
1158 {
1159  CompactContext *compact = wctx->priv;
1160 
1161  if (!compact->nested_section[wctx->level] &&
1162  compact->terminate_line[wctx->level] &&
1164  av_log(NULL, AV_LOG_STDERR, "\n");
1165 }
1166 
1167 static void compact_print_str(WriterContext *wctx, const char *key, const char *value)
1168 {
1169  CompactContext *compact = wctx->priv;
1170  AVBPrint buf;
1171 
1172  if (wctx->nb_item[wctx->level]) av_log(NULL, AV_LOG_STDERR, "%c", compact->item_sep);
1173  if (!compact->nokey)
1174  av_log(NULL, AV_LOG_STDERR, "%s%s=", wctx->section_pbuf[wctx->level].str, key);
1175  av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1176  av_log(NULL, AV_LOG_STDERR, "%s", compact->escape_str(&buf, value, compact->item_sep, wctx));
1177  av_bprint_finalize(&buf, NULL);
1178 }
1179 
1180 static void compact_print_int(WriterContext *wctx, const char *key, long long int value)
1181 {
1182  CompactContext *compact = wctx->priv;
1183 
1184  if (wctx->nb_item[wctx->level]) av_log(NULL, AV_LOG_STDERR, "%c", compact->item_sep);
1185  if (!compact->nokey)
1186  av_log(NULL, AV_LOG_STDERR, "%s%s=", wctx->section_pbuf[wctx->level].str, key);
1187  av_log(NULL, AV_LOG_STDERR, "%lld", value);
1188 }
1189 
1190 static const Writer compact_writer = {
1191  .name = "compact",
1192  .priv_size = sizeof(CompactContext),
1193  .init = compact_init,
1196  .print_integer = compact_print_int,
1197  .print_string = compact_print_str,
1199  .priv_class = &compact_class,
1200 };
1201 
1202 /* CSV output */
1203 
1204 #undef OFFSET
1205 #define OFFSET(x) offsetof(CompactContext, x)
1206 
1207 static const AVOption csv_options[] = {
1208  {"item_sep", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=","}, CHAR_MIN, CHAR_MAX },
1209  {"s", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=","}, CHAR_MIN, CHAR_MAX },
1210  {"nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1211  {"nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1212  {"escape", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="csv"}, CHAR_MIN, CHAR_MAX },
1213  {"e", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="csv"}, CHAR_MIN, CHAR_MAX },
1214  {"print_section", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1215  {"p", "print section name", OFFSET(print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1216  {NULL},
1217 };
1218 
1220 
1221 static const Writer csv_writer = {
1222  .name = "csv",
1223  .priv_size = sizeof(CompactContext),
1224  .init = compact_init,
1227  .print_integer = compact_print_int,
1228  .print_string = compact_print_str,
1230  .priv_class = &csv_class,
1231 };
1232 
1233 /* Flat output */
1234 
1235 typedef struct FlatContext {
1236  const AVClass *class;
1237  const char *sep_str;
1238  char sep;
1241 
1242 #undef OFFSET
1243 #define OFFSET(x) offsetof(FlatContext, x)
1244 
1245 static const AVOption flat_options[]= {
1246  {"sep_char", "set separator", OFFSET(sep_str), AV_OPT_TYPE_STRING, {.str="."}, CHAR_MIN, CHAR_MAX },
1247  {"s", "set separator", OFFSET(sep_str), AV_OPT_TYPE_STRING, {.str="."}, CHAR_MIN, CHAR_MAX },
1248  {"hierarchical", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1249  {"h", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1250  {NULL},
1251 };
1252 
1254 
1255 static av_cold int flat_init(WriterContext *wctx)
1256 {
1257  FlatContext *flat = wctx->priv;
1258 
1259  if (strlen(flat->sep_str) != 1) {
1260  av_log(wctx, AV_LOG_ERROR, "Item separator '%s' specified, but must contain a single character\n",
1261  flat->sep_str);
1262  return AVERROR(EINVAL);
1263  }
1264  flat->sep = flat->sep_str[0];
1265 
1266  return 0;
1267 }
1268 
1269 static const char *flat_escape_key_str(AVBPrint *dst, const char *src, const char sep)
1270 {
1271  const char *p;
1272 
1273  for (p = src; *p; p++) {
1274  if (!((*p >= '0' && *p <= '9') ||
1275  (*p >= 'a' && *p <= 'z') ||
1276  (*p >= 'A' && *p <= 'Z')))
1277  av_bprint_chars(dst, '_', 1);
1278  else
1279  av_bprint_chars(dst, *p, 1);
1280  }
1281  return dst->str;
1282 }
1283 
1284 static const char *flat_escape_value_str(AVBPrint *dst, const char *src)
1285 {
1286  const char *p;
1287 
1288  for (p = src; *p; p++) {
1289  switch (*p) {
1290  case '\n': av_bprintf(dst, "%s", "\\n"); break;
1291  case '\r': av_bprintf(dst, "%s", "\\r"); break;
1292  case '\\': av_bprintf(dst, "%s", "\\\\"); break;
1293  case '"': av_bprintf(dst, "%s", "\\\""); break;
1294  case '`': av_bprintf(dst, "%s", "\\`"); break;
1295  case '$': av_bprintf(dst, "%s", "\\$"); break;
1296  default: av_bprint_chars(dst, *p, 1); break;
1297  }
1298  }
1299  return dst->str;
1300 }
1301 
1303 {
1304  FlatContext *flat = wctx->priv;
1305  AVBPrint *buf = &wctx->section_pbuf[wctx->level];
1306  const struct section *section = wctx->section[wctx->level];
1307  const struct section *parent_section = wctx->level ?
1308  wctx->section[wctx->level-1] : NULL;
1309 
1310  /* build section header */
1311  av_bprint_clear(buf);
1312  if (!parent_section)
1313  return;
1314  av_bprintf(buf, "%s", wctx->section_pbuf[wctx->level-1].str);
1315 
1316  if (flat->hierarchical ||
1318  av_bprintf(buf, "%s%s", wctx->section[wctx->level]->name, flat->sep_str);
1319 
1320  if (parent_section->flags & SECTION_FLAG_IS_ARRAY) {
1321  int n = parent_section->id == SECTION_ID_PACKETS_AND_FRAMES ?
1322  wctx->nb_section_packet_frame : wctx->nb_item[wctx->level-1];
1323  av_bprintf(buf, "%d%s", n, flat->sep_str);
1324  }
1325  }
1326 }
1327 
1328 static void flat_print_int(WriterContext *wctx, const char *key, long long int value)
1329 {
1330  av_log(NULL, AV_LOG_STDERR, "%s%s=%lld\n", wctx->section_pbuf[wctx->level].str, key, value);
1331 }
1332 
1333 static void flat_print_str(WriterContext *wctx, const char *key, const char *value)
1334 {
1335  FlatContext *flat = wctx->priv;
1336  AVBPrint buf;
1337 
1338  av_log(NULL, AV_LOG_STDERR, "%s", wctx->section_pbuf[wctx->level].str);
1339  av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1340  av_log(NULL, AV_LOG_STDERR, "%s=", flat_escape_key_str(&buf, key, flat->sep));
1341  av_bprint_clear(&buf);
1342  av_log(NULL, AV_LOG_STDERR, "\"%s\"\n", flat_escape_value_str(&buf, value));
1343  av_bprint_finalize(&buf, NULL);
1344 }
1345 
1346 static const Writer flat_writer = {
1347  .name = "flat",
1348  .priv_size = sizeof(FlatContext),
1349  .init = flat_init,
1351  .print_integer = flat_print_int,
1352  .print_string = flat_print_str,
1354  .priv_class = &flat_class,
1355 };
1356 
1357 /* INI format output */
1358 
1359 typedef struct INIContext {
1360  const AVClass *class;
1363 
1364 #undef OFFSET
1365 #define OFFSET(x) offsetof(INIContext, x)
1366 
1367 static const AVOption ini_options[] = {
1368  {"hierarchical", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1369  {"h", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1370  {NULL},
1371 };
1372 
1374 
1375 static char *ini_escape_str(AVBPrint *dst, const char *src)
1376 {
1377  int i = 0;
1378  char c = 0;
1379 
1380  while ((c = src[i++])) {
1381  switch (c) {
1382  case '\b': av_bprintf(dst, "%s", "\\b"); break;
1383  case '\f': av_bprintf(dst, "%s", "\\f"); break;
1384  case '\n': av_bprintf(dst, "%s", "\\n"); break;
1385  case '\r': av_bprintf(dst, "%s", "\\r"); break;
1386  case '\t': av_bprintf(dst, "%s", "\\t"); break;
1387  case '\\':
1388  case '#' :
1389  case '=' :
1390  case ':' : av_bprint_chars(dst, '\\', 1);
1391  default:
1392  if ((unsigned char)c < 32)
1393  av_bprintf(dst, "\\x00%02x", c & 0xff);
1394  else
1395  av_bprint_chars(dst, c, 1);
1396  break;
1397  }
1398  }
1399  return dst->str;
1400 }
1401 
1403 {
1404  INIContext *ini = wctx->priv;
1405  AVBPrint *buf = &wctx->section_pbuf[wctx->level];
1406  const struct section *section = wctx->section[wctx->level];
1407  const struct section *parent_section = wctx->level ?
1408  wctx->section[wctx->level-1] : NULL;
1409 
1410  av_bprint_clear(buf);
1411  if (!parent_section) {
1412  av_log(NULL, AV_LOG_STDERR, "# ffprobe output\n\n");
1413  return;
1414  }
1415 
1416  if (wctx->nb_item[wctx->level-1])
1417  av_log(NULL, AV_LOG_STDERR, "\n");
1418 
1419  av_bprintf(buf, "%s", wctx->section_pbuf[wctx->level-1].str);
1420  if (ini->hierarchical ||
1422  av_bprintf(buf, "%s%s", buf->str[0] ? "." : "", wctx->section[wctx->level]->name);
1423 
1424  if (parent_section->flags & SECTION_FLAG_IS_ARRAY) {
1425  int n = parent_section->id == SECTION_ID_PACKETS_AND_FRAMES ?
1426  wctx->nb_section_packet_frame : wctx->nb_item[wctx->level-1];
1427  av_bprintf(buf, ".%d", n);
1428  }
1429  }
1430 
1432  av_log(NULL, AV_LOG_STDERR, "[%s]\n", buf->str);
1433 }
1434 
1435 static void ini_print_str(WriterContext *wctx, const char *key, const char *value)
1436 {
1437  AVBPrint buf;
1438 
1439  av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1440  av_log(NULL, AV_LOG_STDERR, "%s=", ini_escape_str(&buf, key));
1441  av_bprint_clear(&buf);
1442  av_log(NULL, AV_LOG_STDERR, "%s\n", ini_escape_str(&buf, value));
1443  av_bprint_finalize(&buf, NULL);
1444 }
1445 
1446 static void ini_print_int(WriterContext *wctx, const char *key, long long int value)
1447 {
1448  av_log(NULL, AV_LOG_STDERR, "%s=%lld\n", key, value);
1449 }
1450 
1451 static const Writer ini_writer = {
1452  .name = "ini",
1453  .priv_size = sizeof(INIContext),
1455  .print_integer = ini_print_int,
1456  .print_string = ini_print_str,
1458  .priv_class = &ini_class,
1459 };
1460 
1461 /* JSON output */
1462 
1463 typedef struct JSONContext {
1464  const AVClass *class;
1466  int compact;
1467  const char *item_sep, *item_start_end;
1469 
1470 #undef OFFSET
1471 #define OFFSET(x) offsetof(JSONContext, x)
1472 
1473 static const AVOption json_options[]= {
1474  { "compact", "enable compact output", OFFSET(compact), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1475  { "c", "enable compact output", OFFSET(compact), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1476  { NULL }
1477 };
1478 
1480 
1481 static av_cold int json_init(WriterContext *wctx)
1482 {
1483  JSONContext *json = wctx->priv;
1484 
1485  json->item_sep = json->compact ? ", " : ",\n";
1486  json->item_start_end = json->compact ? " " : "\n";
1487 
1488  return 0;
1489 }
1490 
1491 static const char *json_escape_str(AVBPrint *dst, const char *src, void *log_ctx)
1492 {
1493  static const char json_escape[] = {'"', '\\', '\b', '\f', '\n', '\r', '\t', 0};
1494  static const char json_subst[] = {'"', '\\', 'b', 'f', 'n', 'r', 't', 0};
1495  const char *p;
1496 
1497  for (p = src; *p; p++) {
1498  char *s = strchr(json_escape, *p);
1499  if (s) {
1500  av_bprint_chars(dst, '\\', 1);
1501  av_bprint_chars(dst, json_subst[s - json_escape], 1);
1502  } else if ((unsigned char)*p < 32) {
1503  av_bprintf(dst, "\\u00%02x", *p & 0xff);
1504  } else {
1505  av_bprint_chars(dst, *p, 1);
1506  }
1507  }
1508  return dst->str;
1509 }
1510 
1511 #define JSON_INDENT() av_log(NULL, AV_LOG_STDERR, "%*c", json->indent_level * 4, ' ')
1514 {
1515  JSONContext *json = wctx->priv;
1516  AVBPrint buf;
1517  const struct section *section = wctx->section[wctx->level];
1518  const struct section *parent_section = wctx->level ?
1519  wctx->section[wctx->level-1] : NULL;
1520 
1521  if (wctx->level && wctx->nb_item[wctx->level-1])
1522  av_log(NULL, AV_LOG_STDERR, ",\n");
1523 
1525  av_log(NULL, AV_LOG_STDERR, "{\n");
1526  json->indent_level++;
1527  } else {
1528  av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1529  json_escape_str(&buf, section->name, wctx);
1530  JSON_INDENT();
1531 
1532  json->indent_level++;
1534  av_log(NULL, AV_LOG_STDERR, "\"%s\": [\n", buf.str);
1535  } else if (parent_section && !(parent_section->flags & SECTION_FLAG_IS_ARRAY)) {
1536  av_log(NULL, AV_LOG_STDERR, "\"%s\": {%s", buf.str, json->item_start_end);
1537  } else {
1538  av_log(NULL, AV_LOG_STDERR, "{%s", json->item_start_end);
1539 
1540  /* this is required so the parser can distinguish between packets and frames */
1541  if (parent_section && parent_section->id == SECTION_ID_PACKETS_AND_FRAMES) {
1542  if (!json->compact)
1543  JSON_INDENT();
1544  av_log(NULL, AV_LOG_STDERR, "\"type\": \"%s\"", section->name);
1545  }
1546  }
1547  av_bprint_finalize(&buf, NULL);
1548  }
1549 }
1550 
1552 {
1553  JSONContext *json = wctx->priv;
1554  const struct section *section = wctx->section[wctx->level];
1555 
1556  if (wctx->level == 0) {
1557  json->indent_level--;
1558  av_log(NULL, AV_LOG_STDERR, "\n}\n");
1559  } else if (section->flags & SECTION_FLAG_IS_ARRAY) {
1560  av_log(NULL, AV_LOG_STDERR, "\n");
1561  json->indent_level--;
1562  JSON_INDENT();
1563  av_log(NULL, AV_LOG_STDERR, "]");
1564  } else {
1565  av_log(NULL, AV_LOG_STDERR, "%s", json->item_start_end);
1566  json->indent_level--;
1567  if (!json->compact)
1568  JSON_INDENT();
1569  av_log(NULL, AV_LOG_STDERR, "}");
1570  }
1571 }
1572 
1573 static inline void json_print_item_str(WriterContext *wctx,
1574  const char *key, const char *value)
1575 {
1576  AVBPrint buf;
1577 
1578  av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1579  av_log(NULL, AV_LOG_STDERR, "\"%s\":", json_escape_str(&buf, key, wctx));
1580  av_bprint_clear(&buf);
1581  av_log(NULL, AV_LOG_STDERR, " \"%s\"", json_escape_str(&buf, value, wctx));
1582  av_bprint_finalize(&buf, NULL);
1583 }
1584 
1585 static void json_print_str(WriterContext *wctx, const char *key, const char *value)
1586 {
1587  JSONContext *json = wctx->priv;
1588  const struct section *parent_section = wctx->level ?
1589  wctx->section[wctx->level-1] : NULL;
1590 
1591  if (wctx->nb_item[wctx->level] || (parent_section && parent_section->id == SECTION_ID_PACKETS_AND_FRAMES))
1592  av_log(NULL, AV_LOG_STDERR, "%s", json->item_sep);
1593  if (!json->compact)
1594  JSON_INDENT();
1595  json_print_item_str(wctx, key, value);
1596 }
1597 
1598 static void json_print_int(WriterContext *wctx, const char *key, long long int value)
1599 {
1600  JSONContext *json = wctx->priv;
1601  const struct section *parent_section = wctx->level ?
1602  wctx->section[wctx->level-1] : NULL;
1603  AVBPrint buf;
1604 
1605  if (wctx->nb_item[wctx->level] || (parent_section && parent_section->id == SECTION_ID_PACKETS_AND_FRAMES))
1606  av_log(NULL, AV_LOG_STDERR, "%s", json->item_sep);
1607  if (!json->compact)
1608  JSON_INDENT();
1609 
1610  av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1611  av_log(NULL, AV_LOG_STDERR, "\"%s\": %lld", json_escape_str(&buf, key, wctx), value);
1612  av_bprint_finalize(&buf, NULL);
1613 }
1614 
1615 static const Writer json_writer = {
1616  .name = "json",
1617  .priv_size = sizeof(JSONContext),
1618  .init = json_init,
1621  .print_integer = json_print_int,
1622  .print_string = json_print_str,
1624  .priv_class = &json_class,
1625 };
1626 
1627 /* XML output */
1628 
1629 typedef struct XMLContext {
1630  const AVClass *class;
1636 
1637 #undef OFFSET
1638 #define OFFSET(x) offsetof(XMLContext, x)
1640 static const AVOption xml_options[] = {
1641  {"fully_qualified", "specify if the output should be fully qualified", OFFSET(fully_qualified), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1642  {"q", "specify if the output should be fully qualified", OFFSET(fully_qualified), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1643  {"xsd_strict", "ensure that the output is XSD compliant", OFFSET(xsd_strict), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1644  {"x", "ensure that the output is XSD compliant", OFFSET(xsd_strict), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1645  {NULL},
1646 };
1647 
1649 
1650 static av_cold int xml_init(WriterContext *wctx)
1651 {
1652  XMLContext *xml = wctx->priv;
1653 
1654  if (xml->xsd_strict) {
1655  xml->fully_qualified = 1;
1656 #define CHECK_COMPLIANCE(opt, opt_name) \
1657  if (opt) { \
1658  av_log(wctx, AV_LOG_ERROR, \
1659  "XSD-compliant output selected but option '%s' was selected, XML output may be non-compliant.\n" \
1660  "You need to disable such option with '-no%s'\n", opt_name, opt_name); \
1661  return AVERROR(EINVAL); \
1662  }
1663  CHECK_COMPLIANCE(show_private_data, "private");
1666 
1668  av_log(wctx, AV_LOG_ERROR,
1669  "Interleaved frames and packets are not allowed in XSD. "
1670  "Select only one between the -show_frames and the -show_packets options.\n");
1671  return AVERROR(EINVAL);
1672  }
1673  }
1674 
1675  return 0;
1676 }
1677 
1678 static const char *xml_escape_str(AVBPrint *dst, const char *src, void *log_ctx)
1679 {
1680  const char *p;
1681 
1682  for (p = src; *p; p++) {
1683  switch (*p) {
1684  case '&' : av_bprintf(dst, "%s", "&amp;"); break;
1685  case '<' : av_bprintf(dst, "%s", "&lt;"); break;
1686  case '>' : av_bprintf(dst, "%s", "&gt;"); break;
1687  case '"' : av_bprintf(dst, "%s", "&quot;"); break;
1688  case '\'': av_bprintf(dst, "%s", "&apos;"); break;
1689  default: av_bprint_chars(dst, *p, 1);
1690  }
1691  }
1692 
1693  return dst->str;
1694 }
1695 
1696 #define XML_INDENT() av_log(NULL, AV_LOG_STDERR, "%*c", xml->indent_level * 4, ' ')
1699 {
1700  XMLContext *xml = wctx->priv;
1701  const struct section *section = wctx->section[wctx->level];
1702  const struct section *parent_section = wctx->level ?
1703  wctx->section[wctx->level-1] : NULL;
1704 
1705  if (wctx->level == 0) {
1706  const char *qual = " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' "
1707  "xmlns:ffprobe='http://www.ffmpeg.org/schema/ffprobe' "
1708  "xsi:schemaLocation='http://www.ffmpeg.org/schema/ffprobe ffprobe.xsd'";
1709 
1710  av_log(NULL, AV_LOG_STDERR, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
1711  av_log(NULL, AV_LOG_STDERR, "<%sffprobe%s>\n",
1712  xml->fully_qualified ? "ffprobe:" : "",
1713  xml->fully_qualified ? qual : "");
1714  return;
1715  }
1716 
1717  if (xml->within_tag) {
1718  xml->within_tag = 0;
1719  av_log(NULL, AV_LOG_STDERR, ">\n");
1720  }
1722  xml->indent_level++;
1723  } else {
1724  if (parent_section && (parent_section->flags & SECTION_FLAG_IS_WRAPPER) &&
1725  wctx->level && wctx->nb_item[wctx->level-1])
1726  av_log(NULL, AV_LOG_STDERR, "\n");
1727  xml->indent_level++;
1728 
1730  XML_INDENT(); av_log(NULL, AV_LOG_STDERR, "<%s>\n", section->name);
1731  } else {
1732  XML_INDENT(); av_log(NULL, AV_LOG_STDERR, "<%s ", section->name);
1733  xml->within_tag = 1;
1734  }
1735  }
1736 }
1737 
1739 {
1740  XMLContext *xml = wctx->priv;
1741  const struct section *section = wctx->section[wctx->level];
1742 
1743  if (wctx->level == 0) {
1744  av_log(NULL, AV_LOG_STDERR, "</%sffprobe>\n", xml->fully_qualified ? "ffprobe:" : "");
1745  } else if (xml->within_tag) {
1746  xml->within_tag = 0;
1747  av_log(NULL, AV_LOG_STDERR, "/>\n");
1748  xml->indent_level--;
1750  xml->indent_level--;
1751  } else {
1752  XML_INDENT(); av_log(NULL, AV_LOG_STDERR, "</%s>\n", section->name);
1753  xml->indent_level--;
1754  }
1755 }
1756 
1757 static void xml_print_str(WriterContext *wctx, const char *key, const char *value)
1758 {
1759  AVBPrint buf;
1760  XMLContext *xml = wctx->priv;
1761  const struct section *section = wctx->section[wctx->level];
1762 
1763  av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1764 
1766  XML_INDENT();
1767  av_log(NULL, AV_LOG_STDERR, "<%s key=\"%s\"",
1768  section->element_name, xml_escape_str(&buf, key, wctx));
1769  av_bprint_clear(&buf);
1770  av_log(NULL, AV_LOG_STDERR, " value=\"%s\"/>\n", xml_escape_str(&buf, value, wctx));
1771  } else {
1772  if (wctx->nb_item[wctx->level])
1773  av_log(NULL, AV_LOG_STDERR, " ");
1774  av_log(NULL, AV_LOG_STDERR, "%s=\"%s\"", key, xml_escape_str(&buf, value, wctx));
1775  }
1776 
1777  av_bprint_finalize(&buf, NULL);
1778 }
1779 
1780 static void xml_print_int(WriterContext *wctx, const char *key, long long int value)
1781 {
1782  if (wctx->nb_item[wctx->level])
1783  av_log(NULL, AV_LOG_STDERR, " ");
1784  av_log(NULL, AV_LOG_STDERR, "%s=\"%lld\"", key, value);
1785 }
1786 
1787 static Writer xml_writer = {
1788  .name = "xml",
1789  .priv_size = sizeof(XMLContext),
1790  .init = xml_init,
1793  .print_integer = xml_print_int,
1794  .print_string = xml_print_str,
1796  .priv_class = &xml_class,
1797 };
1798 
1799 static void writer_register_all(void)
1800 {
1801 
1809 }
1810 
1811 #define print_fmt(k, f, ...) do { \
1812  av_bprint_clear(&pbuf); \
1813  av_bprintf(&pbuf, f, __VA_ARGS__); \
1814  writer_print_string(w, k, pbuf.str, 0); \
1815 } while (0)
1816 
1817 #define print_int(k, v) writer_print_integer(w, k, v)
1818 #define print_q(k, v, s) writer_print_rational(w, k, v, s)
1819 #define print_str(k, v) writer_print_string(w, k, v, 0)
1820 #define print_str_opt(k, v) writer_print_string(w, k, v, PRINT_STRING_OPT)
1821 #define print_str_validate(k, v) writer_print_string(w, k, v, PRINT_STRING_VALIDATE)
1822 #define print_time(k, v, tb) writer_print_time(w, k, v, tb, 0)
1823 #define print_ts(k, v) writer_print_ts(w, k, v, 0)
1824 #define print_duration_time(k, v, tb) writer_print_time(w, k, v, tb, 1)
1825 #define print_duration_ts(k, v) writer_print_ts(w, k, v, 1)
1826 #define print_val(k, v, u) do { \
1827  struct unit_value uv; \
1828  uv.val.i = v; \
1829  uv.unit = u; \
1830  writer_print_string(w, k, value_string(val_str, sizeof(val_str), uv), 0); \
1831 } while (0)
1832 
1833 #define print_section_header(s) writer_print_section_header(w, s)
1834 #define print_section_footer(s) writer_print_section_footer(w, s)
1836 #define REALLOCZ_ARRAY_STREAM(ptr, cur_n, new_n) \
1837 { \
1838  ret = av_reallocp_array(&(ptr), (new_n), sizeof(*(ptr))); \
1839  if (ret < 0) \
1840  goto end; \
1841  memset( (ptr) + (cur_n), 0, ((new_n) - (cur_n)) * sizeof(*(ptr)) ); \
1842 }
1843 
1844 static inline int show_tags(WriterContext *w, AVDictionary *tags, int section_id)
1845 {
1846  AVDictionaryEntry *tag = NULL;
1847  int ret = 0;
1848 
1849  if (!tags)
1850  return 0;
1851  writer_print_section_header(w, section_id);
1852 
1853  while ((tag = av_dict_get(tags, "", tag, AV_DICT_IGNORE_SUFFIX))) {
1854  if ((ret = print_str_validate(tag->key, tag->value)) < 0)
1855  break;
1856  }
1858 
1859  return ret;
1860 }
1861 
1863  AVCodecParameters *par,
1864  const AVPacketSideData *side_data,
1865  int nb_side_data,
1866  SectionID id_data_list,
1867  SectionID id_data)
1868 {
1869  int i;
1870 
1871  writer_print_section_header(w, id_data_list);
1872  for (i = 0; i < nb_side_data; i++) {
1873  const AVPacketSideData *sd = &side_data[i];
1874  const char *name = av_packet_side_data_name(sd->type);
1875 
1876  writer_print_section_header(w, id_data);
1877  print_str("side_data_type", name ? name : "unknown");
1878  if (sd->type == AV_PKT_DATA_DISPLAYMATRIX && sd->size >= 9*4) {
1879  writer_print_integers(w, "displaymatrix", sd->data, 9, " %11d", 3, 4, 1);
1880  print_int("rotation", av_display_rotation_get((int32_t *)sd->data));
1881  } else if (sd->type == AV_PKT_DATA_STEREO3D) {
1882  const AVStereo3D *stereo = (AVStereo3D *)sd->data;
1883  print_str("type", av_stereo3d_type_name(stereo->type));
1884  print_int("inverted", !!(stereo->flags & AV_STEREO3D_FLAG_INVERT));
1885  } else if (sd->type == AV_PKT_DATA_SPHERICAL) {
1886  const AVSphericalMapping *spherical = (AVSphericalMapping *)sd->data;
1887  print_str("projection", av_spherical_projection_name(spherical->projection));
1888  if (spherical->projection == AV_SPHERICAL_CUBEMAP) {
1889  print_int("padding", spherical->padding);
1890  } else if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR_TILE) {
1891  size_t l, t, r, b;
1892  av_spherical_tile_bounds(spherical, par->width, par->height,
1893  &l, &t, &r, &b);
1894  print_int("bound_left", l);
1895  print_int("bound_top", t);
1896  print_int("bound_right", r);
1897  print_int("bound_bottom", b);
1898  }
1899 
1900  print_int("yaw", (double) spherical->yaw / (1 << 16));
1901  print_int("pitch", (double) spherical->pitch / (1 << 16));
1902  print_int("roll", (double) spherical->roll / (1 << 16));
1903  } else if (sd->type == AV_PKT_DATA_SKIP_SAMPLES && sd->size == 10) {
1904  print_int("skip_samples", AV_RL32(sd->data));
1905  print_int("discard_padding", AV_RL32(sd->data + 4));
1906  print_int("skip_reason", AV_RL8(sd->data + 8));
1907  print_int("discard_reason", AV_RL8(sd->data + 9));
1908  } else if (sd->type == AV_PKT_DATA_MASTERING_DISPLAY_METADATA) {
1909  AVMasteringDisplayMetadata *metadata = (AVMasteringDisplayMetadata *)sd->data;
1910 
1911  if (metadata->has_primaries) {
1912  print_q("red_x", metadata->display_primaries[0][0], '/');
1913  print_q("red_y", metadata->display_primaries[0][1], '/');
1914  print_q("green_x", metadata->display_primaries[1][0], '/');
1915  print_q("green_y", metadata->display_primaries[1][1], '/');
1916  print_q("blue_x", metadata->display_primaries[2][0], '/');
1917  print_q("blue_y", metadata->display_primaries[2][1], '/');
1918 
1919  print_q("white_point_x", metadata->white_point[0], '/');
1920  print_q("white_point_y", metadata->white_point[1], '/');
1921  }
1922 
1923  if (metadata->has_luminance) {
1924  print_q("min_luminance", metadata->min_luminance, '/');
1925  print_q("max_luminance", metadata->max_luminance, '/');
1926  }
1927  } else if (sd->type == AV_PKT_DATA_CONTENT_LIGHT_LEVEL) {
1928  AVContentLightMetadata *metadata = (AVContentLightMetadata *)sd->data;
1929  print_int("max_content", metadata->MaxCLL);
1930  print_int("max_average", metadata->MaxFALL);
1931  }
1933  }
1935 }
1936 
1937 static void print_color_range(WriterContext *w, enum AVColorRange color_range)
1938 {
1939  const char *val = av_color_range_name(color_range);
1940  if (!val || color_range == AVCOL_RANGE_UNSPECIFIED) {
1941  print_str_opt("color_range", "unknown");
1942  } else {
1943  print_str("color_range", val);
1944  }
1945 }
1946 
1947 static void print_color_space(WriterContext *w, enum AVColorSpace color_space)
1948 {
1949  const char *val = av_color_space_name(color_space);
1950  if (!val || color_space == AVCOL_SPC_UNSPECIFIED) {
1951  print_str_opt("color_space", "unknown");
1952  } else {
1953  print_str("color_space", val);
1954  }
1955 }
1956 
1957 static void print_primaries(WriterContext *w, enum AVColorPrimaries color_primaries)
1958 {
1959  const char *val = av_color_primaries_name(color_primaries);
1960  if (!val || color_primaries == AVCOL_PRI_UNSPECIFIED) {
1961  print_str_opt("color_primaries", "unknown");
1962  } else {
1963  print_str("color_primaries", val);
1964  }
1965 }
1966 
1967 static void print_color_trc(WriterContext *w, enum AVColorTransferCharacteristic color_trc)
1968 {
1969  const char *val = av_color_transfer_name(color_trc);
1970  if (!val || color_trc == AVCOL_TRC_UNSPECIFIED) {
1971  print_str_opt("color_transfer", "unknown");
1972  } else {
1973  print_str("color_transfer", val);
1974  }
1975 }
1976 
1977 static void print_chroma_location(WriterContext *w, enum AVChromaLocation chroma_location)
1978 {
1979  const char *val = av_chroma_location_name(chroma_location);
1980  if (!val || chroma_location == AVCHROMA_LOC_UNSPECIFIED) {
1981  print_str_opt("chroma_location", "unspecified");
1982  } else {
1983  print_str("chroma_location", val);
1984  }
1985 }
1986 
1987 
1988 static void clear_log(int need_lock)
1989 {
1990  int i;
1991 
1992  if (need_lock)
1993  pthread_mutex_lock(&log_mutex);
1994  for (i=0; i<log_buffer_size; i++) {
1995  av_freep(&log_buffer[i].context_name);
1996  av_freep(&log_buffer[i].parent_name);
1997  av_freep(&log_buffer[i].log_message);
1998  }
1999  log_buffer_size = 0;
2000  if(need_lock)
2001  pthread_mutex_unlock(&log_mutex);
2002 }
2003 
2004 static int show_log(WriterContext *w, int section_ids, int section_id, int log_level)
2005 {
2006  int i;
2007  pthread_mutex_lock(&log_mutex);
2008  if (!log_buffer_size) {
2009  pthread_mutex_unlock(&log_mutex);
2010  return 0;
2011  }
2012  writer_print_section_header(w, section_ids);
2013 
2014  for (i=0; i<log_buffer_size; i++) {
2015  if (log_buffer[i].log_level <= log_level) {
2016  writer_print_section_header(w, section_id);
2017  print_str("context", log_buffer[i].context_name);
2018  print_int("level", log_buffer[i].log_level);
2019  print_int("category", log_buffer[i].category);
2020  if (log_buffer[i].parent_name) {
2021  print_str("parent_context", log_buffer[i].parent_name);
2022  print_int("parent_category", log_buffer[i].parent_category);
2023  } else {
2024  print_str_opt("parent_context", "N/A");
2025  print_str_opt("parent_category", "N/A");
2026  }
2027  print_str("message", log_buffer[i].log_message);
2029  }
2030  }
2031  clear_log(0);
2032  pthread_mutex_unlock(&log_mutex);
2033 
2035 
2036  return 0;
2037 }
2038 
2039 static void show_packet(WriterContext *w, InputFile *ifile, AVPacket *pkt, int packet_idx)
2040 {
2041  char val_str[128];
2042  AVStream *st = ifile->streams[pkt->stream_index].st;
2043  AVBPrint pbuf;
2044  const char *s;
2045 
2046  av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2047 
2049 
2050  s = av_get_media_type_string(st->codecpar->codec_type);
2051  if (s) print_str ("codec_type", s);
2052  else print_str_opt("codec_type", "unknown");
2053  print_int("stream_index", pkt->stream_index);
2054  print_ts ("pts", pkt->pts);
2055  print_time("pts_time", pkt->pts, &st->time_base);
2056  print_ts ("dts", pkt->dts);
2057  print_time("dts_time", pkt->dts, &st->time_base);
2058  print_duration_ts("duration", pkt->duration);
2059  print_duration_time("duration_time", pkt->duration, &st->time_base);
2060  print_duration_ts("convergence_duration", pkt->convergence_duration);
2061  print_duration_time("convergence_duration_time", pkt->convergence_duration, &st->time_base);
2062  print_val("size", pkt->size, unit_byte_str);
2063  if (pkt->pos != -1) print_fmt ("pos", "%"PRId64, pkt->pos);
2064  else print_str_opt("pos", "N/A");
2065  print_fmt("flags", "%c%c", pkt->flags & AV_PKT_FLAG_KEY ? 'K' : '_',
2066  pkt->flags & AV_PKT_FLAG_DISCARD ? 'D' : '_');
2067 
2068  if (pkt->side_data_elems) {
2069  int size;
2070  const uint8_t *side_metadata;
2071 
2072  side_metadata = av_packet_get_side_data(pkt, AV_PKT_DATA_STRINGS_METADATA, &size);
2073  if (side_metadata && size && do_show_packet_tags) {
2074  AVDictionary *dict = NULL;
2075  if (av_packet_unpack_dictionary(side_metadata, size, &dict) >= 0)
2077  av_dict_free(&dict);
2078  }
2079 
2080  print_pkt_side_data(w, st->codecpar, pkt->side_data, pkt->side_data_elems,
2083  }
2084 
2085  if (do_show_data)
2086  writer_print_data(w, "data", pkt->data, pkt->size);
2087  writer_print_data_hash(w, "data_hash", pkt->data, pkt->size);
2089 
2090  av_bprint_finalize(&pbuf, NULL);
2091  fflush(stdout);
2092 }
2093 
2094 static void show_subtitle(WriterContext *w, AVSubtitle *sub, AVStream *stream,
2095  AVFormatContext *fmt_ctx)
2096 {
2097  AVBPrint pbuf;
2098 
2099  av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2100 
2102 
2103  print_str ("media_type", "subtitle");
2104  print_ts ("pts", sub->pts);
2105  print_time("pts_time", sub->pts, &AV_TIME_BASE_Q);
2106  print_int ("format", sub->format);
2107  print_int ("start_display_time", sub->start_display_time);
2108  print_int ("end_display_time", sub->end_display_time);
2109  print_int ("num_rects", sub->num_rects);
2110 
2112 
2113  av_bprint_finalize(&pbuf, NULL);
2114  fflush(stdout);
2115 }
2116 
2117 static void show_frame(WriterContext *w, AVFrame *frame, AVStream *stream,
2118  AVFormatContext *fmt_ctx)
2119 {
2120  AVBPrint pbuf;
2121  char val_str[128];
2122  const char *s;
2123  int i;
2124 
2125  av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2126 
2128 
2129  s = av_get_media_type_string(stream->codecpar->codec_type);
2130  if (s) print_str ("media_type", s);
2131  else print_str_opt("media_type", "unknown");
2132  print_int("stream_index", stream->index);
2133  print_int("key_frame", frame->key_frame);
2134  print_ts ("pkt_pts", frame->pts);
2135  print_time("pkt_pts_time", frame->pts, &stream->time_base);
2136  print_ts ("pkt_dts", frame->pkt_dts);
2137  print_time("pkt_dts_time", frame->pkt_dts, &stream->time_base);
2138  print_ts ("best_effort_timestamp", frame->best_effort_timestamp);
2139  print_time("best_effort_timestamp_time", frame->best_effort_timestamp, &stream->time_base);
2140  print_duration_ts ("pkt_duration", frame->pkt_duration);
2141  print_duration_time("pkt_duration_time", frame->pkt_duration, &stream->time_base);
2142  if (frame->pkt_pos != -1) print_fmt ("pkt_pos", "%"PRId64, frame->pkt_pos);
2143  else print_str_opt("pkt_pos", "N/A");
2144  if (frame->pkt_size != -1) print_val ("pkt_size", frame->pkt_size, unit_byte_str);
2145  else print_str_opt("pkt_size", "N/A");
2146 
2147  switch (stream->codecpar->codec_type) {
2148  AVRational sar;
2149 
2150  case AVMEDIA_TYPE_VIDEO:
2151  print_int("width", frame->width);
2152  print_int("height", frame->height);
2153  s = av_get_pix_fmt_name(frame->format);
2154  if (s) print_str ("pix_fmt", s);
2155  else print_str_opt("pix_fmt", "unknown");
2156  sar = av_guess_sample_aspect_ratio(fmt_ctx, stream, frame);
2157  if (sar.num) {
2158  print_q("sample_aspect_ratio", sar, ':');
2159  } else {
2160  print_str_opt("sample_aspect_ratio", "N/A");
2161  }
2162  print_fmt("pict_type", "%c", av_get_picture_type_char(frame->pict_type));
2163  print_int("coded_picture_number", frame->coded_picture_number);
2164  print_int("display_picture_number", frame->display_picture_number);
2165  print_int("interlaced_frame", frame->interlaced_frame);
2166  print_int("top_field_first", frame->top_field_first);
2167  print_int("repeat_pict", frame->repeat_pict);
2168 
2169  print_color_range(w, frame->color_range);
2170  print_color_space(w, frame->colorspace);
2171  print_primaries(w, frame->color_primaries);
2172  print_color_trc(w, frame->color_trc);
2173  print_chroma_location(w, frame->chroma_location);
2174  break;
2175 
2176  case AVMEDIA_TYPE_AUDIO:
2177  s = av_get_sample_fmt_name(frame->format);
2178  if (s) print_str ("sample_fmt", s);
2179  else print_str_opt("sample_fmt", "unknown");
2180  print_int("nb_samples", frame->nb_samples);
2181  print_int("channels", frame->channels);
2182  if (frame->channel_layout) {
2183  av_bprint_clear(&pbuf);
2184  av_bprint_channel_layout(&pbuf, frame->channels,
2185  frame->channel_layout);
2186  print_str ("channel_layout", pbuf.str);
2187  } else
2188  print_str_opt("channel_layout", "unknown");
2189  break;
2190  }
2191  if (do_show_frame_tags)
2192  show_tags(w, frame->metadata, SECTION_ID_FRAME_TAGS);
2193  if (do_show_log)
2195  if (frame->nb_side_data) {
2197  for (i = 0; i < frame->nb_side_data; i++) {
2198  AVFrameSideData *sd = frame->side_data[i];
2199  const char *name;
2200 
2202  name = av_frame_side_data_name(sd->type);
2203  print_str("side_data_type", name ? name : "unknown");
2204  if (sd->type == AV_FRAME_DATA_DISPLAYMATRIX && sd->size >= 9*4) {
2205  writer_print_integers(w, "displaymatrix", sd->data, 9, " %11d", 3, 4, 1);
2206  print_int("rotation", av_display_rotation_get((int32_t *)sd->data));
2207  } else if (sd->type == AV_FRAME_DATA_GOP_TIMECODE && sd->size >= 8) {
2208  char tcbuf[AV_TIMECODE_STR_SIZE];
2209  av_timecode_make_mpeg_tc_string(tcbuf, *(int64_t *)(sd->data));
2210  print_str("timecode", tcbuf);
2211  } else if (sd->type == AV_FRAME_DATA_S12M_TIMECODE && sd->size == 16) {
2212  uint32_t *tc = (uint32_t*)sd->data;
2213  int m = FFMIN(tc[0],3);
2215  for (int j = 1; j <= m ; j++) {
2216  char tcbuf[AV_TIMECODE_STR_SIZE];
2217  av_timecode_make_smpte_tc_string(tcbuf, tc[j], 0);
2219  print_str("value", tcbuf);
2221  }
2223  } else if (sd->type == AV_FRAME_DATA_MASTERING_DISPLAY_METADATA) {
2224  AVMasteringDisplayMetadata *metadata = (AVMasteringDisplayMetadata *)sd->data;
2225 
2226  if (metadata->has_primaries) {
2227  print_q("red_x", metadata->display_primaries[0][0], '/');
2228  print_q("red_y", metadata->display_primaries[0][1], '/');
2229  print_q("green_x", metadata->display_primaries[1][0], '/');
2230  print_q("green_y", metadata->display_primaries[1][1], '/');
2231  print_q("blue_x", metadata->display_primaries[2][0], '/');
2232  print_q("blue_y", metadata->display_primaries[2][1], '/');
2233 
2234  print_q("white_point_x", metadata->white_point[0], '/');
2235  print_q("white_point_y", metadata->white_point[1], '/');
2236  }
2237 
2238  if (metadata->has_luminance) {
2239  print_q("min_luminance", metadata->min_luminance, '/');
2240  print_q("max_luminance", metadata->max_luminance, '/');
2241  }
2242  } else if (sd->type == AV_FRAME_DATA_CONTENT_LIGHT_LEVEL) {
2243  AVContentLightMetadata *metadata = (AVContentLightMetadata *)sd->data;
2244  print_int("max_content", metadata->MaxCLL);
2245  print_int("max_average", metadata->MaxFALL);
2246  } else if (sd->type == AV_FRAME_DATA_ICC_PROFILE) {
2247  AVDictionaryEntry *tag = av_dict_get(sd->metadata, "name", NULL, AV_DICT_MATCH_CASE);
2248  if (tag)
2249  print_str(tag->key, tag->value);
2250  print_int("size", sd->size);
2251  }
2253  }
2255  }
2256 
2258 
2259  av_bprint_finalize(&pbuf, NULL);
2260  fflush(stdout);
2261 }
2262 
2263 static av_always_inline int process_frame(WriterContext *w,
2264  InputFile *ifile,
2265  AVFrame *frame, AVPacket *pkt,
2266  int *packet_new)
2267 {
2268  AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2269  AVCodecContext *dec_ctx = ifile->streams[pkt->stream_index].dec_ctx;
2270  AVCodecParameters *par = ifile->streams[pkt->stream_index].st->codecpar;
2271  AVSubtitle sub;
2272  int ret = 0, got_frame = 0;
2273 
2274  clear_log(1);
2275  if (dec_ctx && dec_ctx->codec) {
2276  switch (par->codec_type) {
2277  case AVMEDIA_TYPE_VIDEO:
2278  case AVMEDIA_TYPE_AUDIO:
2279  if (*packet_new) {
2280  ret = avcodec_send_packet(dec_ctx, pkt);
2281  if (ret == AVERROR(EAGAIN)) {
2282  ret = 0;
2283  } else if (ret >= 0 || ret == AVERROR_EOF) {
2284  ret = 0;
2285  *packet_new = 0;
2286  }
2287  }
2288  if (ret >= 0) {
2289  ret = avcodec_receive_frame(dec_ctx, frame);
2290  if (ret >= 0) {
2291  got_frame = 1;
2292  } else if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
2293  ret = 0;
2294  }
2295  }
2296  break;
2297 
2298  case AVMEDIA_TYPE_SUBTITLE:
2299  if (*packet_new)
2300  ret = avcodec_decode_subtitle2(dec_ctx, &sub, &got_frame, pkt);
2301  *packet_new = 0;
2302  break;
2303  default:
2304  *packet_new = 0;
2305  }
2306  } else {
2307  *packet_new = 0;
2308  }
2309 
2310  if (ret < 0)
2311  return ret;
2312  if (got_frame) {
2313  int is_sub = (par->codec_type == AVMEDIA_TYPE_SUBTITLE);
2314  nb_streams_frames[pkt->stream_index]++;
2315  if (do_show_frames) {
2316  if (is_sub) {
2317  show_subtitle(w, &sub, ifile->streams[pkt->stream_index].st, fmt_ctx);
2318  } else {
2319  show_frame(w, frame, ifile->streams[pkt->stream_index].st, fmt_ctx);
2320  }
2321  }
2322  if (is_sub) {
2323  avsubtitle_free(&sub);
2324  }
2325  }
2326  return got_frame || *packet_new;
2327 }
2328 
2329 static void log_read_interval(const ReadInterval *interval, void *log_ctx, int log_level)
2330 {
2331  av_log(log_ctx, log_level, "id:%d", interval->id);
2332 
2333  if (interval->has_start) {
2334  av_log(log_ctx, log_level, " start:%s%s", interval->start_is_offset ? "+" : "",
2335  av_ts2timestr(interval->start, &AV_TIME_BASE_Q));
2336  } else {
2337  av_log(log_ctx, log_level, " start:N/A");
2338  }
2339 
2340  if (interval->has_end) {
2341  av_log(log_ctx, log_level, " end:%s", interval->end_is_offset ? "+" : "");
2342  if (interval->duration_frames)
2343  av_log(log_ctx, log_level, "#%"PRId64, interval->end);
2344  else
2345  av_log(log_ctx, log_level, "%s", av_ts2timestr(interval->end, &AV_TIME_BASE_Q));
2346  } else {
2347  av_log(log_ctx, log_level, " end:N/A");
2348  }
2349 
2350  av_log(log_ctx, log_level, "\n");
2351 }
2352 
2354  const ReadInterval *interval, int64_t *cur_ts)
2355 {
2356  AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2357  AVPacket pkt;
2358  AVFrame *frame = NULL;
2359  int ret = 0, i = 0, frame_count = 0;
2360  int64_t start = -INT64_MAX, end = interval->end;
2361  int has_start = 0, has_end = interval->has_end && !interval->end_is_offset;
2362 
2363  av_init_packet(&pkt);
2364 
2365  av_log(NULL, AV_LOG_VERBOSE, "Processing read interval ");
2366  log_read_interval(interval, NULL, AV_LOG_VERBOSE);
2367 
2368  if (interval->has_start) {
2369  int64_t target;
2370  if (interval->start_is_offset) {
2371  if (*cur_ts == AV_NOPTS_VALUE) {
2372  av_log(NULL, AV_LOG_ERROR,
2373  "Could not seek to relative position since current "
2374  "timestamp is not defined\n");
2375  ret = AVERROR(EINVAL);
2376  goto end;
2377  }
2378  target = *cur_ts + interval->start;
2379  } else {
2380  target = interval->start;
2381  }
2382 
2383  av_log(NULL, AV_LOG_VERBOSE, "Seeking to read interval start point %s\n",
2384  av_ts2timestr(target, &AV_TIME_BASE_Q));
2385  if ((ret = avformat_seek_file(fmt_ctx, -1, -INT64_MAX, target, INT64_MAX, 0)) < 0) {
2386  av_log(NULL, AV_LOG_ERROR, "Could not seek to position %"PRId64": %s\n",
2387  interval->start, av_err2str(ret));
2388  goto end;
2389  }
2390  }
2391 
2392  frame = av_frame_alloc();
2393  if (!frame) {
2394  ret = AVERROR(ENOMEM);
2395  goto end;
2396  }
2397  while (!av_read_frame(fmt_ctx, &pkt)) {
2398  if (fmt_ctx->nb_streams > nb_streams) {
2399  REALLOCZ_ARRAY_STREAM(nb_streams_frames, nb_streams, fmt_ctx->nb_streams);
2400  REALLOCZ_ARRAY_STREAM(nb_streams_packets, nb_streams, fmt_ctx->nb_streams);
2401  REALLOCZ_ARRAY_STREAM(selected_streams, nb_streams, fmt_ctx->nb_streams);
2402  nb_streams = fmt_ctx->nb_streams;
2403  }
2404  if (selected_streams[pkt.stream_index]) {
2405  AVRational tb = ifile->streams[pkt.stream_index].st->time_base;
2406 
2407  if (pkt.pts != AV_NOPTS_VALUE)
2408  *cur_ts = av_rescale_q(pkt.pts, tb, AV_TIME_BASE_Q);
2409 
2410  if (!has_start && *cur_ts != AV_NOPTS_VALUE) {
2411  start = *cur_ts;
2412  has_start = 1;
2413  }
2414 
2415  if (has_start && !has_end && interval->end_is_offset) {
2416  end = start + interval->end;
2417  has_end = 1;
2418  }
2419 
2420  if (interval->end_is_offset && interval->duration_frames) {
2421  if (frame_count >= interval->end)
2422  break;
2423  } else if (has_end && *cur_ts != AV_NOPTS_VALUE && *cur_ts >= end) {
2424  break;
2425  }
2426 
2427  frame_count++;
2428  if (do_read_packets) {
2429  if (do_show_packets)
2430  show_packet(w, ifile, &pkt, i++);
2431  nb_streams_packets[pkt.stream_index]++;
2432  }
2433  if (do_read_frames) {
2434  int packet_new = 1;
2435  while (process_frame(w, ifile, frame, &pkt, &packet_new) > 0);
2436  }
2437  }
2438  av_packet_unref(&pkt);
2439  }
2440  av_packet_unref(&pkt);
2441  //Flush remaining frames that are cached in the decoder
2442  for (i = 0; i < fmt_ctx->nb_streams; i++) {
2443  pkt.stream_index = i;
2444  if (do_read_frames)
2445  while (process_frame(w, ifile, frame, &pkt, &(int){1}) > 0);
2446  }
2447 
2448 end:
2449  av_frame_free(&frame);
2450  if (ret < 0) {
2451  av_log(NULL, AV_LOG_ERROR, "Could not read packets in interval ");
2452  log_read_interval(interval, NULL, AV_LOG_ERROR);
2453  }
2454  return ret;
2455 }
2456 
2457 static int read_packets(WriterContext *w, InputFile *ifile)
2458 {
2459  AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2460  int i, ret = 0;
2461  int64_t cur_ts = fmt_ctx->start_time;
2462 
2463  if (read_intervals_nb == 0) {
2464  ReadInterval interval = (ReadInterval) { .has_start = 0, .has_end = 0 };
2465  ret = read_interval_packets(w, ifile, &interval, &cur_ts);
2466  } else {
2467  for (i = 0; i < read_intervals_nb; i++) {
2468  ret = read_interval_packets(w, ifile, &read_intervals[i], &cur_ts);
2469  if (ret < 0)
2470  break;
2471  }
2472  }
2473 
2474  return ret;
2475 }
2476 
2477 static int show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_idx, InputStream *ist, int in_program)
2478 {
2479  AVStream *stream = ist->st;
2480  AVCodecParameters *par;
2481  AVCodecContext *dec_ctx;
2482  char val_str[128];
2483  const char *s;
2484  AVRational sar, dar;
2485  AVBPrint pbuf;
2486  const AVCodecDescriptor *cd;
2487  int ret = 0;
2488  const char *profile = NULL;
2489 
2490  av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2491 
2493 
2494  print_int("index", stream->index);
2495 
2496  par = stream->codecpar;
2497  dec_ctx = ist->dec_ctx;
2498  if ((cd = avcodec_descriptor_get(par->codec_id))) {
2499  print_str("codec_name", cd->name);
2500  if (!do_bitexact) {
2501  print_str("codec_long_name",
2502  cd->long_name ? cd->long_name : "unknown");
2503  }
2504  } else {
2505  print_str_opt("codec_name", "unknown");
2506  if (!do_bitexact) {
2507  print_str_opt("codec_long_name", "unknown");
2508  }
2509  }
2510 
2511  if (!do_bitexact && (profile = avcodec_profile_name(par->codec_id, par->profile)))
2512  print_str("profile", profile);
2513  else {
2514  if (par->profile != FF_PROFILE_UNKNOWN) {
2515  char profile_num[12];
2516  snprintf(profile_num, sizeof(profile_num), "%d", par->profile);
2517  print_str("profile", profile_num);
2518  } else
2519  print_str_opt("profile", "unknown");
2520  }
2521 
2522  s = av_get_media_type_string(par->codec_type);
2523  if (s) print_str ("codec_type", s);
2524  else print_str_opt("codec_type", "unknown");
2525 #if FF_API_LAVF_AVCTX
2526  if (dec_ctx)
2527  print_q("codec_time_base", dec_ctx->time_base, '/');
2528 #endif
2529 
2530  /* print AVI/FourCC tag */
2531  print_str("codec_tag_string", av_fourcc2str(par->codec_tag));
2532  print_fmt("codec_tag", "0x%04"PRIx32, par->codec_tag);
2533 
2534  switch (par->codec_type) {
2535  case AVMEDIA_TYPE_VIDEO:
2536  print_int("width", par->width);
2537  print_int("height", par->height);
2538 #if FF_API_LAVF_AVCTX
2539  if (dec_ctx) {
2540  print_int("coded_width", dec_ctx->coded_width);
2541  print_int("coded_height", dec_ctx->coded_height);
2542  }
2543 #endif
2544  print_int("has_b_frames", par->video_delay);
2545  sar = av_guess_sample_aspect_ratio(fmt_ctx, stream, NULL);
2546  if (sar.num) {
2547  print_q("sample_aspect_ratio", sar, ':');
2548  av_reduce(&dar.num, &dar.den,
2549  par->width * sar.num,
2550  par->height * sar.den,
2551  1024*1024);
2552  print_q("display_aspect_ratio", dar, ':');
2553  } else {
2554  print_str_opt("sample_aspect_ratio", "N/A");
2555  print_str_opt("display_aspect_ratio", "N/A");
2556  }
2557  s = av_get_pix_fmt_name(par->format);
2558  if (s) print_str ("pix_fmt", s);
2559  else print_str_opt("pix_fmt", "unknown");
2560  print_int("level", par->level);
2561 
2562  print_color_range(w, par->color_range);
2563  print_color_space(w, par->color_space);
2564  print_color_trc(w, par->color_trc);
2565  print_primaries(w, par->color_primaries);
2566  print_chroma_location(w, par->chroma_location);
2567 
2568  if (par->field_order == AV_FIELD_PROGRESSIVE)
2569  print_str("field_order", "progressive");
2570  else if (par->field_order == AV_FIELD_TT)
2571  print_str("field_order", "tt");
2572  else if (par->field_order == AV_FIELD_BB)
2573  print_str("field_order", "bb");
2574  else if (par->field_order == AV_FIELD_TB)
2575  print_str("field_order", "tb");
2576  else if (par->field_order == AV_FIELD_BT)
2577  print_str("field_order", "bt");
2578  else
2579  print_str_opt("field_order", "unknown");
2580 
2581 #if FF_API_PRIVATE_OPT
2582  if (dec_ctx && dec_ctx->timecode_frame_start >= 0) {
2583  char tcbuf[AV_TIMECODE_STR_SIZE];
2584  av_timecode_make_mpeg_tc_string(tcbuf, dec_ctx->timecode_frame_start);
2585  print_str("timecode", tcbuf);
2586  } else {
2587  print_str_opt("timecode", "N/A");
2588  }
2589 #endif
2590  if (dec_ctx)
2591  print_int("refs", dec_ctx->refs);
2592  break;
2593 
2594  case AVMEDIA_TYPE_AUDIO:
2595  s = av_get_sample_fmt_name(par->format);
2596  if (s) print_str ("sample_fmt", s);
2597  else print_str_opt("sample_fmt", "unknown");
2598  print_val("sample_rate", par->sample_rate, unit_hertz_str);
2599  print_int("channels", par->channels);
2600 
2601  if (par->channel_layout) {
2602  av_bprint_clear(&pbuf);
2603  av_bprint_channel_layout(&pbuf, par->channels, par->channel_layout);
2604  print_str ("channel_layout", pbuf.str);
2605  } else {
2606  print_str_opt("channel_layout", "unknown");
2607  }
2608 
2609  print_int("bits_per_sample", av_get_bits_per_sample(par->codec_id));
2610  break;
2611 
2612  case AVMEDIA_TYPE_SUBTITLE:
2613  if (par->width)
2614  print_int("width", par->width);
2615  else
2616  print_str_opt("width", "N/A");
2617  if (par->height)
2618  print_int("height", par->height);
2619  else
2620  print_str_opt("height", "N/A");
2621  break;
2622  }
2623 
2624  if (dec_ctx && dec_ctx->codec && dec_ctx->codec->priv_class && show_private_data) {
2625  const AVOption *opt = NULL;
2626  while ((opt = av_opt_next(dec_ctx->priv_data,opt))) {
2627  uint8_t *str;
2628  if (opt->flags) continue;
2629  if (av_opt_get(dec_ctx->priv_data, opt->name, 0, &str) >= 0) {
2630  print_str(opt->name, str);
2631  av_free(str);
2632  }
2633  }
2634  }
2635 
2636  if (fmt_ctx->iformat->flags & AVFMT_SHOW_IDS) print_fmt ("id", "0x%x", stream->id);
2637  else print_str_opt("id", "N/A");
2638  print_q("r_frame_rate", stream->r_frame_rate, '/');
2639  print_q("avg_frame_rate", stream->avg_frame_rate, '/');
2640  print_q("time_base", stream->time_base, '/');
2641  print_ts ("start_pts", stream->start_time);
2642  print_time("start_time", stream->start_time, &stream->time_base);
2643  print_ts ("duration_ts", stream->duration);
2644  print_time("duration", stream->duration, &stream->time_base);
2645  if (par->bit_rate > 0) print_val ("bit_rate", par->bit_rate, unit_bit_per_second_str);
2646  else print_str_opt("bit_rate", "N/A");
2647 #if FF_API_LAVF_AVCTX
2648  if (stream->codec->rc_max_rate > 0) print_val ("max_bit_rate", stream->codec->rc_max_rate, unit_bit_per_second_str);
2649  else print_str_opt("max_bit_rate", "N/A");
2650 #endif
2651  if (dec_ctx && dec_ctx->bits_per_raw_sample > 0) print_fmt("bits_per_raw_sample", "%d", dec_ctx->bits_per_raw_sample);
2652  else print_str_opt("bits_per_raw_sample", "N/A");
2653  if (stream->nb_frames) print_fmt ("nb_frames", "%"PRId64, stream->nb_frames);
2654  else print_str_opt("nb_frames", "N/A");
2655  if (nb_streams_frames[stream_idx]) print_fmt ("nb_read_frames", "%"PRIu64, nb_streams_frames[stream_idx]);
2656  else print_str_opt("nb_read_frames", "N/A");
2657  if (nb_streams_packets[stream_idx]) print_fmt ("nb_read_packets", "%"PRIu64, nb_streams_packets[stream_idx]);
2658  else print_str_opt("nb_read_packets", "N/A");
2659  if (do_show_data)
2660  writer_print_data(w, "extradata", par->extradata,
2661  par->extradata_size);
2662  writer_print_data_hash(w, "extradata_hash", par->extradata,
2663  par->extradata_size);
2664 
2665  /* Print disposition information */
2666 #define PRINT_DISPOSITION(flagname, name) do { \
2667  print_int(name, !!(stream->disposition & AV_DISPOSITION_##flagname)); \
2668  } while (0)
2669 
2672  PRINT_DISPOSITION(DEFAULT, "default");
2673  PRINT_DISPOSITION(DUB, "dub");
2674  PRINT_DISPOSITION(ORIGINAL, "original");
2675  PRINT_DISPOSITION(COMMENT, "comment");
2676  PRINT_DISPOSITION(LYRICS, "lyrics");
2677  PRINT_DISPOSITION(KARAOKE, "karaoke");
2678  PRINT_DISPOSITION(FORCED, "forced");
2679  PRINT_DISPOSITION(HEARING_IMPAIRED, "hearing_impaired");
2680  PRINT_DISPOSITION(VISUAL_IMPAIRED, "visual_impaired");
2681  PRINT_DISPOSITION(CLEAN_EFFECTS, "clean_effects");
2682  PRINT_DISPOSITION(ATTACHED_PIC, "attached_pic");
2683  PRINT_DISPOSITION(TIMED_THUMBNAILS, "timed_thumbnails");
2685  }
2686 
2687  if (do_show_stream_tags)
2688  ret = show_tags(w, stream->metadata, in_program ? SECTION_ID_PROGRAM_STREAM_TAGS : SECTION_ID_STREAM_TAGS);
2689 
2690  if (stream->nb_side_data) {
2691  print_pkt_side_data(w, stream->codecpar, stream->side_data, stream->nb_side_data,
2694  }
2695 
2697  av_bprint_finalize(&pbuf, NULL);
2698  fflush(stdout);
2699 
2700  return ret;
2701 }
2702 
2703 static int show_streams(WriterContext *w, InputFile *ifile)
2704 {
2705  AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2706  int i, ret = 0;
2707 
2709  for (i = 0; i < ifile->nb_streams; i++)
2710  if (selected_streams[i]) {
2711  ret = show_stream(w, fmt_ctx, i, &ifile->streams[i], 0);
2712  if (ret < 0)
2713  break;
2714  }
2716 
2717  return ret;
2718 }
2719 
2720 static int show_program(WriterContext *w, InputFile *ifile, AVProgram *program)
2721 {
2722  AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2723  int i, ret = 0;
2724 
2726  print_int("program_id", program->id);
2727  print_int("program_num", program->program_num);
2728  print_int("nb_streams", program->nb_stream_indexes);
2729  print_int("pmt_pid", program->pmt_pid);
2730  print_int("pcr_pid", program->pcr_pid);
2731  print_ts("start_pts", program->start_time);
2732  print_time("start_time", program->start_time, &AV_TIME_BASE_Q);
2733  print_ts("end_pts", program->end_time);
2734  print_time("end_time", program->end_time, &AV_TIME_BASE_Q);
2736  ret = show_tags(w, program->metadata, SECTION_ID_PROGRAM_TAGS);
2737  if (ret < 0)
2738  goto end;
2739 
2741  for (i = 0; i < program->nb_stream_indexes; i++) {
2742  if (selected_streams[program->stream_index[i]]) {
2743  ret = show_stream(w, fmt_ctx, program->stream_index[i], &ifile->streams[program->stream_index[i]], 1);
2744  if (ret < 0)
2745  break;
2746  }
2747  }
2749 
2750 end:
2752  return ret;
2753 }
2754 
2755 static int show_programs(WriterContext *w, InputFile *ifile)
2756 {
2757  AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2758  int i, ret = 0;
2759 
2761  for (i = 0; i < fmt_ctx->nb_programs; i++) {
2762  AVProgram *program = fmt_ctx->programs[i];
2763  if (!program)
2764  continue;
2765  ret = show_program(w, ifile, program);
2766  if (ret < 0)
2767  break;
2768  }
2770  return ret;
2771 }
2772 
2773 static int show_chapters(WriterContext *w, InputFile *ifile)
2774 {
2775  AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2776  int i, ret = 0;
2777 
2779  for (i = 0; i < fmt_ctx->nb_chapters; i++) {
2780  AVChapter *chapter = fmt_ctx->chapters[i];
2781 
2783  print_int("id", chapter->id);
2784  print_q ("time_base", chapter->time_base, '/');
2785  print_int("start", chapter->start);
2786  print_time("start_time", chapter->start, &chapter->time_base);
2787  print_int("end", chapter->end);
2788  print_time("end_time", chapter->end, &chapter->time_base);
2790  ret = show_tags(w, chapter->metadata, SECTION_ID_CHAPTER_TAGS);
2792  }
2794 
2795  return ret;
2796 }
2797 
2798 static int show_format(WriterContext *w, InputFile *ifile)
2799 {
2800  AVFormatContext *fmt_ctx = ifile->fmt_ctx;
2801  char val_str[128];
2802  int64_t size = fmt_ctx->pb ? avio_size(fmt_ctx->pb) : -1;
2803  int ret = 0;
2804 
2806  print_str_validate("filename", fmt_ctx->url);
2807  print_int("nb_streams", fmt_ctx->nb_streams);
2808  print_int("nb_programs", fmt_ctx->nb_programs);
2809  print_str("format_name", fmt_ctx->iformat->name);
2810  if (!do_bitexact) {
2811  if (fmt_ctx->iformat->long_name) print_str ("format_long_name", fmt_ctx->iformat->long_name);
2812  else print_str_opt("format_long_name", "unknown");
2813  }
2814  print_time("start_time", fmt_ctx->start_time, &AV_TIME_BASE_Q);
2815  print_time("duration", fmt_ctx->duration, &AV_TIME_BASE_Q);
2816  if (size >= 0) print_val ("size", size, unit_byte_str);
2817  else print_str_opt("size", "N/A");
2818  if (fmt_ctx->bit_rate > 0) print_val ("bit_rate", fmt_ctx->bit_rate, unit_bit_per_second_str);
2819  else print_str_opt("bit_rate", "N/A");
2820  print_int("probe_score", fmt_ctx->probe_score);
2821  if (do_show_format_tags)
2822  ret = show_tags(w, fmt_ctx->metadata, SECTION_ID_FORMAT_TAGS);
2823 
2825  fflush(stdout);
2826  return ret;
2827 }
2828 
2829 static void show_error(WriterContext *w, int err)
2830 {
2831  char errbuf[128];
2832  const char *errbuf_ptr = errbuf;
2833 
2834  if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)
2835  errbuf_ptr = strerror(AVUNERROR(err));
2836 
2838  print_int("code", err);
2839  print_str("string", errbuf_ptr);
2841 }
2842 
2843 static int open_input_file(InputFile *ifile, const char *filename)
2844 {
2845  int err, i;
2846  AVFormatContext *fmt_ctx = NULL;
2847  AVDictionaryEntry *t;
2848  int scan_all_pmts_set = 0;
2849 
2850  fmt_ctx = avformat_alloc_context();
2851  if (!fmt_ctx) {
2852  print_error(filename, AVERROR(ENOMEM));
2853  exit_program(1);
2854  }
2855 
2856  if (!av_dict_get(format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
2857  av_dict_set(&format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE);
2858  scan_all_pmts_set = 1;
2859  }
2860  if ((err = avformat_open_input(&fmt_ctx, filename,
2861  iformat, &format_opts)) < 0) {
2862  print_error(filename, err);
2863  return err;
2864  }
2865  ifile->fmt_ctx = fmt_ctx;
2866  if (scan_all_pmts_set)
2867  av_dict_set(&format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
2868  if ((t = av_dict_get(format_opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
2869  av_log(NULL, AV_LOG_ERROR, "Option %s not found.\n", t->key);
2870  return AVERROR_OPTION_NOT_FOUND;
2871  }
2872 
2873  if (find_stream_info) {
2874  AVDictionary **opts = setup_find_stream_info_opts(fmt_ctx, codec_opts);
2875  int orig_nb_streams = fmt_ctx->nb_streams;
2876 
2877  err = avformat_find_stream_info(fmt_ctx, opts);
2878 
2879  for (i = 0; i < orig_nb_streams; i++)
2880  av_dict_free(&opts[i]);
2881  av_freep(&opts);
2882 
2883  if (err < 0) {
2884  print_error(filename, err);
2885  return err;
2886  }
2887  }
2888 
2889  av_dump_format(fmt_ctx, 0, filename, 0);
2890 
2891  ifile->streams = av_mallocz_array(fmt_ctx->nb_streams,
2892  sizeof(*ifile->streams));
2893  if (!ifile->streams)
2894  exit(1);
2895  ifile->nb_streams = fmt_ctx->nb_streams;
2896 
2897  /* bind a decoder to each input stream */
2898  for (i = 0; i < fmt_ctx->nb_streams; i++) {
2899  InputStream *ist = &ifile->streams[i];
2900  AVStream *stream = fmt_ctx->streams[i];
2901  AVCodec *codec;
2902 
2903  ist->st = stream;
2904 
2905  if (stream->codecpar->codec_id == AV_CODEC_ID_PROBE) {
2906  av_log(NULL, AV_LOG_WARNING,
2907  "Failed to probe codec for input stream %d\n",
2908  stream->index);
2909  continue;
2910  }
2911 
2912  codec = avcodec_find_decoder(stream->codecpar->codec_id);
2913  if (!codec) {
2914  av_log(NULL, AV_LOG_WARNING,
2915  "Unsupported codec with id %d for input stream %d\n",
2916  stream->codecpar->codec_id, stream->index);
2917  continue;
2918  }
2919  {
2920  AVDictionary *opts = filter_codec_opts(codec_opts, stream->codecpar->codec_id,
2921  fmt_ctx, stream, codec);
2922 
2923  ist->dec_ctx = avcodec_alloc_context3(codec);
2924  if (!ist->dec_ctx)
2925  exit(1);
2926 
2927  err = avcodec_parameters_to_context(ist->dec_ctx, stream->codecpar);
2928  if (err < 0)
2929  exit(1);
2930 
2931  if (do_show_log) {
2932  // For loging it is needed to disable at least frame threads as otherwise
2933  // the log information would need to be reordered and matches up to contexts and frames
2934  // That is in fact possible but not trivial
2935  av_dict_set(&codec_opts, "threads", "1", 0);
2936  }
2937 
2938  ist->dec_ctx->pkt_timebase = stream->time_base;
2939  ist->dec_ctx->framerate = stream->avg_frame_rate;
2940 #if FF_API_LAVF_AVCTX
2941  ist->dec_ctx->coded_width = stream->codec->coded_width;
2942  ist->dec_ctx->coded_height = stream->codec->coded_height;
2943 #endif
2944 
2945  if (avcodec_open2(ist->dec_ctx, codec, &opts) < 0) {
2946  av_log(NULL, AV_LOG_WARNING, "Could not open codec for input stream %d\n",
2947  stream->index);
2948  exit(1);
2949  }
2950 
2951  if ((t = av_dict_get(opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
2952  av_log(NULL, AV_LOG_ERROR, "Option %s for input stream %d not found\n",
2953  t->key, stream->index);
2954  return AVERROR_OPTION_NOT_FOUND;
2955  }
2956  }
2957  }
2958 
2959  ifile->fmt_ctx = fmt_ctx;
2960  return 0;
2961 }
2962 
2963 static void close_input_file(InputFile *ifile)
2964 {
2965  int i;
2966 
2967  /* close decoder for each stream */
2968  for (i = 0; i < ifile->nb_streams; i++)
2969  if (ifile->streams[i].st->codecpar->codec_id != AV_CODEC_ID_NONE)
2970  avcodec_free_context(&ifile->streams[i].dec_ctx);
2971 
2972  av_freep(&ifile->streams);
2973  ifile->nb_streams = 0;
2974 
2975  avformat_close_input(&ifile->fmt_ctx);
2976 }
2977 
2978 static int probe_file(WriterContext *wctx, const char *filename)
2979 {
2980  InputFile ifile = { 0 };
2981  int ret, i;
2982  int section_id;
2983 
2986 
2987  ret = open_input_file(&ifile, filename);
2988  if (ret < 0)
2989  goto end;
2990 
2991 #define CHECK_END if (ret < 0) goto end
2992 
2993  nb_streams = ifile.fmt_ctx->nb_streams;
2994  REALLOCZ_ARRAY_STREAM(nb_streams_frames,0,ifile.fmt_ctx->nb_streams);
2995  REALLOCZ_ARRAY_STREAM(nb_streams_packets,0,ifile.fmt_ctx->nb_streams);
2996  REALLOCZ_ARRAY_STREAM(selected_streams,0,ifile.fmt_ctx->nb_streams);
2997 
2998  for (i = 0; i < ifile.fmt_ctx->nb_streams; i++) {
2999  if (stream_specifier) {
3000  ret = avformat_match_stream_specifier(ifile.fmt_ctx,
3001  ifile.fmt_ctx->streams[i],
3003  CHECK_END;
3004  else
3005  selected_streams[i] = ret;
3006  ret = 0;
3007  } else {
3008  selected_streams[i] = 1;
3009  }
3010  if (!selected_streams[i])
3011  ifile.fmt_ctx->streams[i]->discard = AVDISCARD_ALL;
3012  }
3013 
3017  section_id = SECTION_ID_PACKETS_AND_FRAMES;
3018  else if (do_show_packets && !do_show_frames)
3019  section_id = SECTION_ID_PACKETS;
3020  else // (!do_show_packets && do_show_frames)
3021  section_id = SECTION_ID_FRAMES;
3023  writer_print_section_header(wctx, section_id);
3024  ret = read_packets(wctx, &ifile);
3027  CHECK_END;
3028  }
3029 
3030  if (do_show_programs) {
3031  ret = show_programs(wctx, &ifile);
3032  CHECK_END;
3033  }
3034 
3035  if (do_show_streams) {
3036  ret = show_streams(wctx, &ifile);
3037  CHECK_END;
3038  }
3039  if (do_show_chapters) {
3040  ret = show_chapters(wctx, &ifile);
3041  CHECK_END;
3042  }
3043  if (do_show_format) {
3044  ret = show_format(wctx, &ifile);
3045  CHECK_END;
3046  }
3047 
3048 end:
3049  if (ifile.fmt_ctx)
3050  close_input_file(&ifile);
3051  av_freep(&nb_streams_frames);
3052  av_freep(&nb_streams_packets);
3053  av_freep(&selected_streams);
3054 
3055  return ret;
3056 }
3057 
3058 static void show_usage(void)
3059 {
3060  av_log(NULL, AV_LOG_INFO, "Simple multimedia streams analyzer\n");
3061  av_log(NULL, AV_LOG_INFO, "usage: %s [OPTIONS] [INPUT_FILE]\n", program_name);
3062  av_log(NULL, AV_LOG_INFO, "\n");
3063 }
3064 
3066 {
3067  AVBPrint pbuf;
3068  av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
3069 
3071  print_str("version", FFMPEG_VERSION);
3072  print_fmt("copyright", "Copyright (c) %d-%d the FFmpeg developers",
3073  program_birth_year, CONFIG_THIS_YEAR);
3074  print_str("compiler_ident", CC_IDENT);
3075  print_str("configuration", FFMPEG_CONFIGURATION);
3077 
3078  av_bprint_finalize(&pbuf, NULL);
3079 }
3080 
3081 #define SHOW_LIB_VERSION(libname, LIBNAME) \
3082  do { \
3083  if (CONFIG_##LIBNAME) { \
3084  unsigned int version = libname##_version(); \
3085  writer_print_section_header(w, SECTION_ID_LIBRARY_VERSION); \
3086  print_str("name", "lib" #libname); \
3087  print_int("major", LIB##LIBNAME##_VERSION_MAJOR); \
3088  print_int("minor", LIB##LIBNAME##_VERSION_MINOR); \
3089  print_int("micro", LIB##LIBNAME##_VERSION_MICRO); \
3090  print_int("version", version); \
3091  print_str("ident", LIB##LIBNAME##_IDENT); \
3092  writer_print_section_footer(w); \
3093  } \
3094  } while (0)
3095 
3097 {
3099  SHOW_LIB_VERSION(avutil, AVUTIL);
3100  SHOW_LIB_VERSION(avcodec, AVCODEC);
3101  SHOW_LIB_VERSION(avformat, AVFORMAT);
3102  SHOW_LIB_VERSION(avdevice, AVDEVICE);
3103  SHOW_LIB_VERSION(avfilter, AVFILTER);
3104  SHOW_LIB_VERSION(swscale, SWSCALE);
3105  SHOW_LIB_VERSION(swresample, SWRESAMPLE);
3107 }
3108 
3109 #define PRINT_PIX_FMT_FLAG(flagname, name) \
3110  do { \
3111  print_int(name, !!(pixdesc->flags & AV_PIX_FMT_FLAG_##flagname)); \
3112  } while (0)
3113 
3115 {
3116  const AVPixFmtDescriptor *pixdesc = NULL;
3117  int i, n;
3118 
3120  while ((pixdesc = av_pix_fmt_desc_next(pixdesc))) {
3122  print_str("name", pixdesc->name);
3123  print_int("nb_components", pixdesc->nb_components);
3124  if ((pixdesc->nb_components >= 3) && !(pixdesc->flags & AV_PIX_FMT_FLAG_RGB)) {
3125  print_int ("log2_chroma_w", pixdesc->log2_chroma_w);
3126  print_int ("log2_chroma_h", pixdesc->log2_chroma_h);
3127  } else {
3128  print_str_opt("log2_chroma_w", "N/A");
3129  print_str_opt("log2_chroma_h", "N/A");
3130  }
3131  n = av_get_bits_per_pixel(pixdesc);
3132  if (n) print_int ("bits_per_pixel", n);
3133  else print_str_opt("bits_per_pixel", "N/A");
3136  PRINT_PIX_FMT_FLAG(BE, "big_endian");
3137  PRINT_PIX_FMT_FLAG(PAL, "palette");
3138  PRINT_PIX_FMT_FLAG(BITSTREAM, "bitstream");
3139  PRINT_PIX_FMT_FLAG(HWACCEL, "hwaccel");
3140  PRINT_PIX_FMT_FLAG(PLANAR, "planar");
3141  PRINT_PIX_FMT_FLAG(RGB, "rgb");
3142 #if FF_API_PSEUDOPAL
3143  PRINT_PIX_FMT_FLAG(PSEUDOPAL, "pseudopal");
3144 #endif
3145  PRINT_PIX_FMT_FLAG(ALPHA, "alpha");
3147  }
3148  if (do_show_pixel_format_components && (pixdesc->nb_components > 0)) {
3150  for (i = 0; i < pixdesc->nb_components; i++) {
3152  print_int("index", i + 1);
3153  print_int("bit_depth", pixdesc->comp[i].depth);
3155  }
3157  }
3159  }
3161 }
3162 
3163 static int opt_format(void *optctx, const char *opt, const char *arg)
3164 {
3165  iformat = av_find_input_format(arg);
3166  if (!iformat) {
3167  av_log(NULL, AV_LOG_ERROR, "Unknown input format: %s\n", arg);
3168  return AVERROR(EINVAL);
3169  }
3170  return 0;
3171 }
3172 
3173 static inline void mark_section_show_entries(SectionID section_id,
3174  int show_all_entries, AVDictionary *entries)
3175 {
3176  struct section *section = &sections[section_id];
3177 
3179  if (show_all_entries) {
3180  SectionID *id;
3181  for (id = section->children_ids; *id != -1; id++)
3183  } else {
3184  av_dict_copy(&section->entries_to_show, entries, 0);
3185  }
3186 }
3187 
3188 static int match_section(const char *section_name,
3189  int show_all_entries, AVDictionary *entries)
3190 {
3191  int i, ret = 0;
3192 
3193  for (i = 0; i < FF_ARRAY_ELEMS(sections); i++) {
3194  const struct section *section = &sections[i];
3195  if (!strcmp(section_name, section->name) ||
3196  (section->unique_name && !strcmp(section_name, section->unique_name))) {
3197  av_log(NULL, AV_LOG_DEBUG,
3198  "'%s' matches section with unique name '%s'\n", section_name,
3199  (char *)av_x_if_null(section->unique_name, section->name));
3200  ret++;
3202  }
3203  }
3204  return ret;
3205 }
3206 
3207 static int opt_show_entries(void *optctx, const char *opt, const char *arg)
3208 {
3209  const char *p = arg;
3210  int ret = 0;
3211 
3212  while (*p) {
3213  AVDictionary *entries = NULL;
3214  char *section_name = av_get_token(&p, "=:");
3215  int show_all_entries = 0;
3216 
3217  if (!section_name) {
3218  av_log(NULL, AV_LOG_ERROR,
3219  "Missing section name for option '%s'\n", opt);
3220  return AVERROR(EINVAL);
3221  }
3222 
3223  if (*p == '=') {
3224  p++;
3225  while (*p && *p != ':') {
3226  char *entry = av_get_token(&p, ",:");
3227  if (!entry)
3228  break;
3229  av_log(NULL, AV_LOG_VERBOSE,
3230  "Adding '%s' to the entries to show in section '%s'\n",
3231  entry, section_name);
3232  av_dict_set(&entries, entry, "", AV_DICT_DONT_STRDUP_KEY);
3233  if (*p == ',')
3234  p++;
3235  }
3236  } else {
3237  show_all_entries = 1;
3238  }
3239 
3240  ret = match_section(section_name, show_all_entries, entries);
3241  if (ret == 0) {
3242  av_log(NULL, AV_LOG_ERROR, "No match for section '%s'\n", section_name);
3243  ret = AVERROR(EINVAL);
3244  }
3245  av_dict_free(&entries);
3246  av_free(section_name);
3247 
3248  if (ret <= 0)
3249  break;
3250  if (*p)
3251  p++;
3252  }
3253 
3254  return ret;
3255 }
3256 
3257 static int opt_show_format_entry(void *optctx, const char *opt, const char *arg)
3258 {
3259  char *buf = av_asprintf("format=%s", arg);
3260  int ret;
3261 
3262  if (!buf)
3263  return AVERROR(ENOMEM);
3264 
3265  av_log(NULL, AV_LOG_WARNING,
3266  "Option '%s' is deprecated, use '-show_entries format=%s' instead\n",
3267  opt, arg);
3268  ret = opt_show_entries(optctx, opt, buf);
3269  av_free(buf);
3270  return ret;
3271 }
3272 
3273 static void opt_input_file(void *optctx, const char *arg)
3274 {
3275  if (input_filename) {
3276  av_log(NULL, AV_LOG_ERROR,
3277  "Argument '%s' provided as input filename, but '%s' was already specified.\n",
3278  arg, input_filename);
3279  exit_program(1);
3280  }
3281  if (!strcmp(arg, "-"))
3282  arg = "pipe:";
3283  input_filename = arg;
3284 }
3285 
3286 static int opt_input_file_i(void *optctx, const char *opt, const char *arg)
3287 {
3288  opt_input_file(optctx, arg);
3289  return 0;
3290 }
3291 
3292 void show_help_default_ffprobe(const char *opt, const char *arg)
3293 {
3294  show_usage();
3295  show_help_options(ffprobe_options, "Main options:", 0, 0, 0);
3296  av_log(NULL, AV_LOG_STDERR, "\n");
3297 
3298  show_help_children(avformat_get_class(), AV_OPT_FLAG_DECODING_PARAM);
3299  show_help_children(avcodec_get_class(), AV_OPT_FLAG_DECODING_PARAM);
3300 }
3301 
3307 static int parse_read_interval(const char *interval_spec,
3308  ReadInterval *interval)
3309 {
3310  int ret = 0;
3311  char *next, *p, *spec = av_strdup(interval_spec);
3312  if (!spec)
3313  return AVERROR(ENOMEM);
3314 
3315  if (!*spec) {
3316  av_log(NULL, AV_LOG_ERROR, "Invalid empty interval specification\n");
3317  ret = AVERROR(EINVAL);
3318  goto end;
3319  }
3320 
3321  p = spec;
3322  next = strchr(spec, '%');
3323  if (next)
3324  *next++ = 0;
3325 
3326  /* parse first part */
3327  if (*p) {
3328  interval->has_start = 1;
3329 
3330  if (*p == '+') {
3331  interval->start_is_offset = 1;
3332  p++;
3333  } else {
3334  interval->start_is_offset = 0;
3335  }
3336 
3337  ret = av_parse_time(&interval->start, p, 1);
3338  if (ret < 0) {
3339  av_log(NULL, AV_LOG_ERROR, "Invalid interval start specification '%s'\n", p);
3340  goto end;
3341  }
3342  } else {
3343  interval->has_start = 0;
3344  }
3345 
3346  /* parse second part */
3347  p = next;
3348  if (p && *p) {
3349  int64_t us;
3350  interval->has_end = 1;
3351 
3352  if (*p == '+') {
3353  interval->end_is_offset = 1;
3354  p++;
3355  } else {
3356  interval->end_is_offset = 0;
3357  }
3358 
3359  if (interval->end_is_offset && *p == '#') {
3360  long long int lli;
3361  char *tail;
3362  interval->duration_frames = 1;
3363  p++;
3364  lli = strtoll(p, &tail, 10);
3365  if (*tail || lli < 0) {
3366  av_log(NULL, AV_LOG_ERROR,
3367  "Invalid or negative value '%s' for duration number of frames\n", p);
3368  goto end;
3369  }
3370  interval->end = lli;
3371  } else {
3372  interval->duration_frames = 0;
3373  ret = av_parse_time(&us, p, 1);
3374  if (ret < 0) {
3375  av_log(NULL, AV_LOG_ERROR, "Invalid interval end/duration specification '%s'\n", p);
3376  goto end;
3377  }
3378  interval->end = us;
3379  }
3380  } else {
3381  interval->has_end = 0;
3382  }
3383 
3384 end:
3385  av_free(spec);
3386  return ret;
3387 }
3388 
3389 static int parse_read_intervals(const char *intervals_spec)
3390 {
3391  int ret, n, i;
3392  char *p, *spec = av_strdup(intervals_spec);
3393  if (!spec)
3394  return AVERROR(ENOMEM);
3395 
3396  /* preparse specification, get number of intervals */
3397  for (n = 0, p = spec; *p; p++)
3398  if (*p == ',')
3399  n++;
3400  n++;
3401 
3402  read_intervals = av_malloc_array(n, sizeof(*read_intervals));
3403  if (!read_intervals) {
3404  ret = AVERROR(ENOMEM);
3405  goto end;
3406  }
3407  read_intervals_nb = n;
3408 
3409  /* parse intervals */
3410  p = spec;
3411  for (i = 0; p; i++) {
3412  char *next;
3413 
3414  av_assert0(i < read_intervals_nb);
3415  next = strchr(p, ',');
3416  if (next)
3417  *next++ = 0;
3418 
3419  read_intervals[i].id = i;
3420  ret = parse_read_interval(p, &read_intervals[i]);
3421  if (ret < 0) {
3422  av_log(NULL, AV_LOG_ERROR, "Error parsing read interval #%d '%s'\n",
3423  i, p);
3424  goto end;
3425  }
3426  av_log(NULL, AV_LOG_VERBOSE, "Parsed log interval ");
3428  p = next;
3429  }
3430  av_assert0(i == read_intervals_nb);
3431 
3432 end:
3433  av_free(spec);
3434  return ret;
3435 }
3436 
3437 static int opt_read_intervals(void *optctx, const char *opt, const char *arg)
3438 {
3439  return parse_read_intervals(arg);
3440 }
3441 
3442 static int opt_pretty(void *optctx, const char *opt, const char *arg)
3443 {
3444  show_value_unit = 1;
3445  use_value_prefix = 1;
3448  return 0;
3449 }
3450 
3451 static void print_section(SectionID id, int level)
3452 {
3453  const SectionID *pid;
3454  const struct section *section = &sections[id];
3455  av_log(NULL, AV_LOG_STDERR, "%c%c%c",
3456  section->flags & SECTION_FLAG_IS_WRAPPER ? 'W' : '.',
3457  section->flags & SECTION_FLAG_IS_ARRAY ? 'A' : '.',
3459  av_log(NULL, AV_LOG_STDERR, "%*c %s", level * 4, ' ', section->name);
3460  if (section->unique_name)
3461  av_log(NULL, AV_LOG_STDERR, "/%s", section->unique_name);
3462  av_log(NULL, AV_LOG_STDERR, "\n");
3463 
3464  for (pid = section->children_ids; *pid != -1; pid++)
3465  print_section(*pid, level+1);
3466 }
3467 
3468 static int opt_sections(void *optctx, const char *opt, const char *arg)
3469 {
3470  av_log(NULL, AV_LOG_STDERR, "Sections:\n"
3471  "W.. = Section is a wrapper (contains other sections, no local entries)\n"
3472  ".A. = Section contains an array of elements of the same type\n"
3473  "..V = Section may contain a variable number of fields with variable keys\n"
3474  "FLAGS NAME/UNIQUE_NAME\n"
3475  "---\n");
3477  return 0;
3478 }
3479 
3480 static int opt_show_versions(void *optctx, const char *opt, const char *arg)
3481 {
3484  return 0;
3485 }
3486 
3487 #define DEFINE_OPT_SHOW_SECTION(section, target_section_id) \
3488  static int opt_show_##section(void *optctx, const char *opt, const char *arg) \
3489  { \
3490  mark_section_show_entries(SECTION_ID_##target_section_id, 1, NULL); \
3491  return 0; \
3492  }
3493 
3494 DEFINE_OPT_SHOW_SECTION(chapters, CHAPTERS)
3495 DEFINE_OPT_SHOW_SECTION(error, ERROR)
3496 DEFINE_OPT_SHOW_SECTION(format, FORMAT)
3497 DEFINE_OPT_SHOW_SECTION(frames, FRAMES)
3498 DEFINE_OPT_SHOW_SECTION(library_versions, LIBRARY_VERSIONS)
3499 DEFINE_OPT_SHOW_SECTION(packets, PACKETS)
3500 DEFINE_OPT_SHOW_SECTION(pixel_formats, PIXEL_FORMATS)
3501 DEFINE_OPT_SHOW_SECTION(program_version, PROGRAM_VERSION)
3502 DEFINE_OPT_SHOW_SECTION(streams, STREAMS)
3503 DEFINE_OPT_SHOW_SECTION(programs, PROGRAMS)
3504 
3505 static inline int check_section_show_entries(int section_id)
3506 {
3507  int *id;
3508  struct section *section = &sections[section_id];
3509  if (sections[section_id].show_all_entries || sections[section_id].entries_to_show)
3510  return 1;
3511  for (id = section->children_ids; *id != -1; id++)
3512  if (check_section_show_entries(*id))
3513  return 1;
3514  return 0;
3515 }
3516 
3517 #define SET_DO_SHOW(id, varname) do { \
3518  if (check_section_show_entries(SECTION_ID_##id)) \
3519  do_show_##varname = 1; \
3520  } while (0)
3521 
3524  longjmp_value = 0;
3525 
3526  do_bitexact = 0;
3527  do_count_frames = 0;
3528  do_count_packets = 0;
3529  do_read_frames = 0;
3530  do_read_packets = 0;
3531  do_show_chapters = 0;
3532  do_show_error = 0;
3533  do_show_format = 0;
3534  do_show_frames = 0;
3535  do_show_packets = 0;
3536  do_show_programs = 0;
3537  do_show_streams = 0;
3539  do_show_data = 0;
3545  do_show_log = 0;
3546 
3548  do_show_format_tags = 0;
3549  do_show_frame_tags = 0;
3551  do_show_stream_tags = 0;
3552  do_show_packet_tags = 0;
3553 
3554  show_value_unit = 0;
3555  use_value_prefix = 0;
3558  show_private_data = 1;
3559 
3560  print_format = NULL;
3561  stream_specifier = NULL;
3562  show_data_hash = NULL;
3563 
3564  read_intervals = NULL;
3565  read_intervals_nb = 0;
3566 
3567  ffprobe_options = NULL;
3568 
3569  input_filename = NULL;
3570  iformat = NULL;
3571 
3572  hash = NULL;
3573 
3575 
3576  nb_streams = 0;
3577  nb_streams_packets = NULL;
3578  nb_streams_frames = NULL;
3579  selected_streams = NULL;
3580 
3581  log_buffer = NULL;
3582  log_buffer_size = 0;
3583 }
3584 
3585 int ffprobe_execute(int argc, char **argv)
3586 {
3587  char _program_name[] = "ffprobe";
3588  program_name = (char*)&_program_name;
3589  program_birth_year = 2007;
3590 
3591  OptionDef options[] = {
3592  { "L", OPT_EXIT, { .func_arg = show_license }, "show license" },
3593  { "h", OPT_EXIT, { .func_arg = show_help }, "show help", "topic" },
3594  { "?", OPT_EXIT, { .func_arg = show_help }, "show help", "topic" },
3595  { "help", OPT_EXIT, { .func_arg = show_help }, "show help", "topic" },
3596  { "-help", OPT_EXIT, { .func_arg = show_help }, "show help", "topic" },
3597  { "version", OPT_EXIT, { .func_arg = show_version }, "show version" },
3598  { "buildconf", OPT_EXIT, { .func_arg = show_buildconf }, "show build configuration" },
3599  { "formats", OPT_EXIT, { .func_arg = show_formats }, "show available formats" },
3600  { "muxers", OPT_EXIT, { .func_arg = show_muxers }, "show available muxers" },
3601  { "demuxers", OPT_EXIT, { .func_arg = show_demuxers }, "show available demuxers" },
3602  { "devices", OPT_EXIT, { .func_arg = show_devices }, "show available devices" },
3603  { "codecs", OPT_EXIT, { .func_arg = show_codecs }, "show available codecs" },
3604  { "decoders", OPT_EXIT, { .func_arg = show_decoders }, "show available decoders" },
3605  { "encoders", OPT_EXIT, { .func_arg = show_encoders }, "show available encoders" },
3606  { "bsfs", OPT_EXIT, { .func_arg = show_bsfs }, "show available bit stream filters" },
3607  { "protocols", OPT_EXIT, { .func_arg = show_protocols }, "show available protocols" },
3608  { "filters", OPT_EXIT, { .func_arg = show_filters }, "show available filters" },
3609  { "pix_fmts", OPT_EXIT, { .func_arg = show_pix_fmts }, "show available pixel formats" },
3610  { "layouts", OPT_EXIT, { .func_arg = show_layouts }, "show standard channel layouts" },
3611  { "sample_fmts", OPT_EXIT, { .func_arg = show_sample_fmts }, "show available audio sample formats" },
3612  { "colors", OPT_EXIT, { .func_arg = show_colors }, "show available color names" },
3613  { "loglevel", HAS_ARG, { .func_arg = opt_loglevel }, "set logging level", "loglevel" },
3614  { "v", HAS_ARG, { .func_arg = opt_loglevel }, "set logging level", "loglevel" },
3615  { "report", 0, { .func_arg = opt_report }, "generate a report" },
3616  { "max_alloc", HAS_ARG, { .func_arg = opt_max_alloc }, "set maximum size of a single allocated block", "bytes" },
3617  { "cpuflags", HAS_ARG | OPT_EXPERT, { .func_arg = opt_cpuflags }, "force specific cpu flags", "flags" },
3618  { "hide_banner", OPT_BOOL | OPT_EXPERT, {&hide_banner}, "do not show program banner", "hide_banner" },
3619 
3620  #if CONFIG_AVDEVICE
3621  { "sources" , OPT_EXIT | HAS_ARG, { .func_arg = show_sources },
3622  "list sources of the input device", "device" },
3623  { "sinks" , OPT_EXIT | HAS_ARG, { .func_arg = show_sinks },
3624  "list sinks of the output device", "device" },
3625  #endif
3626 
3627  { "f", HAS_ARG, {.func_arg = opt_format}, "force format", "format" },
3628  { "unit", OPT_BOOL, {&show_value_unit}, "show unit of the displayed values" },
3629  { "prefix", OPT_BOOL, {&use_value_prefix}, "use SI prefixes for the displayed values" },
3630  { "byte_binary_prefix", OPT_BOOL, {&use_byte_value_binary_prefix},
3631  "use binary prefixes for byte units" },
3632  { "sexagesimal", OPT_BOOL, {&use_value_sexagesimal_format},
3633  "use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units" },
3634  { "pretty", 0, {.func_arg = opt_pretty},
3635  "prettify the format of displayed values, make it more human readable" },
3636  { "print_format", OPT_STRING | HAS_ARG, {(void*)&print_format},
3637  "set the output printing format (available formats are: default, compact, csv, flat, ini, json, xml)", "format" },
3638  { "of", OPT_STRING | HAS_ARG, {(void*)&print_format}, "alias for -print_format", "format" },
3639  { "select_streams", OPT_STRING | HAS_ARG, {(void*)&stream_specifier}, "select the specified streams", "stream_specifier" },
3640  { "sections", OPT_EXIT, {.func_arg = opt_sections}, "print sections structure and section information, and exit" },
3641  { "show_data", OPT_BOOL, {(void*)&do_show_data}, "show packets data" },
3642  { "show_data_hash", OPT_STRING | HAS_ARG, {(void*)&show_data_hash}, "show packets data hash" },
3643  { "show_error", 0, { .func_arg = &opt_show_error }, "show probing error" },
3644  { "show_format", 0, { .func_arg = &opt_show_format }, "show format/container info" },
3645  { "show_frames", 0, { .func_arg = &opt_show_frames }, "show frames info" },
3646  { "show_format_entry", HAS_ARG, {.func_arg = opt_show_format_entry},
3647  "show a particular entry from the format/container info", "entry" },
3648  { "show_entries", HAS_ARG, {.func_arg = opt_show_entries},
3649  "show a set of specified entries", "entry_list" },
3650  #if HAVE_THREADS
3651  { "show_log", OPT_INT|HAS_ARG, {(void*)&do_show_log}, "show log" },
3652  #endif
3653  { "show_packets", 0, { .func_arg = &opt_show_packets }, "show packets info" },
3654  { "show_programs", 0, { .func_arg = &opt_show_programs }, "show programs info" },
3655  { "show_streams", 0, { .func_arg = &opt_show_streams }, "show streams info" },
3656  { "show_chapters", 0, { .func_arg = &opt_show_chapters }, "show chapters info" },
3657  { "count_frames", OPT_BOOL, {(void*)&do_count_frames}, "count the number of frames per stream" },
3658  { "count_packets", OPT_BOOL, {(void*)&do_count_packets}, "count the number of packets per stream" },
3659  { "show_program_version", 0, { .func_arg = &opt_show_program_version }, "show ffprobe version" },
3660  { "show_library_versions", 0, { .func_arg = &opt_show_library_versions }, "show library versions" },
3661  { "show_versions", 0, { .func_arg = &opt_show_versions }, "show program and library versions" },
3662  { "show_pixel_formats", 0, { .func_arg = &opt_show_pixel_formats }, "show pixel format descriptions" },
3663  { "show_private_data", OPT_BOOL, {(void*)&show_private_data}, "show private data" },
3664  { "private", OPT_BOOL, {(void*)&show_private_data}, "same as show_private_data" },
3665  { "bitexact", OPT_BOOL, {&do_bitexact}, "force bitexact output" },
3666  { "read_intervals", HAS_ARG, {.func_arg = opt_read_intervals}, "set read intervals", "read_intervals" },
3667  { "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {.func_arg = opt_default}, "generic catch all option", "" },
3668  { "i", HAS_ARG, {.func_arg = opt_input_file_i}, "read specified file", "input_file"},
3669  { "find_stream_info", OPT_BOOL | OPT_INPUT | OPT_EXPERT, { &find_stream_info },
3670  "read and decode the streams to fill missing information with heuristics" },
3671  { NULL, },
3672  };
3673 
3674  const Writer *w;
3675  WriterContext *wctx;
3676  char *buf;
3677  char *w_name = NULL, *w_args = NULL;
3678  int ret, i;
3679 
3680  int savedCode = setjmp(ex_buf__);
3681  if (savedCode == 0) {
3682 
3684 
3685  init_dynload();
3686 
3687  #if HAVE_THREADS
3688  ret = pthread_mutex_init(&log_mutex, NULL);
3689  if (ret != 0) {
3690  goto end;
3691  }
3692  #endif
3693  av_log_set_flags(AV_LOG_SKIP_REPEATED);
3695 
3696  ffprobe_options = options;
3697  parse_loglevel(argc, argv, options);
3698  avformat_network_init();
3699  init_opts();
3700  #if CONFIG_AVDEVICE
3701  avdevice_register_all();
3702  #endif
3703 
3704  show_banner(argc, argv, options);
3705  parse_options(NULL, argc, argv, options, opt_input_file);
3706 
3707  if (do_show_log)
3708  av_log_set_callback(log_callback);
3709 
3710  /* mark things to show, based on -show_entries */
3711  SET_DO_SHOW(CHAPTERS, chapters);
3712  SET_DO_SHOW(ERROR, error);
3713  SET_DO_SHOW(FORMAT, format);
3714  SET_DO_SHOW(FRAMES, frames);
3715  SET_DO_SHOW(LIBRARY_VERSIONS, library_versions);
3716  SET_DO_SHOW(PACKETS, packets);
3717  SET_DO_SHOW(PIXEL_FORMATS, pixel_formats);
3718  SET_DO_SHOW(PIXEL_FORMAT_FLAGS, pixel_format_flags);
3719  SET_DO_SHOW(PIXEL_FORMAT_COMPONENTS, pixel_format_components);
3720  SET_DO_SHOW(PROGRAM_VERSION, program_version);
3721  SET_DO_SHOW(PROGRAMS, programs);
3722  SET_DO_SHOW(STREAMS, streams);
3723  SET_DO_SHOW(STREAM_DISPOSITION, stream_disposition);
3724  SET_DO_SHOW(PROGRAM_STREAM_DISPOSITION, stream_disposition);
3725 
3726  SET_DO_SHOW(CHAPTER_TAGS, chapter_tags);
3727  SET_DO_SHOW(FORMAT_TAGS, format_tags);
3728  SET_DO_SHOW(FRAME_TAGS, frame_tags);
3729  SET_DO_SHOW(PROGRAM_TAGS, program_tags);
3730  SET_DO_SHOW(STREAM_TAGS, stream_tags);
3731  SET_DO_SHOW(PROGRAM_STREAM_TAGS, stream_tags);
3732  SET_DO_SHOW(PACKET_TAGS, packet_tags);
3733 
3735  av_log(NULL, AV_LOG_ERROR,
3736  "-bitexact and -show_program_version or -show_library_versions "
3737  "options are incompatible\n");
3738  ret = AVERROR(EINVAL);
3739  goto end;
3740  }
3741 
3743 
3744  if (!print_format)
3745  print_format = av_strdup("default");
3746  if (!print_format) {
3747  ret = AVERROR(ENOMEM);
3748  goto end;
3749  }
3750  w_name = av_strtok(print_format, "=", &buf);
3751  if (!w_name) {
3752  av_log(NULL, AV_LOG_ERROR,
3753  "No name specified for the output format\n");
3754  ret = AVERROR(EINVAL);
3755  goto end;
3756  }
3757  w_args = buf;
3758 
3759  if (show_data_hash) {
3760  if ((ret = av_hash_alloc(&hash, show_data_hash)) < 0) {
3761  if (ret == AVERROR(EINVAL)) {
3762  const char *n;
3763  av_log(NULL, AV_LOG_ERROR,
3764  "Unknown hash algorithm '%s'\nKnown algorithms:",
3765  show_data_hash);
3766  for (i = 0; (n = av_hash_names(i)); i++)
3767  av_log(NULL, AV_LOG_ERROR, " %s", n);
3768  av_log(NULL, AV_LOG_ERROR, "\n");
3769  }
3770  goto end;
3771  }
3772  }
3773 
3774  w = writer_get_by_name(w_name);
3775  if (!w) {
3776  av_log(NULL, AV_LOG_ERROR, "Unknown output format with name '%s'\n", w_name);
3777  ret = AVERROR(EINVAL);
3778  goto end;
3779  }
3780 
3781  if ((ret = writer_open(&wctx, w, w_args,
3782  sections, FF_ARRAY_ELEMS(sections))) >= 0) {
3783  if (w == &xml_writer)
3784  wctx->string_validation_utf8_flags |= AV_UTF8_FLAG_EXCLUDE_XML_INVALID_CONTROL_CODES;
3785 
3787 
3794 
3795  if (!input_filename &&
3798  show_usage();
3799  av_log(NULL, AV_LOG_ERROR, "You have to specify one input file.\n");
3800  av_log(NULL, AV_LOG_ERROR, "Use -h to get full help or, even better, run 'man %s'.\n", program_name);
3801  ret = AVERROR(EINVAL);
3802  } else if (input_filename) {
3803  ret = probe_file(wctx, input_filename);
3804  if (ret < 0 && do_show_error)
3805  show_error(wctx, ret);
3806  }
3807 
3809  writer_close(&wctx);
3810  }
3811 
3812  main_ffprobe_return_code = ret < 0;
3813 
3814  } else {
3816  }
3817 
3818 end:
3819  av_freep(&print_format);
3820  av_freep(&read_intervals);
3821  av_hash_freep(&hash);
3822 
3823  uninit_opts();
3824  for (i = 0; i < FF_ARRAY_ELEMS(sections); i++)
3825  av_dict_free(&(sections[i].entries_to_show));
3826 
3827  avformat_network_deinit();
3828 
3829  return main_ffprobe_return_code;
3830 }
xml_print_str
static void xml_print_str(WriterContext *wctx, const char *key, const char *value)
Definition: fftools_ffprobe.c:1757
SECTION_ID_PROGRAM_TAGS
@ SECTION_ID_PROGRAM_TAGS
Definition: fftools_ffprobe.c:193
show_private_data
__thread int show_private_data
Definition: fftools_ffprobe.c:121
input_filename
__thread const char * input_filename
Definition: fftools_ffprobe.c:259
ffprobe_show_pixel_formats
static void ffprobe_show_pixel_formats(WriterContext *w)
Definition: fftools_ffprobe.c:3114
json_print_item_str
static void json_print_item_str(WriterContext *wctx, const char *key, const char *value)
Definition: fftools_ffprobe.c:1573
JSON_INDENT
#define JSON_INDENT()
Definition: fftools_ffprobe.c:1511
bin_str
const char * bin_str
Definition: fftools_ffprobe.c:270
print_primaries
static void print_primaries(WriterContext *w, enum AVColorPrimaries color_primaries)
Definition: fftools_ffprobe.c:1957
SECTION_ID_FRAME_SIDE_DATA_TIMECODE
@ SECTION_ID_FRAME_SIDE_DATA_TIMECODE
Definition: fftools_ffprobe.c:172
writer_print_integer
static void writer_print_integer(WriterContext *wctx, const char *key, long long int val)
Definition: fftools_ffprobe.c:676
clear_log
static void clear_log(int need_lock)
Definition: fftools_ffprobe.c:1988
validate_string
static int validate_string(WriterContext *wctx, char **dstp, const char *src)
Definition: fftools_ffprobe.c:687
opt_show_versions
static int opt_show_versions(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffprobe.c:3480
close_input_file
static void close_input_file(InputFile *ifile)
Definition: fftools_ffprobe.c:2963
show_decoders
int show_decoders(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1687
json_print_str
static void json_print_str(WriterContext *wctx, const char *key, const char *value)
Definition: fftools_ffprobe.c:1585
log_buffer
__thread LogBuffer * log_buffer
Definition: fftools_ffprobe.c:303
print_section_footer
#define print_section_footer(s)
Definition: fftools_ffprobe.c:1834
Writer::uninit
void(* uninit)(WriterContext *wctx)
Definition: fftools_ffprobe.c:444
CompactContext::terminate_line
int terminate_line[SECTION_MAX_NB_LEVELS]
Definition: fftools_ffprobe.c:1085
AV_LOG_INFO
#define AV_LOG_INFO
Definition: MobileFFmpegConfig.h:66
PRINT_STRING_VALIDATE
#define PRINT_STRING_VALIDATE
Definition: fftools_ffprobe.c:743
print_int
#define print_int(k, v)
Definition: fftools_ffprobe.c:1817
do_count_packets
__thread int do_count_packets
Definition: fftools_ffprobe.c:91
LogBuffer
struct LogBuffer LogBuffer
flat_options
static const AVOption flat_options[]
Definition: fftools_ffprobe.c:1245
default_print_section_footer
static void default_print_section_footer(WriterContext *wctx)
Definition: fftools_ffprobe.c:982
print_section_header
#define print_section_header(s)
Definition: fftools_ffprobe.c:1833
FlatContext::sep
char sep
Definition: fftools_ffprobe.c:1238
DefaultContext
Definition: fftools_ffprobe.c:927
writer_options
static const AVOption writer_options[]
Definition: fftools_ffprobe.c:492
do_show_pixel_format_flags
__thread int do_show_pixel_format_flags
Definition: fftools_ffprobe.c:106
ini_print_str
static void ini_print_str(WriterContext *wctx, const char *key, const char *value)
Definition: fftools_ffprobe.c:1435
ini_writer
static const Writer ini_writer
Definition: fftools_ffprobe.c:1451
OPT_EXIT
#define OPT_EXIT
Definition: fftools_cmdutils.h:198
SECTION_ID_PIXEL_FORMAT
@ SECTION_ID_PIXEL_FORMAT
Definition: fftools_ffprobe.c:183
SECTION_ID_PACKET
@ SECTION_ID_PACKET
Definition: fftools_ffprobe.c:177
writer_print_integers
static void writer_print_integers(WriterContext *wctx, const char *name, uint8_t *data, int size, const char *format, int columns, int bytes, int offset_add)
Definition: fftools_ffprobe.c:859
CompactContext::nested_section
int nested_section[SECTION_MAX_NB_LEVELS]
Definition: fftools_ffprobe.c:1083
MAX_REGISTERED_WRITERS_NB
#define MAX_REGISTERED_WRITERS_NB
Definition: fftools_ffprobe.c:885
SECTION_FLAG_HAS_VARIABLE_FIELDS
#define SECTION_FLAG_HAS_VARIABLE_FIELDS
Definition: fftools_ffprobe.c:148
program_name
__thread char * program_name
Definition: fftools_cmdutils.c:98
SECTION_ID_FRAME_SIDE_DATA
@ SECTION_ID_FRAME_SIDE_DATA
Definition: fftools_ffprobe.c:170
read_interval_packets
static int read_interval_packets(WriterContext *w, InputFile *ifile, const ReadInterval *interval, int64_t *cur_ts)
Definition: fftools_ffprobe.c:2353
Writer::flags
int flags
a combination or WRITER_FLAG_*
Definition: fftools_ffprobe.c:451
LogBuffer::parent_category
AVClassCategory parent_category
Definition: fftools_ffprobe.c:300
codec_opts
__thread AVDictionary * codec_opts
Definition: fftools_cmdutils.c:103
DefaultContext::nokey
int nokey
Definition: fftools_ffprobe.c:929
do_show_format
__thread int do_show_format
Definition: fftools_ffprobe.c:96
ffprobe_show_program_version
static void ffprobe_show_program_version(WriterContext *w)
Definition: fftools_ffprobe.c:3065
writer_register_all
static void writer_register_all(void)
Definition: fftools_ffprobe.c:1799
WriterContext::name
char * name
name of this writer instance
Definition: fftools_ffprobe.c:459
writer_get_name
static const char * writer_get_name(void *p)
Definition: fftools_ffprobe.c:484
selected_streams
__thread int * selected_streams
Definition: fftools_ffprobe.c:289
OPT_INPUT
#define OPT_INPUT
Definition: fftools_cmdutils.h:205
WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS
#define WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS
Definition: fftools_ffprobe.c:428
do_show_stream_tags
__thread int do_show_stream_tags
Definition: fftools_ffprobe.c:114
INIContext
Definition: fftools_ffprobe.c:1359
writer_print_ts
static void writer_print_ts(WriterContext *wctx, const char *key, int64_t ts, int is_duration)
Definition: fftools_ffprobe.c:807
c_escape_str
static const char * c_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
Definition: fftools_ffprobe.c:1029
ini_escape_str
static char * ini_escape_str(AVBPrint *dst, const char *src)
Definition: fftools_ffprobe.c:1375
show_pix_fmts
int show_pix_fmts(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1787
LogBuffer::category
AVClassCategory category
Definition: fftools_ffprobe.c:298
DEFINE_OPT_SHOW_SECTION
#define DEFINE_OPT_SHOW_SECTION(section, target_section_id)
Definition: fftools_ffprobe.c:3487
WriterContext::writer
const Writer * writer
the Writer of which this is an instance
Definition: fftools_ffprobe.c:458
AV_LOG_WARNING
#define AV_LOG_WARNING
Definition: MobileFFmpegConfig.h:61
CompactContext::item_sep_str
char * item_sep_str
Definition: fftools_ffprobe.c:1077
SectionID
SectionID
Definition: fftools_ffprobe.c:158
ReadInterval::end
int64_t end
start, end in second/AV_TIME_BASE units
Definition: fftools_ffprobe.c:129
exit_program
void exit_program(int ret)
Definition: fftools_cmdutils.c:166
section::element_name
const char * element_name
name of the contained element, if provided
Definition: fftools_ffprobe.c:152
compact_print_section_footer
static void compact_print_section_footer(WriterContext *wctx)
Definition: fftools_ffprobe.c:1157
DefaultContext::nested_section
int nested_section[SECTION_MAX_NB_LEVELS]
Definition: fftools_ffprobe.c:931
InputFile::fmt_ctx
AVFormatContext * fmt_ctx
Definition: fftools_ffprobe.c:83
parse_options
void parse_options(void *optctx, int argc, char **argv, const OptionDef *options, void(*parse_arg_function)(void *, const char *))
Definition: fftools_cmdutils.c:416
do_show_chapter_tags
__thread int do_show_chapter_tags
Definition: fftools_ffprobe.c:110
writer_print_string
static int writer_print_string(WriterContext *wctx, const char *key, const char *val, int flags)
Definition: fftools_ffprobe.c:745
InputStream
Definition: fftools_ffmpeg.h:318
upcase_string
static char * upcase_string(char *dst, size_t dst_size, const char *src)
Definition: fftools_ffprobe.c:948
SECTION_ID_PROGRAM_STREAMS
@ SECTION_ID_PROGRAM_STREAMS
Definition: fftools_ffprobe.c:191
DEFINE_WRITER_CLASS
#define DEFINE_WRITER_CLASS(name)
Definition: fftools_ffprobe.c:914
show_encoders
int show_encoders(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1693
registered_writers
__thread const Writer * registered_writers[MAX_REGISTERED_WRITERS_NB+1]
Definition: fftools_ffprobe.c:887
flat_print_section_header
static void flat_print_section_header(WriterContext *wctx)
Definition: fftools_ffprobe.c:1302
show_demuxers
int show_demuxers(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1407
section::id
int id
unique id identifying a section
Definition: fftools_ffprobe.c:143
LogBuffer
Definition: fftools_ffprobe.c:294
bin_val
double bin_val
Definition: fftools_ffprobe.c:268
JSONContext::indent_level
int indent_level
Definition: fftools_ffprobe.c:1465
CHECK_COMPLIANCE
#define CHECK_COMPLIANCE(opt, opt_name)
value_string
static char * value_string(char *buf, int buf_size, struct unit_value uv)
Definition: fftools_ffprobe.c:371
WriterContext::level
int level
current level, starting from 0
Definition: fftools_ffprobe.c:465
find_stream_info
__thread int find_stream_info
Definition: fftools_ffmpeg_opt.c:139
print_color_trc
static void print_color_trc(WriterContext *w, enum AVColorTransferCharacteristic color_trc)
Definition: fftools_ffprobe.c:1967
do_show_program_tags
__thread int do_show_program_tags
Definition: fftools_ffprobe.c:113
writer_print_rational
static void writer_print_rational(WriterContext *wctx, const char *key, AVRational q, char sep)
Definition: fftools_ffprobe.c:781
do_show_packets
__thread int do_show_packets
Definition: fftools_ffprobe.c:98
show_muxers
int show_muxers(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1402
section::unique_name
const char * unique_name
unique section name, in case the name is ambiguous
Definition: fftools_ffprobe.c:153
show_streams
static int show_streams(WriterContext *w, InputFile *ifile)
Definition: fftools_ffprobe.c:2703
ffprobe_options
__thread OptionDef * ffprobe_options
Definition: fftools_ffprobe.c:256
FlatContext::hierarchical
int hierarchical
Definition: fftools_ffprobe.c:1239
AV_LOG_ERROR
#define AV_LOG_ERROR
Definition: MobileFFmpegConfig.h:55
print_str_opt
#define print_str_opt(k, v)
Definition: fftools_ffprobe.c:1820
LogBuffer::context_name
char * context_name
Definition: fftools_ffprobe.c:295
StringValidation
StringValidation
Definition: fftools_ffprobe.c:431
XMLContext::within_tag
int within_tag
Definition: fftools_ffprobe.c:1631
show_help_options
void show_help_options(const OptionDef *options, const char *msg, int req_flags, int rej_flags, int alt_flags)
Definition: fftools_cmdutils.c:210
do_show_programs
__thread int do_show_programs
Definition: fftools_ffprobe.c:99
do_show_frame_tags
__thread int do_show_frame_tags
Definition: fftools_ffprobe.c:112
print_chroma_location
static void print_chroma_location(WriterContext *w, enum AVChromaLocation chroma_location)
Definition: fftools_ffprobe.c:1977
main_ffprobe_return_code
__thread volatile int main_ffprobe_return_code
Definition: fftools_ffprobe.c:264
ex_buf__
__thread jmp_buf ex_buf__
Definition: mobileffmpeg_exception.m:23
show_value_unit
__thread int show_value_unit
Definition: fftools_ffprobe.c:117
InputFile
struct InputFile InputFile
do_count_frames
__thread int do_count_frames
Definition: fftools_ffprobe.c:90
compact_print_int
static void compact_print_int(WriterContext *wctx, const char *key, long long int value)
Definition: fftools_ffprobe.c:1180
flat_writer
static const Writer flat_writer
Definition: fftools_ffprobe.c:1346
show_help_default_ffprobe
void show_help_default_ffprobe(const char *opt, const char *arg)
Definition: fftools_ffprobe.c:3292
none_escape_str
static const char * none_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
Definition: fftools_ffprobe.c:1070
ReadInterval::start_is_offset
int start_is_offset
Definition: fftools_ffprobe.c:131
SECTION_FLAG_IS_WRAPPER
#define SECTION_FLAG_IS_WRAPPER
the section only contains other sections, but has no data at its own level
Definition: fftools_ffprobe.c:146
SECTION_ID_FRAME_SIDE_DATA_TIMECODE_LIST
@ SECTION_ID_FRAME_SIDE_DATA_TIMECODE_LIST
Definition: fftools_ffprobe.c:171
SECTION_ID_CHAPTER_TAGS
@ SECTION_ID_CHAPTER_TAGS
Definition: fftools_ffprobe.c:161
log_read_interval
static void log_read_interval(const ReadInterval *interval, void *log_ctx, int log_level)
Definition: fftools_ffprobe.c:2329
REALLOCZ_ARRAY_STREAM
#define REALLOCZ_ARRAY_STREAM(ptr, cur_n, new_n)
Definition: fftools_ffprobe.c:1836
xml_print_int
static void xml_print_int(WriterContext *wctx, const char *key, long long int value)
Definition: fftools_ffprobe.c:1780
do_show_format_tags
__thread int do_show_format_tags
Definition: fftools_ffprobe.c:111
XMLContext::indent_level
int indent_level
Definition: fftools_ffprobe.c:1632
print_color_range
static void print_color_range(WriterContext *w, enum AVColorRange color_range)
Definition: fftools_ffprobe.c:1937
show_help
int show_help(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:2019
OPT_VIDEO
#define OPT_VIDEO
Definition: fftools_cmdutils.h:192
writer_class
static const AVClass writer_class
Definition: fftools_ffprobe.c:513
unit_value::val
union unit_value::@4 val
next_registered_writer_idx
__thread int next_registered_writer_idx
Definition: fftools_ffprobe.c:889
xml_init
static av_cold int xml_init(WriterContext *wctx)
Definition: fftools_ffprobe.c:1650
pthread_mutex_lock
#define pthread_mutex_lock(a)
Definition: fftools_ffprobe.c:69
SECTION_ID_FRAME_LOGS
@ SECTION_ID_FRAME_LOGS
Definition: fftools_ffprobe.c:174
sections
static struct section sections[]
Definition: fftools_ffprobe.c:206
DefaultContext::noprint_wrappers
int noprint_wrappers
Definition: fftools_ffprobe.c:930
use_value_prefix
__thread int use_value_prefix
Definition: fftools_ffprobe.c:118
flat_escape_value_str
static const char * flat_escape_value_str(AVBPrint *dst, const char *src)
Definition: fftools_ffprobe.c:1284
SECTION_ID_FORMAT
@ SECTION_ID_FORMAT
Definition: fftools_ffprobe.c:164
SECTION_ID_PROGRAM
@ SECTION_ID_PROGRAM
Definition: fftools_ffprobe.c:190
match_section
static int match_section(const char *section_name, int show_all_entries, AVDictionary *entries)
Definition: fftools_ffprobe.c:3188
OPT_INT
#define OPT_INT
Definition: fftools_cmdutils.h:194
opt_default
int opt_default(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:582
opt_read_intervals
static int opt_read_intervals(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffprobe.c:3437
CompactContext::print_section
int print_section
Definition: fftools_ffprobe.c:1080
show_filters
int show_filters(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1726
iformat
__thread AVInputFormat * iformat
Definition: fftools_ffprobe.c:260
process_frame
static av_always_inline int process_frame(WriterContext *w, InputFile *ifile, AVFrame *frame, AVPacket *pkt, int *packet_new)
Definition: fftools_ffprobe.c:2263
writer_print_section_header
static void writer_print_section_header(WriterContext *wctx, int section_id)
Definition: fftools_ffprobe.c:635
FlatContext
struct FlatContext FlatContext
xml_print_section_header
static void xml_print_section_header(WriterContext *wctx)
Definition: fftools_ffprobe.c:1698
print_fmt
#define print_fmt(k, f,...)
Definition: fftools_ffprobe.c:1811
print_str_validate
#define print_str_validate(k, v)
Definition: fftools_ffprobe.c:1821
compact_init
static av_cold int compact_init(WriterContext *wctx)
Definition: fftools_ffprobe.c:1105
opt_input_file_i
static int opt_input_file_i(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffprobe.c:3286
show_version
int show_version(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1238
use_byte_value_binary_prefix
__thread int use_byte_value_binary_prefix
Definition: fftools_ffprobe.c:119
writer_close
static void writer_close(WriterContext **wctx)
Definition: fftools_ffprobe.c:521
parse_loglevel
void parse_loglevel(int argc, char **argv, const OptionDef *options)
Definition: fftools_cmdutils.c:543
default_print_int
static void default_print_int(WriterContext *wctx, const char *key, long long int value)
Definition: fftools_ffprobe.c:1004
DefaultContext
struct DefaultContext DefaultContext
bprint_bytes
static void bprint_bytes(AVBPrint *bp, const uint8_t *ubuf, size_t ubuf_size)
Definition: fftools_ffprobe.c:539
show_program
static int show_program(WriterContext *w, InputFile *ifile, AVProgram *program)
Definition: fftools_ffprobe.c:2720
dec_val
double dec_val
Definition: fftools_ffprobe.c:269
show_programs
static int show_programs(WriterContext *w, InputFile *ifile)
Definition: fftools_ffprobe.c:2755
HAS_ARG
#define HAS_ARG
Definition: fftools_cmdutils.h:188
flat_init
static av_cold int flat_init(WriterContext *wctx)
Definition: fftools_ffprobe.c:1255
json_writer
static const Writer json_writer
Definition: fftools_ffprobe.c:1615
mark_section_show_entries
static void mark_section_show_entries(SectionID section_id, int show_all_entries, AVDictionary *entries)
Definition: fftools_ffprobe.c:3173
print_q
#define print_q(k, v, s)
Definition: fftools_ffprobe.c:1818
show_data_hash
__thread char * show_data_hash
Definition: fftools_ffprobe.c:125
print_duration_ts
#define print_duration_ts(k, v)
Definition: fftools_ffprobe.c:1825
ReadInterval::has_end
int has_end
Definition: fftools_ffprobe.c:130
SECTION_MAX_NB_CHILDREN
#define SECTION_MAX_NB_CHILDREN
Definition: fftools_ffprobe.c:140
section::show_all_entries
int show_all_entries
Definition: fftools_ffprobe.c:155
Writer::init
int(* init)(WriterContext *wctx)
Definition: fftools_ffprobe.c:443
opt_format
static int opt_format(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffprobe.c:3163
PRINT_STRING_OPT
#define PRINT_STRING_OPT
Definition: fftools_ffprobe.c:742
SECTION_ID_PIXEL_FORMAT_FLAGS
@ SECTION_ID_PIXEL_FORMAT_FLAGS
Definition: fftools_ffprobe.c:184
ReadInterval::end_is_offset
int end_is_offset
Definition: fftools_ffprobe.c:131
InputFile
Definition: fftools_ffmpeg.h:416
default_print_section_header
static void default_print_section_header(WriterContext *wctx)
Definition: fftools_ffprobe.c:957
log_callback
static void log_callback(void *ptr, int level, const char *fmt, va_list vl)
Definition: fftools_ffprobe.c:306
SECTION_ID_STREAM_SIDE_DATA
@ SECTION_ID_STREAM_SIDE_DATA
Definition: fftools_ffprobe.c:202
OPT_STRING
#define OPT_STRING
Definition: fftools_cmdutils.h:191
SECTION_ID_PACKET_SIDE_DATA
@ SECTION_ID_PACKET_SIDE_DATA
Definition: fftools_ffprobe.c:182
InputStream
struct InputStream InputStream
do_show_packet_tags
__thread int do_show_packet_tags
Definition: fftools_ffprobe.c:115
flat_escape_key_str
static const char * flat_escape_key_str(AVBPrint *dst, const char *src, const char sep)
Definition: fftools_ffprobe.c:1269
section::name
const char * name
Definition: fftools_ffprobe.c:144
opt_show_entries
static int opt_show_entries(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffprobe.c:3207
InputFile::streams
InputStream * streams
Definition: fftools_ffprobe.c:85
print_ts
#define print_ts(k, v)
Definition: fftools_ffprobe.c:1823
SECTION_ID_PROGRAM_STREAM_TAGS
@ SECTION_ID_PROGRAM_STREAM_TAGS
Definition: fftools_ffprobe.c:189
show_colors
int show_colors(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1773
opt_show_format_entry
static int opt_show_format_entry(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffprobe.c:3257
default_print_str
static void default_print_str(WriterContext *wctx, const char *key, const char *value)
Definition: fftools_ffprobe.c:995
section::children_ids
int children_ids[SECTION_MAX_NB_CHILDREN+1]
list of children section IDS, terminated by -1
Definition: fftools_ffprobe.c:151
Writer::print_rational
void(* print_rational)(WriterContext *wctx, AVRational *q, char *sep)
Definition: fftools_ffprobe.c:449
CompactContext
Definition: fftools_ffprobe.c:1075
show_bsfs
int show_bsfs(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1699
csv_escape_str
static const char * csv_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
Definition: fftools_ffprobe.c:1052
SECTION_ID_FRAME_SIDE_DATA_LIST
@ SECTION_ID_FRAME_SIDE_DATA_LIST
Definition: fftools_ffprobe.c:169
xml_escape_str
static const char * xml_escape_str(AVBPrint *dst, const char *src, void *log_ctx)
Definition: fftools_ffprobe.c:1678
unit_bit_per_second_str
static const char unit_bit_per_second_str[]
Definition: fftools_ffprobe.c:284
SECTION_ID_FORMAT_TAGS
@ SECTION_ID_FORMAT_TAGS
Definition: fftools_ffprobe.c:165
show_tags
static int show_tags(WriterContext *w, AVDictionary *tags, int section_id)
Definition: fftools_ffprobe.c:1844
Writer::priv_class
const AVClass * priv_class
private class of the writer, if any
Definition: fftools_ffprobe.c:439
Writer
Definition: fftools_ffprobe.c:438
SHOW_LIB_VERSION
#define SHOW_LIB_VERSION(libname, LIBNAME)
Definition: fftools_ffprobe.c:3081
print_time
#define print_time(k, v, tb)
Definition: fftools_ffprobe.c:1822
filter_codec_opts
AVDictionary * filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id, AVFormatContext *s, AVStream *st, AVCodec *codec)
Definition: fftools_cmdutils.c:2131
print_duration_time
#define print_duration_time(k, v, tb)
Definition: fftools_ffprobe.c:1824
SECTION_ID_FRAMES
@ SECTION_ID_FRAMES
Definition: fftools_ffprobe.c:167
show_frame
static void show_frame(WriterContext *w, AVFrame *frame, AVStream *stream, AVFormatContext *fmt_ctx)
Definition: fftools_ffprobe.c:2117
dec_str
const char * dec_str
Definition: fftools_ffprobe.c:271
SECTION_ID_PIXEL_FORMAT_COMPONENTS
@ SECTION_ID_PIXEL_FORMAT_COMPONENTS
Definition: fftools_ffprobe.c:186
SECTION_ID_ROOT
@ SECTION_ID_ROOT
Definition: fftools_ffprobe.c:196
SECTION_ID_ERROR
@ SECTION_ID_ERROR
Definition: fftools_ffprobe.c:163
JSONContext
struct JSONContext JSONContext
csv_writer
static const Writer csv_writer
Definition: fftools_ffprobe.c:1221
WRITER_STRING_VALIDATION_FAIL
@ WRITER_STRING_VALIDATION_FAIL
Definition: fftools_ffprobe.c:432
xml_print_section_footer
static void xml_print_section_footer(WriterContext *wctx)
Definition: fftools_ffprobe.c:1738
SECTION_ID_SUBTITLE
@ SECTION_ID_SUBTITLE
Definition: fftools_ffprobe.c:203
print_color_space
static void print_color_space(WriterContext *w, enum AVColorSpace color_space)
Definition: fftools_ffprobe.c:1947
program_birth_year
__thread int program_birth_year
Definition: fftools_cmdutils.c:99
SECTION_FLAG_IS_ARRAY
#define SECTION_FLAG_IS_ARRAY
the section contains an array of elements of the same type
Definition: fftools_ffprobe.c:147
WriterContext::string_validation_replacement
char * string_validation_replacement
Definition: fftools_ffprobe.c:480
uninit_opts
void uninit_opts(void)
Definition: fftools_cmdutils.c:121
hash
__thread struct AVHashContext * hash
Definition: fftools_ffprobe.c:262
SECTION_ID_PIXEL_FORMATS
@ SECTION_ID_PIXEL_FORMATS
Definition: fftools_ffprobe.c:187
open_input_file
static int open_input_file(InputFile *ifile, const char *filename)
Definition: fftools_ffprobe.c:2843
show_error
static void show_error(WriterContext *w, int err)
Definition: fftools_ffprobe.c:2829
InputFile::nb_streams
int nb_streams
Definition: fftools_ffmpeg.h:432
format_opts
__thread AVDictionary * format_opts
Definition: fftools_cmdutils.c:103
json_escape_str
static const char * json_escape_str(AVBPrint *dst, const char *src, void *log_ctx)
Definition: fftools_ffprobe.c:1491
XMLContext::xsd_strict
int xsd_strict
Definition: fftools_ffprobe.c:1634
compact_print_section_header
static void compact_print_section_header(WriterContext *wctx)
Definition: fftools_ffprobe.c:1127
opt_loglevel
int opt_loglevel(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:913
do_show_chapters
__thread int do_show_chapters
Definition: fftools_ffprobe.c:94
show_sample_fmts
int show_sample_fmts(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1849
json_print_section_header
static void json_print_section_header(WriterContext *wctx)
Definition: fftools_ffprobe.c:1513
do_show_frames
__thread int do_show_frames
Definition: fftools_ffprobe.c:97
register_exit
void register_exit(void(*cb)(int ret))
Definition: fftools_cmdutils.c:161
ReadInterval::id
int id
identifier
Definition: fftools_ffprobe.c:128
Writer::print_section_footer
void(* print_section_footer)(WriterContext *wctx)
Definition: fftools_ffprobe.c:447
unit_second_str
static const char unit_second_str[]
Definition: fftools_ffprobe.c:281
WRITER_STRING_VALIDATION_NB
@ WRITER_STRING_VALIDATION_NB
Definition: fftools_ffprobe.c:435
print_error
void print_error(const char *filename, int err)
Definition: fftools_cmdutils.c:1130
writer_print_time
static void writer_print_time(WriterContext *wctx, const char *key, int64_t ts, const AVRational *time_base, int is_duration)
Definition: fftools_ffprobe.c:790
SECTION_ID_PROGRAM_STREAM
@ SECTION_ID_PROGRAM_STREAM
Definition: fftools_ffprobe.c:192
csv_options
static const AVOption csv_options[]
Definition: fftools_ffprobe.c:1207
value
long value
Definition: AtomicLong.m:22
SECTION_ID_PROGRAM_VERSION
@ SECTION_ID_PROGRAM_VERSION
Definition: fftools_ffprobe.c:194
Writer::name
const char * name
Definition: fftools_ffprobe.c:441
section
Definition: fftools_ffprobe.c:142
opt_sections
static int opt_sections(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffprobe.c:3468
SECTION_ID_PACKETS_AND_FRAMES
@ SECTION_ID_PACKETS_AND_FRAMES
Definition: fftools_ffprobe.c:180
probe_file
static int probe_file(WriterContext *wctx, const char *filename)
Definition: fftools_ffprobe.c:2978
do_show_log
__thread int do_show_log
Definition: fftools_ffprobe.c:108
show_banner
void show_banner(int argc, char **argv, const OptionDef *options)
Definition: fftools_cmdutils.c:1227
WriterContext::priv
void * priv
private data for use by the filter
Definition: fftools_ffprobe.c:460
unit_value
Definition: fftools_ffprobe.c:366
InputStream::st
AVStream * st
Definition: fftools_ffmpeg.h:320
ini_print_section_header
static void ini_print_section_header(WriterContext *wctx)
Definition: fftools_ffprobe.c:1402
JSONContext
Definition: fftools_ffprobe.c:1463
ReadInterval::has_start
int has_start
Definition: fftools_ffprobe.c:130
WriterContext::nb_sections
int nb_sections
number of sections
Definition: fftools_ffprobe.c:463
parse_read_interval
static int parse_read_interval(const char *interval_spec, ReadInterval *interval)
Definition: fftools_ffprobe.c:3307
Writer::print_integer
void(* print_integer)(WriterContext *wctx, const char *, long long int)
Definition: fftools_ffprobe.c:448
InputStream::dec_ctx
AVCodecContext * dec_ctx
Definition: fftools_ffmpeg.h:327
LogBuffer::log_level
int log_level
Definition: fftools_ffprobe.c:296
WriterContext::sections
const struct section * sections
array containing all sections
Definition: fftools_ffprobe.c:462
si_prefixes
static const struct @3 si_prefixes[]
mobileffmpeg_exception.h
SECTION_ID_STREAM_TAGS
@ SECTION_ID_STREAM_TAGS
Definition: fftools_ffprobe.c:200
WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER
#define WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER
Definition: fftools_ffprobe.c:429
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Definition: MobileFFmpegConfig.h:71
compact_writer
static const Writer compact_writer
Definition: fftools_ffprobe.c:1190
read_packets
static int read_packets(WriterContext *w, InputFile *ifile)
Definition: fftools_ffprobe.c:2457
stream_specifier
__thread char * stream_specifier
Definition: fftools_ffprobe.c:124
opt_cpuflags
int opt_cpuflags(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:901
section::entries_to_show
AVDictionary * entries_to_show
Definition: fftools_ffprobe.c:154
ReadInterval::duration_frames
int duration_frames
Definition: fftools_ffprobe.c:132
WRITER_STRING_VALIDATION_IGNORE
@ WRITER_STRING_VALIDATION_IGNORE
Definition: fftools_ffprobe.c:434
print_val
#define print_val(k, v, u)
Definition: fftools_ffprobe.c:1826
OFFSET
#define OFFSET(x)
Definition: fftools_ffprobe.c:1638
AV_LOG_STDERR
#define AV_LOG_STDERR
Definition: fftools_cmdutils.h:61
show_log
static int show_log(WriterContext *w, int section_ids, int section_id, int log_level)
Definition: fftools_ffprobe.c:2004
PRINT_PIX_FMT_FLAG
#define PRINT_PIX_FMT_FLAG(flagname, name)
Definition: fftools_ffprobe.c:3109
do_show_data
__thread int do_show_data
Definition: fftools_ffprobe.c:102
show_protocols
int show_protocols(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1711
Writer
struct Writer Writer
writer_register
static int writer_register(const Writer *writer)
Definition: fftools_ffprobe.c:891
do_show_program_version
__thread int do_show_program_version
Definition: fftools_ffprobe.c:103
XMLContext
Definition: fftools_ffprobe.c:1629
unit_value::unit
const char * unit
Definition: fftools_ffprobe.c:368
WriterContext::nb_section_packet_frame
unsigned int nb_section_packet_frame
nb_section_packet or nb_section_frame according if is_packets_and_frames
Definition: fftools_ffprobe.c:477
SECTION_ID_NONE
@ SECTION_ID_NONE
Definition: fftools_ffprobe.c:159
section::flags
int flags
For these sections the element_name field is mandatory.
Definition: fftools_ffprobe.c:150
int
int
Definition: fftools_ffmpeg_filter.c:199
SECTION_ID_PROGRAMS
@ SECTION_ID_PROGRAMS
Definition: fftools_ffprobe.c:195
show_codecs
int show_codecs(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1594
print_pkt_side_data
static void print_pkt_side_data(WriterContext *w, AVCodecParameters *par, const AVPacketSideData *side_data, int nb_side_data, SectionID id_data_list, SectionID id_data)
Definition: fftools_ffprobe.c:1862
CompactContext::nokey
int nokey
Definition: fftools_ffprobe.c:1079
SECTION_ID_CHAPTER
@ SECTION_ID_CHAPTER
Definition: fftools_ffprobe.c:160
ffprobe_execute
int ffprobe_execute(int argc, char **argv)
Definition: fftools_ffprobe.c:3585
XMLContext
struct XMLContext XMLContext
SECTION_ID_PACKETS
@ SECTION_ID_PACKETS
Definition: fftools_ffprobe.c:179
do_show_stream_disposition
__thread int do_show_stream_disposition
Definition: fftools_ffprobe.c:101
XML_INDENT
#define XML_INDENT()
Definition: fftools_ffprobe.c:1696
hide_banner
__thread int hide_banner
Definition: fftools_cmdutils.c:107
default_writer
static const Writer default_writer
Definition: fftools_ffprobe.c:1013
writer_get_by_name
static const Writer * writer_get_by_name(const char *name)
Definition: fftools_ffprobe.c:900
log_buffer_size
__thread int log_buffer_size
Definition: fftools_ffprobe.c:304
FlatContext
Definition: fftools_ffprobe.c:1235
WriterContext
Definition: fftools_ffprobe.c:456
read_intervals
__thread ReadInterval * read_intervals
Definition: fftools_ffprobe.c:135
OptionDef
Definition: fftools_cmdutils.h:185
opt_report
int opt_report(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1098
unit_byte_str
static const char unit_byte_str[]
Definition: fftools_ffprobe.c:283
opt_input_file
static void opt_input_file(void *optctx, const char *arg)
Definition: fftools_ffprobe.c:3273
show_chapters
static int show_chapters(WriterContext *w, InputFile *ifile)
Definition: fftools_ffprobe.c:2773
nb_streams_frames
__thread uint64_t * nb_streams_frames
Definition: fftools_ffprobe.c:288
opt_pretty
static int opt_pretty(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffprobe.c:3442
ini_options
static const AVOption ini_options[]
Definition: fftools_ffprobe.c:1367
SECTION_ID_STREAM_SIDE_DATA_LIST
@ SECTION_ID_STREAM_SIDE_DATA_LIST
Definition: fftools_ffprobe.c:201
WriterContext::nb_section_frame
unsigned int nb_section_frame
number of the frame section in case we are in "packets_and_frames" section
Definition: fftools_ffprobe.c:476
JSONContext::compact
int compact
Definition: fftools_ffprobe.c:1466
WriterContext::string_validation
int string_validation
Definition: fftools_ffprobe.c:479
do_show_error
__thread int do_show_error
Definition: fftools_ffprobe.c:95
show_usage
static void show_usage(void)
Definition: fftools_ffprobe.c:3058
ini_print_int
static void ini_print_int(WriterContext *wctx, const char *key, long long int value)
Definition: fftools_ffprobe.c:1446
WriterContext::nb_section_packet
unsigned int nb_section_packet
number of the packet section in case we are in "packets_and_frames" section
Definition: fftools_ffprobe.c:475
ReadInterval::start
int64_t start
Definition: fftools_ffprobe.c:129
json_print_int
static void json_print_int(WriterContext *wctx, const char *key, long long int value)
Definition: fftools_ffprobe.c:1598
writer_print_data
static void writer_print_data(WriterContext *wctx, const char *name, uint8_t *data, int size)
Definition: fftools_ffprobe.c:816
SECTION_ID_FRAME_LOG
@ SECTION_ID_FRAME_LOG
Definition: fftools_ffprobe.c:173
check_section_show_entries
static int check_section_show_entries(int section_id)
Definition: fftools_ffprobe.c:3505
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Definition: MobileFFmpegConfig.h:76
show_devices
int show_devices(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1412
show_subtitle
static void show_subtitle(WriterContext *w, AVSubtitle *sub, AVStream *stream, AVFormatContext *fmt_ctx)
Definition: fftools_ffprobe.c:2094
nb_streams
__thread int nb_streams
Definition: fftools_ffprobe.c:286
compact_options
static const AVOption compact_options[]
Definition: fftools_ffprobe.c:1091
SECTION_ID_FRAME
@ SECTION_ID_FRAME
Definition: fftools_ffprobe.c:166
INIContext::hierarchical
int hierarchical
Definition: fftools_ffprobe.c:1361
Writer::print_string
void(* print_string)(WriterContext *wctx, const char *, const char *)
Definition: fftools_ffprobe.c:450
ffprobe_var_cleanup
void ffprobe_var_cleanup()
Definition: fftools_ffprobe.c:3522
do_show_streams
__thread int do_show_streams
Definition: fftools_ffprobe.c:100
ffprobe_cleanup
static void ffprobe_cleanup(int ret)
Definition: fftools_ffprobe.c:355
OPT_AUDIO
#define OPT_AUDIO
Definition: fftools_cmdutils.h:193
WriterContext::section
const struct section * section[SECTION_MAX_NB_LEVELS]
Definition: fftools_ffprobe.c:471
Writer::print_section_header
void(* print_section_header)(WriterContext *wctx)
Definition: fftools_ffprobe.c:446
compact_print_str
static void compact_print_str(WriterContext *wctx, const char *key, const char *value)
Definition: fftools_ffprobe.c:1167
OPT_BOOL
#define OPT_BOOL
Definition: fftools_cmdutils.h:189
ReadInterval
struct ReadInterval ReadInterval
WriterContext::nb_item
unsigned int nb_item[SECTION_MAX_NB_LEVELS]
Definition: fftools_ffprobe.c:468
writer_print_data_hash
static void writer_print_data_hash(WriterContext *wctx, const char *name, uint8_t *data, int size)
Definition: fftools_ffprobe.c:844
fftools_cmdutils.h
show_help_children
void show_help_children(const AVClass *class, int flags)
Definition: fftools_cmdutils.c:239
writer_print_section_footer
static void writer_print_section_footer(WriterContext *wctx)
Definition: fftools_ffprobe.c:659
json_options
static const AVOption json_options[]
Definition: fftools_ffprobe.c:1473
use_value_sexagesimal_format
__thread int use_value_sexagesimal_format
Definition: fftools_ffprobe.c:120
SECTION_ID_PIXEL_FORMAT_COMPONENT
@ SECTION_ID_PIXEL_FORMAT_COMPONENT
Definition: fftools_ffprobe.c:185
CHECK_END
#define CHECK_END
flat_print_str
static void flat_print_str(WriterContext *wctx, const char *key, const char *value)
Definition: fftools_ffprobe.c:1333
do_read_frames
__thread int do_read_frames
Definition: fftools_ffprobe.c:92
flat_print_int
static void flat_print_int(WriterContext *wctx, const char *key, long long int value)
Definition: fftools_ffprobe.c:1328
SECTION_ID_STREAMS
@ SECTION_ID_STREAMS
Definition: fftools_ffprobe.c:199
show_format
static int show_format(WriterContext *w, InputFile *ifile)
Definition: fftools_ffprobe.c:2798
XMLContext::fully_qualified
int fully_qualified
Definition: fftools_ffprobe.c:1633
unit_hertz_str
static const char unit_hertz_str[]
Definition: fftools_ffprobe.c:282
writer_child_next
static void * writer_child_next(void *obj, void *prev)
Definition: fftools_ffprobe.c:505
show_stream
static int show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_idx, InputStream *ist, int in_program)
Definition: fftools_ffprobe.c:2477
setup_find_stream_info_opts
AVDictionary ** setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *codec_opts)
Definition: fftools_cmdutils.c:2188
CompactContext::has_nested_elems
int has_nested_elems[SECTION_MAX_NB_LEVELS]
Definition: fftools_ffprobe.c:1084
WriterContext::section_pbuf
AVBPrint section_pbuf[SECTION_MAX_NB_LEVELS]
Definition: fftools_ffprobe.c:472
SECTION_ID_LIBRARY_VERSIONS
@ SECTION_ID_LIBRARY_VERSIONS
Definition: fftools_ffprobe.c:176
Writer::priv_size
int priv_size
private size for the writer context
Definition: fftools_ffprobe.c:440
JSONContext::item_sep
const char * item_sep
Definition: fftools_ffprobe.c:1467
SECTION_ID_FRAME_TAGS
@ SECTION_ID_FRAME_TAGS
Definition: fftools_ffprobe.c:168
SECTION_MAX_NB_LEVELS
#define SECTION_MAX_NB_LEVELS
Definition: fftools_ffprobe.c:454
init_opts
void init_opts(void)
Definition: fftools_cmdutils.c:116
unit_value::i
long long int i
Definition: fftools_ffprobe.c:367
SET_DO_SHOW
#define SET_DO_SHOW(id, varname)
Definition: fftools_ffprobe.c:3517
SECTION_ID_CHAPTERS
@ SECTION_ID_CHAPTERS
Definition: fftools_ffprobe.c:162
show_layouts
int show_layouts(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1820
print_section
static void print_section(SectionID id, int level)
Definition: fftools_ffprobe.c:3451
xml_options
static const AVOption xml_options[]
Definition: fftools_ffprobe.c:1640
size
long size
Definition: Statistics.m:27
ffprobe_show_library_versions
static void ffprobe_show_library_versions(WriterContext *w)
Definition: fftools_ffprobe.c:3096
parse_read_intervals
static int parse_read_intervals(const char *intervals_spec)
Definition: fftools_ffprobe.c:3389
SECTION_ID_PACKET_TAGS
@ SECTION_ID_PACKET_TAGS
Definition: fftools_ffprobe.c:178
show_license
int show_license(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1253
SECTION_ID_STREAM
@ SECTION_ID_STREAM
Definition: fftools_ffprobe.c:197
WriterContext::string_validation_utf8_flags
unsigned int string_validation_utf8_flags
Definition: fftools_ffprobe.c:481
show_buildconf
int show_buildconf(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1246
show_formats
int show_formats(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1397
INIContext
struct INIContext INIContext
writer_open
static int writer_open(WriterContext **wctx, const Writer *writer, const char *args, const struct section *sections, int nb_sections)
Definition: fftools_ffprobe.c:548
JSONContext::item_start_end
const char * item_start_end
Definition: fftools_ffprobe.c:1467
SECTION_ID_PACKET_SIDE_DATA_LIST
@ SECTION_ID_PACKET_SIDE_DATA_LIST
Definition: fftools_ffprobe.c:181
CompactContext
struct CompactContext CompactContext
ReadInterval
Definition: fftools_ffprobe.c:127
do_show_library_versions
__thread int do_show_library_versions
Definition: fftools_ffprobe.c:104
xml_writer
static Writer xml_writer
Definition: fftools_ffprobe.c:1787
CompactContext::escape_str
const char *(* escape_str)(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
Definition: fftools_ffprobe.c:1082
PRINT_DISPOSITION
#define PRINT_DISPOSITION(flagname, name)
read_intervals_nb
__thread int read_intervals_nb
Definition: fftools_ffprobe.c:136
LogBuffer::parent_name
char * parent_name
Definition: fftools_ffprobe.c:299
opt_max_alloc
int opt_max_alloc(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:1103
CompactContext::escape_mode_str
char * escape_mode_str
Definition: fftools_ffprobe.c:1081
do_show_pixel_formats
__thread int do_show_pixel_formats
Definition: fftools_ffprobe.c:105
print_str
#define print_str(k, v)
Definition: fftools_ffprobe.c:1819
LogBuffer::log_message
char * log_message
Definition: fftools_ffprobe.c:297
SECTION_ID_LIBRARY_VERSION
@ SECTION_ID_LIBRARY_VERSION
Definition: fftools_ffprobe.c:175
do_bitexact
__thread int do_bitexact
Definition: fftools_ffprobe.c:89
init_dynload
void init_dynload(void)
Definition: fftools_cmdutils.c:150
unit_value::d
double d
Definition: fftools_ffprobe.c:367
CompactContext::item_sep
char item_sep
Definition: fftools_ffprobe.c:1078
WRITER_STRING_VALIDATION_REPLACE
@ WRITER_STRING_VALIDATION_REPLACE
Definition: fftools_ffprobe.c:433
print_format
__thread char * print_format
Definition: fftools_ffprobe.c:123
pthread_mutex_unlock
#define pthread_mutex_unlock(a)
Definition: fftools_ffprobe.c:73
nb_streams_packets
__thread uint64_t * nb_streams_packets
Definition: fftools_ffprobe.c:287
SECTION_ID_PROGRAM_STREAM_DISPOSITION
@ SECTION_ID_PROGRAM_STREAM_DISPOSITION
Definition: fftools_ffprobe.c:188
OPT_EXPERT
#define OPT_EXPERT
Definition: fftools_cmdutils.h:190
do_read_packets
__thread int do_read_packets
Definition: fftools_ffprobe.c:93
longjmp_value
__thread volatile int longjmp_value
Definition: fftools_cmdutils.c:108
show_packet
static void show_packet(WriterContext *w, InputFile *ifile, AVPacket *pkt, int packet_idx)
Definition: fftools_ffprobe.c:2039
json_init
static av_cold int json_init(WriterContext *wctx)
Definition: fftools_ffprobe.c:1481
FlatContext::sep_str
const char * sep_str
Definition: fftools_ffprobe.c:1237
json_print_section_footer
static void json_print_section_footer(WriterContext *wctx)
Definition: fftools_ffprobe.c:1551
do_show_pixel_format_components
__thread int do_show_pixel_format_components
Definition: fftools_ffprobe.c:107
SECTION_ID_STREAM_DISPOSITION
@ SECTION_ID_STREAM_DISPOSITION
Definition: fftools_ffprobe.c:198
default_options
static const AVOption default_options[]
Definition: fftools_ffprobe.c:937