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