76 #define SECTION_MAX_NB_CHILDREN 10 
   82 #define SECTION_FLAG_IS_WRAPPER      1  
   83 #define SECTION_FLAG_IS_ARRAY        2 
 
   84 #define SECTION_FLAG_HAS_VARIABLE_FIELDS 4 
 
  163     union { 
double d; 
long long int i; } 
val;
 
  177         vald = vali = uv.
val.
i;
 
  184         mins  = (int)secs / 60;
 
  185         secs  = secs - mins * 60;
 
  188         snprintf(buf, buf_size, 
"%d:%02d:%09.6f", hours, mins, secs);
 
  190         const char *prefix_string = 
"";
 
  196                 index = (
long long int) (
log2(vald)) / 10;
 
  198                 vald /= 
exp2(index * 10);
 
  201                 index = (
long long int) (log10(vald)) / 3;
 
  203                 vald /= pow(10, index * 3);
 
  209             snprintf(buf, buf_size, 
"%f", vald);
 
  211             snprintf(buf, buf_size, 
"%lld", vali);
 
  223 #define WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS 1 
  224 #define WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER 2 
  242 #define SECTION_MAX_NB_LEVELS 10 
  288     if ((*wctx)->writer->uninit)
 
  289         (*wctx)->writer->uninit(*wctx);
 
  292     if ((*wctx)->writer->priv_class)
 
  299                        const struct section *sections, 
int nb_sections)
 
  314     (*wctx)->writer = writer;
 
  317     (*wctx)->nb_sections = nb_sections;
 
  320         void *priv_ctx = (*wctx)->priv;
 
  332     if ((*wctx)->writer->init)
 
  333         ret = (*wctx)->writer->init(*wctx);
 
  347     int parent_section_id;
 
  350     parent_section_id = wctx->
level ?
 
  371     int parent_section_id = wctx->
level ?
 
  386                                         const char *key, 
long long int val)
 
  397                                        const char *key, 
const char *val, 
int opt)
 
  420                               int64_t ts, 
