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
168 #define SECTION_FLAG_IS_WRAPPER 1
169 #define SECTION_FLAG_IS_ARRAY 2
170 #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;
396 union {
double d;
long long int i; }
val;
410 vald = vali = uv.
val.
i;
417 mins = (
int)secs / 60;
418 secs = secs - mins * 60;
421 snprintf(buf, buf_size,
"%d:%02d:%09.6f", hours, mins, secs);
423 const char *prefix_string =
"";
434 index = (
long long int) (log10(vald)) / 3;
443 snprintf(buf, buf_size,
"%f", vald);
445 snprintf(buf, buf_size,
"%lld", vali);
457 #define WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS 1
458 #define WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER 2
483 #define SECTION_MAX_NB_LEVELS 10
525 #define OFFSET(x) offsetof(WriterContext, x)
528 {
"string_validation",
"set string validation mode",
530 {
"sv",
"set string validation mode",
535 {
"string_validation_replacement",
"set string validation replacement string",
OFFSET(string_validation_replacement),
AV_OPT_TYPE_STRING, {.str=
""}},
536 {
"svr",
"set string validation replacement string",
OFFSET(string_validation_replacement),
AV_OPT_TYPE_STRING, {.str=
"\xEF\xBF\xBD"}},
543 if (!prev &&
ctx->writer &&
ctx->writer->priv_class &&
ctx->priv)
564 if ((*wctx)->writer->uninit)
565 (*wctx)->writer->uninit(*wctx);
568 if ((*wctx)->writer->priv_class)
580 static void bprint_bytes(AVBPrint *bp,
const uint8_t *ubuf,
size_t ubuf_size)
584 for (
i = 0;
i < ubuf_size;
i++)
642 (*wctx)->writer = writer;
645 (*wctx)->nb_sections = nb_sections;
650 void *priv_ctx = (*wctx)->priv;
661 av_log(*wctx,
AV_LOG_ERROR,
"Failed to parse option string '%s' provided to writer context\n", args);
668 av_log(*wctx,
AV_LOG_ERROR,
"Failed to set option '%s' with value '%s' provided to writer context\n",
680 const uint8_t *p = (*wctx)->string_validation_replacement;
681 const uint8_t *endp = p + strlen(p);
683 const uint8_t *p0 = p;
691 "Invalid UTF8 sequence %s found in string validation replace '%s'\n",
692 bp.str, (*wctx)->string_validation_replacement);
716 if ((*wctx)->writer->init)
717 ret = (*wctx)->writer->init(*wctx);
731 int parent_section_id;
734 parent_section_id = wctx->
level ?
755 int parent_section_id = wctx->
level ?
770 const char *
key,
long long int val)
782 const uint8_t *p, *endp;
784 int invalid_chars_nb = 0,
ret = 0;
789 for (p = (uint8_t *)
src; *p;) {
792 const uint8_t *p0 = p;
799 "Invalid UTF-8 sequence %s found in string '%s'\n", bp.str,
src);
809 "Invalid UTF-8 sequence found in string '%s'\n",
src);
826 "%d invalid UTF-8 sequence(s) found in string '%s', replaced with '%s'\n",
835 #define PRINT_STRING_OPT 1
836 #define PRINT_STRING_VALIDATE 2
854 if (
ret < 0)
goto end;
856 if (
ret < 0)
goto end;
861 "Invalid key=value string combination %s=%s in section %s\n",
886 int64_t ts,
const AVRational *time_base,
int is_duration)
890 if ((!is_duration && ts ==
AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
893 double d = ts *
av_q2d(*time_base);
904 if ((!is_duration && ts ==
AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
922 for (
i = 0;
i < l;
i++) {
928 for (
i = 0;
i < l;
i++)
949 p = buf + strlen(buf);
956 int columns,
int bytes,
int offset_add)
966 for (
i = 0;
i < l;
i++) {
980 #define writer_w8(wctx_, b_) (wctx_)->writer_w8(wctx_, b_)
981 #define writer_put_str(wctx_, str_) (wctx_)->writer_put_str(wctx_, str_)
982 #define writer_printf(wctx_, fmt_, ...) (wctx_)->writer_printf(wctx_, fmt_, __VA_ARGS__)
984 #define MAX_REGISTERED_WRITERS_NB 64
990 static int next_registered_writer_idx = 0;
1013 #define DEFINE_WRITER_CLASS(name) \
1014 static const char *name##_get_name(void *ctx) \
1018 static const AVClass name##_class = { \
1019 .class_name = #name, \
1020 .item_name = name##_get_name, \
1021 .option = name##_options \
1034 #define OFFSET(x) offsetof(DefaultContext, x)
1037 {
"noprint_wrappers",
"do not print headers and footers",
OFFSET(noprint_wrappers),
AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1038 {
"nw",
"do not print headers and footers",
OFFSET(noprint_wrappers),
AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1050 for (
i = 0;
src[
i] &&
i < dst_size-1;
i++)
1065 if (parent_section &&
1120 .priv_class = &default_class,
1128 static const char *
c_escape_str(AVBPrint *dst,
const char *
src,
const char sep,
void *log_ctx)
1132 for (p =
src; *p; p++) {
1134 case '\b':
av_bprintf(dst,
"%s",
"\\b");
break;
1135 case '\f':
av_bprintf(dst,
"%s",
"\\f");
break;
1136 case '\n':
av_bprintf(dst,
"%s",
"\\n");
break;
1137 case '\r':
av_bprintf(dst,
"%s",
"\\r");
break;
1138 case '\\':
av_bprintf(dst,
"%s",
"\\\\");
break;
1153 char meta_chars[] = { sep,
'"',
'\n',
'\r',
'\0' };
1154 int needs_quoting = !!
src[strcspn(
src, meta_chars)];
1181 const char * (*escape_str)(AVBPrint *dst,
const char *
src,
const char sep,
void *log_ctx);
1188 #define OFFSET(x) offsetof(CompactContext, x)
1209 av_log(wctx,
AV_LOG_ERROR,
"Item separator '%s' specified, but must contain a single character\n",
1274 if (!compact->
nokey)
1286 if (!compact->
nokey)
1300 .priv_class = &compact_class,
1306 #define OFFSET(x) offsetof(CompactContext, x)
1331 .priv_class = &csv_class,
1344 #define OFFSET(x) offsetof(FlatContext, x)
1349 {
"hierarchical",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical),
AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1350 {
"h",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical),
AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1360 if (strlen(
flat->sep_str) != 1) {
1361 av_log(wctx,
AV_LOG_ERROR,
"Item separator '%s' specified, but must contain a single character\n",
1374 for (p =
src; *p; p++) {
1375 if (!((*p >=
'0' && *p <=
'9') ||
1376 (*p >=
'a' && *p <=
'z') ||
1377 (*p >=
'A' && *p <=
'Z')))
1389 for (p =
src; *p; p++) {
1391 case '\n':
av_bprintf(dst,
"%s",
"\\n");
break;
1392 case '\r':
av_bprintf(dst,
"%s",
"\\r");
break;
1393 case '\\':
av_bprintf(dst,
"%s",
"\\\\");
break;
1394 case '"':
av_bprintf(dst,
"%s",
"\\\"");
break;
1395 case '`':
av_bprintf(dst,
"%s",
"\\`");
break;
1396 case '$':
av_bprintf(dst,
"%s",
"\\$");
break;
1413 if (!parent_section)
1417 if (
flat->hierarchical ||
1455 .priv_class = &flat_class,
1466 #define OFFSET(x) offsetof(INIContext, x)
1469 {
"hierarchical",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical),
AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1470 {
"h",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical),
AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1481 while (
c =
src[
i++]) {
1483 case '\b':
av_bprintf(dst,
"%s",
"\\b");
break;
1484 case '\f':
av_bprintf(dst,
"%s",
"\\f");
break;
1485 case '\n':
av_bprintf(dst,
"%s",
"\\n");
break;
1486 case '\r':
av_bprintf(dst,
"%s",
"\\r");
break;
1487 case '\t':
av_bprintf(dst,
"%s",
"\\t");
break;
1493 if ((
unsigned char)
c < 32)
1512 if (!parent_section) {
1559 .priv_class = &ini_class,
1572 #define OFFSET(x) offsetof(JSONContext, x)
1594 static const char json_escape[] = {
'"',
'\\',
'\b',
'\f',
'\n',
'\r',
'\t', 0};
1595 static const char json_subst[] = {
'"',
'\\',
'b',
'f',
'n',
'r',
't', 0};
1598 for (p =
src; *p; p++) {
1599 char *
s = strchr(json_escape, *p);
1603 }
else if ((
unsigned char)*p < 32) {
1612 #define JSON_INDENT() writer_printf(wctx, "%*c", json->indent_level * 4, ' ')
1658 if (wctx->
level == 0) {
1676 const char *
key,
const char *
value)
1726 .priv_class = &json_class,
1740 #define OFFSET(x) offsetof(XMLContext, x)
1743 {
"fully_qualified",
"specify if the output should be fully qualified",
OFFSET(fully_qualified),
AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1744 {
"q",
"specify if the output should be fully qualified",
OFFSET(fully_qualified),
AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1745 {
"xsd_strict",
"ensure that the output is XSD compliant",
OFFSET(xsd_strict),
AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1758 #define CHECK_COMPLIANCE(opt, opt_name) \
1760 av_log(wctx, AV_LOG_ERROR, \
1761 "XSD-compliant output selected but option '%s' was selected, XML output may be non-compliant.\n" \
1762 "You need to disable such option with '-no%s'\n", opt_name, opt_name); \
1763 return AVERROR(EINVAL); \
1773 #define XML_INDENT() writer_printf(wctx, "%*c", xml->indent_level * 4, ' ')
1782 if (wctx->
level == 0) {
1783 const char *qual =
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
1784 "xmlns:ffprobe=\"http://www.ffmpeg.org/schema/ffprobe\" "
1785 "xsi:schemaLocation=\"http://www.ffmpeg.org/schema/ffprobe ffprobe.xsd\"";
1787 writer_put_str(wctx,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
1820 if (wctx->
level == 0) {
1881 .priv_class = &xml_class,
1901 #define print_fmt(k, f, ...) do { \
1902 av_bprint_clear(&pbuf); \
1903 av_bprintf(&pbuf, f, __VA_ARGS__); \
1904 writer_print_string(w, k, pbuf.str, 0); \
1907 #define print_list_fmt(k, f, n, m, ...) do { \
1908 av_bprint_clear(&pbuf); \
1909 for (int idx = 0; idx < n; idx++) { \
1910 for (int idx2 = 0; idx2 < m; idx2++) { \
1911 if (idx > 0 || idx2 > 0) \
1912 av_bprint_chars(&pbuf, ' ', 1); \
1913 av_bprintf(&pbuf, f, __VA_ARGS__); \
1916 writer_print_string(w, k, pbuf.str, 0); \
1919 #define print_int(k, v) writer_print_integer(w, k, v)
1920 #define print_q(k, v, s) writer_print_rational(w, k, v, s)
1921 #define print_str(k, v) writer_print_string(w, k, v, 0)
1922 #define print_str_opt(k, v) writer_print_string(w, k, v, PRINT_STRING_OPT)
1923 #define print_str_validate(k, v) writer_print_string(w, k, v, PRINT_STRING_VALIDATE)
1924 #define print_time(k, v, tb) writer_print_time(w, k, v, tb, 0)
1925 #define print_ts(k, v) writer_print_ts(w, k, v, 0)
1926 #define print_duration_time(k, v, tb) writer_print_time(w, k, v, tb, 1)
1927 #define print_duration_ts(k, v) writer_print_ts(w, k, v, 1)
1928 #define print_val(k, v, u) do { \
1929 struct unit_value uv; \
1932 writer_print_string(w, k, value_string(val_str, sizeof(val_str), uv), 0); \
1935 #define print_section_header(s) writer_print_section_header(w, s)
1936 #define print_section_footer(s) writer_print_section_footer(w, s)
1938 #define REALLOCZ_ARRAY_STREAM(ptr, cur_n, new_n) \
1940 ret = av_reallocp_array(&(ptr), (new_n), sizeof(*(ptr))); \
1943 memset( (ptr) + (cur_n), 0, ((new_n) - (cur_n)) * sizeof(*(ptr)) ); \
1982 print_int(
"chroma_resampling_explicit_filter_flag",
1991 print_int(
"spatial_resampling_filter_flag",
1993 print_int(
"el_spatial_resampling_filter_flag",
2006 print_str(
"nlq_method_idc_name",
"none");
2009 print_str(
"nlq_method_idc_name",
"linear_dz");
2012 print_str(
"nlq_method_idc_name",
"unknown");
2021 for (
int c = 0;
c < 3;
c++) {
2034 print_str(
"mapping_idc_name",
"polynomial");
2049 print_str(
"mapping_idc_name",
"unknown");
2085 color->ycc_to_rgb_matrix[idx].num,
2086 color->ycc_to_rgb_matrix[idx].den);
2089 color->ycc_to_rgb_offset[idx].num,
2090 color->ycc_to_rgb_offset[idx].den);
2093 color->rgb_to_lms_matrix[idx].num,
2094 color->rgb_to_lms_matrix[idx].den);
2102 print_int(
"signal_full_range_flag",
color->signal_full_range_flag);
2119 print_q(
"window_upper_left_corner_x",
2121 print_q(
"window_upper_left_corner_y",
2123 print_q(
"window_lower_right_corner_x",
2125 print_q(
"window_lower_right_corner_y",
2127 print_q(
"window_upper_left_corner_x",
2129 print_q(
"window_upper_left_corner_y",
2137 print_int(
"semimajor_axis_internal_ellipse",
2139 print_int(
"semimajor_axis_external_ellipse",
2141 print_int(
"semiminor_axis_external_ellipse",
2146 print_q(
"targeted_system_display_maximum_luminance",
2149 print_int(
"num_rows_targeted_system_display_actual_peak_luminance",
2151 print_int(
"num_cols_targeted_system_display_actual_peak_luminance",
2155 print_q(
"targeted_system_display_actual_peak_luminance",
2162 for (
int i = 0;
i < 3;
i++) {
2167 print_int(
"num_distribution_maxrgb_percentiles",
2170 print_int(
"distribution_maxrgb_percentage",
2172 print_q(
"distribution_maxrgb_percentile",
2175 print_q(
"fraction_bright_pixels",
2179 print_int(
"num_rows_mastering_display_actual_peak_luminance",
2181 print_int(
"num_cols_mastering_display_actual_peak_luminance",
2185 print_q(
"mastering_display_actual_peak_luminance",
2199 print_q(
"bezier_curve_anchors",
2204 print_q(
"color_saturation_weight",
2235 print_q(
"targeted_system_display_maximum_luminance",
2248 print_int(
"base_param_Delta_enable_mode",
2301 for (
i = 0;
i < nb_side_data;
i++) {
2309 if (
isnan(rotation))
2533 const uint8_t *side_metadata;
2567 print_int (
"start_display_time",
sub->start_display_time);
2599 print_ts (
"best_effort_timestamp",
frame->best_effort_timestamp);
2601 #if LIBAVUTIL_VERSION_MAJOR < 59
2625 print_q(
"sample_aspect_ratio", sar,
':');
2630 #if LIBAVUTIL_VERSION_MAJOR < 59
2633 print_int(
"display_picture_number",
frame->display_picture_number);
2664 if (
frame->nb_side_data) {
2666 for (
i = 0;
i <
frame->nb_side_data;
i++) {
2675 if (
isnan(rotation))
2686 uint32_t *
tc = (uint32_t*)sd->
data;
2689 for (
int j = 1; j <= m ; j++) {
2757 int ret = 0, got_frame = 0;
2808 return got_frame || *packet_new;
2813 av_log(log_ctx, log_level,
"id:%d", interval->
id);
2819 av_log(log_ctx, log_level,
" start:N/A");
2825 av_log(log_ctx, log_level,
"#%"PRId64, interval->
end);
2829 av_log(log_ctx, log_level,
" end:N/A");
2832 av_log(log_ctx, log_level,
"\n");
2841 int ret = 0,
i = 0, frame_count = 0;
2842 int64_t start = -INT64_MAX, end = interval->
end;
2853 "Could not seek to relative position since current "
2854 "timestamp is not defined\n");
2858 target = *cur_ts + interval->
start;
2860 target = interval->
start;
2902 end = start + interval->
end;
2907 if (frame_count >= interval->
end)
2909 }
else if (has_end && *cur_ts !=
AV_NOPTS_VALUE && *cur_ts >= end) {
2937 for (
i = 0;
i <
ifile->nb_streams;
i++) {
2941 if (
ifile->streams[
i].dec_ctx)
3014 char profile_num[12];
3042 print_q(
"sample_aspect_ratio", sar,
':');
3047 print_q(
"display_aspect_ratio", dar,
':');
3064 print_str(
"field_order",
"progressive");
3157 #define PRINT_DISPOSITION(flagname, name) do { \
3158 print_int(name, !!(stream->disposition & AV_DISPOSITION_##flagname)); \
3205 for (
i = 0;
i <
ifile->nb_streams;
i++)
3233 for (
i = 0;
i <
program->nb_stream_indexes;
i++) {
3330 const char *print_filename)
3335 int scan_all_pmts_set = 0;
3343 scan_all_pmts_set = 1;
3350 if (print_filename) {
3355 if (scan_all_pmts_set)
3366 for (
i = 0;
i < orig_nb_streams;
i++)
3379 if (!
ifile->streams)
3393 "Failed to probe codec for input stream %d\n",
3401 "Unsupported codec with id %d for input stream %d\n",
3451 for (
i = 0;
i <
ifile->nb_streams;
i++)
3455 ifile->nb_streams = 0;
3461 const char *print_filename)
3474 #define CHECK_END if (ret < 0) goto end
3481 for (
i = 0;
i <
ifile.fmt_ctx->nb_streams;
i++) {
3484 ifile.fmt_ctx->streams[
i],
3555 print_fmt(
"copyright",
"Copyright (c) %d-%d the FFmpeg developers",
3558 print_str(
"configuration", FFMPEG_CONFIGURATION);
3564 #define SHOW_LIB_VERSION(libname, LIBNAME) \
3566 if (CONFIG_##LIBNAME) { \
3567 unsigned int version = libname##_version(); \
3568 writer_print_section_header(w, SECTION_ID_LIBRARY_VERSION); \
3569 print_str("name", "lib" #libname); \
3570 print_int("major", LIB##LIBNAME##_VERSION_MAJOR); \
3571 print_int("minor", LIB##LIBNAME##_VERSION_MINOR); \
3572 print_int("micro", LIB##LIBNAME##_VERSION_MICRO); \
3573 print_int("version", version); \
3574 print_str("ident", LIB##LIBNAME##_IDENT); \
3575 writer_print_section_footer(w); \
3593 #define PRINT_PIX_FMT_FLAG(flagname, name) \
3595 print_int(name, !!(pixdesc->flags & AV_PIX_FMT_FLAG_##flagname)); \
3690 "'%s' matches section with unique name '%s'\n", section_name,
3701 const char *p =
arg;
3709 if (!section_name) {
3711 "Missing section name for option '%s'\n", opt);
3717 while (*p && *p !=
':') {
3722 "Adding '%s' to the entries to show in section '%s'\n",
3723 entry, section_name);
3753 "Argument '%s' provided as input filename, but '%s' was already specified.\n",
3757 if (!strcmp(
arg,
"-"))
3772 "Argument '%s' provided as output filename, but '%s' was already specified.\n",
3776 if (!strcmp(
arg,
"-"))
3813 char *next, *p, *spec =
av_strdup(interval_spec);
3824 next = strchr(spec,
'%');
3866 lli = strtoll(p, &tail, 10);
3867 if (*tail || lli < 0) {
3869 "Invalid or negative value '%s' for duration number of frames\n", p);
3872 interval->
end = lli;
3894 char *p, *spec =
av_strdup(intervals_spec);
3899 for (n = 0, p = spec; *p; p++)
3913 for (
i = 0; p;
i++) {
3917 next = strchr(p,
',');
3973 "W.. = Section is a wrapper (contains other sections, no local entries)\n"
3974 ".A. = Section contains an array of elements of the same type\n"
3975 "..V = Section may contain a variable number of fields with variable keys\n"
3976 "FLAGS NAME/UNIQUE_NAME\n"
3989 #define DEFINE_OPT_SHOW_SECTION(section, target_section_id) \
3990 static int opt_show_##section(void *optctx, const char *opt, const char *arg) \
3992 mark_section_show_entries(SECTION_ID_##target_section_id, 1, NULL); \
4013 "use binary prefixes for byte units" },
4015 "use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units" },
4017 "prettify the format of displayed values, make it more human readable" },
4019 "set the output printing format (available formats are: default, compact, csv, flat, ini, json, xml)",
"format" },
4022 {
"sections",
OPT_EXIT, {.func_arg =
opt_sections},
"print sections structure and section information, and exit" },