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
224 #define SECTION_FLAG_HAS_TYPE 8
231 const char *(* get_type)(
void *
data);
309 static const struct {
315 { 1.0, 1.0,
"",
"" },
316 { 1.024e3, 1e3,
"Ki",
"K" },
317 { 1.048576e6, 1e6,
"Mi",
"M" },
318 { 1.073741824e9, 1e9,
"Gi",
"G" },
319 { 1.099511627776e12, 1e12,
"Ti",
"T" },
320 { 1.125899906842624e15, 1e15,
"Pi",
"P" },
353 static int print_prefix = 1;
354 void *new_log_buffer;
365 if (new_log_buffer) {
378 for (
i=strlen(msg) - 1;
i>=0 && msg[
i] ==
'\n';
i--) {
384 if (parent && *parent) {
387 (*parent)->get_category ? (*parent)->get_category(parent) :(*parent)->category;
398 union {
double d;
long long int i; }
val;
412 vald = vali = uv.
val.
i;
419 mins = (
int)secs / 60;
420 secs = secs - mins * 60;
423 snprintf(buf, buf_size,
"%d:%02d:%09.6f", hours, mins, secs);
425 const char *prefix_string =
"";
436 index = (
long long int) (log10(vald)) / 3;
445 snprintf(buf, buf_size,
"%f", vald);
447 snprintf(buf, buf_size,
"%lld", vali);
459 #define WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS 1
460 #define WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER 2
485 #define SECTION_MAX_NB_LEVELS 10
527 #define OFFSET(x) offsetof(WriterContext, x)
530 {
"string_validation",
"set string validation mode",
532 {
"sv",
"set string validation mode",
537 {
"string_validation_replacement",
"set string validation replacement string",
OFFSET(string_validation_replacement),
AV_OPT_TYPE_STRING, {.str=
""}},
538 {
"svr",
"set string validation replacement string",
OFFSET(string_validation_replacement),
AV_OPT_TYPE_STRING, {.str=
"\xEF\xBF\xBD"}},
545 if (!prev &&
ctx->writer &&
ctx->writer->priv_class &&
ctx->priv)
566 if ((*wctx)->writer->uninit)
567 (*wctx)->writer->uninit(*wctx);
570 if ((*wctx)->writer->priv_class)
582 static void bprint_bytes(AVBPrint *bp,
const uint8_t *ubuf,
size_t ubuf_size)
586 for (
i = 0;
i < ubuf_size;
i++)
644 (*wctx)->writer = writer;
647 (*wctx)->nb_sections = nb_sections;
652 void *priv_ctx = (*wctx)->priv;
663 av_log(*wctx,
AV_LOG_ERROR,
"Failed to parse option string '%s' provided to writer context\n", args);
670 av_log(*wctx,
AV_LOG_ERROR,
"Failed to set option '%s' with value '%s' provided to writer context\n",
682 const uint8_t *p = (*wctx)->string_validation_replacement;
683 const uint8_t *endp = p + strlen(p);
685 const uint8_t *p0 = p;
693 "Invalid UTF8 sequence %s found in string validation replace '%s'\n",
694 bp.str, (*wctx)->string_validation_replacement);
718 if ((*wctx)->writer->init)
719 ret = (*wctx)->writer->init(*wctx);
734 int parent_section_id;
737 parent_section_id = wctx->
level ?
758 int parent_section_id = wctx->
level ?
773 const char *
key,
long long int val)
785 const uint8_t *p, *endp;
787 int invalid_chars_nb = 0,
ret = 0;
792 for (p = (uint8_t *)
src; *p;) {
795 const uint8_t *p0 = p;
802 "Invalid UTF-8 sequence %s found in string '%s'\n", bp.str,
src);
812 "Invalid UTF-8 sequence found in string '%s'\n",
src);
829 "%d invalid UTF-8 sequence(s) found in string '%s', replaced with '%s'\n",
838 #define PRINT_STRING_OPT 1
839 #define PRINT_STRING_VALIDATE 2
857 if (
ret < 0)
goto end;
859 if (
ret < 0)
goto end;
864 "Invalid key=value string combination %s=%s in section %s\n",
889 int64_t ts,
const AVRational *time_base,
int is_duration)
893 if ((!is_duration && ts ==
AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
896 double d = ts *
av_q2d(*time_base);
907 if ((!is_duration && ts ==
AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
925 for (
i = 0;
i < l;
i++) {
931 for (
i = 0;
i < l;
i++)
952 p = buf + strlen(buf);
959 int columns,
int bytes,
int offset_add)
969 for (
i = 0;
i < l;
i++) {
983 #define writer_w8(wctx_, b_) (wctx_)->writer_w8(wctx_, b_)
984 #define writer_put_str(wctx_, str_) (wctx_)->writer_put_str(wctx_, str_)
985 #define writer_printf(wctx_, fmt_, ...) (wctx_)->writer_printf(wctx_, fmt_, __VA_ARGS__)
987 #define MAX_REGISTERED_WRITERS_NB 64
993 static int next_registered_writer_idx = 0;
1016 #define DEFINE_WRITER_CLASS(name) \
1017 static const char *name##_get_name(void *ctx) \
1021 static const AVClass name##_class = { \
1022 .class_name = #name, \
1023 .item_name = name##_get_name, \
1024 .option = name##_options \
1037 #define OFFSET(x) offsetof(DefaultContext, x)
1040 {
"noprint_wrappers",
"do not print headers and footers",
OFFSET(noprint_wrappers),
AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1041 {
"nw",
"do not print headers and footers",
OFFSET(noprint_wrappers),
AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1053 for (
i = 0;
src[
i] &&
i < dst_size-1;
i++)
1068 if (parent_section &&
1123 .priv_class = &default_class,
1131 static const char *
c_escape_str(AVBPrint *dst,
const char *
src,
const char sep,
void *log_ctx)
1135 for (p =
src; *p; p++) {
1137 case '\b':
av_bprintf(dst,
"%s",
"\\b");
break;
1138 case '\f':
av_bprintf(dst,
"%s",
"\\f");
break;
1139 case '\n':
av_bprintf(dst,
"%s",
"\\n");
break;
1140 case '\r':
av_bprintf(dst,
"%s",
"\\r");
break;
1141 case '\\':
av_bprintf(dst,
"%s",
"\\\\");
break;
1156 char meta_chars[] = { sep,
'"',
'\n',
'\r',
'\0' };
1157 int needs_quoting = !!
src[strcspn(
src, meta_chars)];
1184 const char * (*escape_str)(AVBPrint *dst,
const char *
src,
const char sep,
void *log_ctx);
1191 #define OFFSET(x) offsetof(CompactContext, x)
1212 av_log(wctx,
AV_LOG_ERROR,
"Item separator '%s' specified, but must contain a single character\n",
1239 if (parent_section &&
1262 (*p >=
'0' && *p <=
'9') ||
1263 (*p >=
'a' && *p <=
'z') ||
1264 (*p >=
'A' && *p <=
'Z') ?
av_tolower(*p) :
'_';
1297 if (!compact->
nokey)
1309 if (!compact->
nokey)
1323 .priv_class = &compact_class,
1329 #define OFFSET(x) offsetof(CompactContext, x)
1354 .priv_class = &csv_class,
1367 #define OFFSET(x) offsetof(FlatContext, x)
1372 {
"hierarchical",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical),
AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1373 {
"h",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical),
AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1383 if (strlen(
flat->sep_str) != 1) {
1384 av_log(wctx,
AV_LOG_ERROR,
"Item separator '%s' specified, but must contain a single character\n",
1397 for (p =
src; *p; p++) {
1398 if (!((*p >=
'0' && *p <=
'9') ||
1399 (*p >=
'a' && *p <=
'z') ||
1400 (*p >=
'A' && *p <=
'Z')))
1412 for (p =
src; *p; p++) {
1414 case '\n':
av_bprintf(dst,
"%s",
"\\n");
break;
1415 case '\r':
av_bprintf(dst,
"%s",
"\\r");
break;
1416 case '\\':
av_bprintf(dst,
"%s",
"\\\\");
break;
1417 case '"':
av_bprintf(dst,
"%s",
"\\\"");
break;
1418 case '`':
av_bprintf(dst,
"%s",
"\\`");
break;
1419 case '$':
av_bprintf(dst,
"%s",
"\\$");
break;
1436 if (!parent_section)
1440 if (
flat->hierarchical ||
1478 .priv_class = &flat_class,
1489 #define OFFSET(x) offsetof(INIContext, x)
1492 {
"hierarchical",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical),
AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1493 {
"h",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical),
AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1504 while (
c =
src[
i++]) {
1506 case '\b':
av_bprintf(dst,
"%s",
"\\b");
break;
1507 case '\f':
av_bprintf(dst,
"%s",
"\\f");
break;
1508 case '\n':
av_bprintf(dst,
"%s",
"\\n");
break;
1509 case '\r':
av_bprintf(dst,
"%s",
"\\r");
break;
1510 case '\t':
av_bprintf(dst,
"%s",
"\\t");
break;
1516 if ((
unsigned char)
c < 32)
1535 if (!parent_section) {
1582 .priv_class = &ini_class,
1595 #define OFFSET(x) offsetof(JSONContext, x)
1617 static const char json_escape[] = {
'"',
'\\',
'\b',
'\f',
'\n',
'\r',
'\t', 0};
1618 static const char json_subst[] = {
'"',
'\\',
'b',
'f',
'n',
'r',
't', 0};
1621 for (p =
src; *p; p++) {
1622 char *
s = strchr(json_escape, *p);
1626 }
else if ((
unsigned char)*p < 32) {
1635 #define JSON_INDENT() writer_printf(wctx, "%*c", json->indent_level * 4, ' ')
1681 if (wctx->
level == 0) {
1699 const char *
key,
const char *
value)
1749 .priv_class = &json_class,
1763 #define OFFSET(x) offsetof(XMLContext, x)
1766 {
"fully_qualified",
"specify if the output should be fully qualified",
OFFSET(fully_qualified),
AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1767 {
"q",
"specify if the output should be fully qualified",
OFFSET(fully_qualified),
AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1768 {
"xsd_strict",
"ensure that the output is XSD compliant",
OFFSET(xsd_strict),
AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1781 #define CHECK_COMPLIANCE(opt, opt_name) \
1783 av_log(wctx, AV_LOG_ERROR, \
1784 "XSD-compliant output selected but option '%s' was selected, XML output may be non-compliant.\n" \
1785 "You need to disable such option with '-no%s'\n", opt_name, opt_name); \
1786 return AVERROR(EINVAL); \
1796 #define XML_INDENT() writer_printf(wctx, "%*c", xml->indent_level * 4, ' ')
1805 if (wctx->
level == 0) {
1806 const char *qual =
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
1807 "xmlns:ffprobe=\"http://www.ffmpeg.org/schema/ffprobe\" "
1808 "xsi:schemaLocation=\"http://www.ffmpeg.org/schema/ffprobe ffprobe.xsd\"";
1810 writer_put_str(wctx,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
1849 if (wctx->
level == 0) {
1919 .priv_class = &xml_class,
1939 #define print_fmt(k, f, ...) do { \
1940 av_bprint_clear(&pbuf); \
1941 av_bprintf(&pbuf, f, __VA_ARGS__); \
1942 writer_print_string(w, k, pbuf.str, 0); \
1945 #define print_list_fmt(k, f, n, m, ...) do { \
1946 av_bprint_clear(&pbuf); \
1947 for (int idx = 0; idx < n; idx++) { \
1948 for (int idx2 = 0; idx2 < m; idx2++) { \
1949 if (idx > 0 || idx2 > 0) \
1950 av_bprint_chars(&pbuf, ' ', 1); \
1951 av_bprintf(&pbuf, f, __VA_ARGS__); \
1954 writer_print_string(w, k, pbuf.str, 0); \
1957 #define print_int(k, v) writer_print_integer(w, k, v)
1958 #define print_q(k, v, s) writer_print_rational(w, k, v, s)
1959 #define print_str(k, v) writer_print_string(w, k, v, 0)
1960 #define print_str_opt(k, v) writer_print_string(w, k, v, PRINT_STRING_OPT)
1961 #define print_str_validate(k, v) writer_print_string(w, k, v, PRINT_STRING_VALIDATE)
1962 #define print_time(k, v, tb) writer_print_time(w, k, v, tb, 0)
1963 #define print_ts(k, v) writer_print_ts(w, k, v, 0)
1964 #define print_duration_time(k, v, tb) writer_print_time(w, k, v, tb, 1)
1965 #define print_duration_ts(k, v) writer_print_ts(w, k, v, 1)
1966 #define print_val(k, v, u) do { \
1967 struct unit_value uv; \
1970 writer_print_string(w, k, value_string(val_str, sizeof(val_str), uv), 0); \
1973 #define print_section_header(s) writer_print_section_header(w, NULL, s)
1974 #define print_section_header_data(s, d) writer_print_section_header(w, d, s)
1975 #define print_section_footer(s) writer_print_section_footer(w, s)
1977 #define REALLOCZ_ARRAY_STREAM(ptr, cur_n, new_n) \
1979 ret = av_reallocp_array(&(ptr), (new_n), sizeof(*(ptr))); \
1982 memset( (ptr) + (cur_n), 0, ((new_n) - (cur_n)) * sizeof(*(ptr)) ); \
2021 print_int(
"chroma_resampling_explicit_filter_flag",
2030 print_int(
"spatial_resampling_filter_flag",
2032 print_int(
"el_spatial_resampling_filter_flag",
2045 print_str(
"nlq_method_idc_name",
"none");
2048 print_str(
"nlq_method_idc_name",
"linear_dz");
2051 print_str(
"nlq_method_idc_name",
"unknown");
2060 for (
int c = 0;
c < 3;
c++) {
2073 print_str(
"mapping_idc_name",
"polynomial");
2088 print_str(
"mapping_idc_name",
"unknown");
2124 color->ycc_to_rgb_matrix[idx].num,
2125 color->ycc_to_rgb_matrix[idx].den);
2128 color->ycc_to_rgb_offset[idx].num,
2129 color->ycc_to_rgb_offset[idx].den);
2132 color->rgb_to_lms_matrix[idx].num,
2133 color->rgb_to_lms_matrix[idx].den);
2141 print_int(
"signal_full_range_flag",
color->signal_full_range_flag);
2158 print_q(
"window_upper_left_corner_x",
2160 print_q(
"window_upper_left_corner_y",
2162 print_q(
"window_lower_right_corner_x",
2164 print_q(
"window_lower_right_corner_y",
2166 print_q(
"window_upper_left_corner_x",
2168 print_q(
"window_upper_left_corner_y",
2176 print_int(
"semimajor_axis_internal_ellipse",
2178 print_int(
"semimajor_axis_external_ellipse",
2180 print_int(
"semiminor_axis_external_ellipse",
2185 print_q(
"targeted_system_display_maximum_luminance",
2188 print_int(
"num_rows_targeted_system_display_actual_peak_luminance",
2190 print_int(
"num_cols_targeted_system_display_actual_peak_luminance",
2194 print_q(
"targeted_system_display_actual_peak_luminance",
2201 for (
int i = 0;
i < 3;
i++) {
2206 print_int(
"num_distribution_maxrgb_percentiles",
2209 print_int(
"distribution_maxrgb_percentage",
2211 print_q(
"distribution_maxrgb_percentile",
2214 print_q(
"fraction_bright_pixels",
2218 print_int(
"num_rows_mastering_display_actual_peak_luminance",
2220 print_int(
"num_cols_mastering_display_actual_peak_luminance",
2224 print_q(
"mastering_display_actual_peak_luminance",
2238 print_q(
"bezier_curve_anchors",
2243 print_q(
"color_saturation_weight",
2274 print_q(
"targeted_system_display_maximum_luminance",
2287 print_int(
"base_param_Delta_enable_mode",
2341 if (
isnan(rotation))
2577 const uint8_t *side_metadata;
2640 if (
isnan(rotation))
2651 uint32_t *
tc = (uint32_t*)sd->data;
2654 for (
int j = 1; j <= m ; j++) {
2729 #if LIBAVUTIL_VERSION_MAJOR < 59
2757 print_q(
"sample_aspect_ratio", sar,
':');
2762 #if LIBAVUTIL_VERSION_MAJOR < 59
2814 int ret = 0, got_frame = 0;
2865 return got_frame || *packet_new;
2870 av_log(log_ctx, log_level,
"id:%d", interval->
id);
2876 av_log(log_ctx, log_level,
" start:N/A");
2882 av_log(log_ctx, log_level,
"#%"PRId64, interval->
end);
2886 av_log(log_ctx, log_level,
" end:N/A");
2889 av_log(log_ctx, log_level,
"\n");
2898 int ret = 0,
i = 0, frame_count = 0;
2899 int64_t start = -INT64_MAX, end = interval->
end;
2910 "Could not seek to relative position since current "
2911 "timestamp is not defined\n");
2915 target = *cur_ts + interval->
start;
2917 target = interval->
start;
2959 end = start + interval->
end;
2964 if (frame_count >= interval->
end)
2966 }
else if (has_end && *cur_ts !=
AV_NOPTS_VALUE && *cur_ts >= end) {
3073 char profile_num[12];
3101 print_q(
"sample_aspect_ratio", sar,
':');
3106 print_q(
"display_aspect_ratio", dar,
':');
3123 print_str(
"field_order",
"progressive");
3211 #define PRINT_DISPOSITION(flagname, name) do { \
3212 print_int(name, !!(stream->disposition & AV_DISPOSITION_##flagname)); \
3292 for (
i = 0;
i <
program->nb_stream_indexes;
i++) {
3389 const char *print_filename)
3394 int scan_all_pmts_set = 0;
3402 scan_all_pmts_set = 1;
3409 if (print_filename) {
3414 if (scan_all_pmts_set)
3429 for (
i = 0;
i < orig_nb_streams;
i++)
3456 "Failed to probe codec for input stream %d\n",
3464 "Unsupported codec with id %d for input stream %d\n",
3528 const char *print_filename)
3541 #define CHECK_END if (ret < 0) goto end
3622 print_fmt(
"copyright",
"Copyright (c) %d-%d the FFmpeg developers",
3625 print_str(
"configuration", FFMPEG_CONFIGURATION);
3631 #define SHOW_LIB_VERSION(libname, LIBNAME) \
3633 if (CONFIG_##LIBNAME) { \
3634 unsigned int version = libname##_version(); \
3635 writer_print_section_header(w, NULL, SECTION_ID_LIBRARY_VERSION); \
3636 print_str("name", "lib" #libname); \
3637 print_int("major", LIB##LIBNAME##_VERSION_MAJOR); \
3638 print_int("minor", LIB##LIBNAME##_VERSION_MINOR); \
3639 print_int("micro", LIB##LIBNAME##_VERSION_MICRO); \
3640 print_int("version", version); \
3641 print_str("ident", LIB##LIBNAME##_IDENT); \
3642 writer_print_section_footer(w); \
3660 #define PRINT_PIX_FMT_FLAG(flagname, name) \
3662 print_int(name, !!(pixdesc->flags & AV_PIX_FMT_FLAG_##flagname)); \
3762 "'%s' matches section with unique name '%s'\n", section_name,
3773 const char *p =
arg;
3781 if (!section_name) {
3783 "Missing section name for option '%s'\n", opt);
3789 while (*p && *p !=
':') {
3794 "Adding '%s' to the entries to show in section '%s'\n",
3795 entry, section_name);
3825 "Argument '%s' provided as input filename, but '%s' was already specified.\n",
3829 if (!strcmp(
arg,
"-"))
3846 "Argument '%s' provided as output filename, but '%s' was already specified.\n",
3850 if (!strcmp(
arg,
"-"))
3883 char *next, *p, *spec =
av_strdup(interval_spec);
3894 next = strchr(spec,
'%');
3936 lli = strtoll(p, &tail, 10);
3937 if (*tail || lli < 0) {
3939 "Invalid or negative value '%s' for duration number of frames\n", p);
3942 interval->
end = lli;
3964 char *p, *spec =
av_strdup(intervals_spec);
3969 for (n = 0, p = spec; *p; p++)
3983 for (
i = 0; p;
i++) {
3987 next = strchr(p,
',');