const AVRational *time_base, 
int is_duration)
 
  424     if ((!is_duration && ts == 
AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
 
  427         double d = ts * 
av_q2d(*time_base);
 
  438     if ((!is_duration && ts == 
AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
 
  456         for (i = 0; i < l; i++) {
 
  462         for (i = 0; i < l; i++)
 
  473 #define MAX_REGISTERED_WRITERS_NB 64 
  479     static int next_registered_writer_idx = 0;
 
  484     registered_writers[next_registered_writer_idx++] = writer;
 
  492     for (i = 0; registered_writers[
i]; i++)
 
  493         if (!strcmp(registered_writers[i]->name, name))
 
  494             return registered_writers[
i];
 
  502 #define DEFINE_WRITER_CLASS(name)                   \ 
  503 static const char *name##_get_name(void *ctx)       \ 
  507 static const AVClass name##_class = {               \ 
  522 #define OFFSET(x) offsetof(DefaultContext, x) 
  525     { 
"noprint_wrappers", 
"do not print headers and footers", 
OFFSET(noprint_wrappers), 
AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
 
  526     { 
"nw",               
"do not print headers and footers", 
OFFSET(noprint_wrappers), 
AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
 
  538     for (i = 0; src[i] && i < dst_size-1; i++)
 
  549     const struct section *parent_section = wctx->
level ?
 
  553     if (parent_section &&
 
  588     printf(
"%s\n", value);
 
  597     printf(
"%lld\n", value);
 
  608     .priv_class            = &default_class,
 
  620     for (p = src; *p; p++) {
 
  622         case '\b': 
av_bprintf(dst, 
"%s", 
"\\b");  
break;
 
  623         case '\f': 
av_bprintf(dst, 
"%s", 
"\\f");  
break;
 
  624         case '\n': 
av_bprintf(dst, 
"%s", 
"\\n");  
break;
 
  625         case '\r': 
av_bprintf(dst, 
"%s", 
"\\r");  
break;
 
  626         case '\\': 
av_bprintf(dst, 
"%s", 
"\\\\"); 
break;
 
  641     char meta_chars[] = { sep, 
'"', 
'\n', 
'\r', 
'\0' };
 
  642     int needs_quoting = !!src[strcspn(src, meta_chars)];
 
  647     for (; *src; src++) {
 
  669     const char * (*escape_str)(
AVBPrint *
dst, 
const char *src, 
const char sep, 
void *log_ctx);
 
  674 #define OFFSET(x) offsetof(CompactContext, x) 
  695         av_log(wctx, 
AV_LOG_ERROR, 
"Item separator '%s' specified, but must contain a single character\n",
 
  716     const struct section *parent_section = wctx->
level ?
 
  720     if (parent_section &&
 
  761     printf(
"%lld", value);
 
  773     .priv_class           = &compact_class,
 
  779 #define OFFSET(x) offsetof(CompactContext, x) 
  804     .priv_class           = &csv_class,
 
  817 #define OFFSET(x) offsetof(FlatContext, x) 
  822     {
"hierarchical", 
"specify if the section specification should be hierarchical", 
OFFSET(hierarchical), 
AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
 
  823     {
"h",           
"specify if the section specification should be hierarchical", 
OFFSET(hierarchical), 
AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
 
  833     if (strlen(flat->
sep_str) != 1) {
 
  834         av_log(wctx, 
AV_LOG_ERROR, 
"Item separator '%s' specified, but must contain a single character\n",
 
  847     for (p = src; *p; p++) {
 
  848         if (!((*p >= 
'0' && *p <= 
'9') ||
 
  849               (*p >= 
'a' && *p <= 
'z') ||
 
  850               (*p >= 
'A' && *p <= 
'Z')))
 
  862     for (p = src; *p; p++) {
 
  864         case '\n': 
av_bprintf(dst, 
"%s", 
"\\n");  
break;
 
  865         case '\r': 
av_bprintf(dst, 
"%s", 
"\\r");  
break;
 
  866         case '\\': 
av_bprintf(dst, 
"%s", 
"\\\\"); 
break;
 
  867         case '"':  
av_bprintf(dst, 
"%s", 
"\\\""); 
break;
 
  868         case '`':  
av_bprintf(dst, 
"%s", 
"\\`");  
break;
 
  869         case '$':  
av_bprintf(dst, 
"%s", 
"\\$");  
break;
 
  881     const struct section *parent_section = wctx->
level ?
 
  928     .priv_class            = &flat_class,
 
  939 #define OFFSET(x) offsetof(INIContext, x) 
  942     {
"hierarchical", 
"specify if the section specification should be hierarchical", 
OFFSET(hierarchical), 
AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
 
  943     {
"h",           
"specify if the section specification should be hierarchical", 
OFFSET(hierarchical), 
AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
 
  954     while (c = src[i++]) {
 
  956         case '\b': 
av_bprintf(dst, 
"%s", 
"\\b"); 
break;
 
  957         case '\f': 
av_bprintf(dst, 
"%s", 
"\\f"); 
break;
 
  958         case '\n': 
av_bprintf(dst, 
"%s", 
"\\n"); 
break;
 
  959         case '\r': 
av_bprintf(dst, 
"%s", 
"\\r"); 
break;
 
  960         case '\t': 
av_bprintf(dst, 
"%s", 
"\\t"); 
break;
 
  966             if ((
unsigned char)c < 32)
 
  981     const struct section *parent_section = wctx->
level ?
 
  985     if (!parent_section) {
 
  986         printf(
"# ffprobe output\n\n");
 
 1006         printf(
"[%s]\n", buf->str);
 
 1022     printf(
"%s=%lld\n", key, value);
 
 1032     .priv_class            = &ini_class,
 
 1045 #define OFFSET(x) offsetof(JSONContext, x) 
 1067     static const char json_escape[] = {
'"', 
'\\', 
'\b', 
'\f', 
'\n', 
'\r', 
'\t', 0};
 
 1068     static const char json_subst[]  = {
'"', 
'\\',  
'b',  
'f',  
'n',  
'r',  
't', 0};
 
 1071     for (p = src; *p; p++) {
 
 1072         char *s = strchr(json_escape, *p);
 
 1076         } 
else if ((
unsigned char)*p < 32) {
 
 1085 #define JSON_INDENT() printf("%*c", json->indent_level * 4, ' ') 
 1092     const struct section *parent_section = wctx->
level ?
 
 1108             printf(
"\"%s\": [\n", buf.str);
 
 1118                 printf(
"\"type\": \"%s\"%s", section->
name, json->
item_sep);
 
 1130     if (wctx->
level == 0) {
 
 1148                                        const char *key, 
const char *
value)
 
 1194     .priv_class           = &json_class,
 
 1208 #define OFFSET(x) offsetof(XMLContext, x) 
 1211     {
"fully_qualified", 
"specify if the output should be fully qualified", 
OFFSET(fully_qualified), 
AV_OPT_TYPE_INT, {.i64=0},  0, 1 },
 
 1212     {
"q",               
"specify if the output should be fully qualified", 
OFFSET(fully_qualified), 
AV_OPT_TYPE_INT, {.i64=0},  0, 1 },
 
 1213     {
"xsd_strict",      
"ensure that the output is XSD compliant",         
OFFSET(xsd_strict),      
AV_OPT_TYPE_INT, {.i64=0},  0, 1 },
 
 1214     {
"x",               
"ensure that the output is XSD compliant",         
OFFSET(xsd_strict),      
AV_OPT_TYPE_INT, {.i64=0},  0, 1 },
 
 1226 #define CHECK_COMPLIANCE(opt, opt_name)                                 \ 
 1228             av_log(wctx, AV_LOG_ERROR,                                  \ 
 1229                    "XSD-compliant output selected but option '%s' was selected, XML output may be non-compliant.\n" \ 
 1230                    "You need to disable such option with '-no%s'\n", opt_name, opt_name); \ 
 1231             return AVERROR(EINVAL);                                     \ 
 1239                    "Interleaved frames and packets are not allowed in XSD. " 
 1240                    "Select only one between the -show_frames and the -show_packets options.\n");
 
 1252     for (p = src; *p; p++) {
 
 1254         case '&' : 
av_bprintf(dst, 
"%s", 
"&");  
break;
 
 1255         case '<' : 
av_bprintf(dst, 
"%s", 
"<");   
break;
 
 1256         case '>' : 
av_bprintf(dst, 
"%s", 
">");   
break;
 
 1257         case '"' : 
av_bprintf(dst, 
"%s", 
"""); 
break;
 
 1258         case '\'': 
av_bprintf(dst, 
"%s", 
"'"); 
break;
 
 1266 #define XML_INDENT() printf("%*c", xml->indent_level * 4, ' ') 
 1272     const struct section *parent_section = wctx->
level ?
 
 1275     if (wctx->
level == 0) {
 
 1276         const char *qual = 
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " 
 1277             "xmlns:ffprobe='http://www.ffmpeg.org/schema/ffprobe' " 
 1278             "xsi:schemaLocation='http://www.ffmpeg.org/schema/ffprobe ffprobe.xsd'";
 
 1280         printf(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
 
 1281         printf(
"<%sffprobe%s>\n",
 
 1313     if (wctx->
level == 0) {
 
 1337         printf(
"<%s key=\"%s\"",
 
 1354     printf(
"%s=\"%lld\"", key, value);
 
 1366     .priv_class           = &xml_class,
 
 1371     static int initialized;
 
 1386 #define print_fmt(k, f, ...) do {              \ 
 1387     av_bprint_clear(&pbuf);                    \ 
 1388     av_bprintf(&pbuf, f, __VA_ARGS__);         \ 
 1389     writer_print_string(w, k, pbuf.str, 0);    \ 
 1392 #define print_int(k, v)         writer_print_integer(w, k, v) 
 1393 #define print_q(k, v, s)        writer_print_rational(w, k, v, s) 
 1394 #define print_str(k, v)         writer_print_string(w, k, v, 0) 
 1395 #define print_str_opt(k, v)     writer_print_string(w, k, v, 1) 
 1396 #define print_time(k, v, tb)    writer_print_time(w, k, v, tb, 0) 
 1397 #define print_ts(k, v)          writer_print_ts(w, k, v, 0) 
 1398 #define print_duration_time(k, v, tb) writer_print_time(w, k, v, tb, 1) 
 1399 #define print_duration_ts(k, v)       writer_print_ts(w, k, v, 1) 
 1400 #define print_val(k, v, u) do {                                     \ 
 1401     struct unit_value uv;                                           \ 
 1404     writer_print_string(w, k, value_string(val_str, sizeof(val_str), uv), 0); \ 
 1407 #define print_section_header(s) writer_print_section_header(w, s) 
 1408 #define print_section_footer(s) writer_print_section_footer(w, s) 
 1493             print_q(
"sample_aspect_ratio", sar, 
':');
 
 1534     int ret = 0, got_frame = 0;
 
 1537     if (dec_ctx->
codec) {
 
 1611     if ((dec_ctx = stream->
codec)) {
 
 1612         const char *profile = 
NULL;
 
 1613         dec = dec_ctx->
codec;
 
 1649                 print_q(
"sample_aspect_ratio", sar, 
':');
 
 1654                 print_q(
"display_aspect_ratio", dar, 
':');
 
 1688             if (opt->
flags) 
continue;
 
 1698     print_q(
"r_frame_rate",   stream->r_frame_rate,   
'/');
 
 1718 #define PRINT_DISPOSITION(flagname, name) do {                                \ 
 1719         print_int(name, !!(stream->disposition & AV_DISPOSITION_##flagname)); \ 
 1783     const char *errbuf_ptr = errbuf;
 
 1826                    "Failed to probe codec for input stream %d\n",
 
 1830                     "Unsupported codec with id %d for input stream %d\n",
 
 1926     print_fmt(
"copyright", 
"Copyright (c) %d-%d the FFmpeg developers",
 
 1931     print_str(
"configuration", FFMPEG_CONFIGURATION);
 
 1937 #define SHOW_LIB_VERSION(libname, LIBNAME)                              \ 
 1939         if (CONFIG_##LIBNAME) {                                         \ 
 1940             unsigned int version = libname##_version();                 \ 
 1941             writer_print_section_header(w, SECTION_ID_LIBRARY_VERSION); \ 
 1942             print_str("name",    "lib" #libname);                       \ 
 1943             print_int("major",   LIB##LIBNAME##_VERSION_MAJOR);         \ 
 1944             print_int("minor",   LIB##LIBNAME##_VERSION_MINOR);         \ 
 1945             print_int("micro",   LIB##LIBNAME##_VERSION_MICRO);         \ 
 1946             print_int("version", version);                              \ 
 1947             print_str("ident",   LIB##LIBNAME##_IDENT);                 \ 
 1948             writer_print_section_footer(w);                             \ 
 1982     if (show_all_entries) {
 
 1998         if (!strcmp(section_name, section->
name) ||
 
 2001                    "'%s' matches section with unique name '%s'\n", section_name,
 
 2012     const char *p = 
arg;
 
 2020         if (!section_name) {
 
 2022                    "Missing section name for option '%s'\n", opt);
 
 2028             while (*p && *p != 
':') {
 
 2033                        "Adding '%s' to the entries to show in section '%s'\n",
 
 2034                        entry, section_name);
 
 2040             show_all_entries = 1;
 
 2043         ret = 
match_section(section_name, show_all_entries, entries);
 
 2066            "Option '%s' is deprecated, use '-show_entries format=%s' instead\n",
 
 2077                 "Argument '%s' provided as input filename, but '%s' was already specified.\n",
 
 2081     if (!strcmp(arg, 
"-"))
 
 2119     printf(
"%*c  %s", level * 4, 
' ', section->
name);
 
 2130     printf(
"Sections:\n" 
 2131            "W.. = Section is a wrapper (contains other sections, no local entries)\n" 
 2132            ".A. = Section contains an array of elements of the same type\n" 
 2133            "..V = Section may contain a variable number of fields with variable keys\n" 
 2134            "FLAGS NAME/UNIQUE_NAME\n" 
 2147 #define DEFINE_OPT_SHOW_SECTION(section, target_section_id)             \ 
 2148     static int opt_show_##section(const char *opt, const char *arg)     \ 
 2150         mark_section_show_entries(SECTION_ID_##target_section_id, 1, NULL); \ 
 2168       "use binary prefixes for byte units" },
 
 2170       "use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units" },
 
 2172       "prettify the format of displayed values, make it more human readable" },
 
 2174       "set the output printing format (available formats are: default, compact, csv, flat, ini, json, xml)", 
"format" },
 
 2177     { 
"sections", 
OPT_EXIT, {.func_arg = 
opt_sections}, 
"print sections structure and section information, and exit" },
 
 2179     { 
"show_error",   0, {(
void*)&opt_show_error},  
"show probing error" },
 
 2180     { 
"show_format",  0, {(
void*)&opt_show_format}, 
"show format/container info" },
 
 2181     { 
"show_frames",  0, {(
void*)&opt_show_frames}, 
"show frames info" },
 
 2183       "show a particular entry from the format/container info", 
"entry" },
 
 2185       "show a set of specified entries", 
"entry_list" },
 
 2186     { 
"show_packets", 0, {(
void*)&opt_show_packets}, 
"show packets info" },
 
 2187     { 
"show_streams", 0, {(
void*)&opt_show_streams}, 
"show streams info" },
 
 2190     { 
"show_program_version",  0, {(
void*)&opt_show_program_version},  
"show ffprobe version" },
 
 2191     { 
"show_library_versions", 0, {(
void*)&opt_show_library_versions}, 
"show library versions" },
 
 2192     { 
"show_versions",         0, {(
void*)&
opt_show_versions}, 
"show program and library versions" },
 
 2213 #define SET_DO_SHOW(id, varname) do {                                   \ 
 2214         if (check_section_show_entries(SECTION_ID_##id))                \ 
 2215             do_show_##varname = 1;                                      \ 
 2223     char *w_name = 
NULL, *w_args = 
NULL;
 
 2249     SET_DO_SHOW(STREAM_DISPOSITION, stream_disposition);
 
 2253                "-bitexact and -show_program_version or -show_library_versions " 
 2254                "options are incompatible\n");