27 #include "libavutil/ffversion.h"
72 # ifdef pthread_mutex_lock
73 # undef pthread_mutex_lock
75 # define pthread_mutex_lock(a) do{}while(0)
76 # ifdef pthread_mutex_unlock
77 # undef pthread_mutex_unlock
79 # define pthread_mutex_unlock(a) do{}while(0)
138 #define SHOW_OPTIONAL_FIELDS_AUTO -1
139 #define SHOW_OPTIONAL_FIELDS_NEVER 0
140 #define SHOW_OPTIONAL_FIELDS_ALWAYS 1
162 #define SECTION_MAX_NB_CHILDREN 10
220 #define SECTION_FLAG_IS_WRAPPER 1
221 #define SECTION_FLAG_IS_ARRAY 2
222 #define SECTION_FLAG_HAS_VARIABLE_FIELDS 4
296 static const struct {
302 { 1.0, 1.0,
"",
"" },
303 { 1.024e3, 1e3,
"Ki",
"K" },
304 { 1.048576e6, 1e6,
"Mi",
"M" },
305 { 1.073741824e9, 1e9,
"Gi",
"G" },
306 { 1.099511627776e12, 1e12,
"Ti",
"T" },
307 { 1.125899906842624e15, 1e15,
"Pi",
"P" },
340 static int print_prefix = 1;
341 void *new_log_buffer;
352 if (new_log_buffer) {
365 for (
i=strlen(msg) - 1;
i>=0 && msg[
i] ==
'\n';
i--) {
371 if (parent && *parent) {
374 (*parent)->get_category ? (*parent)->get_category(parent) :(*parent)->category;
385 union {
double d;
long long int i; }
val;
399 vald = vali = uv.
val.
i;
406 mins = (
int)secs / 60;
407 secs = secs - mins * 60;
410 snprintf(buf, buf_size,
"%d:%02d:%09.6f", hours, mins, secs);
412 const char *prefix_string =
"";
423 index = (
long long int) (log10(vald)) / 3;
432 snprintf(buf, buf_size,
"%f", vald);
434 snprintf(buf, buf_size,
"%lld", vali);
446 #define WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS 1
447 #define WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER 2
472 #define SECTION_MAX_NB_LEVELS 10
514 #define OFFSET(x) offsetof(WriterContext, x)
517 {
"string_validation",
"set string validation mode",
519 {
"sv",
"set string validation mode",
524 {
"string_validation_replacement",
"set string validation replacement string",
OFFSET(string_validation_replacement),
AV_OPT_TYPE_STRING, {.str=
""}},
525 {
"svr",
"set string validation replacement string",
OFFSET(string_validation_replacement),
AV_OPT_TYPE_STRING, {.str=
"\xEF\xBF\xBD"}},
532 if (!prev &&
ctx->writer &&
ctx->writer->priv_class &&
ctx->priv)
553 if ((*wctx)->writer->uninit)
554 (*wctx)->writer->uninit(*wctx);
557 if ((*wctx)->writer->priv_class)
569 static void bprint_bytes(AVBPrint *bp,
const uint8_t *ubuf,
size_t ubuf_size)
573 for (
i = 0;
i < ubuf_size;
i++)
631 (*wctx)->writer = writer;
634 (*wctx)->nb_sections = nb_sections;
639 void *priv_ctx = (*wctx)->priv;
650 av_log(*wctx,
AV_LOG_ERROR,
"Failed to parse option string '%s' provided to writer context\n", args);
657 av_log(*wctx,
AV_LOG_ERROR,
"Failed to set option '%s' with value '%s' provided to writer context\n",
669 const uint8_t *p = (*wctx)->string_validation_replacement;
670 const uint8_t *endp = p + strlen(p);
672 const uint8_t *p0 = p;
680 "Invalid UTF8 sequence %s found in string validation replace '%s'\n",
681 bp.str, (*wctx)->string_validation_replacement);
705 if ((*wctx)->writer->init)
706 ret = (*wctx)->writer->init(*wctx);
720 int parent_section_id;
723 parent_section_id = wctx->
level ?
744 int parent_section_id = wctx->
level ?
759 const char *
key,
long long int val)
771 const uint8_t *p, *endp;
773 int invalid_chars_nb = 0,
ret = 0;
778 for (p = (uint8_t *)
src; *p;) {
781 const uint8_t *p0 = p;
788 "Invalid UTF-8 sequence %s found in string '%s'\n", bp.str,
src);
798 "Invalid UTF-8 sequence found in string '%s'\n",
src);
815 "%d invalid UTF-8 sequence(s) found in string '%s', replaced with '%s'\n",
824 #define PRINT_STRING_OPT 1
825 #define PRINT_STRING_VALIDATE 2
843 if (
ret < 0)
goto end;
845 if (
ret < 0)
goto end;
850 "Invalid key=value string combination %s=%s in section %s\n",
875 int64_t ts,
const AVRational *time_base,
int is_duration)
879 if ((!is_duration && ts ==
AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
882 double d = ts *
av_q2d(*time_base);
893 if ((!is_duration && ts ==
AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
911 for (
i = 0;
i < l;
i++) {
917 for (
i = 0;
i < l;
i++)
938 p = buf + strlen(buf);
945 int columns,
int bytes,
int offset_add)
955 for (
i = 0;
i < l;
i++) {
969 #define writer_w8(wctx_, b_) (wctx_)->writer_w8(wctx_, b_)
970 #define writer_put_str(wctx_, str_) (wctx_)->writer_put_str(wctx_, str_)
971 #define writer_printf(wctx_, fmt_, ...) (wctx_)->writer_printf(wctx_, fmt_, __VA_ARGS__)
973 #define MAX_REGISTERED_WRITERS_NB 64
979 static int next_registered_writer_idx = 0;
1002 #define DEFINE_WRITER_CLASS(name) \
1003 static const char *name##_get_name(void *ctx) \
1007 static const AVClass name##_class = { \
1008 .class_name = #name, \
1009 .item_name = name##_get_name, \
1010 .option = name##_options \
1023 #define OFFSET(x) offsetof(DefaultContext, x)
1026 {
"noprint_wrappers",
"do not print headers and footers",
OFFSET(noprint_wrappers),
AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1027 {
"nw",
"do not print headers and footers",
OFFSET(noprint_wrappers),
AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1039 for (
i = 0;
src[
i] &&
i < dst_size-1;
i++)
1054 if (parent_section &&
1109 .priv_class = &default_class,
1117 static const char *
c_escape_str(AVBPrint *dst,
const char *
src,
const char sep,
void *log_ctx)
1121 for (p =
src; *p; p++) {
1123 case '\b':
av_bprintf(dst,
"%s",
"\\b");
break;
1124 case '\f':
av_bprintf(dst,
"%s",
"\\f");
break;
1125 case '\n':
av_bprintf(dst,
"%s",
"\\n");
break;
1126 case '\r':
av_bprintf(dst,
"%s",
"\\r");
break;
1127 case '\\':
av_bprintf(dst,
"%s",
"\\\\");
break;
1142 char meta_chars[] = { sep,
'"',
'\n',
'\r',
'\0' };
1143 int needs_quoting = !!
src[strcspn(
src, meta_chars)];
1170 const char * (*escape_str)(AVBPrint *dst,
const char *
src,
const char sep,
void *log_ctx);
1177 #define OFFSET(x) offsetof(CompactContext, x)
1198 av_log(wctx,
AV_LOG_ERROR,
"Item separator '%s' specified, but must contain a single character\n",
1263 if (!compact->
nokey)
1275 if (!compact->
nokey)
1289 .priv_class = &compact_class,
1295 #define OFFSET(x) offsetof(CompactContext, x)
1320 .priv_class = &csv_class,
1333 #define OFFSET(x) offsetof(FlatContext, x)
1338 {
"hierarchical",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical),
AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1339 {
"h",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical),
AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1349 if (strlen(
flat->sep_str) != 1) {
1350 av_log(wctx,
AV_LOG_ERROR,
"Item separator '%s' specified, but must contain a single character\n",
1363 for (p =
src; *p; p++) {
1364 if (!((*p >=
'0' && *p <=
'9') ||
1365 (*p >=
'a' && *p <=
'z') ||
1366 (*p >=
'A' && *p <=
'Z')))
1378 for (p =
src; *p; p++) {
1380 case '\n':
av_bprintf(dst,
"%s",
"\\n");
break;
1381 case '\r':
av_bprintf(dst,
"%s",
"\\r");
break;
1382 case '\\':
av_bprintf(dst,
"%s",
"\\\\");
break;
1383 case '"':
av_bprintf(dst,
"%s",
"\\\"");
break;
1384 case '`':
av_bprintf(dst,
"%s",
"\\`");
break;
1385 case '$':
av_bprintf(dst,
"%s",
"\\$");
break;
1402 if (!parent_section)
1406 if (
flat->hierarchical ||
1444 .priv_class = &flat_class,
1455 #define OFFSET(x) offsetof(INIContext, x)
1458 {
"hierarchical",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical),
AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1459 {
"h",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical),
AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1470 while (
c =
src[
i++]) {
1472 case '\b':
av_bprintf(dst,
"%s",
"\\b");
break;
1473 case '\f':
av_bprintf(dst,
"%s",
"\\f");
break;
1474 case '\n':
av_bprintf(dst,
"%s",
"\\n");
break;
1475 case '\r':
av_bprintf(dst,
"%s",
"\\r");
break;
1476 case '\t':
av_bprintf(dst,
"%s",
"\\t");
break;
1482 if ((
unsigned char)
c < 32)
1501 if (!parent_section) {
1548 .priv_class = &ini_class,
1561 #define OFFSET(x) offsetof(JSONContext, x)
1583 static const char json_escape[] = {
'"',
'\\',
'\b',
'\f',
'\n',
'\r',
'\t', 0};
1584 static const char json_subst[] = {
'"',
'\\',
'b',
'f',
'n',
'r',
't', 0};
1587 for (p =
src; *p; p++) {
1588 char *
s = strchr(json_escape, *p);
1592 }
else if ((
unsigned char)*p < 32) {
1601 #define JSON_INDENT() writer_printf(wctx, "%*c", json->indent_level * 4, ' ')
1647 if (wctx->
level == 0) {
1665 const char *
key,
const char *
value)
1715 .priv_class = &json_class,
1729 #define OFFSET(x) offsetof(XMLContext, x)
1732 {
"fully_qualified",
"specify if the output should be fully qualified",
OFFSET(fully_qualified),
AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1733 {
"q",
"specify if the output should be fully qualified",
OFFSET(fully_qualified),
AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1734 {
"xsd_strict",
"ensure that the output is XSD compliant",
OFFSET(xsd_strict),
AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1747 #define CHECK_COMPLIANCE(opt, opt_name) \
1749 av_log(wctx, AV_LOG_ERROR, \
1750 "XSD-compliant output selected but option '%s' was selected, XML output may be non-compliant.\n" \
1751 "You need to disable such option with '-no%s'\n", opt_name, opt_name); \
1752 return AVERROR(EINVAL); \
1762 #define XML_INDENT() writer_printf(wctx, "%*c", xml->indent_level * 4, ' ')
1771 if (wctx->
level == 0) {
1772 const char *qual =
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
1773 "xmlns:ffprobe=\"http://www.ffmpeg.org/schema/ffprobe\" "
1774 "xsi:schemaLocation=\"http://www.ffmpeg.org/schema/ffprobe ffprobe.xsd\"";
1776 writer_put_str(wctx,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
1809 if (wctx->
level == 0) {
1870 .priv_class = &xml_class,
1890 #define print_fmt(k, f, ...) do { \
1891 av_bprint_clear(&pbuf); \
1892 av_bprintf(&pbuf, f, __VA_ARGS__); \
1893 writer_print_string(w, k, pbuf.str, 0); \
1896 #define print_list_fmt(k, f, n, m, ...) do { \
1897 av_bprint_clear(&pbuf); \
1898 for (int idx = 0; idx < n; idx++) { \
1899 for (int idx2 = 0; idx2 < m; idx2++) { \
1900 if (idx > 0 || idx2 > 0) \
1901 av_bprint_chars(&pbuf, ' ', 1); \
1902 av_bprintf(&pbuf, f, __VA_ARGS__); \
1905 writer_print_string(w, k, pbuf.str, 0); \
1908 #define print_int(k, v) writer_print_integer(w, k, v)
1909 #define print_q(k, v, s) writer_print_rational(w, k, v, s)
1910 #define print_str(k, v) writer_print_string(w, k, v, 0)
1911 #define print_str_opt(k, v) writer_print_string(w, k, v, PRINT_STRING_OPT)
1912 #define print_str_validate(k, v) writer_print_string(w, k, v, PRINT_STRING_VALIDATE)
1913 #define print_time(k, v, tb) writer_print_time(w, k, v, tb, 0)
1914 #define print_ts(k, v) writer_print_ts(w, k, v, 0)
1915 #define print_duration_time(k, v, tb) writer_print_time(w, k, v, tb, 1)
1916 #define print_duration_ts(k, v) writer_print_ts(w, k, v, 1)
1917 #define print_val(k, v, u) do { \
1918 struct unit_value uv; \
1921 writer_print_string(w, k, value_string(val_str, sizeof(val_str), uv), 0); \
1924 #define print_section_header(s) writer_print_section_header(w, s)
1925 #define print_section_footer(s) writer_print_section_footer(w, s)
1927 #define REALLOCZ_ARRAY_STREAM(ptr, cur_n, new_n) \
1929 ret = av_reallocp_array(&(ptr), (new_n), sizeof(*(ptr))); \
1932 memset( (ptr) + (cur_n), 0, ((new_n) - (cur_n)) * sizeof(*(ptr)) ); \
1971 print_int(
"chroma_resampling_explicit_filter_flag",
1980 print_int(
"spatial_resampling_filter_flag",
1982 print_int(
"el_spatial_resampling_filter_flag",
1995 print_str(
"nlq_method_idc_name",
"none");
1998 print_str(
"nlq_method_idc_name",
"linear_dz");
2001 print_str(
"nlq_method_idc_name",
"unknown");
2010 for (
int c = 0;
c < 3;
c++) {
2023 print_str(
"mapping_idc_name",
"polynomial");
2038 print_str(
"mapping_idc_name",
"unknown");
2074 color->ycc_to_rgb_matrix[idx].num,
2075 color->ycc_to_rgb_matrix[idx].den);
2078 color->ycc_to_rgb_offset[idx].num,
2079 color->ycc_to_rgb_offset[idx].den);
2082 color->rgb_to_lms_matrix[idx].num,
2083 color->rgb_to_lms_matrix[idx].den);
2091 print_int(
"signal_full_range_flag",
color->signal_full_range_flag);
2108 print_q(
"window_upper_left_corner_x",
2110 print_q(
"window_upper_left_corner_y",
2112 print_q(
"window_lower_right_corner_x",
2114 print_q(
"window_lower_right_corner_y",
2116 print_q(
"window_upper_left_corner_x",
2118 print_q(
"window_upper_left_corner_y",
2126 print_int(
"semimajor_axis_internal_ellipse",
2128 print_int(
"semimajor_axis_external_ellipse",
2130 print_int(
"semiminor_axis_external_ellipse",
2135 print_q(
"targeted_system_display_maximum_luminance",
2138 print_int(
"num_rows_targeted_system_display_actual_peak_luminance",
2140 print_int(
"num_cols_targeted_system_display_actual_peak_luminance",
2144 print_q(
"targeted_system_display_actual_peak_luminance",
2151 for (
int i = 0;
i < 3;
i++) {
2156 print_int(
"num_distribution_maxrgb_percentiles",
2159 print_int(
"distribution_maxrgb_percentage",
2161 print_q(
"distribution_maxrgb_percentile",
2164 print_q(
"fraction_bright_pixels",
2168 print_int(
"num_rows_mastering_display_actual_peak_luminance",
2170 print_int(
"num_cols_mastering_display_actual_peak_luminance",
2174 print_q(
"mastering_display_actual_peak_luminance",
2188 print_q(
"bezier_curve_anchors",
2193 print_q(
"color_saturation_weight",
2224 print_q(
"targeted_system_display_maximum_luminance",
2237 print_int(
"base_param_Delta_enable_mode",
2290 for (
i = 0;
i < nb_side_data;
i++) {
2298 if (
isnan(rotation))
2537 const uint8_t *side_metadata;
2603 print_ts (
"best_effort_timestamp",
frame->best_effort_timestamp);
2605 #if LIBAVUTIL_VERSION_MAJOR < 59
2633 print_q(
"sample_aspect_ratio", sar,
':');
2638 #if LIBAVUTIL_VERSION_MAJOR < 59
2641 print_int(
"display_picture_number",
frame->display_picture_number);
2672 if (
frame->nb_side_data) {
2674 for (
i = 0;
i <
frame->nb_side_data;
i++) {
2683 if (
isnan(rotation))
2694 uint32_t *
tc = (uint32_t*)sd->
data;
2697 for (
int j = 1; j <= m ; j++) {
2765 int ret = 0, got_frame = 0;
2816 return got_frame || *packet_new;
2821 av_log(log_ctx, log_level,
"id:%d", interval->
id);
2827 av_log(log_ctx, log_level,
" start:N/A");
2833 av_log(log_ctx, log_level,
"#%"PRId64, interval->
end);
2837 av_log(log_ctx, log_level,
" end:N/A");
2840 av_log(log_ctx, log_level,
"\n");
2849 int ret = 0,
i = 0, frame_count = 0;
2850 int64_t start = -INT64_MAX, end = interval->
end;
2861 "Could not seek to relative position since current "
2862 "timestamp is not defined\n");
2866 target = *cur_ts + interval->
start;
2868 target = interval->
start;
2910 end = start + interval->
end;
2915 if (frame_count >= interval->
end)
2917 }
else if (has_end && *cur_ts !=
AV_NOPTS_VALUE && *cur_ts >= end) {
3024 char profile_num[12];
3052 print_q(
"sample_aspect_ratio", sar,
':');
3057 print_q(
"display_aspect_ratio", dar,
':');
3074 print_str(
"field_order",
"progressive");
3162 #define PRINT_DISPOSITION(flagname, name) do { \
3163 print_int(name, !!(stream->disposition & AV_DISPOSITION_##flagname)); \
3238 for (
i = 0;
i <
program->nb_stream_indexes;
i++) {
3335 const char *print_filename)
3340 int scan_all_pmts_set = 0;
3348 scan_all_pmts_set = 1;
3355 if (print_filename) {
3360 if (scan_all_pmts_set)
3375 for (
i = 0;
i < orig_nb_streams;
i++)
3402 "Failed to probe codec for input stream %d\n",
3410 "Unsupported codec with id %d for input stream %d\n",
3474 const char *print_filename)
3487 #define CHECK_END if (ret < 0) goto end
3568 print_fmt(
"copyright",
"Copyright (c) %d-%d the FFmpeg developers",
3571 print_str(
"configuration", FFMPEG_CONFIGURATION);
3577 #define SHOW_LIB_VERSION(libname, LIBNAME) \
3579 if (CONFIG_##LIBNAME) { \
3580 unsigned int version = libname##_version(); \
3581 writer_print_section_header(w, SECTION_ID_LIBRARY_VERSION); \
3582 print_str("name", "lib" #libname); \
3583 print_int("major", LIB##LIBNAME##_VERSION_MAJOR); \
3584 print_int("minor", LIB##LIBNAME##_VERSION_MINOR); \
3585 print_int("micro", LIB##LIBNAME##_VERSION_MICRO); \
3586 print_int("version", version); \
3587 print_str("ident", LIB##LIBNAME##_IDENT); \
3588 writer_print_section_footer(w); \
3606 #define PRINT_PIX_FMT_FLAG(flagname, name) \
3608 print_int(name, !!(pixdesc->flags & AV_PIX_FMT_FLAG_##flagname)); \
3708 "'%s' matches section with unique name '%s'\n", section_name,
3719 const char *p =
arg;
3727 if (!section_name) {
3729 "Missing section name for option '%s'\n", opt);
3735 while (*p && *p !=
':') {
3740 "Adding '%s' to the entries to show in section '%s'\n",
3741 entry, section_name);
3771 "Argument '%s' provided as input filename, but '%s' was already specified.\n",
3775 if (!strcmp(
arg,
"-"))
3792 "Argument '%s' provided as output filename, but '%s' was already specified.\n",
3796 if (!strcmp(
arg,
"-"))
3829 char *next, *p, *spec =
av_strdup(interval_spec);
3840 next = strchr(spec,
'%');
3882 lli = strtoll(p, &tail, 10);
3883 if (*tail || lli < 0) {
3885 "Invalid or negative value '%s' for duration number of frames\n", p);
3888 interval->
end = lli;
3910 char *p, *spec =
av_strdup(intervals_spec);
3915 for (n = 0, p = spec; *p; p++)
3929 for (
i = 0; p;
i++) {
3933 next = strchr(p,
',');
3989 "W.. = Section is a wrapper (contains other sections, no local entries)\n"
3990 ".A. = Section contains an array of elements of the same type\n"
3991 "..V = Section may contain a variable number of fields with variable keys\n"
3992 "FLAGS NAME/UNIQUE_NAME\n"
4005 #define DEFINE_OPT_SHOW_SECTION(section, target_section_id) \
4006 static int opt_show_##section(void *optctx, const char *opt, const char *arg) \
4008 mark_section_show_entries(SECTION_ID_##target_section_id, 1, NULL); \
4029 "use binary prefixes for byte units" },
4031 "use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units" },
4033 "prettify the format of displayed values, make it more human readable" },
4035 "set the output printing format (available formats are: default, compact, csv, flat, ini, json, xml)",
"format" },