60#include "libavutil/ffversion.h"
65#include "libavformat/avformat.h"
66#include "libavcodec/avcodec.h"
67#include "libavutil/ambient_viewing_environment.h"
68#include "libavutil/avassert.h"
69#include "libavutil/avstring.h"
70#include "libavutil/bprint.h"
71#include "libavutil/channel_layout.h"
72#include "libavutil/display.h"
73#include "libavutil/hash.h"
74#include "libavutil/hdr_dynamic_metadata.h"
75#include "libavutil/mastering_display_metadata.h"
76#include "libavutil/hdr_dynamic_vivid_metadata.h"
77#include "libavutil/dovi_meta.h"
78#include "libavutil/opt.h"
79#include "libavutil/pixdesc.h"
80#include "libavutil/spherical.h"
81#include "libavutil/stereo3d.h"
82#include "libavutil/dict.h"
83#include "libavutil/intreadwrite.h"
84#include "libavutil/libm.h"
85#include "libavutil/parseutils.h"
86#include "libavutil/timecode.h"
87#include "libavutil/timestamp.h"
88#include "libavdevice/avdevice.h"
89#include "libswscale/swscale.h"
90#include "libswresample/swresample.h"
94#include "libavutil/thread.h"
99# ifdef pthread_mutex_lock
100# undef pthread_mutex_lock
102# define pthread_mutex_lock(a) do{}while(0)
103# ifdef pthread_mutex_unlock
104# undef pthread_mutex_unlock
106# define pthread_mutex_unlock(a) do{}while(0)
156#define SHOW_OPTIONAL_FIELDS_AUTO -1
157#define SHOW_OPTIONAL_FIELDS_NEVER 0
158#define SHOW_OPTIONAL_FIELDS_ALWAYS 1
180#define SECTION_MAX_NB_CHILDREN 10
186#define SECTION_FLAG_IS_WRAPPER 1
187#define SECTION_FLAG_IS_ARRAY 2
188#define SECTION_FLAG_HAS_VARIABLE_FIELDS 4
312__thread
struct AVHashContext *
hash;
323 { 1.0, 1.0,
"",
"" },
324 { 1.024e3, 1e3,
"Ki",
"K" },
325 { 1.048576e6, 1e6,
"Mi",
"M" },
326 { 1.073741824e9, 1e9,
"Gi",
"G" },
327 { 1.099511627776e12, 1e12,
"Ti",
"T" },
328 { 1.125899906842624e15, 1e15,
"Pi",
"P" },
342__thread pthread_mutex_t log_mutex;
356static void log_callback(
void *ptr,
int level,
const char *fmt, va_list vl)
358 AVClass* avc = ptr ? *(AVClass **) ptr : NULL;
361 static int print_prefix = 1;
362 void *new_log_buffer;
365 av_log_default_callback(ptr, level, fmt, vl);
366 av_log_format_line(ptr, level, fmt, vl2, line,
sizeof(line), &print_prefix);
373 if (new_log_buffer) {
386 for (i=strlen(msg) - 1; i>=0 && msg[i] ==
'\n'; i--) {
389 if (avc && avc->parent_log_context_offset) {
390 AVClass** parent = *(AVClass ***) (((uint8_t *) ptr) +
391 avc->parent_log_context_offset);
392 if (parent && *parent) {
395 (*parent)->get_category ? (*parent)->get_category(parent) :(*parent)->category;
408 for (i = 0; i < FF_ARRAY_ELEMS(
sections); i++)
409 av_dict_free(&(
sections[i].entries_to_show));
412 pthread_mutex_destroy(&log_mutex);
417 union {
double d;
long long int i; }
val;
431 vald = vali = uv.
val.
i;
438 mins = (
int)secs / 60;
439 secs = secs - mins * 60;
442 snprintf(buf, buf_size,
"%d:%02d:%09.6f", hours, mins, secs);
444 const char *prefix_string =
"";
450 index = (
long long int) (log2(vald)) / 10;
451 index = av_clip(index, 0, FF_ARRAY_ELEMS(
si_prefixes) - 1);
455 index = (
long long int) (log10(vald)) / 3;
456 index = av_clip(index, 0, FF_ARRAY_ELEMS(
si_prefixes) - 1);
464 snprintf(buf, buf_size,
"%f", vald);
466 snprintf(buf, buf_size,
"%lld", vali);
467 av_strlcatf(buf, buf_size,
"%s%s%s", *prefix_string ||
show_value_unit ?
" " :
"",
478#define WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS 1
479#define WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER 2
504#define SECTION_MAX_NB_LEVELS 10
507 const AVClass *
class;
546#define OFFSET(x) offsetof(WriterContext, x)
549 {
"string_validation",
"set string validation mode",
551 {
"sv",
"set string validation mode",
556 {
"string_validation_replacement",
"set string validation replacement string",
OFFSET(string_validation_replacement), AV_OPT_TYPE_STRING, {.str=
""}},
557 {
"svr",
"set string validation replacement string",
OFFSET(string_validation_replacement), AV_OPT_TYPE_STRING, {.str=
"\xEF\xBF\xBD"}},
570 .class_name =
"Writer",
573 .version = LIBAVUTIL_VERSION_INT,
585 if ((*wctx)->writer->uninit)
586 (*wctx)->writer->uninit(*wctx);
588 av_bprint_finalize(&(*wctx)->section_pbuf[i], NULL);
589 if ((*wctx)->writer->priv_class)
590 av_opt_free((*wctx)->priv);
591 av_freep(&((*wctx)->priv));
594 avio_flush((*wctx)->avio);
595 ret = avio_close((*wctx)->avio);
601static void bprint_bytes(AVBPrint *bp,
const uint8_t *ubuf,
size_t ubuf_size)
604 av_bprintf(bp,
"0X");
605 for (i = 0; i < ubuf_size; i++)
606 av_bprintf(bp,
"%02X", ubuf[i]);
611 avio_w8(wctx->
avio, b);
616 avio_write(wctx->
avio, str, strlen(str));
624 avio_vprintf(wctx->
avio, fmt, ap);
653 ret = AVERROR(ENOMEM);
657 if (!((*wctx)->priv = av_mallocz(writer->
priv_size))) {
658 ret = AVERROR(ENOMEM);
663 (*wctx)->writer = writer;
666 (*wctx)->nb_sections = nb_sections;
668 av_opt_set_defaults(*wctx);
671 void *priv_ctx = (*wctx)->priv;
672 *((
const AVClass **)priv_ctx) = writer->
priv_class;
673 av_opt_set_defaults(priv_ctx);
678 AVDictionary *opts = NULL;
679 const AVDictionaryEntry *opt = NULL;
681 if ((ret = av_dict_parse_string(&opts, args,
"=",
":", 0)) < 0) {
682 av_log(*wctx, AV_LOG_ERROR,
"Failed to parse option string '%s' provided to writer context\n", args);
687 while ((opt = av_dict_iterate(opts, opt))) {
688 if ((ret = av_opt_set(*wctx, opt->key, opt->value, AV_OPT_SEARCH_CHILDREN)) < 0) {
689 av_log(*wctx, AV_LOG_ERROR,
"Failed to set option '%s' with value '%s' provided to writer context\n",
690 opt->key, opt->value);
701 const uint8_t *p = (*wctx)->string_validation_replacement;
702 const uint8_t *endp = p + strlen(p);
704 const uint8_t *p0 = p;
706 ret = av_utf8_decode(&code, &p, endp, (*wctx)->string_validation_utf8_flags);
709 av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
711 av_log(wctx, AV_LOG_ERROR,
712 "Invalid UTF8 sequence %s found in string validation replace '%s'\n",
724 if ((ret = avio_open(&(*wctx)->avio, output, AVIO_FLAG_WRITE)) < 0) {
725 av_log(*wctx, AV_LOG_ERROR,
726 "Failed to open output '%s' with error: %s\n", output, av_err2str(ret));
735 av_bprint_init(&(*wctx)->section_pbuf[i], 1, AV_BPRINT_SIZE_UNLIMITED);
737 if ((*wctx)->writer->init)
738 ret = (*wctx)->writer->init(*wctx);
752 int parent_section_id;
755 parent_section_id = wctx->
level ?
776 int parent_section_id = wctx->
level ?
791 const char *key,
long long int val)
803 const uint8_t *p, *endp;
805 int invalid_chars_nb = 0, ret = 0;
807 av_bprint_init(&dstbuf, 0, AV_BPRINT_SIZE_UNLIMITED);
809 endp = src + strlen(src);
810 for (p = (uint8_t *)src; *p;) {
813 const uint8_t *p0 = p;
817 av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
819 av_log(wctx, AV_LOG_DEBUG,
820 "Invalid UTF-8 sequence %s found in string '%s'\n", bp.str, src);
829 av_log(wctx, AV_LOG_ERROR,
830 "Invalid UTF-8 sequence found in string '%s'\n", src);
831 ret = AVERROR_INVALIDDATA;
842 av_bprint_append_data(&dstbuf, p0, p-p0);
846 av_log(wctx, AV_LOG_WARNING,
847 "%d invalid UTF-8 sequence(s) found in string '%s', replaced with '%s'\n",
852 av_bprint_finalize(&dstbuf, dstp);
856#define PRINT_STRING_OPT 1
857#define PRINT_STRING_VALIDATE 2
860 const char *key,
const char *val,
int flags)
873 char *key1 = NULL, *val1 = NULL;
875 if (ret < 0)
goto end;
877 if (ret < 0)
goto end;
881 av_log(wctx, AV_LOG_ERROR,
882 "Invalid key=value string combination %s=%s in section %s\n",
898 const char *key, AVRational q,
char sep)
901 av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC);
902 av_bprintf(&buf,
"%d%c%d", q.num, sep, q.den);
907 int64_t ts,
const AVRational *time_base,
int is_duration)
911 if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
914 double d = ts * av_q2d(*time_base);
925 if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
933 const uint8_t *data,
int size)
936 int offset = 0, l,
i;
938 av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
939 av_bprintf(&bp,
"\n");
941 av_bprintf(&bp,
"%08x: ", offset);
943 for (
i = 0;
i < l;
i++) {
944 av_bprintf(&bp,
"%02x", data[
i]);
946 av_bprintf(&bp,
" ");
948 av_bprint_chars(&bp,
' ', 41 - 2 *
i -
i / 2);
949 for (
i = 0;
i < l;
i++)
950 av_bprint_chars(&bp, data[
i] - 32U < 95 ? data[
i] :
'.', 1);
951 av_bprintf(&bp,
"\n");
957 av_bprint_finalize(&bp, NULL);
961 const uint8_t *data,
int size)
963 char *p, buf[AV_HASH_MAX_SIZE * 2 + 64] = { 0 };
968 av_hash_update(
hash, data, size);
969 snprintf(buf,
sizeof(buf),
"%s:", av_hash_get_name(
hash));
970 p = buf + strlen(buf);
971 av_hash_final_hex(
hash, p, buf +
sizeof(buf) - p);
976 uint8_t *data,
int size,
const char *format,
977 int columns,
int bytes,
int offset_add)
980 int offset = 0, l,
i;
982 av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
983 av_bprintf(&bp,
"\n");
985 av_bprintf(&bp,
"%08x: ", offset);
986 l = FFMIN(size, columns);
987 for (
i = 0;
i < l;
i++) {
988 if (bytes == 1) av_bprintf(&bp, format, *data);
989 else if (bytes == 2) av_bprintf(&bp, format, AV_RN16(data));
990 else if (bytes == 4) av_bprintf(&bp, format, AV_RN32(data));
994 av_bprintf(&bp,
"\n");
995 offset += offset_add;
998 av_bprint_finalize(&bp, NULL);
1001#define writer_w8(wctx_, b_) (wctx_)->writer_w8(wctx_, b_)
1002#define writer_put_str(wctx_, str_) (wctx_)->writer_put_str(wctx_, str_)
1003#define writer_printf(wctx_, fmt_, ...) (wctx_)->writer_printf(wctx_, fmt_, __VA_ARGS__)
1005#define MAX_REGISTERED_WRITERS_NB 64
1014 return AVERROR(ENOMEM);
1034#define DEFINE_WRITER_CLASS(name) \
1035static const char *name##_get_name(void *ctx) \
1039static const AVClass name##_class = { \
1040 .class_name = #name, \
1041 .item_name = name##_get_name, \
1042 .option = name##_options \
1048 const AVClass *
class;
1055#define OFFSET(x) offsetof(DefaultContext, x)
1058 {
"noprint_wrappers",
"do not print headers and footers",
OFFSET(noprint_wrappers), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1059 {
"nw",
"do not print headers and footers",
OFFSET(noprint_wrappers), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1060 {
"nokey",
"force no key printing",
OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1061 {
"nk",
"force no key printing",
OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1071 for (i = 0; src[i] && i < dst_size-1; i++)
1072 dst[i] = av_toupper(src[i]);
1086 if (parent_section &&
1141 .priv_class = &default_class,
1149static const char *
c_escape_str(AVBPrint *dst,
const char *src,
const char sep,
void *log_ctx)
1153 for (p = src; *p; p++) {
1155 case '\b': av_bprintf(dst,
"%s",
"\\b");
break;
1156 case '\f': av_bprintf(dst,
"%s",
"\\f");
break;
1157 case '\n': av_bprintf(dst,
"%s",
"\\n");
break;
1158 case '\r': av_bprintf(dst,
"%s",
"\\r");
break;
1159 case '\\': av_bprintf(dst,
"%s",
"\\\\");
break;
1162 av_bprint_chars(dst,
'\\', 1);
1163 av_bprint_chars(dst, *p, 1);
1172static const char *
csv_escape_str(AVBPrint *dst,
const char *src,
const char sep,
void *log_ctx)
1174 char meta_chars[] = { sep,
'"',
'\n',
'\r',
'\0' };
1175 int needs_quoting = !!src[strcspn(src, meta_chars)];
1178 av_bprint_chars(dst,
'"', 1);
1180 for (; *src; src++) {
1182 av_bprint_chars(dst,
'"', 1);
1183 av_bprint_chars(dst, *src, 1);
1186 av_bprint_chars(dst,
'"', 1);
1190static const char *
none_escape_str(AVBPrint *dst,
const char *src,
const char sep,
void *log_ctx)
1196 const AVClass *
class;
1202 const char * (*escape_str)(AVBPrint *dst,
const char *src,
const char sep,
void *log_ctx);
1209#define OFFSET(x) offsetof(CompactContext, x)
1212 {
"item_sep",
"set item separator",
OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=
"|"}, 0, 0 },
1213 {
"s",
"set item separator",
OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=
"|"}, 0, 0 },
1214 {
"nokey",
"force no key printing",
OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1215 {
"nk",
"force no key printing",
OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1216 {
"escape",
"set escape mode",
OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str=
"c"}, 0, 0 },
1217 {
"e",
"set escape mode",
OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str=
"c"}, 0, 0 },
1218 {
"print_section",
"print section name",
OFFSET(
print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1230 av_log(wctx, AV_LOG_ERROR,
"Item separator '%s' specified, but must contain a single character\n",
1232 return AVERROR(EINVAL);
1240 av_log(wctx, AV_LOG_ERROR,
"Unknown escape mode '%s'\n", compact->
escape_mode_str);
1241 return AVERROR(EINVAL);
1295 if (!compact->
nokey)
1297 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1299 av_bprint_finalize(&buf, NULL);
1307 if (!compact->
nokey)
1321 .priv_class = &compact_class,
1327#define OFFSET(x) offsetof(CompactContext, x)
1330 {
"item_sep",
"set item separator",
OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=
","}, 0, 0 },
1331 {
"s",
"set item separator",
OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=
","}, 0, 0 },
1332 {
"nokey",
"force no key printing",
OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1333 {
"nk",
"force no key printing",
OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1334 {
"escape",
"set escape mode",
OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str=
"csv"}, 0, 0 },
1335 {
"e",
"set escape mode",
OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str=
"csv"}, 0, 0 },
1336 {
"print_section",
"print section name",
OFFSET(
print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1352 .priv_class = &csv_class,
1358 const AVClass *
class;
1365#define OFFSET(x) offsetof(FlatContext, x)
1368 {
"sep_char",
"set separator",
OFFSET(sep_str), AV_OPT_TYPE_STRING, {.str=
"."}, 0, 0 },
1369 {
"s",
"set separator",
OFFSET(sep_str), AV_OPT_TYPE_STRING, {.str=
"."}, 0, 0 },
1370 {
"hierarchical",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1371 {
"h",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1381 if (strlen(flat->
sep_str) != 1) {
1382 av_log(wctx, AV_LOG_ERROR,
"Item separator '%s' specified, but must contain a single character\n",
1384 return AVERROR(EINVAL);
1395 for (p = src; *p; p++) {
1396 if (!((*p >=
'0' && *p <=
'9') ||
1397 (*p >=
'a' && *p <=
'z') ||
1398 (*p >=
'A' && *p <=
'Z')))
1399 av_bprint_chars(dst,
'_', 1);
1401 av_bprint_chars(dst, *p, 1);
1410 for (p = src; *p; p++) {
1412 case '\n': av_bprintf(dst,
"%s",
"\\n");
break;
1413 case '\r': av_bprintf(dst,
"%s",
"\\r");
break;
1414 case '\\': av_bprintf(dst,
"%s",
"\\\\");
break;
1415 case '"': av_bprintf(dst,
"%s",
"\\\"");
break;
1416 case '`': av_bprintf(dst,
"%s",
"\\`");
break;
1417 case '$': av_bprintf(dst,
"%s",
"\\$");
break;
1418 default: av_bprint_chars(dst, *p, 1);
break;
1433 av_bprint_clear(buf);
1434 if (!parent_section)
1445 av_bprintf(buf,
"%d%s", n, flat->
sep_str);
1461 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1463 av_bprint_clear(&buf);
1465 av_bprint_finalize(&buf, NULL);
1476 .priv_class = &flat_class,
1482 const AVClass *
class;
1487#define OFFSET(x) offsetof(INIContext, x)
1490 {
"hierarchical",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1491 {
"h",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1502 while ((c = src[i++])) {
1504 case '\b': av_bprintf(dst,
"%s",
"\\b");
break;
1505 case '\f': av_bprintf(dst,
"%s",
"\\f");
break;
1506 case '\n': av_bprintf(dst,
"%s",
"\\n");
break;
1507 case '\r': av_bprintf(dst,
"%s",
"\\r");
break;
1508 case '\t': av_bprintf(dst,
"%s",
"\\t");
break;
1512 case ':' : av_bprint_chars(dst,
'\\', 1);
1514 if ((
unsigned char)c < 32)
1515 av_bprintf(dst,
"\\x00%02x", c & 0xff);
1517 av_bprint_chars(dst, c, 1);
1532 av_bprint_clear(buf);
1533 if (!parent_section) {
1544 av_bprintf(buf,
"%s%s", buf->str[0] ?
"." :
"", wctx->
section[wctx->
level]->
name);
1549 av_bprintf(buf,
".%d", n);
1561 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1563 av_bprint_clear(&buf);
1565 av_bprint_finalize(&buf, NULL);
1580 .priv_class = &ini_class,
1586 const AVClass *
class;
1593#define OFFSET(x) offsetof(JSONContext, x)
1596 {
"compact",
"enable compact output",
OFFSET(compact), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1597 {
"c",
"enable compact output",
OFFSET(compact), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1615 static const char json_escape[] = {
'"',
'\\',
'\b',
'\f',
'\n',
'\r',
'\t', 0};
1616 static const char json_subst[] = {
'"',
'\\',
'b',
'f',
'n',
'r',
't', 0};
1619 for (p = src; *p; p++) {
1620 char *s = strchr(json_escape, *p);
1622 av_bprint_chars(dst,
'\\', 1);
1623 av_bprint_chars(dst, json_subst[s - json_escape], 1);
1624 }
else if ((
unsigned char)*p < 32) {
1625 av_bprintf(dst,
"\\u00%02x", *p & 0xff);
1627 av_bprint_chars(dst, *p, 1);
1633#define JSON_INDENT() writer_printf(wctx, "%*c", json->indent_level * 4, ' ')
1650 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1670 av_bprint_finalize(&buf, NULL);
1679 if (wctx->
level == 0) {
1697 const char *key,
const char *value)
1701 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1703 av_bprint_clear(&buf);
1705 av_bprint_finalize(&buf, NULL);
1733 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1735 av_bprint_finalize(&buf, NULL);
1747 .priv_class = &json_class,
1753 const AVClass *
class;
1761#define OFFSET(x) offsetof(XMLContext, x)
1764 {
"fully_qualified",
"specify if the output should be fully qualified",
OFFSET(fully_qualified), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1765 {
"q",
"specify if the output should be fully qualified",
OFFSET(fully_qualified), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1766 {
"xsd_strict",
"ensure that the output is XSD compliant",
OFFSET(xsd_strict), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1767 {
"x",
"ensure that the output is XSD compliant",
OFFSET(xsd_strict), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1779#define CHECK_COMPLIANCE(opt, opt_name) \
1781 av_log(wctx, AV_LOG_ERROR, \
1782 "XSD-compliant output selected but option '%s' was selected, XML output may be non-compliant.\n" \
1783 "You need to disable such option with '-no%s'\n", opt_name, opt_name); \
1784 return AVERROR(EINVAL); \
1794#define XML_INDENT() writer_printf(wctx, "%*c", xml->indent_level * 4, ' ')
1803 if (wctx->
level == 0) {
1804 const char *qual =
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
1805 "xmlns:ffprobe=\"http://www.ffmpeg.org/schema/ffprobe\" "
1806 "xsi:schemaLocation=\"http://www.ffmpeg.org/schema/ffprobe ffprobe.xsd\"";
1808 writer_put_str(wctx,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
1841 if (wctx->
level == 0) {
1861 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1865 av_bprint_escape(&buf, key, NULL,
1866 AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
1869 av_bprint_clear(&buf);
1871 av_bprint_escape(&buf, value, NULL,
1872 AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
1878 av_bprint_escape(&buf, value, NULL,
1879 AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
1883 av_bprint_finalize(&buf, NULL);
1902 .priv_class = &xml_class,
1917#define print_fmt(k, f, ...) do { \
1918 av_bprint_clear(&pbuf); \
1919 av_bprintf(&pbuf, f, __VA_ARGS__); \
1920 writer_print_string(w, k, pbuf.str, 0); \
1923#define print_list_fmt(k, f, n, m, ...) do { \
1924 av_bprint_clear(&pbuf); \
1925 for (int idx = 0; idx < n; idx++) { \
1926 for (int idx2 = 0; idx2 < m; idx2++) { \
1927 if (idx > 0 || idx2 > 0) \
1928 av_bprint_chars(&pbuf, ' ', 1); \
1929 av_bprintf(&pbuf, f, __VA_ARGS__); \
1932 writer_print_string(w, k, pbuf.str, 0); \
1935#define print_int(k, v) writer_print_integer(w, k, v)
1936#define print_q(k, v, s) writer_print_rational(w, k, v, s)
1937#define print_str(k, v) writer_print_string(w, k, v, 0)
1938#define print_str_opt(k, v) writer_print_string(w, k, v, PRINT_STRING_OPT)
1939#define print_str_validate(k, v) writer_print_string(w, k, v, PRINT_STRING_VALIDATE)
1940#define print_time(k, v, tb) writer_print_time(w, k, v, tb, 0)
1941#define print_ts(k, v) writer_print_ts(w, k, v, 0)
1942#define print_duration_time(k, v, tb) writer_print_time(w, k, v, tb, 1)
1943#define print_duration_ts(k, v) writer_print_ts(w, k, v, 1)
1944#define print_val(k, v, u) do { \
1945 struct unit_value uv; \
1948 writer_print_string(w, k, value_string(val_str, sizeof(val_str), uv), 0); \
1951#define print_section_header(s) writer_print_section_header(w, s)
1952#define print_section_footer(s) writer_print_section_footer(w, s)
1954#define REALLOCZ_ARRAY_STREAM(ptr, cur_n, new_n) \
1956 ret = av_reallocp_array(&(ptr), (new_n), sizeof(*(ptr))); \
1959 memset( (ptr) + (cur_n), 0, ((new_n) - (cur_n)) * sizeof(*(ptr)) ); \
1964 const AVDictionaryEntry *tag = NULL;
1971 while ((tag = av_dict_iterate(tags, tag))) {
1986 const AVDOVIRpuDataHeader *hdr = av_dovi_get_header(dovi);
1987 const AVDOVIDataMapping *mapping = av_dovi_get_mapping(dovi);
1988 const AVDOVIColorMetadata *color = av_dovi_get_color(dovi);
1991 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
1995 print_int(
"rpu_format", hdr->rpu_format);
1996 print_int(
"vdr_rpu_profile", hdr->vdr_rpu_profile);
1997 print_int(
"vdr_rpu_level", hdr->vdr_rpu_level);
1998 print_int(
"chroma_resampling_explicit_filter_flag",
1999 hdr->chroma_resampling_explicit_filter_flag);
2000 print_int(
"coef_data_type", hdr->coef_data_type);
2001 print_int(
"coef_log2_denom", hdr->coef_log2_denom);
2002 print_int(
"vdr_rpu_normalized_idc", hdr->vdr_rpu_normalized_idc);
2003 print_int(
"bl_video_full_range_flag", hdr->bl_video_full_range_flag);
2004 print_int(
"bl_bit_depth", hdr->bl_bit_depth);
2005 print_int(
"el_bit_depth", hdr->el_bit_depth);
2006 print_int(
"vdr_bit_depth", hdr->vdr_bit_depth);
2007 print_int(
"spatial_resampling_filter_flag",
2008 hdr->spatial_resampling_filter_flag);
2009 print_int(
"el_spatial_resampling_filter_flag",
2010 hdr->el_spatial_resampling_filter_flag);
2011 print_int(
"disable_residual_flag", hdr->disable_residual_flag);
2014 print_int(
"vdr_rpu_id", mapping->vdr_rpu_id);
2015 print_int(
"mapping_color_space", mapping->mapping_color_space);
2017 mapping->mapping_chroma_format_idc);
2019 print_int(
"nlq_method_idc", mapping->nlq_method_idc);
2020 switch (mapping->nlq_method_idc) {
2021 case AV_DOVI_NLQ_NONE:
2022 print_str(
"nlq_method_idc_name",
"none");
2024 case AV_DOVI_NLQ_LINEAR_DZ:
2025 print_str(
"nlq_method_idc_name",
"linear_dz");
2028 print_str(
"nlq_method_idc_name",
"unknown");
2032 print_int(
"num_x_partitions", mapping->num_x_partitions);
2033 print_int(
"num_y_partitions", mapping->num_y_partitions);
2037 for (
int c = 0; c < 3; c++) {
2038 const AVDOVIReshapingCurve *curve = &mapping->curves[c];
2041 print_list_fmt(
"pivots",
"%"PRIu16, curve->num_pivots, 1, curve->pivots[idx]);
2044 for (
int i = 0; i < curve->num_pivots - 1; i++) {
2047 print_int(
"mapping_idc", curve->mapping_idc[i]);
2048 switch (curve->mapping_idc[i]) {
2049 case AV_DOVI_MAPPING_POLYNOMIAL:
2050 print_str(
"mapping_idc_name",
"polynomial");
2051 print_int(
"poly_order", curve->poly_order[i]);
2053 curve->poly_order[i] + 1, 1,
2054 curve->poly_coef[i][idx]);
2056 case AV_DOVI_MAPPING_MMR:
2058 print_int(
"mmr_order", curve->mmr_order[i]);
2059 print_int(
"mmr_constant", curve->mmr_constant[i]);
2061 curve->mmr_order[i], 7,
2062 curve->mmr_coef[i][idx][idx2]);
2065 print_str(
"mapping_idc_name",
"unknown");
2076 if (mapping->nlq_method_idc != AV_DOVI_NLQ_NONE) {
2077 const AVDOVINLQParams *nlq = &mapping->nlq[c];
2078 print_int(
"nlq_offset", nlq->nlq_offset);
2079 print_int(
"vdr_in_max", nlq->vdr_in_max);
2081 switch (mapping->nlq_method_idc) {
2082 case AV_DOVI_NLQ_LINEAR_DZ:
2083 print_int(
"linear_deadzone_slope", nlq->linear_deadzone_slope);
2084 print_int(
"linear_deadzone_threshold", nlq->linear_deadzone_threshold);
2097 print_int(
"dm_metadata_id", color->dm_metadata_id);
2098 print_int(
"scene_refresh_flag", color->scene_refresh_flag);
2100 FF_ARRAY_ELEMS(color->ycc_to_rgb_matrix), 1,
2101 color->ycc_to_rgb_matrix[idx].num,
2102 color->ycc_to_rgb_matrix[idx].den);
2104 FF_ARRAY_ELEMS(color->ycc_to_rgb_offset), 1,
2105 color->ycc_to_rgb_offset[idx].num,
2106 color->ycc_to_rgb_offset[idx].den);
2108 FF_ARRAY_ELEMS(color->rgb_to_lms_matrix), 1,
2109 color->rgb_to_lms_matrix[idx].num,
2110 color->rgb_to_lms_matrix[idx].den);
2111 print_int(
"signal_eotf", color->signal_eotf);
2112 print_int(
"signal_eotf_param0", color->signal_eotf_param0);
2113 print_int(
"signal_eotf_param1", color->signal_eotf_param1);
2114 print_int(
"signal_eotf_param2", color->signal_eotf_param2);
2115 print_int(
"signal_bit_depth", color->signal_bit_depth);
2116 print_int(
"signal_color_space", color->signal_color_space);
2117 print_int(
"signal_chroma_format", color->signal_chroma_format);
2118 print_int(
"signal_full_range_flag", color->signal_full_range_flag);
2119 print_int(
"source_min_pq", color->source_min_pq);
2120 print_int(
"source_max_pq", color->source_max_pq);
2121 print_int(
"source_diagonal", color->source_diagonal);
2123 av_bprint_finalize(&pbuf, NULL);
2131 print_int(
"application version", metadata->application_version);
2132 print_int(
"num_windows", metadata->num_windows);
2133 for (
int n = 1; n < metadata->num_windows; n++) {
2134 const AVHDRPlusColorTransformParams *params = &metadata->params[n];
2135 print_q(
"window_upper_left_corner_x",
2136 params->window_upper_left_corner_x,
'/');
2137 print_q(
"window_upper_left_corner_y",
2138 params->window_upper_left_corner_y,
'/');
2139 print_q(
"window_lower_right_corner_x",
2140 params->window_lower_right_corner_x,
'/');
2141 print_q(
"window_lower_right_corner_y",
2142 params->window_lower_right_corner_y,
'/');
2143 print_q(
"window_upper_left_corner_x",
2144 params->window_upper_left_corner_x,
'/');
2145 print_q(
"window_upper_left_corner_y",
2146 params->window_upper_left_corner_y,
'/');
2148 params->center_of_ellipse_x ) ;
2150 params->center_of_ellipse_y );
2152 params->rotation_angle);
2153 print_int(
"semimajor_axis_internal_ellipse",
2154 params->semimajor_axis_internal_ellipse);
2155 print_int(
"semimajor_axis_external_ellipse",
2156 params->semimajor_axis_external_ellipse);
2157 print_int(
"semiminor_axis_external_ellipse",
2158 params->semiminor_axis_external_ellipse);
2160 params->overlap_process_option);
2162 print_q(
"targeted_system_display_maximum_luminance",
2163 metadata->targeted_system_display_maximum_luminance,
'/');
2164 if (metadata->targeted_system_display_actual_peak_luminance_flag) {
2165 print_int(
"num_rows_targeted_system_display_actual_peak_luminance",
2166 metadata->num_rows_targeted_system_display_actual_peak_luminance);
2167 print_int(
"num_cols_targeted_system_display_actual_peak_luminance",
2168 metadata->num_cols_targeted_system_display_actual_peak_luminance);
2169 for (
int i = 0; i < metadata->num_rows_targeted_system_display_actual_peak_luminance; i++) {
2170 for (
int j = 0; j < metadata->num_cols_targeted_system_display_actual_peak_luminance; j++) {
2171 print_q(
"targeted_system_display_actual_peak_luminance",
2172 metadata->targeted_system_display_actual_peak_luminance[i][j],
'/');
2176 for (
int n = 0; n < metadata->num_windows; n++) {
2177 const AVHDRPlusColorTransformParams *params = &metadata->params[n];
2178 for (
int i = 0; i < 3; i++) {
2179 print_q(
"maxscl",params->maxscl[i],
'/');
2182 params->average_maxrgb,
'/');
2183 print_int(
"num_distribution_maxrgb_percentiles",
2184 params->num_distribution_maxrgb_percentiles);
2185 for (
int i = 0; i < params->num_distribution_maxrgb_percentiles; i++) {
2186 print_int(
"distribution_maxrgb_percentage",
2187 params->distribution_maxrgb[i].percentage);
2188 print_q(
"distribution_maxrgb_percentile",
2189 params->distribution_maxrgb[i].percentile,
'/');
2191 print_q(
"fraction_bright_pixels",
2192 params->fraction_bright_pixels,
'/');
2194 if (metadata->mastering_display_actual_peak_luminance_flag) {
2195 print_int(
"num_rows_mastering_display_actual_peak_luminance",
2196 metadata->num_rows_mastering_display_actual_peak_luminance);
2197 print_int(
"num_cols_mastering_display_actual_peak_luminance",
2198 metadata->num_cols_mastering_display_actual_peak_luminance);
2199 for (
int i = 0; i < metadata->num_rows_mastering_display_actual_peak_luminance; i++) {
2200 for (
int j = 0; j < metadata->num_cols_mastering_display_actual_peak_luminance; j++) {
2201 print_q(
"mastering_display_actual_peak_luminance",
2202 metadata->mastering_display_actual_peak_luminance[i][j],
'/');
2207 for (
int n = 0; n < metadata->num_windows; n++) {
2208 const AVHDRPlusColorTransformParams *params = &metadata->params[n];
2209 if (params->tone_mapping_flag) {
2210 print_q(
"knee_point_x", params->knee_point_x,
'/');
2211 print_q(
"knee_point_y", params->knee_point_y,
'/');
2213 params->num_bezier_curve_anchors );
2214 for (
int i = 0; i < params->num_bezier_curve_anchors; i++) {
2215 print_q(
"bezier_curve_anchors",
2216 params->bezier_curve_anchors[i],
'/');
2219 if (params->color_saturation_mapping_flag) {
2220 print_q(
"color_saturation_weight",
2221 params->color_saturation_weight,
'/');
2230 print_int(
"system_start_code", metadata->system_start_code);
2231 print_int(
"num_windows", metadata->num_windows);
2233 for (
int n = 0; n < metadata->num_windows; n++) {
2234 const AVHDRVividColorTransformParams *params = &metadata->params[n];
2236 print_q(
"minimum_maxrgb", params->minimum_maxrgb,
'/');
2237 print_q(
"average_maxrgb", params->average_maxrgb,
'/');
2238 print_q(
"variance_maxrgb", params->variance_maxrgb,
'/');
2239 print_q(
"maximum_maxrgb", params->maximum_maxrgb,
'/');
2242 for (
int n = 0; n < metadata->num_windows; n++) {
2243 const AVHDRVividColorTransformParams *params = &metadata->params[n];
2245 print_int(
"tone_mapping_mode_flag", params->tone_mapping_mode_flag);
2246 print_int(
"tone_mapping_param_num", params->tone_mapping_param_num);
2247 if (params->tone_mapping_mode_flag) {
2248 for (
int i = 0; i < params->tone_mapping_param_num; i++) {
2249 const AVHDRVividColorToneMappingParams *tm_params = ¶ms->tm_params[i];
2251 print_q(
"targeted_system_display_maximum_luminance",
2252 tm_params->targeted_system_display_maximum_luminance,
'/');
2253 print_int(
"base_enable_flag", tm_params->base_enable_flag);
2254 if (tm_params->base_enable_flag) {
2255 print_q(
"base_param_m_p", tm_params->base_param_m_p,
'/');
2256 print_q(
"base_param_m_m", tm_params->base_param_m_m,
'/');
2257 print_q(
"base_param_m_a", tm_params->base_param_m_a,
'/');
2258 print_q(
"base_param_m_b", tm_params->base_param_m_b,
'/');
2259 print_q(
"base_param_m_n", tm_params->base_param_m_n,
'/');
2261 print_int(
"base_param_k1", tm_params->base_param_k1);
2262 print_int(
"base_param_k2", tm_params->base_param_k2);
2263 print_int(
"base_param_k3", tm_params->base_param_k3);
2264 print_int(
"base_param_Delta_enable_mode",
2265 tm_params->base_param_Delta_enable_mode);
2266 print_q(
"base_param_Delta", tm_params->base_param_Delta,
'/');
2268 print_int(
"3Spline_enable_flag", tm_params->three_Spline_enable_flag);
2269 if (tm_params->three_Spline_enable_flag) {
2270 print_int(
"3Spline_num", tm_params->three_Spline_num);
2271 print_int(
"3Spline_TH_mode", tm_params->three_Spline_TH_mode);
2273 for (
int j = 0; j < tm_params->three_Spline_num; j++) {
2274 print_q(
"3Spline_TH_enable_MB", tm_params->three_Spline_TH_enable_MB,
'/');
2275 print_q(
"3Spline_TH_enable", tm_params->three_Spline_TH_enable,
'/');
2276 print_q(
"3Spline_TH_Delta1", tm_params->three_Spline_TH_Delta1,
'/');
2277 print_q(
"3Spline_TH_Delta2", tm_params->three_Spline_TH_Delta2,
'/');
2278 print_q(
"3Spline_enable_Strength", tm_params->three_Spline_enable_Strength,
'/');
2284 print_int(
"color_saturation_mapping_flag", params->color_saturation_mapping_flag);
2285 if (params->color_saturation_mapping_flag) {
2286 print_int(
"color_saturation_num", params->color_saturation_num);
2287 for (
int i = 0; i < params->color_saturation_num; i++) {
2288 print_q(
"color_saturation_gain", params->color_saturation_gain[i],
'/');
2295 const AVAmbientViewingEnvironment *env)
2300 print_q(
"ambient_illuminance", env->ambient_illuminance,
'/');
2301 print_q(
"ambient_light_x", env->ambient_light_x,
'/');
2302 print_q(
"ambient_light_y", env->ambient_light_y,
'/');
2306 AVCodecParameters *par,
2307 const AVPacketSideData *side_data,
2315 for (i = 0; i < nb_side_data; i++) {
2316 const AVPacketSideData *sd = &side_data[i];
2317 const char *
name = av_packet_side_data_name(sd->type);
2321 if (sd->type == AV_PKT_DATA_DISPLAYMATRIX && sd->size >= 9*4) {
2322 double rotation = av_display_rotation_get((int32_t *)sd->data);
2323 if (isnan(rotation))
2327 }
else if (sd->type == AV_PKT_DATA_STEREO3D) {
2328 const AVStereo3D *stereo = (AVStereo3D *)sd->data;
2329 print_str(
"type", av_stereo3d_type_name(stereo->type));
2330 print_int(
"inverted", !!(stereo->flags & AV_STEREO3D_FLAG_INVERT));
2331 }
else if (sd->type == AV_PKT_DATA_SPHERICAL) {
2332 const AVSphericalMapping *spherical = (AVSphericalMapping *)sd->data;
2333 print_str(
"projection", av_spherical_projection_name(spherical->projection));
2334 if (spherical->projection == AV_SPHERICAL_CUBEMAP) {
2335 print_int(
"padding", spherical->padding);
2336 }
else if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR_TILE) {
2338 av_spherical_tile_bounds(spherical, par->width, par->height,
2346 print_int(
"yaw", (
double) spherical->yaw / (1 << 16));
2347 print_int(
"pitch", (
double) spherical->pitch / (1 << 16));
2348 print_int(
"roll", (
double) spherical->roll / (1 << 16));
2349 }
else if (sd->type == AV_PKT_DATA_SKIP_SAMPLES && sd->size == 10) {
2350 print_int(
"skip_samples", AV_RL32(sd->data));
2351 print_int(
"discard_padding", AV_RL32(sd->data + 4));
2352 print_int(
"skip_reason", AV_RL8(sd->data + 8));
2353 print_int(
"discard_reason", AV_RL8(sd->data + 9));
2354 }
else if (sd->type == AV_PKT_DATA_MASTERING_DISPLAY_METADATA) {
2355 AVMasteringDisplayMetadata *metadata = (AVMasteringDisplayMetadata *)sd->data;
2357 if (metadata->has_primaries) {
2358 print_q(
"red_x", metadata->display_primaries[0][0],
'/');
2359 print_q(
"red_y", metadata->display_primaries[0][1],
'/');
2360 print_q(
"green_x", metadata->display_primaries[1][0],
'/');
2361 print_q(
"green_y", metadata->display_primaries[1][1],
'/');
2362 print_q(
"blue_x", metadata->display_primaries[2][0],
'/');
2363 print_q(
"blue_y", metadata->display_primaries[2][1],
'/');
2365 print_q(
"white_point_x", metadata->white_point[0],
'/');
2366 print_q(
"white_point_y", metadata->white_point[1],
'/');
2369 if (metadata->has_luminance) {
2370 print_q(
"min_luminance", metadata->min_luminance,
'/');
2371 print_q(
"max_luminance", metadata->max_luminance,
'/');
2373 }
else if (sd->type == AV_PKT_DATA_CONTENT_LIGHT_LEVEL) {
2374 AVContentLightMetadata *metadata = (AVContentLightMetadata *)sd->data;
2375 print_int(
"max_content", metadata->MaxCLL);
2376 print_int(
"max_average", metadata->MaxFALL);
2377 }
else if (sd->type == AV_PKT_DATA_DOVI_CONF) {
2378 AVDOVIDecoderConfigurationRecord *dovi = (AVDOVIDecoderConfigurationRecord *)sd->data;
2379 print_int(
"dv_version_major", dovi->dv_version_major);
2380 print_int(
"dv_version_minor", dovi->dv_version_minor);
2381 print_int(
"dv_profile", dovi->dv_profile);
2383 print_int(
"rpu_present_flag", dovi->rpu_present_flag);
2384 print_int(
"el_present_flag", dovi->el_present_flag);
2385 print_int(
"bl_present_flag", dovi->bl_present_flag);
2386 print_int(
"dv_bl_signal_compatibility_id", dovi->dv_bl_signal_compatibility_id);
2387 }
else if (sd->type == AV_PKT_DATA_AUDIO_SERVICE_TYPE) {
2388 enum AVAudioServiceType *t = (
enum AVAudioServiceType *)sd->data;
2390 }
else if (sd->type == AV_PKT_DATA_MPEGTS_STREAM_ID) {
2392 }
else if (sd->type == AV_PKT_DATA_CPB_PROPERTIES) {
2393 const AVCPBProperties *prop = (AVCPBProperties *)sd->data;
2394 print_int(
"max_bitrate", prop->max_bitrate);
2395 print_int(
"min_bitrate", prop->min_bitrate);
2396 print_int(
"avg_bitrate", prop->avg_bitrate);
2397 print_int(
"buffer_size", prop->buffer_size);
2398 print_int(
"vbv_delay", prop->vbv_delay);
2399 }
else if (sd->type == AV_PKT_DATA_WEBVTT_IDENTIFIER ||
2400 sd->type == AV_PKT_DATA_WEBVTT_SETTINGS) {
2404 }
else if (sd->type == AV_PKT_DATA_AFD && sd->size > 0) {
2414 const char *val = av_color_range_name(color_range);
2415 if (!val || color_range == AVCOL_RANGE_UNSPECIFIED) {
2424 const char *val = av_color_space_name(color_space);
2425 if (!val || color_space == AVCOL_SPC_UNSPECIFIED) {
2434 const char *val = av_color_primaries_name(color_primaries);
2435 if (!val || color_primaries == AVCOL_PRI_UNSPECIFIED) {
2444 const char *val = av_color_transfer_name(color_trc);
2445 if (!val || color_trc == AVCOL_TRC_UNSPECIFIED) {
2454 const char *val = av_chroma_location_name(chroma_location);
2455 if (!val || chroma_location == AVCHROMA_LOC_UNSPECIFIED) {
2517 AVStream *st = ifile->
streams[pkt->stream_index].
st;
2521 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2525 s = av_get_media_type_string(st->codecpar->codec_type);
2528 print_int(
"stream_index", pkt->stream_index);
2530 print_time(
"pts_time", pkt->pts, &st->time_base);
2532 print_time(
"dts_time", pkt->dts, &st->time_base);
2536 if (pkt->pos != -1)
print_fmt (
"pos",
"%"PRId64, pkt->pos);
2538 print_fmt(
"flags",
"%c%c%c", pkt->flags & AV_PKT_FLAG_KEY ?
'K' :
'_',
2539 pkt->flags & AV_PKT_FLAG_DISCARD ?
'D' :
'_',
2540 pkt->flags & AV_PKT_FLAG_CORRUPT ?
'C' :
'_');
2545 if (pkt->side_data_elems) {
2547 const uint8_t *side_metadata;
2549 side_metadata = av_packet_get_side_data(pkt, AV_PKT_DATA_STRINGS_METADATA, &size);
2551 AVDictionary *dict = NULL;
2552 if (av_packet_unpack_dictionary(side_metadata, size, &dict) >= 0)
2554 av_dict_free(&dict);
2564 av_bprint_finalize(&pbuf, NULL);
2569 AVFormatContext *fmt_ctx)
2573 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2579 print_time(
"pts_time", sub->pts, &AV_TIME_BASE_Q);
2581 print_int (
"start_display_time", sub->start_display_time);
2582 print_int (
"end_display_time", sub->end_display_time);
2583 print_int (
"num_rects", sub->num_rects);
2587 av_bprint_finalize(&pbuf, NULL);
2592 AVFormatContext *fmt_ctx)
2599 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2603 s = av_get_media_type_string(stream->codecpar->codec_type);
2606 print_int(
"stream_index", stream->index);
2607 print_int(
"key_frame", frame->key_frame);
2609 print_time(
"pts_time", frame->pts, &stream->time_base);
2610 print_ts (
"pkt_dts", frame->pkt_dts);
2611 print_time(
"pkt_dts_time", frame->pkt_dts, &stream->time_base);
2612 print_ts (
"best_effort_timestamp", frame->best_effort_timestamp);
2613 print_time(
"best_effort_timestamp_time", frame->best_effort_timestamp, &stream->time_base);
2614#if LIBAVUTIL_VERSION_MAJOR < 59
2615 AV_NOWARN_DEPRECATED(
2622 if (frame->pkt_pos != -1)
print_fmt (
"pkt_pos",
"%"PRId64, frame->pkt_pos);
2627 switch (stream->codecpar->codec_type) {
2630 case AVMEDIA_TYPE_VIDEO:
2633 s = av_get_pix_fmt_name(frame->format);
2636 sar = av_guess_sample_aspect_ratio(fmt_ctx, stream, frame);
2638 print_q(
"sample_aspect_ratio", sar,
':');
2642 print_fmt(
"pict_type",
"%c", av_get_picture_type_char(frame->pict_type));
2643#if LIBAVUTIL_VERSION_MAJOR < 59
2644 AV_NOWARN_DEPRECATED(
2645 print_int(
"coded_picture_number", frame->coded_picture_number);
2646 print_int(
"display_picture_number", frame->display_picture_number);
2649 print_int(
"interlaced_frame", frame->interlaced_frame);
2650 print_int(
"top_field_first", frame->top_field_first);
2651 print_int(
"repeat_pict", frame->repeat_pict);
2660 case AVMEDIA_TYPE_AUDIO:
2661 s = av_get_sample_fmt_name(frame->format);
2664 print_int(
"nb_samples", frame->nb_samples);
2665 print_int(
"channels", frame->ch_layout.nb_channels);
2666 if (frame->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) {
2667 av_channel_layout_describe(&frame->ch_layout, val_str,
sizeof(val_str));
2677 if (frame->nb_side_data) {
2679 for (i = 0; i < frame->nb_side_data; i++) {
2680 AVFrameSideData *sd = frame->side_data[i];
2684 name = av_frame_side_data_name(sd->type);
2686 if (sd->type == AV_FRAME_DATA_DISPLAYMATRIX && sd->size >= 9*4) {
2687 double rotation = av_display_rotation_get((int32_t *)sd->data);
2688 if (isnan(rotation))
2692 }
else if (sd->type == AV_FRAME_DATA_AFD && sd->size > 0) {
2694 }
else if (sd->type == AV_FRAME_DATA_GOP_TIMECODE && sd->size >= 8) {
2695 char tcbuf[AV_TIMECODE_STR_SIZE];
2696 av_timecode_make_mpeg_tc_string(tcbuf, *(int64_t *)(sd->data));
2698 }
else if (sd->type == AV_FRAME_DATA_S12M_TIMECODE && sd->size == 16) {
2699 uint32_t *tc = (uint32_t*)sd->data;
2700 int m = FFMIN(tc[0],3);
2702 for (
int j = 1; j <= m ; j++) {
2703 char tcbuf[AV_TIMECODE_STR_SIZE];
2704 av_timecode_make_smpte_tc_string2(tcbuf, stream->avg_frame_rate, tc[j], 0, 0);
2710 }
else if (sd->type == AV_FRAME_DATA_MASTERING_DISPLAY_METADATA) {
2711 AVMasteringDisplayMetadata *metadata = (AVMasteringDisplayMetadata *)sd->data;
2713 if (metadata->has_primaries) {
2714 print_q(
"red_x", metadata->display_primaries[0][0],
'/');
2715 print_q(
"red_y", metadata->display_primaries[0][1],
'/');
2716 print_q(
"green_x", metadata->display_primaries[1][0],
'/');
2717 print_q(
"green_y", metadata->display_primaries[1][1],
'/');
2718 print_q(
"blue_x", metadata->display_primaries[2][0],
'/');
2719 print_q(
"blue_y", metadata->display_primaries[2][1],
'/');
2721 print_q(
"white_point_x", metadata->white_point[0],
'/');
2722 print_q(
"white_point_y", metadata->white_point[1],
'/');
2725 if (metadata->has_luminance) {
2726 print_q(
"min_luminance", metadata->min_luminance,
'/');
2727 print_q(
"max_luminance", metadata->max_luminance,
'/');
2729 }
else if (sd->type == AV_FRAME_DATA_DYNAMIC_HDR_PLUS) {
2730 AVDynamicHDRPlus *metadata = (AVDynamicHDRPlus *)sd->data;
2732 }
else if (sd->type == AV_FRAME_DATA_CONTENT_LIGHT_LEVEL) {
2733 AVContentLightMetadata *metadata = (AVContentLightMetadata *)sd->data;
2734 print_int(
"max_content", metadata->MaxCLL);
2735 print_int(
"max_average", metadata->MaxFALL);
2736 }
else if (sd->type == AV_FRAME_DATA_ICC_PROFILE) {
2737 const AVDictionaryEntry *tag = av_dict_get(sd->metadata,
"name", NULL, AV_DICT_MATCH_CASE);
2741 }
else if (sd->type == AV_FRAME_DATA_DOVI_METADATA) {
2743 }
else if (sd->type == AV_FRAME_DATA_DYNAMIC_HDR_VIVID) {
2744 AVDynamicHDRVivid *metadata = (AVDynamicHDRVivid *)sd->data;
2746 }
else if (sd->type == AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT) {
2748 w, (
const AVAmbientViewingEnvironment *)sd->data);
2757 av_bprint_finalize(&pbuf, NULL);
2763 AVFrame *frame,
const AVPacket *pkt,
2766 AVFormatContext *fmt_ctx = ifile->
fmt_ctx;
2767 AVCodecContext *dec_ctx = ifile->
streams[pkt->stream_index].
dec_ctx;
2768 AVCodecParameters *par = ifile->
streams[pkt->stream_index].
st->codecpar;
2770 int ret = 0, got_frame = 0;
2774 switch (par->codec_type) {
2775 case AVMEDIA_TYPE_VIDEO:
2776 case AVMEDIA_TYPE_AUDIO:
2778 ret = avcodec_send_packet(dec_ctx, pkt);
2779 if (ret == AVERROR(EAGAIN)) {
2781 }
else if (ret >= 0 || ret == AVERROR_EOF) {
2787 ret = avcodec_receive_frame(dec_ctx, frame);
2790 }
else if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
2796 case AVMEDIA_TYPE_SUBTITLE:
2798 ret = avcodec_decode_subtitle2(dec_ctx, &sub, &got_frame, pkt);
2811 int is_sub = (par->codec_type == AVMEDIA_TYPE_SUBTITLE);
2821 avsubtitle_free(&sub);
2824 return got_frame || *packet_new;
2829 av_log(log_ctx, log_level,
"id:%d", interval->
id);
2832 av_log(log_ctx, log_level,
" start:%s%s", interval->
start_is_offset ?
"+" :
"",
2833 av_ts2timestr(interval->
start, &AV_TIME_BASE_Q));
2835 av_log(log_ctx, log_level,
" start:N/A");
2839 av_log(log_ctx, log_level,
" end:%s", interval->
end_is_offset ?
"+" :
"");
2841 av_log(log_ctx, log_level,
"#%"PRId64, interval->
end);
2843 av_log(log_ctx, log_level,
"%s", av_ts2timestr(interval->
end, &AV_TIME_BASE_Q));
2845 av_log(log_ctx, log_level,
" end:N/A");
2848 av_log(log_ctx, log_level,
"\n");
2854 AVFormatContext *fmt_ctx = ifile->
fmt_ctx;
2855 AVPacket *pkt = NULL;
2856 AVFrame *frame = NULL;
2857 int ret = 0, i = 0, frame_count = 0;
2858 int64_t start = -INT64_MAX, end = interval->
end;
2861 av_log(NULL, AV_LOG_VERBOSE,
"Processing read interval ");
2867 if (*cur_ts == AV_NOPTS_VALUE) {
2868 av_log(NULL, AV_LOG_ERROR,
2869 "Could not seek to relative position since current "
2870 "timestamp is not defined\n");
2871 ret = AVERROR(EINVAL);
2874 target = *cur_ts + interval->
start;
2876 target = interval->
start;
2879 av_log(NULL, AV_LOG_VERBOSE,
"Seeking to read interval start point %s\n",
2880 av_ts2timestr(target, &AV_TIME_BASE_Q));
2881 if ((ret = avformat_seek_file(fmt_ctx, -1, -INT64_MAX, target, INT64_MAX, 0)) < 0) {
2882 av_log(NULL, AV_LOG_ERROR,
"Could not seek to position %"PRId64
": %s\n",
2883 interval->
start, av_err2str(ret));
2888 frame = av_frame_alloc();
2890 ret = AVERROR(ENOMEM);
2893 pkt = av_packet_alloc();
2895 ret = AVERROR(ENOMEM);
2898 while (!av_read_frame(fmt_ctx, pkt)) {
2906 AVRational tb = ifile->
streams[pkt->stream_index].
st->time_base;
2907 int64_t pts = pkt->pts != AV_NOPTS_VALUE ? pkt->pts : pkt->dts;
2909 if (pts != AV_NOPTS_VALUE)
2910 *cur_ts = av_rescale_q(pts, tb, AV_TIME_BASE_Q);
2912 if (!has_start && *cur_ts != AV_NOPTS_VALUE) {
2918 end = start + interval->
end;
2923 if (frame_count >= interval->
end)
2925 }
else if (has_end && *cur_ts != AV_NOPTS_VALUE && *cur_ts >= end) {
2937 while (
process_frame(w, ifile, frame, pkt, &packet_new) > 0);
2940 av_packet_unref(pkt);
2942 av_packet_unref(pkt);
2945 pkt->stream_index = i;
2954 av_frame_free(&frame);
2955 av_packet_free(&pkt);
2957 av_log(NULL, AV_LOG_ERROR,
"Could not read packets in interval ");
2965 AVFormatContext *fmt_ctx = ifile->
fmt_ctx;
2967 int64_t cur_ts = fmt_ctx->start_time;
2985 AVStream *stream = ist->
st;
2986 AVCodecParameters *par;
2987 AVCodecContext *dec_ctx;
2990 AVRational sar, dar;
2992 const AVCodecDescriptor *cd;
2994 const char *profile = NULL;
2996 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
3002 par = stream->codecpar;
3004 if ((cd = avcodec_descriptor_get(par->codec_id))) {
3008 cd->long_name ? cd->long_name :
"unknown");
3017 if (!
do_bitexact && (profile = avcodec_profile_name(par->codec_id, par->profile)))
3020 if (par->profile != FF_PROFILE_UNKNOWN) {
3021 char profile_num[12];
3022 snprintf(profile_num,
sizeof(profile_num),
"%d", par->profile);
3028 s = av_get_media_type_string(par->codec_type);
3033 print_str(
"codec_tag_string", av_fourcc2str(par->codec_tag));
3034 print_fmt(
"codec_tag",
"0x%04"PRIx32, par->codec_tag);
3036 switch (par->codec_type) {
3037 case AVMEDIA_TYPE_VIDEO:
3041 print_int(
"coded_width", dec_ctx->coded_width);
3042 print_int(
"coded_height", dec_ctx->coded_height);
3043 print_int(
"closed_captions", !!(dec_ctx->properties & FF_CODEC_PROPERTY_CLOSED_CAPTIONS));
3044 print_int(
"film_grain", !!(dec_ctx->properties & FF_CODEC_PROPERTY_FILM_GRAIN));
3046 print_int(
"has_b_frames", par->video_delay);
3047 sar = av_guess_sample_aspect_ratio(fmt_ctx, stream, NULL);
3049 print_q(
"sample_aspect_ratio", sar,
':');
3050 av_reduce(&dar.num, &dar.den,
3051 par->width * sar.num,
3052 par->height * sar.den,
3054 print_q(
"display_aspect_ratio", dar,
':');
3059 s = av_get_pix_fmt_name(par->format);
3070 if (par->field_order == AV_FIELD_PROGRESSIVE)
3071 print_str(
"field_order",
"progressive");
3072 else if (par->field_order == AV_FIELD_TT)
3074 else if (par->field_order == AV_FIELD_BB)
3076 else if (par->field_order == AV_FIELD_TB)
3078 else if (par->field_order == AV_FIELD_BT)
3087 case AVMEDIA_TYPE_AUDIO:
3088 s = av_get_sample_fmt_name(par->format);
3092 print_int(
"channels", par->ch_layout.nb_channels);
3094 if (par->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) {
3095 av_channel_layout_describe(&par->ch_layout, val_str,
sizeof(val_str));
3101 print_int(
"bits_per_sample", av_get_bits_per_sample(par->codec_id));
3103 print_int(
"initial_padding", par->initial_padding);
3106 case AVMEDIA_TYPE_SUBTITLE:
3119 const AVOption *opt = NULL;
3120 while ((opt = av_opt_next(dec_ctx->priv_data,opt))) {
3122 if (!(opt->flags & AV_OPT_FLAG_EXPORT))
continue;
3123 if (av_opt_get(dec_ctx->priv_data, opt->name, 0, &str) >= 0) {
3130 if (fmt_ctx->iformat->flags & AVFMT_SHOW_IDS)
print_fmt (
"id",
"0x%x", stream->id);
3132 print_q(
"r_frame_rate", stream->r_frame_rate,
'/');
3133 print_q(
"avg_frame_rate", stream->avg_frame_rate,
'/');
3134 print_q(
"time_base", stream->time_base,
'/');
3135 print_ts (
"start_pts", stream->start_time);
3136 print_time(
"start_time", stream->start_time, &stream->time_base);
3137 print_ts (
"duration_ts", stream->duration);
3138 print_time(
"duration", stream->duration, &stream->time_base);
3141 if (dec_ctx && dec_ctx->rc_max_rate > 0)
3145 if (dec_ctx && dec_ctx->bits_per_raw_sample > 0)
print_fmt(
"bits_per_raw_sample",
"%d", dec_ctx->bits_per_raw_sample);
3147 if (stream->nb_frames)
print_fmt (
"nb_frames",
"%"PRId64, stream->nb_frames);
3155 par->extradata_size);
3157 if (par->extradata_size > 0) {
3158 print_int(
"extradata_size", par->extradata_size);
3160 par->extradata_size);
3164#define PRINT_DISPOSITION(flagname, name) do { \
3165 print_int(name, !!(stream->disposition & AV_DISPOSITION_##flagname)); \
3193 if (stream->nb_side_data) {
3200 av_bprint_finalize(&pbuf, NULL);
3208 AVFormatContext *fmt_ctx = ifile->
fmt_ctx;
3225 AVFormatContext *fmt_ctx = ifile->
fmt_ctx;
3230 print_int(
"program_num", program->program_num);
3231 print_int(
"nb_streams", program->nb_stream_indexes);
3240 for (i = 0; i < program->nb_stream_indexes; i++) {
3242 ret =
show_stream(w, fmt_ctx, program->stream_index[i], &ifile->
streams[program->stream_index[i]], 1);
3256 AVFormatContext *fmt_ctx = ifile->
fmt_ctx;
3260 for (i = 0; i < fmt_ctx->nb_programs; i++) {
3261 AVProgram *program = fmt_ctx->programs[i];
3274 AVFormatContext *fmt_ctx = ifile->
fmt_ctx;
3278 for (i = 0; i < fmt_ctx->nb_chapters; i++) {
3279 AVChapter *chapter = fmt_ctx->chapters[i];
3283 print_q (
"time_base", chapter->time_base,
'/');
3285 print_time(
"start_time", chapter->start, &chapter->time_base);
3287 print_time(
"end_time", chapter->end, &chapter->time_base);
3299 AVFormatContext *fmt_ctx = ifile->
fmt_ctx;
3301 int64_t size = fmt_ctx->pb ? avio_size(fmt_ctx->pb) : -1;
3306 print_int(
"nb_streams", fmt_ctx->nb_streams);
3307 print_int(
"nb_programs", fmt_ctx->nb_programs);
3308 print_str(
"format_name", fmt_ctx->iformat->name);
3310 if (fmt_ctx->iformat->long_name)
print_str (
"format_long_name", fmt_ctx->iformat->long_name);
3313 print_time(
"start_time", fmt_ctx->start_time, &AV_TIME_BASE_Q);
3314 print_time(
"duration", fmt_ctx->duration, &AV_TIME_BASE_Q);
3319 print_int(
"probe_score", fmt_ctx->probe_score);
3337 const char *print_filename)
3340 AVFormatContext *fmt_ctx = NULL;
3341 const AVDictionaryEntry *t = NULL;
3342 int scan_all_pmts_set = 0;
3344 fmt_ctx = avformat_alloc_context();
3348 if (!av_dict_get(
format_opts,
"scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
3349 av_dict_set(&
format_opts,
"scan_all_pmts",
"1", AV_DICT_DONT_OVERWRITE);
3350 scan_all_pmts_set = 1;
3352 if ((err = avformat_open_input(&fmt_ctx, filename,
3357 if (print_filename) {
3358 av_freep(&fmt_ctx->url);
3359 fmt_ctx->url = av_strdup(print_filename);
3362 if (scan_all_pmts_set)
3363 av_dict_set(&
format_opts,
"scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
3365 av_log(NULL, AV_LOG_WARNING,
"Option %s skipped - not known to demuxer.\n", t->key);
3369 int orig_nb_streams = fmt_ctx->nb_streams;
3371 err = avformat_find_stream_info(fmt_ctx, opts);
3373 for (i = 0; i < orig_nb_streams; i++)
3374 av_dict_free(&opts[i]);
3383 av_dump_format(fmt_ctx, 0, filename, 0);
3385 ifile->
streams = av_calloc(fmt_ctx->nb_streams,
sizeof(*ifile->
streams));
3391 for (i = 0; i < fmt_ctx->nb_streams; i++) {
3393 AVStream *stream = fmt_ctx->streams[i];
3394 const AVCodec *codec;
3398 if (stream->codecpar->codec_id == AV_CODEC_ID_PROBE) {
3399 av_log(NULL, AV_LOG_WARNING,
3400 "Failed to probe codec for input stream %d\n",
3405 codec = avcodec_find_decoder(stream->codecpar->codec_id);
3407 av_log(NULL, AV_LOG_WARNING,
3408 "Unsupported codec with id %d for input stream %d\n",
3409 stream->codecpar->codec_id, stream->index);
3414 fmt_ctx, stream, codec);
3416 ist->
dec_ctx = avcodec_alloc_context3(codec);
3420 err = avcodec_parameters_to_context(ist->
dec_ctx, stream->codecpar);
3431 ist->
dec_ctx->pkt_timebase = stream->time_base;
3433 if (avcodec_open2(ist->
dec_ctx, codec, &opts) < 0) {
3434 av_log(NULL, AV_LOG_WARNING,
"Could not open codec for input stream %d\n",
3439 if ((t = av_dict_get(opts,
"", NULL, AV_DICT_IGNORE_SUFFIX))) {
3440 av_log(NULL, AV_LOG_ERROR,
"Option %s for input stream %d not found\n",
3441 t->key, stream->index);
3442 return AVERROR_OPTION_NOT_FOUND;
3462 avformat_close_input(&ifile->
fmt_ctx);
3466 const char *print_filename)
3479#define CHECK_END if (ret < 0) goto end
3486 for (i = 0; i < ifile.
fmt_ctx->nb_streams; i++) {
3488 ret = avformat_match_stream_specifier(ifile.
fmt_ctx,
3499 ifile.
fmt_ctx->streams[i]->discard = AVDISCARD_ALL;
3548 av_log(NULL, AV_LOG_INFO,
"Simple multimedia streams analyzer\n");
3549 av_log(NULL, AV_LOG_INFO,
"usage: %s [OPTIONS] INPUT_FILE\n",
program_name);
3550 av_log(NULL, AV_LOG_INFO,
"\n");
3556 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
3560 print_fmt(
"copyright",
"Copyright (c) %d-%d the FFmpeg developers",
3563 print_str(
"configuration", FFMPEG_CONFIGURATION);
3566 av_bprint_finalize(&pbuf, NULL);
3569#define SHOW_LIB_VERSION(libname, LIBNAME) \
3571 if (CONFIG_##LIBNAME) { \
3572 unsigned int version = libname##_version(); \
3573 writer_print_section_header(w, SECTION_ID_LIBRARY_VERSION); \
3574 print_str("name", "lib" #libname); \
3575 print_int("major", LIB##LIBNAME##_VERSION_MAJOR); \
3576 print_int("minor", LIB##LIBNAME##_VERSION_MINOR); \
3577 print_int("micro", LIB##LIBNAME##_VERSION_MICRO); \
3578 print_int("version", version); \
3579 print_str("ident", LIB##LIBNAME##_IDENT); \
3580 writer_print_section_footer(w); \
3597#define PRINT_PIX_FMT_FLAG(flagname, name) \
3599 print_int(name, !!(pixdesc->flags & AV_PIX_FMT_FLAG_##flagname)); \
3604 const AVPixFmtDescriptor *pixdesc = NULL;
3608 while ((pixdesc = av_pix_fmt_desc_next(pixdesc))) {
3611 print_int(
"nb_components", pixdesc->nb_components);
3612 if ((pixdesc->nb_components >= 3) && !(pixdesc->flags & AV_PIX_FMT_FLAG_RGB)) {
3613 print_int (
"log2_chroma_w", pixdesc->log2_chroma_w);
3614 print_int (
"log2_chroma_h", pixdesc->log2_chroma_h);
3619 n = av_get_bits_per_pixel(pixdesc);
3635 for (i = 0; i < pixdesc->nb_components; i++) {
3638 print_int(
"bit_depth", pixdesc->comp[i].depth);
3659static int opt_format(
void *optctx,
const char *opt,
const char *arg)
3661 iformat = av_find_input_format(arg);
3663 av_log(NULL, AV_LOG_ERROR,
"Unknown input format: %s\n", arg);
3664 return AVERROR(EINVAL);
3689 for (i = 0; i < FF_ARRAY_ELEMS(
sections); i++) {
3693 av_log(NULL, AV_LOG_DEBUG,
3694 "'%s' matches section with unique name '%s'\n", section_name,
3705 const char *p = arg;
3709 AVDictionary *entries = NULL;
3710 char *section_name = av_get_token(&p,
"=:");
3713 if (!section_name) {
3714 av_log(NULL, AV_LOG_ERROR,
3715 "Missing section name for option '%s'\n", opt);
3716 return AVERROR(EINVAL);
3721 while (*p && *p !=
':') {
3722 char *entry = av_get_token(&p,
",:");
3725 av_log(NULL, AV_LOG_VERBOSE,
3726 "Adding '%s' to the entries to show in section '%s'\n",
3727 entry, section_name);
3728 av_dict_set(&entries, entry,
"", AV_DICT_DONT_STRDUP_KEY);
3738 av_log(NULL, AV_LOG_ERROR,
"No match for section '%s'\n", section_name);
3739 ret = AVERROR(EINVAL);
3741 av_dict_free(&entries);
3742 av_free(section_name);
3756 av_log(NULL, AV_LOG_ERROR,
3757 "Argument '%s' provided as input filename, but '%s' was already specified.\n",
3761 if (!strcmp(arg,
"-"))
3775 av_log(NULL, AV_LOG_ERROR,
3776 "Argument '%s' provided as output filename, but '%s' was already specified.\n",
3780 if (!strcmp(arg,
"-"))
3816 char *next, *p, *spec = av_strdup(interval_spec);
3818 return AVERROR(ENOMEM);
3821 av_log(NULL, AV_LOG_ERROR,
"Invalid empty interval specification\n");
3822 ret = AVERROR(EINVAL);
3827 next = strchr(spec,
'%');
3842 ret = av_parse_time(&interval->
start, p, 1);
3844 av_log(NULL, AV_LOG_ERROR,
"Invalid interval start specification '%s'\n", p);
3869 lli = strtoll(p, &tail, 10);
3870 if (*tail || lli < 0) {
3871 av_log(NULL, AV_LOG_ERROR,
3872 "Invalid or negative value '%s' for duration number of frames\n", p);
3875 interval->
end = lli;
3878 ret = av_parse_time(&us, p, 1);
3880 av_log(NULL, AV_LOG_ERROR,
"Invalid interval end/duration specification '%s'\n", p);
3897 char *p, *spec = av_strdup(intervals_spec);
3899 return AVERROR(ENOMEM);
3902 for (n = 0, p = spec; *p; p++)
3909 ret = AVERROR(ENOMEM);
3916 for (i = 0; p; i++) {
3920 next = strchr(p,
',');
3927 av_log(NULL, AV_LOG_ERROR,
"Error parsing read interval #%d '%s'\n",
3931 av_log(NULL, AV_LOG_VERBOSE,
"Parsed log interval ");
3947static int opt_pretty(
void *optctx,
const char *opt,
const char *arg)
3976 "W.. = Section is a wrapper (contains other sections, no local entries)\n"
3977 ".A. = Section contains an array of elements of the same type\n"
3978 "..V = Section may contain a variable number of fields with variable keys\n"
3979 "FLAGS NAME/UNIQUE_NAME\n"
3992#define DEFINE_OPT_SHOW_SECTION(section, target_section_id) \
3993 static int opt_show_##section(void *optctx, const char *opt, const char *arg) \
3995 mark_section_show_entries(SECTION_ID_##target_section_id, 1, NULL); \
4022#define SET_DO_SHOW(id, varname) do { \
4023 if (check_section_show_entries(SECTION_ID_##id)) \
4024 do_show_##varname = 1; \
4091 for (
int i = 0; i < FF_ARRAY_ELEMS(
sections); i++) {
4098 char _program_name[] =
"ffprobe";
4117 {
"bsfs",
OPT_EXIT, { .func_arg =
show_bsfs },
"show available bit stream filters" },
4127 {
"report", 0, { .func_arg =
opt_report },
"generate a report" },
4128 {
"max_alloc",
HAS_ARG, { .func_arg =
opt_max_alloc },
"set maximum size of a single allocated block",
"bytes" },
4135 "list sources of the input device",
"device" },
4137 "list sinks of the output device",
"device" },
4144 "use binary prefixes for byte units" },
4146 "use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units" },
4148 "prettify the format of displayed values, make it more human readable" },
4150 "set the output printing format (available formats are: default, compact, csv, flat, ini, json, xml)",
"format" },
4153 {
"sections",
OPT_EXIT, {.func_arg =
opt_sections},
"print sections structure and section information, and exit" },
4156 {
"show_error", 0, { .func_arg = &opt_show_error },
"show probing error" },
4157 {
"show_format", 0, { .func_arg = &opt_show_format },
"show format/container info" },
4158 {
"show_frames", 0, { .func_arg = &opt_show_frames },
"show frames info" },
4160 "show a set of specified entries",
"entry_list" },
4164 {
"show_packets", 0, { .func_arg = &opt_show_packets },
"show packets info" },
4165 {
"show_programs", 0, { .func_arg = &opt_show_programs },
"show programs info" },
4166 {
"show_streams", 0, { .func_arg = &opt_show_streams },
"show streams info" },
4167 {
"show_chapters", 0, { .func_arg = &opt_show_chapters },
"show chapters info" },
4170 {
"show_program_version", 0, { .func_arg = &opt_show_program_version },
"show ffprobe version" },
4171 {
"show_library_versions", 0, { .func_arg = &opt_show_library_versions },
"show library versions" },
4172 {
"show_versions", 0, { .func_arg = &
opt_show_versions },
"show program and library versions" },
4173 {
"show_pixel_formats", 0, { .func_arg = &opt_show_pixel_formats },
"show pixel format descriptions" },
4183 "read and decode the streams to fill missing information with heuristics" },
4190 char *w_name = NULL, *w_args = NULL;
4191 int ret, input_ret, i;
4194 if (savedCode == 0) {
4201 ret = pthread_mutex_init(&log_mutex, NULL);
4206 av_log_set_flags(AV_LOG_SKIP_REPEATED);
4211 avformat_network_init();
4213 avdevice_register_all();
4230 SET_DO_SHOW(PIXEL_FORMAT_FLAGS, pixel_format_flags);
4231 SET_DO_SHOW(PIXEL_FORMAT_COMPONENTS, pixel_format_components);
4235 SET_DO_SHOW(STREAM_DISPOSITION, stream_disposition);
4236 SET_DO_SHOW(PROGRAM_STREAM_DISPOSITION, stream_disposition);
4247 av_log(NULL, AV_LOG_ERROR,
4248 "-bitexact and -show_program_version or -show_library_versions "
4249 "options are incompatible\n");
4250 ret = AVERROR(EINVAL);
4259 ret = AVERROR(ENOMEM);
4264 av_log(NULL, AV_LOG_ERROR,
4265 "No name specified for the output format\n");
4266 ret = AVERROR(EINVAL);
4273 if (ret == AVERROR(EINVAL)) {
4275 av_log(NULL, AV_LOG_ERROR,
4276 "Unknown hash algorithm '%s'\nKnown algorithms:",
4278 for (i = 0; (n = av_hash_names(i)); i++)
4279 av_log(NULL, AV_LOG_ERROR,
" %s", n);
4280 av_log(NULL, AV_LOG_ERROR,
"\n");
4288 av_log(NULL, AV_LOG_ERROR,
"Unknown output format with name '%s'\n", w_name);
4289 ret = AVERROR(EINVAL);
4311 av_log(NULL, AV_LOG_ERROR,
"You have to specify one input file.\n");
4312 av_log(NULL, AV_LOG_ERROR,
"Use -h to get full help or, even better, run 'man %s'.\n",
program_name);
4313 ret = AVERROR(EINVAL);
4325 av_log(NULL, AV_LOG_ERROR,
"Writing output failed: %s\n", av_err2str(ret));
4327 ret = FFMIN(ret, input_ret);
4339 av_hash_freep(&
hash);
4342 for (i = 0; i < FF_ARRAY_ELEMS(
sections); i++)
4345 avformat_network_deinit();
__thread jmp_buf ex_buf__
int terminate_line[SECTION_MAX_NB_LEVELS]
int has_nested_elems[SECTION_MAX_NB_LEVELS]
int nested_section[SECTION_MAX_NB_LEVELS]
const char *(* escape_str)(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
int nested_section[SECTION_MAX_NB_LEVELS]
const char * item_start_end
AVClassCategory parent_category
int64_t end
start, end in second/AV_TIME_BASE units
unsigned int nb_section_frame
number of the frame section in case we are in "packets_and_frames" section
unsigned int nb_item[SECTION_MAX_NB_LEVELS]
const struct section * section[SECTION_MAX_NB_LEVELS]
void(* writer_put_str)(WriterContext *wctx, const char *str)
char * string_validation_replacement
char * name
name of this writer instance
void * priv
private data for use by the filter
AVBPrint section_pbuf[SECTION_MAX_NB_LEVELS]
void(* writer_w8)(WriterContext *wctx, int b)
unsigned int nb_section_packet_frame
nb_section_packet or nb_section_frame according if is_packets_and_frames
int level
current level, starting from 0
unsigned int nb_section_packet
number of the packet section in case we are in "packets_and_frames" section
AVIOContext * avio
the I/O context used to write
void(* writer_printf)(WriterContext *wctx, const char *fmt,...)
int nb_sections
number of sections
const struct section * sections
array containing all sections
unsigned int string_validation_utf8_flags
const Writer * writer
the Writer of which this is an instance
void(* print_string)(WriterContext *wctx, const char *, const char *)
int flags
a combination or WRITER_FLAG_*
int priv_size
private size for the writer context
const AVClass * priv_class
private class of the writer, if any
void(* print_integer)(WriterContext *wctx, const char *, long long int)
void(* print_rational)(WriterContext *wctx, AVRational *q, char *sep)
int(* init)(WriterContext *wctx)
void(* print_section_header)(WriterContext *wctx)
void(* print_section_footer)(WriterContext *wctx)
void(* uninit)(WriterContext *wctx)
AVDictionary * entries_to_show
const char * element_name
name of the contained element, if provided
int id
unique id identifying a section
const char * unique_name
unique section name, in case the name is ambiguous
int children_ids[SECTION_MAX_NB_CHILDREN+1]
list of children section IDS, terminated by -1