27 #include "libavutil/ffversion.h"
97 #define SECTION_MAX_NB_CHILDREN 10
103 #define SECTION_FLAG_IS_WRAPPER 1
104 #define SECTION_FLAG_IS_ARRAY 2
105 #define SECTION_FLAG_HAS_VARIABLE_FIELDS 4
207 union {
double d;
long long int i; }
val;
221 vald = vali = uv.
val.
i;
228 mins = (int)secs / 60;
229 secs = secs - mins * 60;
232 snprintf(buf, buf_size,
"%d:%02d:%09.6f", hours, mins, secs);
234 const char *prefix_string =
"";
240 index = (
long long int) (
log2(vald)) / 10;
242 vald /=
exp2(index * 10);
245 index = (
long long int) (log10(vald)) / 3;
247 vald /= pow(10, index * 3);
254 snprintf(buf, buf_size,
"%f", vald);
256 snprintf(buf, buf_size,
"%lld", vali);
268 #define WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS 1
269 #define WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER 2
294 #define SECTION_MAX_NB_LEVELS 10
330 #define OFFSET(x) offsetof(WriterContext, x)
333 {
"string_validation",
"set string validation mode",
335 {
"sv",
"set string validation mode",
340 {
"string_validation_replacement",
"set string validation replacement string",
OFFSET(string_validation_replacement),
AV_OPT_TYPE_STRING, {.str=
""}},
341 {
"svr",
"set string validation replacement string",
OFFSET(string_validation_replacement),
AV_OPT_TYPE_STRING, {.str=
"\xEF\xBF\xBD"}},
368 if ((*wctx)->writer->uninit)
369 (*wctx)->writer->uninit(*wctx);
372 if ((*wctx)->writer->priv_class)
383 for (i = 0; i < ubuf_size; i++)
389 const struct section *sections,
int nb_sections)
404 (*wctx)->writer = writer;
407 (*wctx)->nb_sections = nb_sections;
412 void *priv_ctx = (*wctx)->priv;
423 av_log(*wctx,
AV_LOG_ERROR,
"Failed to parse option string '%s' provided to writer context\n", args);
430 av_log(*wctx,
AV_LOG_ERROR,
"Failed to set option '%s' with value '%s' provided to writer context\n",
442 const uint8_t *p = (*wctx)->string_validation_replacement;
443 const uint8_t *endp = p + strlen(p);
447 ret =
av_utf8_decode(&code, &p, endp, (*wctx)->string_validation_utf8_flags);
453 "Invalid UTF8 sequence %s found in string validation replace '%s'\n",
454 bp.str, (*wctx)->string_validation_replacement);
463 if ((*wctx)->writer->init)
464 ret = (*wctx)->writer->init(*wctx);
478 int parent_section_id;
481 parent_section_id = wctx->
level ?
502 int parent_section_id = wctx->
level ?
517 const char *key,
long long int val)
531 int invalid_chars_nb = 0,
ret = 0;
535 endp = src + strlen(src);
536 for (p = (
uint8_t *)src; *p;) {
546 "Invalid UTF-8 sequence %s found in string '%s'\n", bp.str, src);
556 "Invalid UTF-8 sequence found in string '%s'\n", src);
573 "%d invalid UTF-8 sequence(s) found in string '%s', replaced with '%s'\n",
582 #define PRINT_STRING_OPT 1
583 #define PRINT_STRING_VALIDATE 2
586 const char *key,
const char *
val,
int flags)
597 char *key1 = NULL, *val1 = NULL;
599 if (ret < 0)
goto end;
601 if (ret < 0)
goto end;
606 "Invalid key=value string combination %s=%s in section %s\n",
631 int64_t ts,
const AVRational *time_base,
int is_duration)
635 if ((!is_duration && ts ==
AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
638 double d = ts *
av_q2d(*time_base);
649 if ((!is_duration && ts ==
AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
667 for (i = 0; i < l; i++) {
673 for (i = 0; i < l; i++)
684 #define MAX_REGISTERED_WRITERS_NB 64
690 static int next_registered_writer_idx = 0;
695 registered_writers[next_registered_writer_idx++] = writer;
703 for (i = 0; registered_writers[
i]; i++)
704 if (!strcmp(registered_writers[i]->name, name))
705 return registered_writers[
i];
713 #define DEFINE_WRITER_CLASS(name) \
714 static const char *name##_get_name(void *ctx) \
718 static const AVClass name##_class = { \
719 .class_name = #name, \
720 .item_name = name##_get_name, \
721 .option = name##_options \
734 #define OFFSET(x) offsetof(DefaultContext, x)
737 {
"noprint_wrappers",
"do not print headers and footers",
OFFSET(noprint_wrappers),
AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
738 {
"nw",
"do not print headers and footers",
OFFSET(noprint_wrappers),
AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
750 for (i = 0; src[i] && i < dst_size-1; i++)
761 const struct section *parent_section = wctx->
level ?
765 if (parent_section &&
800 printf(
"%s\n", value);
809 printf(
"%lld\n", value);
820 .priv_class = &default_class,
832 for (p = src; *p; p++) {
834 case '\b':
av_bprintf(dst,
"%s",
"\\b");
break;
835 case '\f':
av_bprintf(dst,
"%s",
"\\f");
break;
836 case '\n':
av_bprintf(dst,
"%s",
"\\n");
break;
837 case '\r':
av_bprintf(dst,
"%s",
"\\r");
break;
838 case '\\':
av_bprintf(dst,
"%s",
"\\\\");
break;
853 char meta_chars[] = { sep,
'"',
'\n',
'\r',
'\0' };
854 int needs_quoting = !!src[strcspn(src, meta_chars)];
859 for (; *
src; src++) {
881 const char * (*escape_str)(
AVBPrint *dst,
const char *
src,
const char sep,
void *log_ctx);
888 #define OFFSET(x) offsetof(CompactContext, x)
909 av_log(wctx,
AV_LOG_ERROR,
"Item separator '%s' specified, but must contain a single character\n",
930 const struct section *parent_section = wctx->
level ?
986 printf(
"%lld", value);
998 .priv_class = &compact_class,
1004 #define OFFSET(x) offsetof(CompactContext, x)
1029 .priv_class = &csv_class,
1042 #define OFFSET(x) offsetof(FlatContext, x)
1047 {
"hierarchical",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical),
AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
1048 {
"h",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical),
AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
1058 if (strlen(flat->
sep_str) != 1) {
1059 av_log(wctx,
AV_LOG_ERROR,
"Item separator '%s' specified, but must contain a single character\n",
1072 for (p = src; *p; p++) {
1073 if (!((*p >=
'0' && *p <=
'9') ||
1074 (*p >=
'a' && *p <=
'z') ||
1075 (*p >=
'A' && *p <=
'Z')))
1087 for (p = src; *p; p++) {
1089 case '\n':
av_bprintf(dst,
"%s",
"\\n");
break;
1090 case '\r':
av_bprintf(dst,
"%s",
"\\r");
break;
1091 case '\\':
av_bprintf(dst,
"%s",
"\\\\");
break;
1092 case '"':
av_bprintf(dst,
"%s",
"\\\"");
break;
1093 case '`':
av_bprintf(dst,
"%s",
"\\`");
break;
1094 case '$':
av_bprintf(dst,
"%s",
"\\$");
break;
1106 const struct section *parent_section = wctx->
level ?
1111 if (!parent_section)
1153 .priv_class = &flat_class,
1164 #define OFFSET(x) offsetof(INIContext, x)
1167 {
"hierarchical",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical),
AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
1168 {
"h",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical),
AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
1179 while (c = src[i++]) {
1181 case '\b':
av_bprintf(dst,
"%s",
"\\b");
break;
1182 case '\f':
av_bprintf(dst,
"%s",
"\\f");
break;
1183 case '\n':
av_bprintf(dst,
"%s",
"\\n");
break;
1184 case '\r':
av_bprintf(dst,
"%s",
"\\r");
break;
1185 case '\t':
av_bprintf(dst,
"%s",
"\\t");
break;
1191 if ((
unsigned char)c < 32)
1206 const struct section *parent_section = wctx->
level ?
1210 if (!parent_section) {
1211 printf(
"# ffprobe output\n\n");
1231 printf(
"[%s]\n", buf->str);
1247 printf(
"%s=%lld\n", key, value);
1257 .priv_class = &ini_class,
1270 #define OFFSET(x) offsetof(JSONContext, x)
1292 static const char json_escape[] = {
'"',
'\\',
'\b',
'\f',
'\n',
'\r',
'\t', 0};
1293 static const char json_subst[] = {
'"',
'\\',
'b',
'f',
'n',
'r',
't', 0};
1296 for (p = src; *p; p++) {
1297 char *
s = strchr(json_escape, *p);
1301 }
else if ((
unsigned char)*p < 32) {
1310 #define JSON_INDENT() printf("%*c", json->indent_level * 4, ' ')
1317 const struct section *parent_section = wctx->
level ?
1333 printf(
"\"%s\": [\n", buf.str);
1343 printf(
"\"type\": \"%s\"%s", section->
name, json->
item_sep);
1355 if (wctx->
level == 0) {
1373 const char *key,
const char *
value)
1419 .priv_class = &json_class,
1433 #define OFFSET(x) offsetof(XMLContext, x)
1436 {
"fully_qualified",
"specify if the output should be fully qualified",
OFFSET(fully_qualified),
AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
1437 {
"q",
"specify if the output should be fully qualified",
OFFSET(fully_qualified),
AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
1438 {
"xsd_strict",
"ensure that the output is XSD compliant",
OFFSET(xsd_strict),
AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
1439 {
"x",
"ensure that the output is XSD compliant",
OFFSET(xsd_strict),
AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
1451 #define CHECK_COMPLIANCE(opt, opt_name) \
1453 av_log(wctx, AV_LOG_ERROR, \
1454 "XSD-compliant output selected but option '%s' was selected, XML output may be non-compliant.\n" \
1455 "You need to disable such option with '-no%s'\n", opt_name, opt_name); \
1456 return AVERROR(EINVAL); \
1464 "Interleaved frames and packets are not allowed in XSD. "
1465 "Select only one between the -show_frames and the -show_packets options.\n");
1477 for (p = src; *p; p++) {
1479 case '&' :
av_bprintf(dst,
"%s",
"&");
break;
1480 case '<' :
av_bprintf(dst,
"%s",
"<");
break;
1481 case '>' :
av_bprintf(dst,
"%s",
">");
break;
1482 case '"' :
av_bprintf(dst,
"%s",
""");
break;
1483 case '\'':
av_bprintf(dst,
"%s",
"'");
break;
1491 #define XML_INDENT() printf("%*c", xml->indent_level * 4, ' ')
1497 const struct section *parent_section = wctx->
level ?
1500 if (wctx->
level == 0) {
1501 const char *qual =
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' "
1502 "xmlns:ffprobe='http://www.ffmpeg.org/schema/ffprobe' "
1503 "xsi:schemaLocation='http://www.ffmpeg.org/schema/ffprobe ffprobe.xsd'";
1505 printf(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
1506 printf(
"<%sffprobe%s>\n",
1538 if (wctx->
level == 0) {
1562 printf(
"<%s key=\"%s\"",
1579 printf(
"%s=\"%lld\"", key, value);
1591 .priv_class = &xml_class,
1596 static int initialized;
1611 #define print_fmt(k, f, ...) do { \
1612 av_bprint_clear(&pbuf); \
1613 av_bprintf(&pbuf, f, __VA_ARGS__); \
1614 writer_print_string(w, k, pbuf.str, 0); \
1617 #define print_int(k, v) writer_print_integer(w, k, v)
1618 #define print_q(k, v, s) writer_print_rational(w, k, v, s)
1619 #define print_str(k, v) writer_print_string(w, k, v, 0)
1620 #define print_str_opt(k, v) writer_print_string(w, k, v, PRINT_STRING_OPT)
1621 #define print_str_validate(k, v) writer_print_string(w, k, v, PRINT_STRING_VALIDATE)
1622 #define print_time(k, v, tb) writer_print_time(w, k, v, tb, 0)
1623 #define print_ts(k, v) writer_print_ts(w, k, v, 0)
1624 #define print_duration_time(k, v, tb) writer_print_time(w, k, v, tb, 1)
1625 #define print_duration_ts(k, v) writer_print_ts(w, k, v, 1)
1626 #define print_val(k, v, u) do { \
1627 struct unit_value uv; \
1630 writer_print_string(w, k, value_string(val_str, sizeof(val_str), uv), 0); \
1633 #define print_section_header(s) writer_print_section_header(w, s)
1634 #define print_section_footer(s) writer_print_section_footer(w, s)
1636 #define REALLOCZ_ARRAY_STREAM(ptr, cur_n, new_n) \
1638 ret = av_reallocp_array(&(ptr), (new_n), sizeof(*(ptr))); \
1641 memset( (ptr) + (cur_n), 0, ((new_n) - (cur_n)) * sizeof(*(ptr)) ); \
1758 print_q(
"sample_aspect_ratio", sar,
':');
1800 int ret = 0, got_frame = 0;
1802 if (dec_ctx->
codec) {
1839 av_log(log_ctx, log_level,
"id:%d", interval->
id);
1845 av_log(log_ctx, log_level,
" start:N/A");
1851 av_log(log_ctx, log_level,
"#%"PRId64, interval->
end);
1855 av_log(log_ctx, log_level,
" end:N/A");
1858 av_log(log_ctx, log_level,
"\n");
1866 int ret = 0, i = 0, frame_count = 0;
1880 "Could not seek to relative position since current "
1881 "timestamp is not defined\n");
1885 target = *cur_ts + interval->
start;
1887 target = interval->
start;
1923 end = start + interval->
end;
1928 if (frame_count >= interval->
end)
1930 }
else if (has_end && *cur_ts !=
AV_NOPTS_VALUE && *cur_ts >= end) {
2003 if ((dec_ctx = stream->
codec)) {
2004 const char *profile = NULL;
2005 dec = dec_ctx->
codec;
2047 print_q(
"sample_aspect_ratio", sar,
':');
2052 print_q(
"display_aspect_ratio", dar,
':');
2113 if (opt->
flags)
continue;
2145 #define PRINT_DISPOSITION(flagname, name) do { \
2146 print_int(name, !!(stream->disposition & AV_DISPOSITION_##flagname)); \
2299 const char *errbuf_ptr = errbuf;
2312 int err, i, orig_nb_streams;
2335 for (i = 0; i < orig_nb_streams; i++)
2348 "Failed to probe codec for input stream %d\n",
2352 "Unsupported codec with id %d for input stream %d\n",
2356 fmt_ctx, stream, codec);
2399 #define CHECK_END if (ret < 0) goto end
2477 print_fmt(
"copyright",
"Copyright (c) %d-%d the FFmpeg developers",
2482 print_str(
"configuration", FFMPEG_CONFIGURATION);
2488 #define SHOW_LIB_VERSION(libname, LIBNAME) \
2490 if (CONFIG_##LIBNAME) { \
2491 unsigned int version = libname##_version(); \
2492 writer_print_section_header(w, SECTION_ID_LIBRARY_VERSION); \
2493 print_str("name", "lib" #libname); \
2494 print_int("major", LIB##LIBNAME##_VERSION_MAJOR); \
2495 print_int("minor", LIB##LIBNAME##_VERSION_MINOR); \
2496 print_int("micro", LIB##LIBNAME##_VERSION_MICRO); \
2497 print_int("version", version); \
2498 print_str("ident", LIB##LIBNAME##_IDENT); \
2499 writer_print_section_footer(w); \
2533 if (show_all_entries) {
2549 if (!strcmp(section_name, section->
name) ||
2552 "'%s' matches section with unique name '%s'\n", section_name,
2563 const char *p =
arg;
2571 if (!section_name) {
2573 "Missing section name for option '%s'\n", opt);
2579 while (*p && *p !=
':') {
2584 "Adding '%s' to the entries to show in section '%s'\n",
2585 entry, section_name);
2591 show_all_entries = 1;
2594 ret =
match_section(section_name, show_all_entries, entries);
2617 "Option '%s' is deprecated, use '-show_entries format=%s' instead\n",
2628 "Argument '%s' provided as input filename, but '%s' was already specified.\n",
2632 if (!strcmp(arg,
"-"))
2662 char *next, *p, *spec =
av_strdup(interval_spec);
2673 next = strchr(spec,
'%');
2715 lli = strtoll(p, &tail, 10);
2716 if (*tail || lli < 0) {
2718 "Invalid or negative value '%s' for duration number of frames\n", p);
2721 interval->
end = lli;
2742 char *p, *spec =
av_strdup(intervals_spec);
2747 for (n = 0, p = spec; *p; p++)
2753 if (!read_intervals) {
2761 for (i = 0; p; i++) {
2765 next = strchr(p,
',');
2769 read_intervals[i].
id = i;
2809 printf(
"%*c %s", level * 4,
' ', section->
name);
2820 printf(
"Sections:\n"
2821 "W.. = Section is a wrapper (contains other sections, no local entries)\n"
2822 ".A. = Section contains an array of elements of the same type\n"
2823 "..V = Section may contain a variable number of fields with variable keys\n"
2824 "FLAGS NAME/UNIQUE_NAME\n"
2837 #define DEFINE_OPT_SHOW_SECTION(section, target_section_id) \
2838 static int opt_show_##section(const char *opt, const char *arg) \
2840 mark_section_show_entries(SECTION_ID_##target_section_id, 1, NULL); \
2860 "use binary prefixes for byte units" },
2862 "use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units" },
2864 "prettify the format of displayed values, make it more human readable" },
2866 "set the output printing format (available formats are: default, compact, csv, flat, ini, json, xml)",
"format" },
2869 {
"sections",
OPT_EXIT, {.func_arg =
opt_sections},
"print sections structure and section information, and exit" },
2871 {
"show_error", 0, {(
void*)&opt_show_error},
"show probing error" },
2872 {
"show_format", 0, {(
void*)&opt_show_format},
"show format/container info" },
2873 {
"show_frames", 0, {(
void*)&opt_show_frames},
"show frames info" },
2875 "show a particular entry from the format/container info",
"entry" },
2877 "show a set of specified entries",
"entry_list" },
2878 {
"show_packets", 0, {(
void*)&opt_show_packets},
"show packets info" },
2879 {
"show_programs", 0, {(
void*)&opt_show_programs},
"show programs info" },
2880 {
"show_streams", 0, {(
void*)&opt_show_streams},
"show streams info" },
2881 {
"show_chapters", 0, {(
void*)&opt_show_chapters},
"show chapters info" },
2884 {
"show_program_version", 0, {(
void*)&opt_show_program_version},
"show ffprobe version" },
2885 {
"show_library_versions", 0, {(
void*)&opt_show_library_versions},
"show library versions" },
2886 {
"show_versions", 0, {(
void*)&
opt_show_versions},
"show program and library versions" },
2908 #define SET_DO_SHOW(id, varname) do { \
2909 if (check_section_show_entries(SECTION_ID_##id)) \
2910 do_show_##varname = 1; \
2918 char *w_name = NULL, *w_args = NULL;
2946 SET_DO_SHOW(STREAM_DISPOSITION, stream_disposition);
2947 SET_DO_SHOW(PROGRAM_STREAM_DISPOSITION, stream_disposition);
2957 "-bitexact and -show_program_version or -show_library_versions "
2958 "options are incompatible\n");
2983 if (w == &xml_writer)