27 #include "libavutil/ffversion.h"
99 #define SECTION_MAX_NB_CHILDREN 10
105 #define SECTION_FLAG_IS_WRAPPER 1
106 #define SECTION_FLAG_IS_ARRAY 2
107 #define SECTION_FLAG_HAS_VARIABLE_FIELDS 4
215 union {
double d;
long long int i; }
val;
229 vald = vali = uv.
val.
i;
236 mins = (int)secs / 60;
237 secs = secs - mins * 60;
240 snprintf(buf, buf_size,
"%d:%02d:%09.6f", hours, mins, secs);
242 const char *prefix_string =
"";
248 index = (
long long int) (
log2(vald)) / 10;
250 vald /=
exp2(index * 10);
253 index = (
long long int) (log10(vald)) / 3;
255 vald /= pow(10, index * 3);
262 snprintf(buf, buf_size,
"%f", vald);
264 snprintf(buf, buf_size,
"%lld", vali);
276 #define WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS 1
277 #define WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER 2
302 #define SECTION_MAX_NB_LEVELS 10
338 #define OFFSET(x) offsetof(WriterContext, x)
341 {
"string_validation",
"set string validation mode",
343 {
"sv",
"set string validation mode",
348 {
"string_validation_replacement",
"set string validation replacement string",
OFFSET(string_validation_replacement),
AV_OPT_TYPE_STRING, {.str=
""}},
349 {
"svr",
"set string validation replacement string",
OFFSET(string_validation_replacement),
AV_OPT_TYPE_STRING, {.str=
"\xEF\xBF\xBD"}},
376 if ((*wctx)->writer->uninit)
377 (*wctx)->writer->uninit(*wctx);
380 if ((*wctx)->writer->priv_class)
391 for (i = 0; i < ubuf_size; i++)
397 const struct section *sections,
int nb_sections)
412 (*wctx)->writer = writer;
415 (*wctx)->nb_sections = nb_sections;
420 void *priv_ctx = (*wctx)->priv;
431 av_log(*wctx,
AV_LOG_ERROR,
"Failed to parse option string '%s' provided to writer context\n", args);
438 av_log(*wctx,
AV_LOG_ERROR,
"Failed to set option '%s' with value '%s' provided to writer context\n",
450 const uint8_t *p = (*wctx)->string_validation_replacement;
451 const uint8_t *endp = p + strlen(p);
455 ret =
av_utf8_decode(&code, &p, endp, (*wctx)->string_validation_utf8_flags);
461 "Invalid UTF8 sequence %s found in string validation replace '%s'\n",
462 bp.str, (*wctx)->string_validation_replacement);
471 if ((*wctx)->writer->init)
472 ret = (*wctx)->writer->init(*wctx);
486 int parent_section_id;
489 parent_section_id = wctx->
level ?
510 int parent_section_id = wctx->
level ?
525 const char *key,
long long int val)
539 int invalid_chars_nb = 0,
ret = 0;
543 endp = src + strlen(src);
544 for (p = (
uint8_t *)src; *p;) {
554 "Invalid UTF-8 sequence %s found in string '%s'\n", bp.str, src);
564 "Invalid UTF-8 sequence found in string '%s'\n", src);
581 "%d invalid UTF-8 sequence(s) found in string '%s', replaced with '%s'\n",
590 #define PRINT_STRING_OPT 1
591 #define PRINT_STRING_VALIDATE 2
594 const char *key,
const char *
val,
int flags)
605 char *key1 = NULL, *val1 = NULL;
607 if (ret < 0)
goto end;
609 if (ret < 0)
goto end;
614 "Invalid key=value string combination %s=%s in section %s\n",
639 int64_t ts,
const AVRational *time_base,
int is_duration)
643 if ((!is_duration && ts ==
AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
646 double d = ts *
av_q2d(*time_base);
657 if ((!is_duration && ts ==
AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
675 for (i = 0; i < l; i++) {
681 for (i = 0; i < l; i++)
702 p = buf + strlen(buf);
707 #define MAX_REGISTERED_WRITERS_NB 64
713 static int next_registered_writer_idx = 0;
718 registered_writers[next_registered_writer_idx++] = writer;
726 for (i = 0; registered_writers[
i]; i++)
727 if (!strcmp(registered_writers[i]->name, name))
728 return registered_writers[
i];
736 #define DEFINE_WRITER_CLASS(name) \
737 static const char *name##_get_name(void *ctx) \
741 static const AVClass name##_class = { \
742 .class_name = #name, \
743 .item_name = name##_get_name, \
744 .option = name##_options \
757 #define OFFSET(x) offsetof(DefaultContext, x)
760 {
"noprint_wrappers",
"do not print headers and footers",
OFFSET(noprint_wrappers),
AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
761 {
"nw",
"do not print headers and footers",
OFFSET(noprint_wrappers),
AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
773 for (i = 0; src[i] && i < dst_size-1; i++)
784 const struct section *parent_section = wctx->
level ?
788 if (parent_section &&
823 printf(
"%s\n", value);
832 printf(
"%lld\n", value);
843 .priv_class = &default_class,
855 for (p = src; *p; p++) {
857 case '\b':
av_bprintf(dst,
"%s",
"\\b");
break;
858 case '\f':
av_bprintf(dst,
"%s",
"\\f");
break;
859 case '\n':
av_bprintf(dst,
"%s",
"\\n");
break;
860 case '\r':
av_bprintf(dst,
"%s",
"\\r");
break;
861 case '\\':
av_bprintf(dst,
"%s",
"\\\\");
break;
876 char meta_chars[] = { sep,
'"',
'\n',
'\r',
'\0' };
877 int needs_quoting = !!src[strcspn(src, meta_chars)];
882 for (; *
src; src++) {
904 const char * (*escape_str)(
AVBPrint *dst,
const char *
src,
const char sep,
void *log_ctx);
911 #define OFFSET(x) offsetof(CompactContext, x)
932 av_log(wctx,
AV_LOG_ERROR,
"Item separator '%s' specified, but must contain a single character\n",
953 const struct section *parent_section = wctx->
level ?
1007 if (!compact->
nokey)
1009 printf(
"%lld", value);
1021 .priv_class = &compact_class,
1027 #define OFFSET(x) offsetof(CompactContext, x)
1052 .priv_class = &csv_class,
1065 #define OFFSET(x) offsetof(FlatContext, x)
1070 {
"hierarchical",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical),
AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
1071 {
"h",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical),
AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
1081 if (strlen(flat->
sep_str) != 1) {
1082 av_log(wctx,
AV_LOG_ERROR,
"Item separator '%s' specified, but must contain a single character\n",
1095 for (p = src; *p; p++) {
1096 if (!((*p >=
'0' && *p <=
'9') ||
1097 (*p >=
'a' && *p <=
'z') ||
1098 (*p >=
'A' && *p <=
'Z')))
1110 for (p = src; *p; p++) {
1112 case '\n':
av_bprintf(dst,
"%s",
"\\n");
break;
1113 case '\r':
av_bprintf(dst,
"%s",
"\\r");
break;
1114 case '\\':
av_bprintf(dst,
"%s",
"\\\\");
break;
1115 case '"':
av_bprintf(dst,
"%s",
"\\\"");
break;
1116 case '`':
av_bprintf(dst,
"%s",
"\\`");
break;
1117 case '$':
av_bprintf(dst,
"%s",
"\\$");
break;
1129 const struct section *parent_section = wctx->
level ?
1134 if (!parent_section)
1176 .priv_class = &flat_class,
1187 #define OFFSET(x) offsetof(INIContext, x)
1190 {
"hierarchical",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical),
AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
1191 {
"h",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical),
AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
1202 while (c = src[i++]) {
1204 case '\b':
av_bprintf(dst,
"%s",
"\\b");
break;
1205 case '\f':
av_bprintf(dst,
"%s",
"\\f");
break;
1206 case '\n':
av_bprintf(dst,
"%s",
"\\n");
break;
1207 case '\r':
av_bprintf(dst,
"%s",
"\\r");
break;
1208 case '\t':
av_bprintf(dst,
"%s",
"\\t");
break;
1214 if ((
unsigned char)c < 32)
1229 const struct section *parent_section = wctx->
level ?
1233 if (!parent_section) {
1234 printf(
"# ffprobe output\n\n");
1254 printf(
"[%s]\n", buf->str);
1270 printf(
"%s=%lld\n", key, value);
1280 .priv_class = &ini_class,
1293 #define OFFSET(x) offsetof(JSONContext, x)
1315 static const char json_escape[] = {
'"',
'\\',
'\b',
'\f',
'\n',
'\r',
'\t', 0};
1316 static const char json_subst[] = {
'"',
'\\',
'b',
'f',
'n',
'r',
't', 0};
1319 for (p = src; *p; p++) {
1320 char *
s = strchr(json_escape, *p);
1324 }
else if ((
unsigned char)*p < 32) {
1333 #define JSON_INDENT() printf("%*c", json->indent_level * 4, ' ')
1340 const struct section *parent_section = wctx->
level ?
1356 printf(
"\"%s\": [\n", buf.str);
1366 printf(
"\"type\": \"%s\"%s", section->
name, json->
item_sep);
1378 if (wctx->
level == 0) {
1396 const char *key,
const char *
value)
1442 .priv_class = &json_class,
1456 #define OFFSET(x) offsetof(XMLContext, x)
1459 {
"fully_qualified",
"specify if the output should be fully qualified",
OFFSET(fully_qualified),
AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
1460 {
"q",
"specify if the output should be fully qualified",
OFFSET(fully_qualified),
AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
1461 {
"xsd_strict",
"ensure that the output is XSD compliant",
OFFSET(xsd_strict),
AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
1462 {
"x",
"ensure that the output is XSD compliant",
OFFSET(xsd_strict),
AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
1474 #define CHECK_COMPLIANCE(opt, opt_name) \
1476 av_log(wctx, AV_LOG_ERROR, \
1477 "XSD-compliant output selected but option '%s' was selected, XML output may be non-compliant.\n" \
1478 "You need to disable such option with '-no%s'\n", opt_name, opt_name); \
1479 return AVERROR(EINVAL); \
1487 "Interleaved frames and packets are not allowed in XSD. "
1488 "Select only one between the -show_frames and the -show_packets options.\n");
1500 for (p = src; *p; p++) {
1502 case '&' :
av_bprintf(dst,
"%s",
"&");
break;
1503 case '<' :
av_bprintf(dst,
"%s",
"<");
break;
1504 case '>' :
av_bprintf(dst,
"%s",
">");
break;
1505 case '"' :
av_bprintf(dst,
"%s",
""");
break;
1506 case '\'':
av_bprintf(dst,
"%s",
"'");
break;
1514 #define XML_INDENT() printf("%*c", xml->indent_level * 4, ' ')
1520 const struct section *parent_section = wctx->
level ?
1523 if (wctx->
level == 0) {
1524 const char *qual =
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' "
1525 "xmlns:ffprobe='http://www.ffmpeg.org/schema/ffprobe' "
1526 "xsi:schemaLocation='http://www.ffmpeg.org/schema/ffprobe ffprobe.xsd'";
1528 printf(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
1529 printf(
"<%sffprobe%s>\n",
1561 if (wctx->
level == 0) {
1585 printf(
"<%s key=\"%s\"",
1602 printf(
"%s=\"%lld\"", key, value);
1614 .priv_class = &xml_class,
1619 static int initialized;
1634 #define print_fmt(k, f, ...) do { \
1635 av_bprint_clear(&pbuf); \
1636 av_bprintf(&pbuf, f, __VA_ARGS__); \
1637 writer_print_string(w, k, pbuf.str, 0); \
1640 #define print_int(k, v) writer_print_integer(w, k, v)
1641 #define print_q(k, v, s) writer_print_rational(w, k, v, s)
1642 #define print_str(k, v) writer_print_string(w, k, v, 0)
1643 #define print_str_opt(k, v) writer_print_string(w, k, v, PRINT_STRING_OPT)
1644 #define print_str_validate(k, v) writer_print_string(w, k, v, PRINT_STRING_VALIDATE)
1645 #define print_time(k, v, tb) writer_print_time(w, k, v, tb, 0)
1646 #define print_ts(k, v) writer_print_ts(w, k, v, 0)
1647 #define print_duration_time(k, v, tb) writer_print_time(w, k, v, tb, 1)
1648 #define print_duration_ts(k, v) writer_print_ts(w, k, v, 1)
1649 #define print_val(k, v, u) do { \
1650 struct unit_value uv; \
1653 writer_print_string(w, k, value_string(val_str, sizeof(val_str), uv), 0); \
1656 #define print_section_header(s) writer_print_section_header(w, s)
1657 #define print_section_footer(s) writer_print_section_footer(w, s)
1659 #define REALLOCZ_ARRAY_STREAM(ptr, cur_n, new_n) \
1661 ret = av_reallocp_array(&(ptr), (new_n), sizeof(*(ptr))); \
1664 memset( (ptr) + (cur_n), 0, ((new_n) - (cur_n)) * sizeof(*(ptr)) ); \
1783 print_q(
"sample_aspect_ratio", sar,
':');
1820 print_str(
"side_data_type", name ? name :
"unknown");
1839 int ret = 0, got_frame = 0;
1841 if (dec_ctx->
codec) {
1878 av_log(log_ctx, log_level,
"id:%d", interval->
id);
1884 av_log(log_ctx, log_level,
" start:N/A");
1890 av_log(log_ctx, log_level,
"#%"PRId64, interval->
end);
1894 av_log(log_ctx, log_level,
" end:N/A");
1897 av_log(log_ctx, log_level,
"\n");
1905 int ret = 0, i = 0, frame_count = 0;
1919 "Could not seek to relative position since current "
1920 "timestamp is not defined\n");
1924 target = *cur_ts + interval->
start;
1926 target = interval->
start;
1962 end = start + interval->
end;
1967 if (frame_count >= interval->
end)
1969 }
else if (has_end && *cur_ts !=
AV_NOPTS_VALUE && *cur_ts >= end) {
2042 if ((dec_ctx = stream->
codec)) {
2043 const char *profile = NULL;
2044 dec = dec_ctx->
codec;
2086 print_q(
"sample_aspect_ratio", sar,
':');
2091 print_q(
"display_aspect_ratio", dar,
':');
2152 if (opt->
flags)
continue;
2188 #define PRINT_DISPOSITION(flagname, name) do { \
2189 print_int(name, !!(stream->disposition & AV_DISPOSITION_##flagname)); \
2342 const char *errbuf_ptr = errbuf;
2355 int err, i, orig_nb_streams;
2378 for (i = 0; i < orig_nb_streams; i++)
2391 "Failed to probe codec for input stream %d\n",
2395 "Unsupported codec with id %d for input stream %d\n",
2399 fmt_ctx, stream, codec);
2442 #define CHECK_END if (ret < 0) goto end
2520 print_fmt(
"copyright",
"Copyright (c) %d-%d the FFmpeg developers",
2525 print_str(
"configuration", FFMPEG_CONFIGURATION);
2531 #define SHOW_LIB_VERSION(libname, LIBNAME) \
2533 if (CONFIG_##LIBNAME) { \
2534 unsigned int version = libname##_version(); \
2535 writer_print_section_header(w, SECTION_ID_LIBRARY_VERSION); \
2536 print_str("name", "lib" #libname); \
2537 print_int("major", LIB##LIBNAME##_VERSION_MAJOR); \
2538 print_int("minor", LIB##LIBNAME##_VERSION_MINOR); \
2539 print_int("micro", LIB##LIBNAME##_VERSION_MICRO); \
2540 print_int("version", version); \
2541 print_str("ident", LIB##LIBNAME##_IDENT); \
2542 writer_print_section_footer(w); \
2576 if (show_all_entries) {
2592 if (!strcmp(section_name, section->
name) ||
2595 "'%s' matches section with unique name '%s'\n", section_name,
2606 const char *p =
arg;
2614 if (!section_name) {
2616 "Missing section name for option '%s'\n", opt);
2622 while (*p && *p !=
':') {
2627 "Adding '%s' to the entries to show in section '%s'\n",
2628 entry, section_name);
2634 show_all_entries = 1;
2637 ret =
match_section(section_name, show_all_entries, entries);
2660 "Option '%s' is deprecated, use '-show_entries format=%s' instead\n",
2671 "Argument '%s' provided as input filename, but '%s' was already specified.\n",
2675 if (!strcmp(arg,
"-"))
2705 char *next, *p, *spec =
av_strdup(interval_spec);
2716 next = strchr(spec,
'%');
2758 lli = strtoll(p, &tail, 10);
2759 if (*tail || lli < 0) {
2761 "Invalid or negative value '%s' for duration number of frames\n", p);
2764 interval->
end = lli;
2785 char *p, *spec =
av_strdup(intervals_spec);
2790 for (n = 0, p = spec; *p; p++)
2796 if (!read_intervals) {
2804 for (i = 0; p; i++) {
2808 next = strchr(p,
',');
2812 read_intervals[i].
id = i;
2852 printf(
"%*c %s", level * 4,
' ', section->
name);
2863 printf(
"Sections:\n"
2864 "W.. = Section is a wrapper (contains other sections, no local entries)\n"
2865 ".A. = Section contains an array of elements of the same type\n"
2866 "..V = Section may contain a variable number of fields with variable keys\n"
2867 "FLAGS NAME/UNIQUE_NAME\n"
2880 #define DEFINE_OPT_SHOW_SECTION(section, target_section_id) \
2881 static int opt_show_##section(const char *opt, const char *arg) \
2883 mark_section_show_entries(SECTION_ID_##target_section_id, 1, NULL); \
2903 "use binary prefixes for byte units" },
2905 "use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units" },
2907 "prettify the format of displayed values, make it more human readable" },
2909 "set the output printing format (available formats are: default, compact, csv, flat, ini, json, xml)",
"format" },
2912 {
"sections",
OPT_EXIT, {.func_arg =
opt_sections},
"print sections structure and section information, and exit" },
2915 {
"show_error", 0, {(
void*)&opt_show_error},
"show probing error" },
2916 {
"show_format", 0, {(
void*)&opt_show_format},
"show format/container info" },
2917 {
"show_frames", 0, {(
void*)&opt_show_frames},
"show frames info" },
2919 "show a particular entry from the format/container info",
"entry" },
2921 "show a set of specified entries",
"entry_list" },
2922 {
"show_packets", 0, {(
void*)&opt_show_packets},
"show packets info" },
2923 {
"show_programs", 0, {(
void*)&opt_show_programs},
"show programs info" },
2924 {
"show_streams", 0, {(
void*)&opt_show_streams},
"show streams info" },
2925 {
"show_chapters", 0, {(
void*)&opt_show_chapters},
"show chapters info" },
2928 {
"show_program_version", 0, {(
void*)&opt_show_program_version},
"show ffprobe version" },
2929 {
"show_library_versions", 0, {(
void*)&opt_show_library_versions},
"show library versions" },
2930 {
"show_versions", 0, {(
void*)&
opt_show_versions},
"show program and library versions" },
2952 #define SET_DO_SHOW(id, varname) do { \
2953 if (check_section_show_entries(SECTION_ID_##id)) \
2954 do_show_##varname = 1; \
2962 char *w_name = NULL, *w_args = NULL;
2990 SET_DO_SHOW(STREAM_DISPOSITION, stream_disposition);
2991 SET_DO_SHOW(PROGRAM_STREAM_DISPOSITION, stream_disposition);
3001 "-bitexact and -show_program_version or -show_library_versions "
3002 "options are incompatible\n");
3023 "Unknown hash algorithm '%s'\nKnown algorithms:",
3042 if (w == &xml_writer)