77 #define SECTION_MAX_NB_CHILDREN 10
83 #define SECTION_FLAG_IS_WRAPPER 1
84 #define SECTION_FLAG_IS_ARRAY 2
85 #define SECTION_FLAG_HAS_VARIABLE_FIELDS 4
170 union {
double d;
long long int i; }
val;
184 vald = vali = uv.
val.
i;
191 mins = (int)secs / 60;
192 secs = secs - mins * 60;
195 snprintf(buf, buf_size,
"%d:%02d:%09.6f", hours, mins, secs);
197 const char *prefix_string =
"";
203 index = (
long long int) (
log2(vald)) / 10;
205 vald /=
exp2(index * 10);
208 index = (
long long int) (log10(vald)) / 3;
210 vald /= pow(10, index * 3);
216 snprintf(buf, buf_size,
"%f", vald);
218 snprintf(buf, buf_size,
"%lld", vali);
230 #define WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS 1
231 #define WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER 2
249 #define SECTION_MAX_NB_LEVELS 10
295 if ((*wctx)->writer->uninit)
296 (*wctx)->writer->uninit(*wctx);
299 if ((*wctx)->writer->priv_class)
306 const struct section *sections,
int nb_sections)
321 (*wctx)->writer = writer;
324 (*wctx)->nb_sections = nb_sections;
327 void *priv_ctx = (*wctx)->priv;
339 if ((*wctx)->writer->init)
340 ret = (*wctx)->writer->init(*wctx);
354 int parent_section_id;
357 parent_section_id = wctx->
level ?
378 int parent_section_id = wctx->
level ?
393 const char *key,
long long int val)
404 const char *key,
const char *
val,
int opt)
427 int64_t ts,
const AVRational *time_base,
int is_duration)
431 if ((!is_duration && ts ==
AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
434 double d = ts *
av_q2d(*time_base);
445 if ((!is_duration && ts ==
AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
463 for (i = 0; i < l; i++) {
469 for (i = 0; i < l; i++)
480 #define MAX_REGISTERED_WRITERS_NB 64
486 static int next_registered_writer_idx = 0;
491 registered_writers[next_registered_writer_idx++] = writer;
499 for (i = 0; registered_writers[
i]; i++)
500 if (!strcmp(registered_writers[i]->name, name))
501 return registered_writers[
i];
509 #define DEFINE_WRITER_CLASS(name) \
510 static const char *name##_get_name(void *ctx) \
514 static const AVClass name##_class = { \
529 #define OFFSET(x) offsetof(DefaultContext, x)
532 {
"noprint_wrappers",
"do not print headers and footers",
OFFSET(noprint_wrappers),
AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
533 {
"nw",
"do not print headers and footers",
OFFSET(noprint_wrappers),
AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
545 for (i = 0; src[i] && i < dst_size-1; i++)
556 const struct section *parent_section = wctx->
level ?
560 if (parent_section &&
595 printf(
"%s\n", value);
604 printf(
"%lld\n", value);
615 .priv_class = &default_class,
627 for (p = src; *p; p++) {
629 case '\b':
av_bprintf(dst,
"%s",
"\\b");
break;
630 case '\f':
av_bprintf(dst,
"%s",
"\\f");
break;
631 case '\n':
av_bprintf(dst,
"%s",
"\\n");
break;
632 case '\r':
av_bprintf(dst,
"%s",
"\\r");
break;
633 case '\\':
av_bprintf(dst,
"%s",
"\\\\");
break;
648 char meta_chars[] = { sep,
'"',
'\n',
'\r',
'\0' };
649 int needs_quoting = !!src[strcspn(src, meta_chars)];
654 for (; *
src; src++) {
676 const char * (*escape_str)(
AVBPrint *dst,
const char *
src,
const char sep,
void *log_ctx);
681 #define OFFSET(x) offsetof(CompactContext, x)
702 av_log(wctx,
AV_LOG_ERROR,
"Item separator '%s' specified, but must contain a single character\n",
723 const struct section *parent_section = wctx->
level ?
727 if (parent_section &&
768 printf(
"%lld", value);
780 .priv_class = &compact_class,
786 #define OFFSET(x) offsetof(CompactContext, x)
811 .priv_class = &csv_class,
824 #define OFFSET(x) offsetof(FlatContext, x)
829 {
"hierarchical",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical),
AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
830 {
"h",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical),
AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
840 if (strlen(flat->
sep_str) != 1) {
841 av_log(wctx,
AV_LOG_ERROR,
"Item separator '%s' specified, but must contain a single character\n",
854 for (p = src; *p; p++) {
855 if (!((*p >=
'0' && *p <=
'9') ||
856 (*p >=
'a' && *p <=
'z') ||
857 (*p >=
'A' && *p <=
'Z')))
869 for (p = src; *p; p++) {
871 case '\n':
av_bprintf(dst,
"%s",
"\\n");
break;
872 case '\r':
av_bprintf(dst,
"%s",
"\\r");
break;
873 case '\\':
av_bprintf(dst,
"%s",
"\\\\");
break;
874 case '"':
av_bprintf(dst,
"%s",
"\\\"");
break;
875 case '`':
av_bprintf(dst,
"%s",
"\\`");
break;
876 case '$':
av_bprintf(dst,
"%s",
"\\$");
break;
888 const struct section *parent_section = wctx->
level ?
935 .priv_class = &flat_class,
946 #define OFFSET(x) offsetof(INIContext, x)
949 {
"hierarchical",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical),
AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
950 {
"h",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical),
AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
961 while (c = src[i++]) {
963 case '\b':
av_bprintf(dst,
"%s",
"\\b");
break;
964 case '\f':
av_bprintf(dst,
"%s",
"\\f");
break;
965 case '\n':
av_bprintf(dst,
"%s",
"\\n");
break;
966 case '\r':
av_bprintf(dst,
"%s",
"\\r");
break;
967 case '\t':
av_bprintf(dst,
"%s",
"\\t");
break;
973 if ((
unsigned char)c < 32)
988 const struct section *parent_section = wctx->
level ?
992 if (!parent_section) {
993 printf(
"# ffprobe output\n\n");
1013 printf(
"[%s]\n", buf->str);
1029 printf(
"%s=%lld\n", key, value);
1039 .priv_class = &ini_class,
1052 #define OFFSET(x) offsetof(JSONContext, x)
1074 static const char json_escape[] = {
'"',
'\\',
'\b',
'\f',
'\n',
'\r',
'\t', 0};
1075 static const char json_subst[] = {
'"',
'\\',
'b',
'f',
'n',
'r',
't', 0};
1078 for (p = src; *p; p++) {
1079 char *
s = strchr(json_escape, *p);
1083 }
else if ((
unsigned char)*p < 32) {
1092 #define JSON_INDENT() printf("%*c", json->indent_level * 4, ' ')
1099 const struct section *parent_section = wctx->
level ?
1115 printf(
"\"%s\": [\n", buf.str);
1125 printf(
"\"type\": \"%s\"%s", section->
name, json->
item_sep);
1137 if (wctx->
level == 0) {
1155 const char *key,
const char *
value)
1201 .priv_class = &json_class,
1215 #define OFFSET(x) offsetof(XMLContext, x)
1218 {
"fully_qualified",
"specify if the output should be fully qualified",
OFFSET(fully_qualified),
AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
1219 {
"q",
"specify if the output should be fully qualified",
OFFSET(fully_qualified),
AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
1220 {
"xsd_strict",
"ensure that the output is XSD compliant",
OFFSET(xsd_strict),
AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
1221 {
"x",
"ensure that the output is XSD compliant",
OFFSET(xsd_strict),
AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
1233 #define CHECK_COMPLIANCE(opt, opt_name) \
1235 av_log(wctx, AV_LOG_ERROR, \
1236 "XSD-compliant output selected but option '%s' was selected, XML output may be non-compliant.\n" \
1237 "You need to disable such option with '-no%s'\n", opt_name, opt_name); \
1238 return AVERROR(EINVAL); \
1246 "Interleaved frames and packets are not allowed in XSD. "
1247 "Select only one between the -show_frames and the -show_packets options.\n");
1259 for (p = src; *p; p++) {
1261 case '&' :
av_bprintf(dst,
"%s",
"&");
break;
1262 case '<' :
av_bprintf(dst,
"%s",
"<");
break;
1263 case '>' :
av_bprintf(dst,
"%s",
">");
break;
1264 case '"' :
av_bprintf(dst,
"%s",
""");
break;
1265 case '\'':
av_bprintf(dst,
"%s",
"'");
break;
1273 #define XML_INDENT() printf("%*c", xml->indent_level * 4, ' ')
1279 const struct section *parent_section = wctx->
level ?
1282 if (wctx->
level == 0) {
1283 const char *qual =
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' "
1284 "xmlns:ffprobe='http://www.ffmpeg.org/schema/ffprobe' "
1285 "xsi:schemaLocation='http://www.ffmpeg.org/schema/ffprobe ffprobe.xsd'";
1287 printf(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
1288 printf(
"<%sffprobe%s>\n",
1320 if (wctx->
level == 0) {
1344 printf(
"<%s key=\"%s\"",
1361 printf(
"%s=\"%lld\"", key, value);
1373 .priv_class = &xml_class,
1378 static int initialized;
1393 #define print_fmt(k, f, ...) do { \
1394 av_bprint_clear(&pbuf); \
1395 av_bprintf(&pbuf, f, __VA_ARGS__); \
1396 writer_print_string(w, k, pbuf.str, 0); \
1399 #define print_int(k, v) writer_print_integer(w, k, v)
1400 #define print_q(k, v, s) writer_print_rational(w, k, v, s)
1401 #define print_str(k, v) writer_print_string(w, k, v, 0)
1402 #define print_str_opt(k, v) writer_print_string(w, k, v, 1)
1403 #define print_time(k, v, tb) writer_print_time(w, k, v, tb, 0)
1404 #define print_ts(k, v) writer_print_ts(w, k, v, 0)
1405 #define print_duration_time(k, v, tb) writer_print_time(w, k, v, tb, 1)
1406 #define print_duration_ts(k, v) writer_print_ts(w, k, v, 1)
1407 #define print_val(k, v, u) do { \
1408 struct unit_value uv; \
1411 writer_print_string(w, k, value_string(val_str, sizeof(val_str), uv), 0); \
1414 #define print_section_header(s) writer_print_section_header(w, s)
1415 #define print_section_footer(s) writer_print_section_footer(w, s)
1500 print_q(
"sample_aspect_ratio", sar,
':');
1540 int ret = 0, got_frame = 0;
1543 if (dec_ctx->
codec) {
1617 if ((dec_ctx = stream->
codec)) {
1618 const char *profile = NULL;
1619 dec = dec_ctx->
codec;
1655 print_q(
"sample_aspect_ratio", sar,
':');
1660 print_q(
"display_aspect_ratio", dar,
':');
1694 if (opt->
flags)
continue;
1724 #define PRINT_DISPOSITION(flagname, name) do { \
1725 print_int(name, !!(stream->disposition & AV_DISPOSITION_##flagname)); \
1810 const char *errbuf_ptr = errbuf;
1823 int err, i, orig_nb_streams;
1846 for (i = 0; i < orig_nb_streams; i++)
1859 "Failed to probe codec for input stream %d\n",
1863 "Unsupported codec with id %d for input stream %d\n",
1867 fmt_ctx, stream, codec);
1973 print_fmt(
"copyright",
"Copyright (c) %d-%d the FFmpeg developers",
1978 print_str(
"configuration", FFMPEG_CONFIGURATION);
1984 #define SHOW_LIB_VERSION(libname, LIBNAME) \
1986 if (CONFIG_##LIBNAME) { \
1987 unsigned int version = libname##_version(); \
1988 writer_print_section_header(w, SECTION_ID_LIBRARY_VERSION); \
1989 print_str("name", "lib" #libname); \
1990 print_int("major", LIB##LIBNAME##_VERSION_MAJOR); \
1991 print_int("minor", LIB##LIBNAME##_VERSION_MINOR); \
1992 print_int("micro", LIB##LIBNAME##_VERSION_MICRO); \
1993 print_int("version", version); \
1994 print_str("ident", LIB##LIBNAME##_IDENT); \
1995 writer_print_section_footer(w); \
2029 if (show_all_entries) {
2045 if (!strcmp(section_name, section->
name) ||
2048 "'%s' matches section with unique name '%s'\n", section_name,
2059 const char *p =
arg;
2067 if (!section_name) {
2069 "Missing section name for option '%s'\n", opt);
2075 while (*p && *p !=
':') {
2080 "Adding '%s' to the entries to show in section '%s'\n",
2081 entry, section_name);
2087 show_all_entries = 1;
2090 ret =
match_section(section_name, show_all_entries, entries);
2113 "Option '%s' is deprecated, use '-show_entries format=%s' instead\n",
2124 "Argument '%s' provided as input filename, but '%s' was already specified.\n",
2128 if (!strcmp(arg,
"-"))
2166 printf(
"%*c %s", level * 4,
' ', section->
name);
2177 printf(
"Sections:\n"
2178 "W.. = Section is a wrapper (contains other sections, no local entries)\n"
2179 ".A. = Section contains an array of elements of the same type\n"
2180 "..V = Section may contain a variable number of fields with variable keys\n"
2181 "FLAGS NAME/UNIQUE_NAME\n"
2194 #define DEFINE_OPT_SHOW_SECTION(section, target_section_id) \
2195 static int opt_show_##section(const char *opt, const char *arg) \
2197 mark_section_show_entries(SECTION_ID_##target_section_id, 1, NULL); \
2216 "use binary prefixes for byte units" },
2218 "use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units" },
2220 "prettify the format of displayed values, make it more human readable" },
2222 "set the output printing format (available formats are: default, compact, csv, flat, ini, json, xml)",
"format" },
2225 {
"sections",
OPT_EXIT, {.func_arg =
opt_sections},
"print sections structure and section information, and exit" },
2227 {
"show_error", 0, {(
void*)&opt_show_error},
"show probing error" },
2228 {
"show_format", 0, {(
void*)&opt_show_format},
"show format/container info" },
2229 {
"show_frames", 0, {(
void*)&opt_show_frames},
"show frames info" },
2231 "show a particular entry from the format/container info",
"entry" },
2233 "show a set of specified entries",
"entry_list" },
2234 {
"show_packets", 0, {(
void*)&opt_show_packets},
"show packets info" },
2235 {
"show_streams", 0, {(
void*)&opt_show_streams},
"show streams info" },
2236 {
"show_chapters", 0, {(
void*)&opt_show_chapters},
"show chapters info" },
2239 {
"show_program_version", 0, {(
void*)&opt_show_program_version},
"show ffprobe version" },
2240 {
"show_library_versions", 0, {(
void*)&opt_show_library_versions},
"show library versions" },
2241 {
"show_versions", 0, {(
void*)&
opt_show_versions},
"show program and library versions" },
2262 #define SET_DO_SHOW(id, varname) do { \
2263 if (check_section_show_entries(SECTION_ID_##id)) \
2264 do_show_##varname = 1; \
2272 char *w_name = NULL, *w_args = NULL;
2299 SET_DO_SHOW(STREAM_DISPOSITION, stream_disposition);
2303 "-bitexact and -show_program_version or -show_library_versions "
2304 "options are incompatible\n");