34 #include "libavutil/ffversion.h"
38 #include "libavformat/avformat.h"
39 #include "libavcodec/avcodec.h"
40 #include "libavutil/avassert.h"
41 #include "libavutil/avstring.h"
42 #include "libavutil/bprint.h"
43 #include "libavutil/display.h"
44 #include "libavutil/hash.h"
45 #include "libavutil/hdr_dynamic_metadata.h"
46 #include "libavutil/mastering_display_metadata.h"
47 #include "libavutil/dovi_meta.h"
48 #include "libavutil/opt.h"
49 #include "libavutil/pixdesc.h"
50 #include "libavutil/spherical.h"
51 #include "libavutil/stereo3d.h"
52 #include "libavutil/dict.h"
53 #include "libavutil/intreadwrite.h"
54 #include "libavutil/libm.h"
55 #include "libavutil/parseutils.h"
56 #include "libavutil/timecode.h"
57 #include "libavutil/timestamp.h"
58 #include "libavdevice/avdevice.h"
59 #include "libswscale/swscale.h"
60 #include "libswresample/swresample.h"
63 #include "libavutil/thread.h"
68 # ifdef pthread_mutex_lock
69 # undef pthread_mutex_lock
71 # define pthread_mutex_lock(a) do{}while(0)
72 # ifdef pthread_mutex_unlock
73 # undef pthread_mutex_unlock
75 # define pthread_mutex_unlock(a) do{}while(0)
142 #define SECTION_MAX_NB_CHILDREN 10
148 #define SECTION_FLAG_IS_WRAPPER 1
149 #define SECTION_FLAG_IS_ARRAY 2
150 #define SECTION_FLAG_HAS_VARIABLE_FIELDS 4
265 __thread
struct AVHashContext *
hash;
270 static const struct {
276 { 1.0, 1.0,
"",
"" },
277 { 1.024e3, 1e3,
"Ki",
"K" },
278 { 1.048576e6, 1e6,
"Mi",
"M" },
279 { 1.073741824e9, 1e9,
"Gi",
"G" },
280 { 1.099511627776e12, 1e12,
"Ti",
"T" },
281 { 1.125899906842624e15, 1e15,
"Pi",
"P" },
295 __thread pthread_mutex_t log_mutex;
309 static void log_callback(
void *ptr,
int level,
const char *fmt, va_list vl)
311 AVClass* avc = ptr ? *(AVClass **) ptr : NULL;
314 static int print_prefix = 1;
315 void *new_log_buffer;
318 av_log_default_callback(ptr, level, fmt, vl);
319 av_log_format_line(ptr, level, fmt, vl2, line,
sizeof(line), &print_prefix);
326 if (new_log_buffer) {
339 for (i=strlen(msg) - 1; i>=0 && msg[i] ==
'\n'; i--) {
342 if (avc && avc->parent_log_context_offset) {
343 AVClass** parent = *(AVClass ***) (((uint8_t *) ptr) +
344 avc->parent_log_context_offset);
345 if (parent && *parent) {
348 (*parent)->get_category ? (*parent)->get_category(parent) :(*parent)->category;
361 for (i = 0; i < FF_ARRAY_ELEMS(
sections); i++)
362 av_dict_free(&(
sections[i].entries_to_show));
365 pthread_mutex_destroy(&log_mutex);
370 union {
double d;
long long int i; }
val;
384 vald = vali = uv.
val.
i;
391 mins = (
int)secs / 60;
392 secs = secs - mins * 60;
395 snprintf(buf, buf_size,
"%d:%02d:%09.6f", hours, mins, secs);
397 const char *prefix_string =
"";
403 index = (
long long int) (log2(vald)) / 10;
404 index = av_clip(index, 0, FF_ARRAY_ELEMS(
si_prefixes) - 1);
408 index = (
long long int) (log10(vald)) / 3;
409 index = av_clip(index, 0, FF_ARRAY_ELEMS(
si_prefixes) - 1);
417 snprintf(buf, buf_size,
"%f", vald);
419 snprintf(buf, buf_size,
"%lld", vali);
420 av_strlcatf(buf, buf_size,
"%s%s%s", *prefix_string ||
show_value_unit ?
" " :
"",
431 #define WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS 1
432 #define WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER 2
457 #define SECTION_MAX_NB_LEVELS 10
460 const AVClass *
class;
493 #define OFFSET(x) offsetof(WriterContext, x)
496 {
"string_validation",
"set string validation mode",
498 {
"sv",
"set string validation mode",
503 {
"string_validation_replacement",
"set string validation replacement string",
OFFSET(string_validation_replacement), AV_OPT_TYPE_STRING, {.str=
""}},
504 {
"svr",
"set string validation replacement string",
OFFSET(string_validation_replacement), AV_OPT_TYPE_STRING, {.str=
"\xEF\xBF\xBD"}},
517 .class_name =
"Writer",
520 .version = LIBAVUTIL_VERSION_INT,
531 if ((*wctx)->writer->uninit)
532 (*wctx)->writer->uninit(*wctx);
534 av_bprint_finalize(&(*wctx)->section_pbuf[i], NULL);
535 if ((*wctx)->writer->priv_class)
536 av_opt_free((*wctx)->priv);
537 av_freep(&((*wctx)->priv));
542 static void bprint_bytes(AVBPrint *bp,
const uint8_t *ubuf,
size_t ubuf_size)
545 av_bprintf(bp,
"0X");
546 for (i = 0; i < ubuf_size; i++)
547 av_bprintf(bp,
"%02X", ubuf[i]);
557 ret = AVERROR(ENOMEM);
561 if (!((*wctx)->priv = av_mallocz(writer->
priv_size))) {
562 ret = AVERROR(ENOMEM);
567 (*wctx)->writer = writer;
570 (*wctx)->nb_sections = nb_sections;
572 av_opt_set_defaults(*wctx);
575 void *priv_ctx = (*wctx)->priv;
576 *((
const AVClass **)priv_ctx) = writer->
priv_class;
577 av_opt_set_defaults(priv_ctx);
582 AVDictionary *opts = NULL;
583 AVDictionaryEntry *opt = NULL;
585 if ((ret = av_dict_parse_string(&opts, args,
"=",
":", 0)) < 0) {
586 av_log(*wctx, AV_LOG_ERROR,
"Failed to parse option string '%s' provided to writer context\n", args);
591 while ((opt = av_dict_get(opts,
"", opt, AV_DICT_IGNORE_SUFFIX))) {
592 if ((ret = av_opt_set(*wctx, opt->key, opt->value, AV_OPT_SEARCH_CHILDREN)) < 0) {
593 av_log(*wctx, AV_LOG_ERROR,
"Failed to set option '%s' with value '%s' provided to writer context\n",
594 opt->key, opt->value);
605 const uint8_t *p = (*wctx)->string_validation_replacement;
606 const uint8_t *endp = p + strlen(p);
608 const uint8_t *p0 = p;
610 ret = av_utf8_decode(&code, &p, endp, (*wctx)->string_validation_utf8_flags);
613 av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
615 av_log(wctx, AV_LOG_ERROR,
616 "Invalid UTF8 sequence %s found in string validation replace '%s'\n",
624 av_bprint_init(&(*wctx)->section_pbuf[i], 1, AV_BPRINT_SIZE_UNLIMITED);
626 if ((*wctx)->writer->init)
627 ret = (*wctx)->writer->init(*wctx);
641 int parent_section_id;
644 parent_section_id = wctx->
level ?
665 int parent_section_id = wctx->
level ?
680 const char *key,
long long int val)
692 const uint8_t *p, *endp;
694 int invalid_chars_nb = 0, ret = 0;
696 av_bprint_init(&dstbuf, 0, AV_BPRINT_SIZE_UNLIMITED);
698 endp = src + strlen(src);
699 for (p = (uint8_t *)src; *p;) {
702 const uint8_t *p0 = p;
706 av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
708 av_log(wctx, AV_LOG_DEBUG,
709 "Invalid UTF-8 sequence %s found in string '%s'\n", bp.str, src);
718 av_log(wctx, AV_LOG_ERROR,
719 "Invalid UTF-8 sequence found in string '%s'\n", src);
720 ret = AVERROR_INVALIDDATA;
731 av_bprint_append_data(&dstbuf, p0, p-p0);
735 av_log(wctx, AV_LOG_WARNING,
736 "%d invalid UTF-8 sequence(s) found in string '%s', replaced with '%s'\n",
741 av_bprint_finalize(&dstbuf, dstp);
745 #define PRINT_STRING_OPT 1
746 #define PRINT_STRING_VALIDATE 2
749 const char *key,
const char *val,
int flags)
760 char *key1 = NULL, *val1 = NULL;
762 if (ret < 0)
goto end;
764 if (ret < 0)
goto end;
768 av_log(wctx, AV_LOG_ERROR,
769 "Invalid key=value string combination %s=%s in section %s\n",
785 const char *key, AVRational q,
char sep)
788 av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC);
789 av_bprintf(&buf,
"%d%c%d", q.num, sep, q.den);
794 int64_t ts,
const AVRational *time_base,
int is_duration)
798 if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
801 double d = ts * av_q2d(*time_base);
812 if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
820 uint8_t *data,
int size)
823 int offset = 0, l,
i;
825 av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
826 av_bprintf(&bp,
"\n");
828 av_bprintf(&bp,
"%08x: ", offset);
830 for (
i = 0;
i < l;
i++) {
831 av_bprintf(&bp,
"%02x", data[
i]);
833 av_bprintf(&bp,
" ");
835 av_bprint_chars(&bp,
' ', 41 - 2 *
i -
i / 2);
836 for (
i = 0;
i < l;
i++)
837 av_bprint_chars(&bp, data[
i] - 32U < 95 ? data[
i] :
'.', 1);
838 av_bprintf(&bp,
"\n");
844 av_bprint_finalize(&bp, NULL);
848 uint8_t *data,
int size)
850 char *p, buf[AV_HASH_MAX_SIZE * 2 + 64] = { 0 };
855 av_hash_update(
hash, data, size);
856 snprintf(buf,
sizeof(buf),
"%s:", av_hash_get_name(
hash));
857 p = buf + strlen(buf);
858 av_hash_final_hex(
hash, p, buf +
sizeof(buf) - p);
863 uint8_t *data,
int size,
const char *format,
864 int columns,
int bytes,
int offset_add)
867 int offset = 0, l,
i;
869 av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
870 av_bprintf(&bp,
"\n");
872 av_bprintf(&bp,
"%08x: ", offset);
873 l = FFMIN(size, columns);
874 for (
i = 0;
i < l;
i++) {
875 if (bytes == 1) av_bprintf(&bp, format, *data);
876 else if (bytes == 2) av_bprintf(&bp, format, AV_RN16(data));
877 else if (bytes == 4) av_bprintf(&bp, format, AV_RN32(data));
881 av_bprintf(&bp,
"\n");
882 offset += offset_add;
885 av_bprint_finalize(&bp, NULL);
888 #define MAX_REGISTERED_WRITERS_NB 64
897 return AVERROR(ENOMEM);
917 #define DEFINE_WRITER_CLASS(name) \
918 static const char *name##_get_name(void *ctx) \
922 static const AVClass name##_class = { \
923 .class_name = #name, \
924 .item_name = name##_get_name, \
925 .option = name##_options \
931 const AVClass *
class;
938 #define OFFSET(x) offsetof(DefaultContext, x)
941 {
"noprint_wrappers",
"do not print headers and footers",
OFFSET(noprint_wrappers), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
942 {
"nw",
"do not print headers and footers",
OFFSET(noprint_wrappers), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
943 {
"nokey",
"force no key printing",
OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
944 {
"nk",
"force no key printing",
OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
951 static inline char *
upcase_string(
char *dst,
size_t dst_size,
const char *src)
954 for (i = 0; src[i] && i < dst_size-1; i++)
955 dst[i] = av_toupper(src[i]);
969 if (parent_section &&
1024 .priv_class = &default_class,
1032 static const char *
c_escape_str(AVBPrint *dst,
const char *src,
const char sep,
void *log_ctx)
1036 for (p = src; *p; p++) {
1038 case '\b': av_bprintf(dst,
"%s",
"\\b");
break;
1039 case '\f': av_bprintf(dst,
"%s",
"\\f");
break;
1040 case '\n': av_bprintf(dst,
"%s",
"\\n");
break;
1041 case '\r': av_bprintf(dst,
"%s",
"\\r");
break;
1042 case '\\': av_bprintf(dst,
"%s",
"\\\\");
break;
1045 av_bprint_chars(dst,
'\\', 1);
1046 av_bprint_chars(dst, *p, 1);
1055 static const char *
csv_escape_str(AVBPrint *dst,
const char *src,
const char sep,
void *log_ctx)
1057 char meta_chars[] = { sep,
'"',
'\n',
'\r',
'\0' };
1058 int needs_quoting = !!src[strcspn(src, meta_chars)];
1061 av_bprint_chars(dst,
'"', 1);
1063 for (; *src; src++) {
1065 av_bprint_chars(dst,
'"', 1);
1066 av_bprint_chars(dst, *src, 1);
1069 av_bprint_chars(dst,
'"', 1);
1073 static const char *
none_escape_str(AVBPrint *dst,
const char *src,
const char sep,
void *log_ctx)
1079 const AVClass *
class;
1085 const char * (*escape_str)(AVBPrint *dst,
const char *src,
const char sep,
void *log_ctx);
1092 #define OFFSET(x) offsetof(CompactContext, x)
1095 {
"item_sep",
"set item separator",
OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=
"|"}, 0, 0 },
1096 {
"s",
"set item separator",
OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=
"|"}, 0, 0 },
1097 {
"nokey",
"force no key printing",
OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1098 {
"nk",
"force no key printing",
OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1099 {
"escape",
"set escape mode",
OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str=
"c"}, 0, 0 },
1100 {
"e",
"set escape mode",
OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str=
"c"}, 0, 0 },
1101 {
"print_section",
"print section name",
OFFSET(
print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1113 av_log(wctx, AV_LOG_ERROR,
"Item separator '%s' specified, but must contain a single character\n",
1115 return AVERROR(EINVAL);
1123 av_log(wctx, AV_LOG_ERROR,
"Unknown escape mode '%s'\n", compact->
escape_mode_str);
1124 return AVERROR(EINVAL);
1176 if (!compact->
nokey)
1178 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1180 av_bprint_finalize(&buf, NULL);
1188 if (!compact->
nokey)
1202 .priv_class = &compact_class,
1208 #define OFFSET(x) offsetof(CompactContext, x)
1211 {
"item_sep",
"set item separator",
OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=
","}, 0, 0 },
1212 {
"s",
"set item separator",
OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=
","}, 0, 0 },
1213 {
"nokey",
"force no key printing",
OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1214 {
"nk",
"force no key printing",
OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1215 {
"escape",
"set escape mode",
OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str=
"csv"}, 0, 0 },
1216 {
"e",
"set escape mode",
OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str=
"csv"}, 0, 0 },
1217 {
"print_section",
"print section name",
OFFSET(
print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1233 .priv_class = &csv_class,
1239 const AVClass *
class;
1246 #define OFFSET(x) offsetof(FlatContext, x)
1249 {
"sep_char",
"set separator",
OFFSET(sep_str), AV_OPT_TYPE_STRING, {.str=
"."}, 0, 0 },
1250 {
"s",
"set separator",
OFFSET(sep_str), AV_OPT_TYPE_STRING, {.str=
"."}, 0, 0 },
1251 {
"hierarchical",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1252 {
"h",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1262 if (strlen(flat->
sep_str) != 1) {
1263 av_log(wctx, AV_LOG_ERROR,
"Item separator '%s' specified, but must contain a single character\n",
1265 return AVERROR(EINVAL);
1276 for (p = src; *p; p++) {
1277 if (!((*p >=
'0' && *p <=
'9') ||
1278 (*p >=
'a' && *p <=
'z') ||
1279 (*p >=
'A' && *p <=
'Z')))
1280 av_bprint_chars(dst,
'_', 1);
1282 av_bprint_chars(dst, *p, 1);
1291 for (p = src; *p; p++) {
1293 case '\n': av_bprintf(dst,
"%s",
"\\n");
break;
1294 case '\r': av_bprintf(dst,
"%s",
"\\r");
break;
1295 case '\\': av_bprintf(dst,
"%s",
"\\\\");
break;
1296 case '"': av_bprintf(dst,
"%s",
"\\\"");
break;
1297 case '`': av_bprintf(dst,
"%s",
"\\`");
break;
1298 case '$': av_bprintf(dst,
"%s",
"\\$");
break;
1299 default: av_bprint_chars(dst, *p, 1);
break;
1314 av_bprint_clear(buf);
1315 if (!parent_section)
1326 av_bprintf(buf,
"%d%s", n, flat->
sep_str);
1342 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1344 av_bprint_clear(&buf);
1346 av_bprint_finalize(&buf, NULL);
1357 .priv_class = &flat_class,
1363 const AVClass *
class;
1368 #define OFFSET(x) offsetof(INIContext, x)
1371 {
"hierarchical",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1372 {
"h",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1383 while ((c = src[i++])) {
1385 case '\b': av_bprintf(dst,
"%s",
"\\b");
break;
1386 case '\f': av_bprintf(dst,
"%s",
"\\f");
break;
1387 case '\n': av_bprintf(dst,
"%s",
"\\n");
break;
1388 case '\r': av_bprintf(dst,
"%s",
"\\r");
break;
1389 case '\t': av_bprintf(dst,
"%s",
"\\t");
break;
1393 case ':' : av_bprint_chars(dst,
'\\', 1);
1395 if ((
unsigned char)c < 32)
1396 av_bprintf(dst,
"\\x00%02x", c & 0xff);
1398 av_bprint_chars(dst, c, 1);
1413 av_bprint_clear(buf);
1414 if (!parent_section) {
1425 av_bprintf(buf,
"%s%s", buf->str[0] ?
"." :
"", wctx->
section[wctx->
level]->
name);
1430 av_bprintf(buf,
".%d", n);
1442 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1444 av_bprint_clear(&buf);
1446 av_bprint_finalize(&buf, NULL);
1461 .priv_class = &ini_class,
1467 const AVClass *
class;
1474 #define OFFSET(x) offsetof(JSONContext, x)
1477 {
"compact",
"enable compact output",
OFFSET(compact), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1478 {
"c",
"enable compact output",
OFFSET(compact), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1496 static const char json_escape[] = {
'"',
'\\',
'\b',
'\f',
'\n',
'\r',
'\t', 0};
1497 static const char json_subst[] = {
'"',
'\\',
'b',
'f',
'n',
'r',
't', 0};
1500 for (p = src; *p; p++) {
1501 char *s = strchr(json_escape, *p);
1503 av_bprint_chars(dst,
'\\', 1);
1504 av_bprint_chars(dst, json_subst[s - json_escape], 1);
1505 }
else if ((
unsigned char)*p < 32) {
1506 av_bprintf(dst,
"\\u00%02x", *p & 0xff);
1508 av_bprint_chars(dst, *p, 1);
1514 #define JSON_INDENT() av_log(NULL, AV_LOG_STDERR, "%*c", json->indent_level * 4, ' ')
1531 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1550 av_bprint_finalize(&buf, NULL);
1559 if (wctx->
level == 0) {
1577 const char *key,
const char *value)
1581 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1583 av_bprint_clear(&buf);
1585 av_bprint_finalize(&buf, NULL);
1613 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1615 av_bprint_finalize(&buf, NULL);
1627 .priv_class = &json_class,
1633 const AVClass *
class;
1641 #define OFFSET(x) offsetof(XMLContext, x)
1644 {
"fully_qualified",
"specify if the output should be fully qualified",
OFFSET(fully_qualified), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1645 {
"q",
"specify if the output should be fully qualified",
OFFSET(fully_qualified), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1646 {
"xsd_strict",
"ensure that the output is XSD compliant",
OFFSET(xsd_strict), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1647 {
"x",
"ensure that the output is XSD compliant",
OFFSET(xsd_strict), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1659 #define CHECK_COMPLIANCE(opt, opt_name) \
1661 av_log(wctx, AV_LOG_ERROR, \
1662 "XSD-compliant output selected but option '%s' was selected, XML output may be non-compliant.\n" \
1663 "You need to disable such option with '-no%s'\n", opt_name, opt_name); \
1664 return AVERROR(EINVAL); \
1671 av_log(wctx, AV_LOG_ERROR,
1672 "Interleaved frames and packets are not allowed in XSD. "
1673 "Select only one between the -show_frames and the -show_packets options.\n");
1674 return AVERROR(EINVAL);
1685 for (p = src; *p; p++) {
1687 case '&' : av_bprintf(dst,
"%s",
"&");
break;
1688 case '<' : av_bprintf(dst,
"%s",
"<");
break;
1689 case '>' : av_bprintf(dst,
"%s",
">");
break;
1690 case '"' : av_bprintf(dst,
"%s",
""");
break;
1691 case '\'': av_bprintf(dst,
"%s",
"'");
break;
1692 default: av_bprint_chars(dst, *p, 1);
1699 #define XML_INDENT() av_log(NULL, AV_LOG_STDERR, "%*c", xml->indent_level * 4, ' ')
1708 if (wctx->
level == 0) {
1709 const char *qual =
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' "
1710 "xmlns:ffprobe='http://www.ffmpeg.org/schema/ffprobe' "
1711 "xsi:schemaLocation='http://www.ffmpeg.org/schema/ffprobe ffprobe.xsd'";
1713 av_log(NULL,
AV_LOG_STDERR,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
1746 if (wctx->
level == 0) {
1766 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1772 av_bprint_clear(&buf);
1780 av_bprint_finalize(&buf, NULL);
1799 .priv_class = &xml_class,
1814 #define print_fmt(k, f, ...) do { \
1815 av_bprint_clear(&pbuf); \
1816 av_bprintf(&pbuf, f, __VA_ARGS__); \
1817 writer_print_string(w, k, pbuf.str, 0); \
1820 #define print_int(k, v) writer_print_integer(w, k, v)
1821 #define print_q(k, v, s) writer_print_rational(w, k, v, s)
1822 #define print_str(k, v) writer_print_string(w, k, v, 0)
1823 #define print_str_opt(k, v) writer_print_string(w, k, v, PRINT_STRING_OPT)
1824 #define print_str_validate(k, v) writer_print_string(w, k, v, PRINT_STRING_VALIDATE)
1825 #define print_time(k, v, tb) writer_print_time(w, k, v, tb, 0)
1826 #define print_ts(k, v) writer_print_ts(w, k, v, 0)
1827 #define print_duration_time(k, v, tb) writer_print_time(w, k, v, tb, 1)
1828 #define print_duration_ts(k, v) writer_print_ts(w, k, v, 1)
1829 #define print_val(k, v, u) do { \
1830 struct unit_value uv; \
1833 writer_print_string(w, k, value_string(val_str, sizeof(val_str), uv), 0); \
1836 #define print_section_header(s) writer_print_section_header(w, s)
1837 #define print_section_footer(s) writer_print_section_footer(w, s)
1839 #define REALLOCZ_ARRAY_STREAM(ptr, cur_n, new_n) \
1841 ret = av_reallocp_array(&(ptr), (new_n), sizeof(*(ptr))); \
1844 memset( (ptr) + (cur_n), 0, ((new_n) - (cur_n)) * sizeof(*(ptr)) ); \
1849 AVDictionaryEntry *tag = NULL;
1856 while ((tag = av_dict_get(tags,
"", tag, AV_DICT_IGNORE_SUFFIX))) {
1869 print_int(
"application version", metadata->application_version);
1870 print_int(
"num_windows", metadata->num_windows);
1871 for (
int n = 1; n < metadata->num_windows; n++) {
1872 const AVHDRPlusColorTransformParams *params = &metadata->params[n];
1873 print_q(
"window_upper_left_corner_x",
1874 params->window_upper_left_corner_x,
'/');
1875 print_q(
"window_upper_left_corner_y",
1876 params->window_upper_left_corner_y,
'/');
1877 print_q(
"window_lower_right_corner_x",
1878 params->window_lower_right_corner_x,
'/');
1879 print_q(
"window_lower_right_corner_y",
1880 params->window_lower_right_corner_y,
'/');
1881 print_q(
"window_upper_left_corner_x",
1882 params->window_upper_left_corner_x,
'/');
1883 print_q(
"window_upper_left_corner_y",
1884 params->window_upper_left_corner_y,
'/');
1886 params->center_of_ellipse_x ) ;
1888 params->center_of_ellipse_y );
1890 params->rotation_angle);
1891 print_int(
"semimajor_axis_internal_ellipse",
1892 params->semimajor_axis_internal_ellipse);
1893 print_int(
"semimajor_axis_external_ellipse",
1894 params->semimajor_axis_external_ellipse);
1895 print_int(
"semiminor_axis_external_ellipse",
1896 params->semiminor_axis_external_ellipse);
1898 params->overlap_process_option);
1900 print_q(
"targeted_system_display_maximum_luminance",
1901 metadata->targeted_system_display_maximum_luminance,
'/');
1902 if (metadata->targeted_system_display_actual_peak_luminance_flag) {
1903 print_int(
"num_rows_targeted_system_display_actual_peak_luminance",
1904 metadata->num_rows_targeted_system_display_actual_peak_luminance);
1905 print_int(
"num_cols_targeted_system_display_actual_peak_luminance",
1906 metadata->num_cols_targeted_system_display_actual_peak_luminance);
1907 for (
int i = 0; i < metadata->num_rows_targeted_system_display_actual_peak_luminance; i++) {
1908 for (
int j = 0; j < metadata->num_cols_targeted_system_display_actual_peak_luminance; j++) {
1909 print_q(
"targeted_system_display_actual_peak_luminance",
1910 metadata->targeted_system_display_actual_peak_luminance[i][j],
'/');
1914 for (
int n = 0; n < metadata->num_windows; n++) {
1915 const AVHDRPlusColorTransformParams *params = &metadata->params[n];
1916 for (
int i = 0; i < 3; i++) {
1917 print_q(
"maxscl",params->maxscl[i],
'/');
1920 params->average_maxrgb,
'/');
1921 print_int(
"num_distribution_maxrgb_percentiles",
1922 params->num_distribution_maxrgb_percentiles);
1923 for (
int i = 0; i < params->num_distribution_maxrgb_percentiles; i++) {
1924 print_int(
"distribution_maxrgb_percentage",
1925 params->distribution_maxrgb[i].percentage);
1926 print_q(
"distribution_maxrgb_percentile",
1927 params->distribution_maxrgb[i].percentile,
'/');
1929 print_q(
"fraction_bright_pixels",
1930 params->fraction_bright_pixels,
'/');
1932 if (metadata->mastering_display_actual_peak_luminance_flag) {
1933 print_int(
"num_rows_mastering_display_actual_peak_luminance",
1934 metadata->num_rows_mastering_display_actual_peak_luminance);
1935 print_int(
"num_cols_mastering_display_actual_peak_luminance",
1936 metadata->num_cols_mastering_display_actual_peak_luminance);
1937 for (
int i = 0; i < metadata->num_rows_mastering_display_actual_peak_luminance; i++) {
1938 for (
int j = 0; j < metadata->num_cols_mastering_display_actual_peak_luminance; j++) {
1939 print_q(
"mastering_display_actual_peak_luminance",
1940 metadata->mastering_display_actual_peak_luminance[i][j],
'/');
1945 for (
int n = 0; n < metadata->num_windows; n++) {
1946 const AVHDRPlusColorTransformParams *params = &metadata->params[n];
1947 if (params->tone_mapping_flag) {
1948 print_q(
"knee_point_x", params->knee_point_x,
'/');
1949 print_q(
"knee_point_y", params->knee_point_y,
'/');
1951 params->num_bezier_curve_anchors );
1952 for (
int i = 0; i < params->num_bezier_curve_anchors; i++) {
1953 print_q(
"bezier_curve_anchors",
1954 params->bezier_curve_anchors[i],
'/');
1957 if (params->color_saturation_mapping_flag) {
1958 print_q(
"color_saturation_weight",
1959 params->color_saturation_weight,
'/');
1965 AVCodecParameters *par,
1966 const AVPacketSideData *side_data,
1974 for (i = 0; i < nb_side_data; i++) {
1975 const AVPacketSideData *sd = &side_data[i];
1976 const char *
name = av_packet_side_data_name(sd->type);
1980 if (sd->type == AV_PKT_DATA_DISPLAYMATRIX && sd->size >= 9*4) {
1982 print_int(
"rotation", av_display_rotation_get((int32_t *)sd->data));
1983 }
else if (sd->type == AV_PKT_DATA_STEREO3D) {
1984 const AVStereo3D *stereo = (AVStereo3D *)sd->data;
1985 print_str(
"type", av_stereo3d_type_name(stereo->type));
1986 print_int(
"inverted", !!(stereo->flags & AV_STEREO3D_FLAG_INVERT));
1987 }
else if (sd->type == AV_PKT_DATA_SPHERICAL) {
1988 const AVSphericalMapping *spherical = (AVSphericalMapping *)sd->data;
1989 print_str(
"projection", av_spherical_projection_name(spherical->projection));
1990 if (spherical->projection == AV_SPHERICAL_CUBEMAP) {
1991 print_int(
"padding", spherical->padding);
1992 }
else if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR_TILE) {
1994 av_spherical_tile_bounds(spherical, par->width, par->height,
2002 print_int(
"yaw", (
double) spherical->yaw / (1 << 16));
2003 print_int(
"pitch", (
double) spherical->pitch / (1 << 16));
2004 print_int(
"roll", (
double) spherical->roll / (1 << 16));
2005 }
else if (sd->type == AV_PKT_DATA_SKIP_SAMPLES && sd->size == 10) {
2006 print_int(
"skip_samples", AV_RL32(sd->data));
2007 print_int(
"discard_padding", AV_RL32(sd->data + 4));
2008 print_int(
"skip_reason", AV_RL8(sd->data + 8));
2009 print_int(
"discard_reason", AV_RL8(sd->data + 9));
2010 }
else if (sd->type == AV_PKT_DATA_MASTERING_DISPLAY_METADATA) {
2011 AVMasteringDisplayMetadata *metadata = (AVMasteringDisplayMetadata *)sd->data;
2013 if (metadata->has_primaries) {
2014 print_q(
"red_x", metadata->display_primaries[0][0],
'/');
2015 print_q(
"red_y", metadata->display_primaries[0][1],
'/');
2016 print_q(
"green_x", metadata->display_primaries[1][0],
'/');
2017 print_q(
"green_y", metadata->display_primaries[1][1],
'/');
2018 print_q(
"blue_x", metadata->display_primaries[2][0],
'/');
2019 print_q(
"blue_y", metadata->display_primaries[2][1],
'/');
2021 print_q(
"white_point_x", metadata->white_point[0],
'/');
2022 print_q(
"white_point_y", metadata->white_point[1],
'/');
2025 if (metadata->has_luminance) {
2026 print_q(
"min_luminance", metadata->min_luminance,
'/');
2027 print_q(
"max_luminance", metadata->max_luminance,
'/');
2029 }
else if (sd->type == AV_PKT_DATA_CONTENT_LIGHT_LEVEL) {
2030 AVContentLightMetadata *metadata = (AVContentLightMetadata *)sd->data;
2031 print_int(
"max_content", metadata->MaxCLL);
2032 print_int(
"max_average", metadata->MaxFALL);
2033 }
else if (sd->type == AV_PKT_DATA_DOVI_CONF) {
2034 AVDOVIDecoderConfigurationRecord *dovi = (AVDOVIDecoderConfigurationRecord *)sd->data;
2035 print_int(
"dv_version_major", dovi->dv_version_major);
2036 print_int(
"dv_version_minor", dovi->dv_version_minor);
2037 print_int(
"dv_profile", dovi->dv_profile);
2039 print_int(
"rpu_present_flag", dovi->rpu_present_flag);
2040 print_int(
"el_present_flag", dovi->el_present_flag);
2041 print_int(
"bl_present_flag", dovi->bl_present_flag);
2042 print_int(
"dv_bl_signal_compatibility_id", dovi->dv_bl_signal_compatibility_id);
2051 const char *val = av_color_range_name(color_range);
2052 if (!val || color_range == AVCOL_RANGE_UNSPECIFIED) {
2061 const char *val = av_color_space_name(color_space);
2062 if (!val || color_space == AVCOL_SPC_UNSPECIFIED) {
2071 const char *val = av_color_primaries_name(color_primaries);
2072 if (!val || color_primaries == AVCOL_PRI_UNSPECIFIED) {
2081 const char *val = av_color_transfer_name(color_trc);
2082 if (!val || color_trc == AVCOL_TRC_UNSPECIFIED) {
2091 const char *val = av_chroma_location_name(chroma_location);
2092 if (!val || chroma_location == AVCHROMA_LOC_UNSPECIFIED) {
2154 AVStream *st = ifile->
streams[pkt->stream_index].
st;
2158 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2162 s = av_get_media_type_string(st->codecpar->codec_type);
2165 print_int(
"stream_index", pkt->stream_index);
2167 print_time(
"pts_time", pkt->pts, &st->time_base);
2169 print_time(
"dts_time", pkt->dts, &st->time_base);
2173 print_duration_time(
"convergence_duration_time", pkt->convergence_duration, &st->time_base);
2175 if (pkt->pos != -1)
print_fmt (
"pos",
"%"PRId64, pkt->pos);
2177 print_fmt(
"flags",
"%c%c", pkt->flags & AV_PKT_FLAG_KEY ?
'K' :
'_',
2178 pkt->flags & AV_PKT_FLAG_DISCARD ?
'D' :
'_');
2180 if (pkt->side_data_elems) {
2182 const uint8_t *side_metadata;
2184 side_metadata = av_packet_get_side_data(pkt, AV_PKT_DATA_STRINGS_METADATA, &size);
2186 AVDictionary *dict = NULL;
2187 if (av_packet_unpack_dictionary(side_metadata, size, &dict) >= 0)
2189 av_dict_free(&dict);
2202 av_bprint_finalize(&pbuf, NULL);
2207 AVFormatContext *fmt_ctx)
2211 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2217 print_time(
"pts_time", sub->pts, &AV_TIME_BASE_Q);
2219 print_int (
"start_display_time", sub->start_display_time);
2220 print_int (
"end_display_time", sub->end_display_time);
2221 print_int (
"num_rects", sub->num_rects);
2225 av_bprint_finalize(&pbuf, NULL);
2230 AVFormatContext *fmt_ctx)
2237 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2241 s = av_get_media_type_string(stream->codecpar->codec_type);
2244 print_int(
"stream_index", stream->index);
2245 print_int(
"key_frame", frame->key_frame);
2247 print_time(
"pkt_pts_time", frame->pts, &stream->time_base);
2248 print_ts (
"pkt_dts", frame->pkt_dts);
2249 print_time(
"pkt_dts_time", frame->pkt_dts, &stream->time_base);
2250 print_ts (
"best_effort_timestamp", frame->best_effort_timestamp);
2251 print_time(
"best_effort_timestamp_time", frame->best_effort_timestamp, &stream->time_base);
2254 if (frame->pkt_pos != -1)
print_fmt (
"pkt_pos",
"%"PRId64, frame->pkt_pos);
2259 switch (stream->codecpar->codec_type) {
2262 case AVMEDIA_TYPE_VIDEO:
2265 s = av_get_pix_fmt_name(frame->format);
2268 sar = av_guess_sample_aspect_ratio(fmt_ctx, stream, frame);
2270 print_q(
"sample_aspect_ratio", sar,
':');
2274 print_fmt(
"pict_type",
"%c", av_get_picture_type_char(frame->pict_type));
2275 print_int(
"coded_picture_number", frame->coded_picture_number);
2276 print_int(
"display_picture_number", frame->display_picture_number);
2277 print_int(
"interlaced_frame", frame->interlaced_frame);
2278 print_int(
"top_field_first", frame->top_field_first);
2279 print_int(
"repeat_pict", frame->repeat_pict);
2288 case AVMEDIA_TYPE_AUDIO:
2289 s = av_get_sample_fmt_name(frame->format);
2292 print_int(
"nb_samples", frame->nb_samples);
2294 if (frame->channel_layout) {
2295 av_bprint_clear(&pbuf);
2296 av_bprint_channel_layout(&pbuf, frame->channels,
2297 frame->channel_layout);
2307 if (frame->nb_side_data) {
2309 for (i = 0; i < frame->nb_side_data; i++) {
2310 AVFrameSideData *sd = frame->side_data[i];
2314 name = av_frame_side_data_name(sd->type);
2316 if (sd->type == AV_FRAME_DATA_DISPLAYMATRIX && sd->size >= 9*4) {
2318 print_int(
"rotation", av_display_rotation_get((int32_t *)sd->data));
2319 }
else if (sd->type == AV_FRAME_DATA_GOP_TIMECODE && sd->size >= 8) {
2320 char tcbuf[AV_TIMECODE_STR_SIZE];
2321 av_timecode_make_mpeg_tc_string(tcbuf, *(int64_t *)(sd->data));
2323 }
else if (sd->type == AV_FRAME_DATA_S12M_TIMECODE && sd->size == 16) {
2324 uint32_t *tc = (uint32_t*)sd->data;
2325 int m = FFMIN(tc[0],3);
2327 for (
int j = 1; j <= m ; j++) {
2328 char tcbuf[AV_TIMECODE_STR_SIZE];
2329 av_timecode_make_smpte_tc_string2(tcbuf, stream->avg_frame_rate, tc[j], 0, 0);
2335 }
else if (sd->type == AV_FRAME_DATA_MASTERING_DISPLAY_METADATA) {
2336 AVMasteringDisplayMetadata *metadata = (AVMasteringDisplayMetadata *)sd->data;
2338 if (metadata->has_primaries) {
2339 print_q(
"red_x", metadata->display_primaries[0][0],
'/');
2340 print_q(
"red_y", metadata->display_primaries[0][1],
'/');
2341 print_q(
"green_x", metadata->display_primaries[1][0],
'/');
2342 print_q(
"green_y", metadata->display_primaries[1][1],
'/');
2343 print_q(
"blue_x", metadata->display_primaries[2][0],
'/');
2344 print_q(
"blue_y", metadata->display_primaries[2][1],
'/');
2346 print_q(
"white_point_x", metadata->white_point[0],
'/');
2347 print_q(
"white_point_y", metadata->white_point[1],
'/');
2350 if (metadata->has_luminance) {
2351 print_q(
"min_luminance", metadata->min_luminance,
'/');
2352 print_q(
"max_luminance", metadata->max_luminance,
'/');
2354 }
else if (sd->type == AV_FRAME_DATA_DYNAMIC_HDR_PLUS) {
2355 AVDynamicHDRPlus *metadata = (AVDynamicHDRPlus *)sd->data;
2357 }
else if (sd->type == AV_FRAME_DATA_CONTENT_LIGHT_LEVEL) {
2358 AVContentLightMetadata *metadata = (AVContentLightMetadata *)sd->data;
2359 print_int(
"max_content", metadata->MaxCLL);
2360 print_int(
"max_average", metadata->MaxFALL);
2361 }
else if (sd->type == AV_FRAME_DATA_ICC_PROFILE) {
2362 AVDictionaryEntry *tag = av_dict_get(sd->metadata,
"name", NULL, AV_DICT_MATCH_CASE);
2374 av_bprint_finalize(&pbuf, NULL);
2380 AVFrame *frame, AVPacket *pkt,
2383 AVFormatContext *fmt_ctx = ifile->
fmt_ctx;
2384 AVCodecContext *dec_ctx = ifile->
streams[pkt->stream_index].
dec_ctx;
2385 AVCodecParameters *par = ifile->
streams[pkt->stream_index].
st->codecpar;
2387 int ret = 0, got_frame = 0;
2390 if (dec_ctx && dec_ctx->codec) {
2391 switch (par->codec_type) {
2392 case AVMEDIA_TYPE_VIDEO:
2393 case AVMEDIA_TYPE_AUDIO:
2395 ret = avcodec_send_packet(dec_ctx, pkt);
2396 if (ret == AVERROR(EAGAIN)) {
2398 }
else if (ret >= 0 || ret == AVERROR_EOF) {
2404 ret = avcodec_receive_frame(dec_ctx, frame);
2407 }
else if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
2413 case AVMEDIA_TYPE_SUBTITLE:
2415 ret = avcodec_decode_subtitle2(dec_ctx, &sub, &got_frame, pkt);
2428 int is_sub = (par->codec_type == AVMEDIA_TYPE_SUBTITLE);
2438 avsubtitle_free(&sub);
2441 return got_frame || *packet_new;
2446 av_log(log_ctx, log_level,
"id:%d", interval->
id);
2449 av_log(log_ctx, log_level,
" start:%s%s", interval->
start_is_offset ?
"+" :
"",
2450 av_ts2timestr(interval->
start, &AV_TIME_BASE_Q));
2452 av_log(log_ctx, log_level,
" start:N/A");
2456 av_log(log_ctx, log_level,
" end:%s", interval->
end_is_offset ?
"+" :
"");
2458 av_log(log_ctx, log_level,
"#%"PRId64, interval->
end);
2460 av_log(log_ctx, log_level,
"%s", av_ts2timestr(interval->
end, &AV_TIME_BASE_Q));
2462 av_log(log_ctx, log_level,
" end:N/A");
2465 av_log(log_ctx, log_level,
"\n");
2471 AVFormatContext *fmt_ctx = ifile->
fmt_ctx;
2473 AVFrame *frame = NULL;
2474 int ret = 0, i = 0, frame_count = 0;
2475 int64_t start = -INT64_MAX, end = interval->
end;
2478 av_init_packet(&pkt);
2480 av_log(NULL, AV_LOG_VERBOSE,
"Processing read interval ");
2486 if (*cur_ts == AV_NOPTS_VALUE) {
2487 av_log(NULL, AV_LOG_ERROR,
2488 "Could not seek to relative position since current "
2489 "timestamp is not defined\n");
2490 ret = AVERROR(EINVAL);
2493 target = *cur_ts + interval->
start;
2495 target = interval->
start;
2498 av_log(NULL, AV_LOG_VERBOSE,
"Seeking to read interval start point %s\n",
2499 av_ts2timestr(target, &AV_TIME_BASE_Q));
2500 if ((ret = avformat_seek_file(fmt_ctx, -1, -INT64_MAX, target, INT64_MAX, 0)) < 0) {
2501 av_log(NULL, AV_LOG_ERROR,
"Could not seek to position %"PRId64
": %s\n",
2502 interval->
start, av_err2str(ret));
2507 frame = av_frame_alloc();
2509 ret = AVERROR(ENOMEM);
2512 while (!av_read_frame(fmt_ctx, &pkt)) {
2520 AVRational tb = ifile->
streams[pkt.stream_index].
st->time_base;
2522 if (pkt.pts != AV_NOPTS_VALUE)
2523 *cur_ts = av_rescale_q(pkt.pts, tb, AV_TIME_BASE_Q);
2525 if (!has_start && *cur_ts != AV_NOPTS_VALUE) {
2531 end = start + interval->
end;
2536 if (frame_count >= interval->
end)
2538 }
else if (has_end && *cur_ts != AV_NOPTS_VALUE && *cur_ts >= end) {
2550 while (
process_frame(w, ifile, frame, &pkt, &packet_new) > 0);
2553 av_packet_unref(&pkt);
2555 av_packet_unref(&pkt);
2557 for (i = 0; i < fmt_ctx->nb_streams; i++) {
2558 pkt.stream_index = i;
2560 while (
process_frame(w, ifile, frame, &pkt, &(
int){1}) > 0);
2564 av_frame_free(&frame);
2566 av_log(NULL, AV_LOG_ERROR,
"Could not read packets in interval ");
2574 AVFormatContext *fmt_ctx = ifile->
fmt_ctx;
2576 int64_t cur_ts = fmt_ctx->start_time;
2594 AVStream *stream = ist->
st;
2595 AVCodecParameters *par;
2596 AVCodecContext *dec_ctx;
2599 AVRational sar, dar;
2601 const AVCodecDescriptor *cd;
2603 const char *profile = NULL;
2605 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2611 par = stream->codecpar;
2613 if ((cd = avcodec_descriptor_get(par->codec_id))) {
2617 cd->long_name ? cd->long_name :
"unknown");
2626 if (!
do_bitexact && (profile = avcodec_profile_name(par->codec_id, par->profile)))
2629 if (par->profile != FF_PROFILE_UNKNOWN) {
2630 char profile_num[12];
2631 snprintf(profile_num,
sizeof(profile_num),
"%d", par->profile);
2637 s = av_get_media_type_string(par->codec_type);
2640 #if FF_API_LAVF_AVCTX
2642 print_q(
"codec_time_base", dec_ctx->time_base,
'/');
2646 print_str(
"codec_tag_string", av_fourcc2str(par->codec_tag));
2647 print_fmt(
"codec_tag",
"0x%04"PRIx32, par->codec_tag);
2649 switch (par->codec_type) {
2650 case AVMEDIA_TYPE_VIDEO:
2653 #if FF_API_LAVF_AVCTX
2655 print_int(
"coded_width", dec_ctx->coded_width);
2656 print_int(
"coded_height", dec_ctx->coded_height);
2657 print_int(
"closed_captions", !!(dec_ctx->properties & FF_CODEC_PROPERTY_CLOSED_CAPTIONS));
2660 print_int(
"has_b_frames", par->video_delay);
2661 sar = av_guess_sample_aspect_ratio(fmt_ctx, stream, NULL);
2663 print_q(
"sample_aspect_ratio", sar,
':');
2664 av_reduce(&dar.num, &dar.den,
2665 par->width * sar.num,
2666 par->height * sar.den,
2668 print_q(
"display_aspect_ratio", dar,
':');
2673 s = av_get_pix_fmt_name(par->format);
2684 if (par->field_order == AV_FIELD_PROGRESSIVE)
2685 print_str(
"field_order",
"progressive");
2686 else if (par->field_order == AV_FIELD_TT)
2688 else if (par->field_order == AV_FIELD_BB)
2690 else if (par->field_order == AV_FIELD_TB)
2692 else if (par->field_order == AV_FIELD_BT)
2697 #if FF_API_PRIVATE_OPT
2698 if (dec_ctx && dec_ctx->timecode_frame_start >= 0) {
2699 char tcbuf[AV_TIMECODE_STR_SIZE];
2700 av_timecode_make_mpeg_tc_string(tcbuf, dec_ctx->timecode_frame_start);
2710 case AVMEDIA_TYPE_AUDIO:
2711 s = av_get_sample_fmt_name(par->format);
2717 if (par->channel_layout) {
2718 av_bprint_clear(&pbuf);
2719 av_bprint_channel_layout(&pbuf, par->channels, par->channel_layout);
2725 print_int(
"bits_per_sample", av_get_bits_per_sample(par->codec_id));
2728 case AVMEDIA_TYPE_SUBTITLE:
2740 if (dec_ctx && dec_ctx->codec && dec_ctx->codec->priv_class &&
show_private_data) {
2741 const AVOption *opt = NULL;
2742 while ((opt = av_opt_next(dec_ctx->priv_data,opt))) {
2744 if (opt->flags)
continue;
2745 if (av_opt_get(dec_ctx->priv_data, opt->name, 0, &str) >= 0) {
2752 if (fmt_ctx->iformat->flags & AVFMT_SHOW_IDS)
print_fmt (
"id",
"0x%x", stream->id);
2754 print_q(
"r_frame_rate", stream->r_frame_rate,
'/');
2755 print_q(
"avg_frame_rate", stream->avg_frame_rate,
'/');
2756 print_q(
"time_base", stream->time_base,
'/');
2757 print_ts (
"start_pts", stream->start_time);
2758 print_time(
"start_time", stream->start_time, &stream->time_base);
2759 print_ts (
"duration_ts", stream->duration);
2760 print_time(
"duration", stream->duration, &stream->time_base);
2763 #if FF_API_LAVF_AVCTX
2767 if (dec_ctx && dec_ctx->bits_per_raw_sample > 0)
print_fmt(
"bits_per_raw_sample",
"%d", dec_ctx->bits_per_raw_sample);
2769 if (stream->nb_frames)
print_fmt (
"nb_frames",
"%"PRId64, stream->nb_frames);
2777 par->extradata_size);
2779 par->extradata_size);
2782 #define PRINT_DISPOSITION(flagname, name) do { \
2783 print_int(name, !!(stream->disposition & AV_DISPOSITION_##flagname)); \
2806 if (stream->nb_side_data) {
2813 av_bprint_finalize(&pbuf, NULL);
2821 AVFormatContext *fmt_ctx = ifile->
fmt_ctx;
2838 AVFormatContext *fmt_ctx = ifile->
fmt_ctx;
2843 print_int(
"program_num", program->program_num);
2844 print_int(
"nb_streams", program->nb_stream_indexes);
2847 print_ts(
"start_pts", program->start_time);
2848 print_time(
"start_time", program->start_time, &AV_TIME_BASE_Q);
2849 print_ts(
"end_pts", program->end_time);
2850 print_time(
"end_time", program->end_time, &AV_TIME_BASE_Q);
2857 for (i = 0; i < program->nb_stream_indexes; i++) {
2859 ret =
show_stream(w, fmt_ctx, program->stream_index[i], &ifile->
streams[program->stream_index[i]], 1);
2873 AVFormatContext *fmt_ctx = ifile->
fmt_ctx;
2877 for (i = 0; i < fmt_ctx->nb_programs; i++) {
2878 AVProgram *program = fmt_ctx->programs[i];
2891 AVFormatContext *fmt_ctx = ifile->
fmt_ctx;
2895 for (i = 0; i < fmt_ctx->nb_chapters; i++) {
2896 AVChapter *chapter = fmt_ctx->chapters[i];
2900 print_q (
"time_base", chapter->time_base,
'/');
2902 print_time(
"start_time", chapter->start, &chapter->time_base);
2904 print_time(
"end_time", chapter->end, &chapter->time_base);
2916 AVFormatContext *fmt_ctx = ifile->
fmt_ctx;
2918 int64_t size = fmt_ctx->pb ? avio_size(fmt_ctx->pb) : -1;
2923 print_int(
"nb_streams", fmt_ctx->nb_streams);
2924 print_int(
"nb_programs", fmt_ctx->nb_programs);
2925 print_str(
"format_name", fmt_ctx->iformat->name);
2927 if (fmt_ctx->iformat->long_name)
print_str (
"format_long_name", fmt_ctx->iformat->long_name);
2930 print_time(
"start_time", fmt_ctx->start_time, &AV_TIME_BASE_Q);
2931 print_time(
"duration", fmt_ctx->duration, &AV_TIME_BASE_Q);
2936 print_int(
"probe_score", fmt_ctx->probe_score);
2948 const char *errbuf_ptr = errbuf;
2950 if (av_strerror(err, errbuf,
sizeof(errbuf)) < 0)
2951 errbuf_ptr = strerror(AVUNERROR(err));
2962 AVFormatContext *fmt_ctx = NULL;
2963 AVDictionaryEntry *t = NULL;
2964 int scan_all_pmts_set = 0;
2966 fmt_ctx = avformat_alloc_context();
2972 if (!av_dict_get(
format_opts,
"scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
2973 av_dict_set(&
format_opts,
"scan_all_pmts",
"1", AV_DICT_DONT_OVERWRITE);
2974 scan_all_pmts_set = 1;
2976 if ((err = avformat_open_input(&fmt_ctx, filename,
2981 if (print_filename) {
2982 av_freep(&fmt_ctx->url);
2983 fmt_ctx->url = av_strdup(print_filename);
2986 if (scan_all_pmts_set)
2987 av_dict_set(&
format_opts,
"scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
2988 while ((t = av_dict_get(
format_opts,
"", t, AV_DICT_IGNORE_SUFFIX)))
2989 av_log(NULL, AV_LOG_WARNING,
"Option %s skipped - not known to demuxer.\n", t->key);
2993 int orig_nb_streams = fmt_ctx->nb_streams;
2995 err = avformat_find_stream_info(fmt_ctx, opts);
2997 for (i = 0; i < orig_nb_streams; i++)
2998 av_dict_free(&opts[i]);
3007 av_dump_format(fmt_ctx, 0, filename, 0);
3009 ifile->
streams = av_mallocz_array(fmt_ctx->nb_streams,
3016 for (i = 0; i < fmt_ctx->nb_streams; i++) {
3018 AVStream *stream = fmt_ctx->streams[i];
3023 if (stream->codecpar->codec_id == AV_CODEC_ID_PROBE) {
3024 av_log(NULL, AV_LOG_WARNING,
3025 "Failed to probe codec for input stream %d\n",
3030 codec = avcodec_find_decoder(stream->codecpar->codec_id);
3032 av_log(NULL, AV_LOG_WARNING,
3033 "Unsupported codec with id %d for input stream %d\n",
3034 stream->codecpar->codec_id, stream->index);
3039 fmt_ctx, stream, codec);
3041 ist->
dec_ctx = avcodec_alloc_context3(codec);
3045 err = avcodec_parameters_to_context(ist->
dec_ctx, stream->codecpar);
3056 ist->
dec_ctx->pkt_timebase = stream->time_base;
3057 ist->
dec_ctx->framerate = stream->avg_frame_rate;
3058 #if FF_API_LAVF_AVCTX
3059 ist->
dec_ctx->properties = stream->codec->properties;
3060 ist->
dec_ctx->coded_width = stream->codec->coded_width;
3061 ist->
dec_ctx->coded_height = stream->codec->coded_height;
3064 if (avcodec_open2(ist->
dec_ctx, codec, &opts) < 0) {
3065 av_log(NULL, AV_LOG_WARNING,
"Could not open codec for input stream %d\n",
3070 if ((t = av_dict_get(opts,
"", NULL, AV_DICT_IGNORE_SUFFIX))) {
3071 av_log(NULL, AV_LOG_ERROR,
"Option %s for input stream %d not found\n",
3072 t->key, stream->index);
3073 return AVERROR_OPTION_NOT_FOUND;
3088 if (ifile->
streams[i].
st->codecpar->codec_id != AV_CODEC_ID_NONE)
3094 avformat_close_input(&ifile->
fmt_ctx);
3098 const char *print_filename)
3111 #define CHECK_END if (ret < 0) goto end
3118 for (i = 0; i < ifile.
fmt_ctx->nb_streams; i++) {
3120 ret = avformat_match_stream_specifier(ifile.
fmt_ctx,
3131 ifile.
fmt_ctx->streams[i]->discard = AVDISCARD_ALL;
3180 av_log(NULL, AV_LOG_INFO,
"Simple multimedia streams analyzer\n");
3181 av_log(NULL, AV_LOG_INFO,
"usage: %s [OPTIONS] [INPUT_FILE]\n",
program_name);
3182 av_log(NULL, AV_LOG_INFO,
"\n");
3188 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
3192 print_fmt(
"copyright",
"Copyright (c) %d-%d the FFmpeg developers",
3195 print_str(
"configuration", FFMPEG_CONFIGURATION);
3198 av_bprint_finalize(&pbuf, NULL);
3201 #define SHOW_LIB_VERSION(libname, LIBNAME) \
3203 if (CONFIG_##LIBNAME) { \
3204 unsigned int version = libname##_version(); \
3205 writer_print_section_header(w, SECTION_ID_LIBRARY_VERSION); \
3206 print_str("name", "lib" #libname); \
3207 print_int("major", LIB##LIBNAME##_VERSION_MAJOR); \
3208 print_int("minor", LIB##LIBNAME##_VERSION_MINOR); \
3209 print_int("micro", LIB##LIBNAME##_VERSION_MICRO); \
3210 print_int("version", version); \
3211 print_str("ident", LIB##LIBNAME##_IDENT); \
3212 writer_print_section_footer(w); \
3229 #define PRINT_PIX_FMT_FLAG(flagname, name) \
3231 print_int(name, !!(pixdesc->flags & AV_PIX_FMT_FLAG_##flagname)); \
3236 const AVPixFmtDescriptor *pixdesc = NULL;
3240 while ((pixdesc = av_pix_fmt_desc_next(pixdesc))) {
3243 print_int(
"nb_components", pixdesc->nb_components);
3244 if ((pixdesc->nb_components >= 3) && !(pixdesc->flags & AV_PIX_FMT_FLAG_RGB)) {
3245 print_int (
"log2_chroma_w", pixdesc->log2_chroma_w);
3246 print_int (
"log2_chroma_h", pixdesc->log2_chroma_h);
3251 n = av_get_bits_per_pixel(pixdesc);
3262 #if FF_API_PSEUDOPAL
3270 for (i = 0; i < pixdesc->nb_components; i++) {
3273 print_int(
"bit_depth", pixdesc->comp[i].depth);
3283 static int opt_format(
void *optctx,
const char *opt,
const char *arg)
3285 iformat = av_find_input_format(arg);
3287 av_log(NULL, AV_LOG_ERROR,
"Unknown input format: %s\n", arg);
3288 return AVERROR(EINVAL);
3313 for (i = 0; i < FF_ARRAY_ELEMS(
sections); i++) {
3317 av_log(NULL, AV_LOG_DEBUG,
3318 "'%s' matches section with unique name '%s'\n", section_name,
3329 const char *p = arg;
3333 AVDictionary *entries = NULL;
3334 char *section_name = av_get_token(&p,
"=:");
3337 if (!section_name) {
3338 av_log(NULL, AV_LOG_ERROR,
3339 "Missing section name for option '%s'\n", opt);
3340 return AVERROR(EINVAL);
3345 while (*p && *p !=
':') {
3346 char *entry = av_get_token(&p,
",:");
3349 av_log(NULL, AV_LOG_VERBOSE,
3350 "Adding '%s' to the entries to show in section '%s'\n",
3351 entry, section_name);
3352 av_dict_set(&entries, entry,
"", AV_DICT_DONT_STRDUP_KEY);
3362 av_log(NULL, AV_LOG_ERROR,
"No match for section '%s'\n", section_name);
3363 ret = AVERROR(EINVAL);
3365 av_dict_free(&entries);
3366 av_free(section_name);
3379 char *buf = av_asprintf(
"format=%s", arg);
3383 return AVERROR(ENOMEM);
3385 av_log(NULL, AV_LOG_WARNING,
3386 "Option '%s' is deprecated, use '-show_entries format=%s' instead\n",
3396 av_log(NULL, AV_LOG_ERROR,
3397 "Argument '%s' provided as input filename, but '%s' was already specified.\n",
3401 if (!strcmp(arg,
"-"))
3437 char *next, *p, *spec = av_strdup(interval_spec);
3439 return AVERROR(ENOMEM);
3442 av_log(NULL, AV_LOG_ERROR,
"Invalid empty interval specification\n");
3443 ret = AVERROR(EINVAL);
3448 next = strchr(spec,
'%');
3463 ret = av_parse_time(&interval->
start, p, 1);
3465 av_log(NULL, AV_LOG_ERROR,
"Invalid interval start specification '%s'\n", p);
3490 lli = strtoll(p, &tail, 10);
3491 if (*tail || lli < 0) {
3492 av_log(NULL, AV_LOG_ERROR,
3493 "Invalid or negative value '%s' for duration number of frames\n", p);
3496 interval->
end = lli;
3499 ret = av_parse_time(&us, p, 1);
3501 av_log(NULL, AV_LOG_ERROR,
"Invalid interval end/duration specification '%s'\n", p);
3518 char *p, *spec = av_strdup(intervals_spec);
3520 return AVERROR(ENOMEM);
3523 for (n = 0, p = spec; *p; p++)
3530 ret = AVERROR(ENOMEM);
3537 for (i = 0; p; i++) {
3541 next = strchr(p,
',');
3548 av_log(NULL, AV_LOG_ERROR,
"Error parsing read interval #%d '%s'\n",
3552 av_log(NULL, AV_LOG_VERBOSE,
"Parsed log interval ");
3568 static int opt_pretty(
void *optctx,
const char *opt,
const char *arg)
3597 "W.. = Section is a wrapper (contains other sections, no local entries)\n"
3598 ".A. = Section contains an array of elements of the same type\n"
3599 "..V = Section may contain a variable number of fields with variable keys\n"
3600 "FLAGS NAME/UNIQUE_NAME\n"
3613 #define DEFINE_OPT_SHOW_SECTION(section, target_section_id) \
3614 static int opt_show_##section(void *optctx, const char *opt, const char *arg) \
3616 mark_section_show_entries(SECTION_ID_##target_section_id, 1, NULL); \
3643 #define SET_DO_SHOW(id, varname) do { \
3644 if (check_section_show_entries(SECTION_ID_##id)) \
3645 do_show_##varname = 1; \
3715 char _program_name[] =
"ffprobe";
3734 {
"bsfs",
OPT_EXIT, { .func_arg =
show_bsfs },
"show available bit stream filters" },
3743 {
"report", 0, { .func_arg =
opt_report },
"generate a report" },
3744 {
"max_alloc",
HAS_ARG, { .func_arg =
opt_max_alloc },
"set maximum size of a single allocated block",
"bytes" },
3750 "list sources of the input device",
"device" },
3752 "list sinks of the output device",
"device" },
3759 "use binary prefixes for byte units" },
3761 "use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units" },
3763 "prettify the format of displayed values, make it more human readable" },
3765 "set the output printing format (available formats are: default, compact, csv, flat, ini, json, xml)",
"format" },
3768 {
"sections",
OPT_EXIT, {.func_arg =
opt_sections},
"print sections structure and section information, and exit" },
3771 {
"show_error", 0, { .func_arg = &opt_show_error },
"show probing error" },
3772 {
"show_format", 0, { .func_arg = &opt_show_format },
"show format/container info" },
3773 {
"show_frames", 0, { .func_arg = &opt_show_frames },
"show frames info" },
3775 "show a particular entry from the format/container info",
"entry" },
3777 "show a set of specified entries",
"entry_list" },
3781 {
"show_packets", 0, { .func_arg = &opt_show_packets },
"show packets info" },
3782 {
"show_programs", 0, { .func_arg = &opt_show_programs },
"show programs info" },
3783 {
"show_streams", 0, { .func_arg = &opt_show_streams },
"show streams info" },
3784 {
"show_chapters", 0, { .func_arg = &opt_show_chapters },
"show chapters info" },
3787 {
"show_program_version", 0, { .func_arg = &opt_show_program_version },
"show ffprobe version" },
3788 {
"show_library_versions", 0, { .func_arg = &opt_show_library_versions },
"show library versions" },
3789 {
"show_versions", 0, { .func_arg = &
opt_show_versions },
"show program and library versions" },
3790 {
"show_pixel_formats", 0, { .func_arg = &opt_show_pixel_formats },
"show pixel format descriptions" },
3799 "read and decode the streams to fill missing information with heuristics" },
3806 char *w_name = NULL, *w_args = NULL;
3810 if (savedCode == 0) {
3817 ret = pthread_mutex_init(&log_mutex, NULL);
3822 av_log_set_flags(AV_LOG_SKIP_REPEATED);
3827 avformat_network_init();
3830 avdevice_register_all();
3847 SET_DO_SHOW(PIXEL_FORMAT_FLAGS, pixel_format_flags);
3848 SET_DO_SHOW(PIXEL_FORMAT_COMPONENTS, pixel_format_components);
3852 SET_DO_SHOW(STREAM_DISPOSITION, stream_disposition);
3853 SET_DO_SHOW(PROGRAM_STREAM_DISPOSITION, stream_disposition);
3864 av_log(NULL, AV_LOG_ERROR,
3865 "-bitexact and -show_program_version or -show_library_versions "
3866 "options are incompatible\n");
3867 ret = AVERROR(EINVAL);
3876 ret = AVERROR(ENOMEM);
3881 av_log(NULL, AV_LOG_ERROR,
3882 "No name specified for the output format\n");
3883 ret = AVERROR(EINVAL);
3890 if (ret == AVERROR(EINVAL)) {
3892 av_log(NULL, AV_LOG_ERROR,
3893 "Unknown hash algorithm '%s'\nKnown algorithms:",
3895 for (i = 0; (n = av_hash_names(i)); i++)
3896 av_log(NULL, AV_LOG_ERROR,
" %s", n);
3897 av_log(NULL, AV_LOG_ERROR,
"\n");
3905 av_log(NULL, AV_LOG_ERROR,
"Unknown output format with name '%s'\n", w_name);
3906 ret = AVERROR(EINVAL);
3928 av_log(NULL, AV_LOG_ERROR,
"You have to specify one input file.\n");
3929 av_log(NULL, AV_LOG_ERROR,
"Use -h to get full help or, even better, run 'man %s'.\n",
program_name);
3930 ret = AVERROR(EINVAL);
3950 av_hash_freep(&
hash);
3953 for (i = 0; i < FF_ARRAY_ELEMS(
sections); i++)
3956 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]
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]
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
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
int flags
For these sections the element_name field is mandatory.
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