91 #define SECTION_MAX_NB_CHILDREN 10 
   97 #define SECTION_FLAG_IS_WRAPPER      1  
   98 #define SECTION_FLAG_IS_ARRAY        2 
 
   99 #define SECTION_FLAG_HAS_VARIABLE_FIELDS 4 
 
  198     union { 
double d; 
long long int i; } 
val;
 
  212         vald = vali = uv.
val.
i;
 
  219         mins  = (int)secs / 60;
 
  220         secs  = secs - mins * 60;
 
  223         snprintf(buf, buf_size, 
"%d:%02d:%09.6f", hours, mins, secs);
 
  225         const char *prefix_string = 
"";
 
  231                 index = (
long long int) (
log2(vald)) / 10;
 
  233                 vald /= 
exp2(index * 10);
 
  236                 index = (
long long int) (log10(vald)) / 3;
 
  238                 vald /= pow(10, index * 3);
 
  244             snprintf(buf, buf_size, 
"%f", vald);
 
  246             snprintf(buf, buf_size, 
"%lld", vali);
 
  258 #define WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS 1 
  259 #define WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER 2 
  277 #define SECTION_MAX_NB_LEVELS 10 
  323     if ((*wctx)->writer->uninit)
 
  324         (*wctx)->writer->uninit(*wctx);
 
  327     if ((*wctx)->writer->priv_class)
 
  334                        const struct section *sections, 
int nb_sections)
 
  349     (*wctx)->writer = writer;
 
  352     (*wctx)->nb_sections = nb_sections;
 
  355         void *priv_ctx = (*wctx)->priv;
 
  367     if ((*wctx)->writer->init)
 
  368         ret = (*wctx)->writer->init(*wctx);
 
  382     int parent_section_id;
 
  385     parent_section_id = wctx->
level ?
 
  406     int parent_section_id = wctx->
level ?
 
  421                                         const char *key, 
long long int val)
 
  432                                        const char *key, 
const char *
val, 
int opt)
 
  455                               int64_t ts, 
const AVRational *time_base, 
int is_duration)
 
  459     if ((!is_duration && ts == 
AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
 
  462         double d = ts * 
av_q2d(*time_base);
 
  473     if ((!is_duration && ts == 
AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
 
  491         for (i = 0; i < l; i++) {
 
  497         for (i = 0; i < l; i++)
 
  508 #define MAX_REGISTERED_WRITERS_NB 64 
  514     static int next_registered_writer_idx = 0;
 
  519     registered_writers[next_registered_writer_idx++] = writer;
 
  527     for (i = 0; registered_writers[
i]; i++)
 
  528         if (!strcmp(registered_writers[i]->name, name))
 
  529             return registered_writers[
i];
 
  537 #define DEFINE_WRITER_CLASS(name)                   \ 
  538 static const char *name##_get_name(void *ctx)       \ 
  542 static const AVClass name##_class = {               \ 
  557 #define OFFSET(x) offsetof(DefaultContext, x) 
  560     { 
"noprint_wrappers", 
"do not print headers and footers", 
OFFSET(noprint_wrappers), 
AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
 
  561     { 
"nw",               
"do not print headers and footers", 
OFFSET(noprint_wrappers), 
AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
 
  573     for (i = 0; src[i] && i < dst_size-1; i++)
 
  584     const struct section *parent_section = wctx->
level ?
 
  588     if (parent_section &&
 
  623     printf(
"%s\n", value);
 
  632     printf(
"%lld\n", value);
 
  643     .priv_class            = &default_class,
 
  655     for (p = src; *p; p++) {
 
  657         case '\b': 
av_bprintf(dst, 
"%s", 
"\\b");  
break;
 
  658         case '\f': 
av_bprintf(dst, 
"%s", 
"\\f");  
break;
 
  659         case '\n': 
av_bprintf(dst, 
"%s", 
"\\n");  
break;
 
  660         case '\r': 
av_bprintf(dst, 
"%s", 
"\\r");  
break;
 
  661         case '\\': 
av_bprintf(dst, 
"%s", 
"\\\\"); 
break;
 
  676     char meta_chars[] = { sep, 
'"', 
'\n', 
'\r', 
'\0' };
 
  677     int needs_quoting = !!src[strcspn(src, meta_chars)];
 
  682     for (; *
src; src++) {
 
  704     const char * (*escape_str)(
AVBPrint *dst, 
const char *
src, 
const char sep, 
void *log_ctx);
 
  711 #define OFFSET(x) offsetof(CompactContext, x) 
  732         av_log(wctx, 
AV_LOG_ERROR, 
"Item separator '%s' specified, but must contain a single character\n",
 
  753     const struct section *parent_section = wctx->
level ?
 
  809     printf(
"%lld", value);
 
  821     .priv_class           = &compact_class,
 
  827 #define OFFSET(x) offsetof(CompactContext, x) 
  852     .priv_class           = &csv_class,
 
  865 #define OFFSET(x) offsetof(FlatContext, x) 
  870     {
"hierarchical", 
"specify if the section specification should be hierarchical", 
OFFSET(hierarchical), 
AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
 
  871     {
"h",           
"specify if the section specification should be hierarchical", 
OFFSET(hierarchical), 
AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
 
  881     if (strlen(flat->
sep_str) != 1) {
 
  882         av_log(wctx, 
AV_LOG_ERROR, 
"Item separator '%s' specified, but must contain a single character\n",
 
  895     for (p = src; *p; p++) {
 
  896         if (!((*p >= 
'0' && *p <= 
'9') ||
 
  897               (*p >= 
'a' && *p <= 
'z') ||
 
  898               (*p >= 
'A' && *p <= 
'Z')))
 
  910     for (p = src; *p; p++) {
 
  912         case '\n': 
av_bprintf(dst, 
"%s", 
"\\n");  
break;
 
  913         case '\r': 
av_bprintf(dst, 
"%s", 
"\\r");  
break;
 
  914         case '\\': 
av_bprintf(dst, 
"%s", 
"\\\\"); 
break;
 
  915         case '"':  
av_bprintf(dst, 
"%s", 
"\\\""); 
break;
 
  916         case '`':  
av_bprintf(dst, 
"%s", 
"\\`");  
break;
 
  917         case '$':  
av_bprintf(dst, 
"%s", 
"\\$");  
break;
 
  929     const struct section *parent_section = wctx->
level ?
 
  976     .priv_class            = &flat_class,
 
  987 #define OFFSET(x) offsetof(INIContext, x) 
  990     {
"hierarchical", 
"specify if the section specification should be hierarchical", 
OFFSET(hierarchical), 
AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
 
  991     {
"h",           
"specify if the section specification should be hierarchical", 
OFFSET(hierarchical), 
AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
 
 1002     while (c = src[i++]) {
 
 1004         case '\b': 
av_bprintf(dst, 
"%s", 
"\\b"); 
break;
 
 1005         case '\f': 
av_bprintf(dst, 
"%s", 
"\\f"); 
break;
 
 1006         case '\n': 
av_bprintf(dst, 
"%s", 
"\\n"); 
break;
 
 1007         case '\r': 
av_bprintf(dst, 
"%s", 
"\\r"); 
break;
 
 1008         case '\t': 
av_bprintf(dst, 
"%s", 
"\\t"); 
break;
 
 1014             if ((
unsigned char)c < 32)
 
 1029     const struct section *parent_section = wctx->
level ?
 
 1033     if (!parent_section) {
 
 1034         printf(
"# ffprobe output\n\n");
 
 1054         printf(
"[%s]\n", buf->str);
 
 1070     printf(
"%s=%lld\n", key, value);
 
 1080     .priv_class            = &ini_class,
 
 1093 #define OFFSET(x) offsetof(JSONContext, x) 
 1115     static const char json_escape[] = {
'"', 
'\\', 
'\b', 
'\f', 
'\n', 
'\r', 
'\t', 0};
 
 1116     static const char json_subst[]  = {
'"', 
'\\',  
'b',  
'f',  
'n',  
'r',  
't', 0};
 
 1119     for (p = src; *p; p++) {
 
 1120         char *
s = strchr(json_escape, *p);
 
 1124         } 
else if ((
unsigned char)*p < 32) {
 
 1133 #define JSON_INDENT() printf("%*c", json->indent_level * 4, ' ') 
 1140     const struct section *parent_section = wctx->
level ?
 
 1156             printf(
"\"%s\": [\n", buf.str);
 
 1166                 printf(
"\"type\": \"%s\"%s", section->
name, json->
item_sep);
 
 1178     if (wctx->
level == 0) {
 
 1196                                        const char *key, 
const char *
value)
 
 1242     .priv_class           = &json_class,
 
 1256 #define OFFSET(x) offsetof(XMLContext, x) 
 1259     {
"fully_qualified", 
"specify if the output should be fully qualified", 
OFFSET(fully_qualified), 
AV_OPT_TYPE_INT, {.i64=0},  0, 1 },
 
 1260     {
"q",               
"specify if the output should be fully qualified", 
OFFSET(fully_qualified), 
AV_OPT_TYPE_INT, {.i64=0},  0, 1 },
 
 1261     {
"xsd_strict",      
"ensure that the output is XSD compliant",         
OFFSET(xsd_strict),      
AV_OPT_TYPE_INT, {.i64=0},  0, 1 },
 
 1262     {
"x",               
"ensure that the output is XSD compliant",         
OFFSET(xsd_strict),      
AV_OPT_TYPE_INT, {.i64=0},  0, 1 },
 
 1274 #define CHECK_COMPLIANCE(opt, opt_name)                                 \ 
 1276             av_log(wctx, AV_LOG_ERROR,                                  \ 
 1277                    "XSD-compliant output selected but option '%s' was selected, XML output may be non-compliant.\n" \ 
 1278                    "You need to disable such option with '-no%s'\n", opt_name, opt_name); \ 
 1279             return AVERROR(EINVAL);                                     \ 
 1287                    "Interleaved frames and packets are not allowed in XSD. " 
 1288                    "Select only one between the -show_frames and the -show_packets options.\n");
 
 1300     for (p = src; *p; p++) {
 
 1302         case '&' : 
av_bprintf(dst, 
"%s", 
"&");  
break;
 
 1303         case '<' : 
av_bprintf(dst, 
"%s", 
"<");   
break;
 
 1304         case '>' : 
av_bprintf(dst, 
"%s", 
">");   
break;
 
 1305         case '"' : 
av_bprintf(dst, 
"%s", 
"""); 
break;
 
 1306         case '\'': 
av_bprintf(dst, 
"%s", 
"'"); 
break;
 
 1314 #define XML_INDENT() printf("%*c", xml->indent_level * 4, ' ') 
 1320     const struct section *parent_section = wctx->
level ?
 
 1323     if (wctx->
level == 0) {
 
 1324         const char *qual = 
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " 
 1325             "xmlns:ffprobe='http://www.ffmpeg.org/schema/ffprobe' " 
 1326             "xsi:schemaLocation='http://www.ffmpeg.org/schema/ffprobe ffprobe.xsd'";
 
 1328         printf(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
 
 1329         printf(
"<%sffprobe%s>\n",
 
 1361     if (wctx->
level == 0) {
 
 1385         printf(
"<%s key=\"%s\"",
 
 1402     printf(
"%s=\"%lld\"", key, value);
 
 1414     .priv_class           = &xml_class,
 
 1419     static int initialized;
 
 1434 #define print_fmt(k, f, ...) do {              \ 
 1435     av_bprint_clear(&pbuf);                    \ 
 1436     av_bprintf(&pbuf, f, __VA_ARGS__);         \ 
 1437     writer_print_string(w, k, pbuf.str, 0);    \ 
 1440 #define print_int(k, v)         writer_print_integer(w, k, v) 
 1441 #define print_q(k, v, s)        writer_print_rational(w, k, v, s) 
 1442 #define print_str(k, v)         writer_print_string(w, k, v, 0) 
 1443 #define print_str_opt(k, v)     writer_print_string(w, k, v, 1) 
 1444 #define print_time(k, v, tb)    writer_print_time(w, k, v, tb, 0) 
 1445 #define print_ts(k, v)          writer_print_ts(w, k, v, 0) 
 1446 #define print_duration_time(k, v, tb) writer_print_time(w, k, v, tb, 1) 
 1447 #define print_duration_ts(k, v)       writer_print_ts(w, k, v, 1) 
 1448 #define print_val(k, v, u) do {                                     \ 
 1449     struct unit_value uv;                                           \ 
 1452     writer_print_string(w, k, value_string(val_str, sizeof(val_str), uv), 0); \ 
 1455 #define print_section_header(s) writer_print_section_header(w, s) 
 1456 #define print_section_footer(s) writer_print_section_footer(w, s) 
 1541             print_q(
"sample_aspect_ratio", sar, 
':');
 
 1581     int ret = 0, got_frame = 0;
 
 1583     if (dec_ctx->
codec) {
 
 1610     av_log(log_ctx, log_level, 
"id:%d", interval->
id);
 
 1616         av_log(log_ctx, log_level, 
" start:N/A");
 
 1622             av_log(log_ctx, log_level, 
"#%"PRId64, interval->
end);
 
 1626         av_log(log_ctx, log_level, 
" end:N/A");
 
 1629     av_log(log_ctx, log_level, 
"\n");
 
 1651                        "Could not seek to relative position since current " 
 1652                        "timestamp is not defined\n");
 
 1656             target = *cur_ts + interval->
start;
 
 1658             target = interval->
start;
 
 1688                 end = start + interval->
end;
 
 1695             } 
else if (has_end && *cur_ts != 
AV_NOPTS_VALUE && *cur_ts >= end) {
 
 1764     if ((dec_ctx = stream->
codec)) {
 
 1765         const char *profile = NULL;
 
 1766         dec = dec_ctx->
codec;
 
 1802                 print_q(
"sample_aspect_ratio", sar, 
':');
 
 1807                 print_q(
"display_aspect_ratio", dar, 
':');
 
 1861             if (opt->
flags) 
continue;
 
 1891 #define PRINT_DISPOSITION(flagname, name) do {                                \ 
 1892         print_int(name, !!(stream->disposition & AV_DISPOSITION_##flagname)); \ 
 2019     const char *errbuf_ptr = errbuf;
 
 2032     int err, i, orig_nb_streams;
 
 2055     for (i = 0; i < orig_nb_streams; i++)
 
 2068                    "Failed to probe codec for input stream %d\n",
 
 2072                     "Unsupported codec with id %d for input stream %d\n",
 
 2076                                                    fmt_ctx, stream, codec);
 
 2184     print_fmt(
"copyright", 
"Copyright (c) %d-%d the FFmpeg developers",
 
 2189     print_str(
"configuration", FFMPEG_CONFIGURATION);
 
 2195 #define SHOW_LIB_VERSION(libname, LIBNAME)                              \ 
 2197         if (CONFIG_##LIBNAME) {                                         \ 
 2198             unsigned int version = libname##_version();                 \ 
 2199             writer_print_section_header(w, SECTION_ID_LIBRARY_VERSION); \ 
 2200             print_str("name",    "lib" #libname);                       \ 
 2201             print_int("major",   LIB##LIBNAME##_VERSION_MAJOR);         \ 
 2202             print_int("minor",   LIB##LIBNAME##_VERSION_MINOR);         \ 
 2203             print_int("micro",   LIB##LIBNAME##_VERSION_MICRO);         \ 
 2204             print_int("version", version);                              \ 
 2205             print_str("ident",   LIB##LIBNAME##_IDENT);                 \ 
 2206             writer_print_section_footer(w);                             \ 
 2240     if (show_all_entries) {
 
 2256         if (!strcmp(section_name, section->
name) ||
 
 2259                    "'%s' matches section with unique name '%s'\n", section_name,
 
 2270     const char *p = 
arg;
 
 2278         if (!section_name) {
 
 2280                    "Missing section name for option '%s'\n", opt);
 
 2286             while (*p && *p != 
':') {
 
 2291                        "Adding '%s' to the entries to show in section '%s'\n",
 
 2292                        entry, section_name);
 
 2298             show_all_entries = 1;
 
 2301         ret = 
match_section(section_name, show_all_entries, entries);
 
 2324            "Option '%s' is deprecated, use '-show_entries format=%s' instead\n",
 
 2335                 "Argument '%s' provided as input filename, but '%s' was already specified.\n",
 
 2339     if (!strcmp(arg, 
"-"))
 
 2369     char *next, *p, *spec = 
av_strdup(interval_spec);
 
 2380     next = strchr(spec, 
'%');
 
 2422             lli = strtoll(p, &tail, 10);
 
 2423             if (*tail || lli < 0) {
 
 2425                        "Invalid or negative value '%s' for duration number of frames\n", p);
 
 2428             interval->
end = lli;
 
 2449     char *p, *spec = 
av_strdup(intervals_spec);
 
 2454     for (n = 0, p = spec; *p; p++)
 
 2459     read_intervals = 
av_malloc(n * 
sizeof(*read_intervals));
 
 2460     if (!read_intervals) {
 
 2468     for (i = 0; p; i++) {
 
 2472         next = strchr(p, 
',');
 
 2476         read_intervals[i].
id = i;
 
 2516     printf(
"%*c  %s", level * 4, 
' ', section->
name);
 
 2527     printf(
"Sections:\n" 
 2528            "W.. = Section is a wrapper (contains other sections, no local entries)\n" 
 2529            ".A. = Section contains an array of elements of the same type\n" 
 2530            "..V = Section may contain a variable number of fields with variable keys\n" 
 2531            "FLAGS NAME/UNIQUE_NAME\n" 
 2544 #define DEFINE_OPT_SHOW_SECTION(section, target_section_id)             \ 
 2545     static int opt_show_##section(const char *opt, const char *arg)     \ 
 2547         mark_section_show_entries(SECTION_ID_##target_section_id, 1, NULL); \ 
 2567       "use binary prefixes for byte units" },
 
 2569       "use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units" },
 
 2571       "prettify the format of displayed values, make it more human readable" },
 
 2573       "set the output printing format (available formats are: default, compact, csv, flat, ini, json, xml)", 
"format" },
 
 2576     { 
"sections", 
OPT_EXIT, {.func_arg = 
opt_sections}, 
"print sections structure and section information, and exit" },
 
 2578     { 
"show_error",   0, {(
void*)&opt_show_error},  
"show probing error" },
 
 2579     { 
"show_format",  0, {(
void*)&opt_show_format}, 
"show format/container info" },
 
 2580     { 
"show_frames",  0, {(
void*)&opt_show_frames}, 
"show frames info" },
 
 2582       "show a particular entry from the format/container info", 
"entry" },
 
 2584       "show a set of specified entries", 
"entry_list" },
 
 2585     { 
"show_packets", 0, {(
void*)&opt_show_packets}, 
"show packets info" },
 
 2586     { 
"show_programs", 0, {(
void*)&opt_show_programs}, 
"show programs info" },
 
 2587     { 
"show_streams", 0, {(
void*)&opt_show_streams}, 
"show streams info" },
 
 2588     { 
"show_chapters", 0, {(
void*)&opt_show_chapters}, 
"show chapters info" },
 
 2591     { 
"show_program_version",  0, {(
void*)&opt_show_program_version},  
"show ffprobe version" },
 
 2592     { 
"show_library_versions", 0, {(
void*)&opt_show_library_versions}, 
"show library versions" },
 
 2593     { 
"show_versions",         0, {(
void*)&
opt_show_versions}, 
"show program and library versions" },
 
 2615 #define SET_DO_SHOW(id, varname) do {                                   \ 
 2616         if (check_section_show_entries(SECTION_ID_##id))                \ 
 2617             do_show_##varname = 1;                                      \ 
 2625     char *w_name = NULL, *w_args = NULL;
 
 2653     SET_DO_SHOW(STREAM_DISPOSITION, stream_disposition);
 
 2654     SET_DO_SHOW(PROGRAM_STREAM_DISPOSITION, stream_disposition);
 
 2658                "-bitexact and -show_program_version or -show_library_versions " 
 2659                "options are incompatible\n");