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/channel_layout.h"
44 #include "libavutil/display.h"
45 #include "libavutil/hash.h"
46 #include "libavutil/hdr_dynamic_metadata.h"
47 #include "libavutil/mastering_display_metadata.h"
48 #include "libavutil/dovi_meta.h"
49 #include "libavutil/opt.h"
50 #include "libavutil/pixdesc.h"
51 #include "libavutil/spherical.h"
52 #include "libavutil/stereo3d.h"
53 #include "libavutil/dict.h"
54 #include "libavutil/intreadwrite.h"
55 #include "libavutil/libm.h"
56 #include "libavutil/parseutils.h"
57 #include "libavutil/timecode.h"
58 #include "libavutil/timestamp.h"
59 #include "libavdevice/avdevice.h"
60 #include "libswscale/swscale.h"
61 #include "libswresample/swresample.h"
64 #include "libavutil/thread.h"
69 # ifdef pthread_mutex_lock
70 # undef pthread_mutex_lock
72 # define pthread_mutex_lock(a) do{}while(0)
73 # ifdef pthread_mutex_unlock
74 # undef pthread_mutex_unlock
76 # define pthread_mutex_unlock(a) do{}while(0)
126 #define SHOW_OPTIONAL_FIELDS_AUTO -1
127 #define SHOW_OPTIONAL_FIELDS_NEVER 0
128 #define SHOW_OPTIONAL_FIELDS_ALWAYS 1
148 #define SECTION_MAX_NB_CHILDREN 10
154 #define SECTION_FLAG_IS_WRAPPER 1
155 #define SECTION_FLAG_IS_ARRAY 2
156 #define SECTION_FLAG_HAS_VARIABLE_FIELDS 4
271 __thread
struct AVHashContext *
hash;
276 static const struct {
282 { 1.0, 1.0,
"",
"" },
283 { 1.024e3, 1e3,
"Ki",
"K" },
284 { 1.048576e6, 1e6,
"Mi",
"M" },
285 { 1.073741824e9, 1e9,
"Gi",
"G" },
286 { 1.099511627776e12, 1e12,
"Ti",
"T" },
287 { 1.125899906842624e15, 1e15,
"Pi",
"P" },
301 __thread pthread_mutex_t log_mutex;
315 static void log_callback(
void *ptr,
int level,
const char *fmt, va_list vl)
317 AVClass* avc = ptr ? *(AVClass **) ptr : NULL;
320 static int print_prefix = 1;
321 void *new_log_buffer;
324 av_log_default_callback(ptr, level, fmt, vl);
325 av_log_format_line(ptr, level, fmt, vl2, line,
sizeof(line), &print_prefix);
332 if (new_log_buffer) {
345 for (i=strlen(msg) - 1; i>=0 && msg[i] ==
'\n'; i--) {
348 if (avc && avc->parent_log_context_offset) {
349 AVClass** parent = *(AVClass ***) (((uint8_t *) ptr) +
350 avc->parent_log_context_offset);
351 if (parent && *parent) {
354 (*parent)->get_category ? (*parent)->get_category(parent) :(*parent)->category;
367 for (i = 0; i < FF_ARRAY_ELEMS(
sections); i++)
368 av_dict_free(&(
sections[i].entries_to_show));
371 pthread_mutex_destroy(&log_mutex);
376 union {
double d;
long long int i; }
val;
390 vald = vali = uv.
val.
i;
397 mins = (
int)secs / 60;
398 secs = secs - mins * 60;
401 snprintf(buf, buf_size,
"%d:%02d:%09.6f", hours, mins, secs);
403 const char *prefix_string =
"";
409 index = (
long long int) (log2(vald)) / 10;
414 index = (
long long int) (log10(vald)) / 3;
423 snprintf(buf, buf_size,
"%f", vald);
425 snprintf(buf, buf_size,
"%lld", vali);
426 av_strlcatf(buf, buf_size,
"%s%s%s", *prefix_string ||
show_value_unit ?
" " :
"",
437 #define WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS 1
438 #define WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER 2
463 #define SECTION_MAX_NB_LEVELS 10
466 const AVClass *
class;
499 #define OFFSET(x) offsetof(WriterContext, x)
502 {
"string_validation",
"set string validation mode",
504 {
"sv",
"set string validation mode",
509 {
"string_validation_replacement",
"set string validation replacement string",
OFFSET(string_validation_replacement), AV_OPT_TYPE_STRING, {.str=
""}},
510 {
"svr",
"set string validation replacement string",
OFFSET(string_validation_replacement), AV_OPT_TYPE_STRING, {.str=
"\xEF\xBF\xBD"}},
523 .class_name =
"Writer",
526 .version = LIBAVUTIL_VERSION_INT,
537 if ((*wctx)->writer->uninit)
538 (*wctx)->writer->uninit(*wctx);
540 av_bprint_finalize(&(*wctx)->section_pbuf[i], NULL);
541 if ((*wctx)->writer->priv_class)
542 av_opt_free((*wctx)->priv);
543 av_freep(&((*wctx)->priv));
548 static void bprint_bytes(AVBPrint *bp,
const uint8_t *ubuf,
size_t ubuf_size)
551 av_bprintf(bp,
"0X");
552 for (i = 0; i < ubuf_size; i++)
553 av_bprintf(bp,
"%02X", ubuf[i]);
563 ret = AVERROR(ENOMEM);
567 if (!((*wctx)->priv = av_mallocz(writer->
priv_size))) {
568 ret = AVERROR(ENOMEM);
573 (*wctx)->writer = writer;
576 (*wctx)->nb_sections = nb_sections;
578 av_opt_set_defaults(*wctx);
581 void *priv_ctx = (*wctx)->priv;
582 *((
const AVClass **)priv_ctx) = writer->
priv_class;
583 av_opt_set_defaults(priv_ctx);
588 AVDictionary *opts = NULL;
589 AVDictionaryEntry *opt = NULL;
591 if ((ret = av_dict_parse_string(&opts, args,
"=",
":", 0)) < 0) {
592 av_log(*wctx, AV_LOG_ERROR,
"Failed to parse option string '%s' provided to writer context\n", args);
597 while ((opt = av_dict_get(opts,
"", opt, AV_DICT_IGNORE_SUFFIX))) {
598 if ((ret = av_opt_set(*wctx, opt->key, opt->value, AV_OPT_SEARCH_CHILDREN)) < 0) {
599 av_log(*wctx, AV_LOG_ERROR,
"Failed to set option '%s' with value '%s' provided to writer context\n",
600 opt->key, opt->value);
611 const uint8_t *p = (*wctx)->string_validation_replacement;
612 const uint8_t *endp = p + strlen(p);
614 const uint8_t *p0 = p;
616 ret = av_utf8_decode(&code, &p, endp, (*wctx)->string_validation_utf8_flags);
619 av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
621 av_log(wctx, AV_LOG_ERROR,
622 "Invalid UTF8 sequence %s found in string validation replace '%s'\n",
630 av_bprint_init(&(*wctx)->section_pbuf[i], 1, AV_BPRINT_SIZE_UNLIMITED);
632 if ((*wctx)->writer->init)
633 ret = (*wctx)->writer->init(*wctx);
647 int parent_section_id;
650 parent_section_id = wctx->
level ?
671 int parent_section_id = wctx->
level ?
686 const char *key,
long long int val)
698 const uint8_t *p, *endp;
700 int invalid_chars_nb = 0, ret = 0;
702 av_bprint_init(&dstbuf, 0, AV_BPRINT_SIZE_UNLIMITED);
704 endp = src + strlen(src);
705 for (p = (uint8_t *)src; *p;) {
708 const uint8_t *p0 = p;
712 av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
714 av_log(wctx, AV_LOG_DEBUG,
715 "Invalid UTF-8 sequence %s found in string '%s'\n", bp.str, src);
724 av_log(wctx, AV_LOG_ERROR,
725 "Invalid UTF-8 sequence found in string '%s'\n", src);
726 ret = AVERROR_INVALIDDATA;
737 av_bprint_append_data(&dstbuf, p0, p-p0);
741 av_log(wctx, AV_LOG_WARNING,
742 "%d invalid UTF-8 sequence(s) found in string '%s', replaced with '%s'\n",
747 av_bprint_finalize(&dstbuf, dstp);
751 #define PRINT_STRING_OPT 1
752 #define PRINT_STRING_VALIDATE 2
755 const char *key,
const char *val,
int flags)
768 char *key1 = NULL, *val1 = NULL;
770 if (ret < 0)
goto end;
772 if (ret < 0)
goto end;
776 av_log(wctx, AV_LOG_ERROR,
777 "Invalid key=value string combination %s=%s in section %s\n",
793 const char *key, AVRational q,
char sep)
796 av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC);
797 av_bprintf(&buf,
"%d%c%d", q.num, sep, q.den);
802 int64_t ts,
const AVRational *time_base,
int is_duration)
806 if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
809 double d = ts * av_q2d(*time_base);
820 if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
828 uint8_t *data,
int size)
831 int offset = 0, l,
i;
833 av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
834 av_bprintf(&bp,
"\n");
836 av_bprintf(&bp,
"%08x: ", offset);
838 for (
i = 0;
i < l;
i++) {
839 av_bprintf(&bp,
"%02x", data[
i]);
841 av_bprintf(&bp,
" ");
843 av_bprint_chars(&bp,
' ', 41 - 2 *
i -
i / 2);
844 for (
i = 0;
i < l;
i++)
845 av_bprint_chars(&bp, data[
i] - 32U < 95 ? data[
i] :
'.', 1);
846 av_bprintf(&bp,
"\n");
852 av_bprint_finalize(&bp, NULL);
856 uint8_t *data,
int size)
858 char *p, buf[AV_HASH_MAX_SIZE * 2 + 64] = { 0 };
863 av_hash_update(
hash, data, size);
864 snprintf(buf,
sizeof(buf),
"%s:", av_hash_get_name(
hash));
865 p = buf + strlen(buf);
866 av_hash_final_hex(
hash, p, buf +
sizeof(buf) - p);
871 uint8_t *data,
int size,
const char *
format,
872 int columns,
int bytes,
int offset_add)
875 int offset = 0, l,
i;
877 av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
878 av_bprintf(&bp,
"\n");
880 av_bprintf(&bp,
"%08x: ", offset);
881 l = FFMIN(size, columns);
882 for (
i = 0;
i < l;
i++) {
883 if (bytes == 1) av_bprintf(&bp,
format, *data);
884 else if (bytes == 2) av_bprintf(&bp,
format, AV_RN16(data));
885 else if (bytes == 4) av_bprintf(&bp,
format, AV_RN32(data));
889 av_bprintf(&bp,
"\n");
890 offset += offset_add;
893 av_bprint_finalize(&bp, NULL);
896 #define MAX_REGISTERED_WRITERS_NB 64
905 return AVERROR(ENOMEM);
925 #define DEFINE_WRITER_CLASS(name) \
926 static const char *name##_get_name(void *ctx) \
930 static const AVClass name##_class = { \
931 .class_name = #name, \
932 .item_name = name##_get_name, \
933 .option = name##_options \
939 const AVClass *
class;
946 #define OFFSET(x) offsetof(DefaultContext, x)
949 {
"noprint_wrappers",
"do not print headers and footers",
OFFSET(noprint_wrappers), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
950 {
"nw",
"do not print headers and footers",
OFFSET(noprint_wrappers), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
951 {
"nokey",
"force no key printing",
OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
952 {
"nk",
"force no key printing",
OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
959 static inline char *
upcase_string(
char *dst,
size_t dst_size,
const char *src)
962 for (i = 0; src[i] && i < dst_size-1; i++)
963 dst[i] = av_toupper(src[i]);
977 if (parent_section &&
1032 .priv_class = &default_class,
1040 static const char *
c_escape_str(AVBPrint *dst,
const char *src,
const char sep,
void *log_ctx)
1044 for (p = src; *p; p++) {
1046 case '\b': av_bprintf(dst,
"%s",
"\\b");
break;
1047 case '\f': av_bprintf(dst,
"%s",
"\\f");
break;
1048 case '\n': av_bprintf(dst,
"%s",
"\\n");
break;
1049 case '\r': av_bprintf(dst,
"%s",
"\\r");
break;
1050 case '\\': av_bprintf(dst,
"%s",
"\\\\");
break;
1053 av_bprint_chars(dst,
'\\', 1);
1054 av_bprint_chars(dst, *p, 1);
1063 static const char *
csv_escape_str(AVBPrint *dst,
const char *src,
const char sep,
void *log_ctx)
1065 char meta_chars[] = { sep,
'"',
'\n',
'\r',
'\0' };
1066 int needs_quoting = !!src[strcspn(src, meta_chars)];
1069 av_bprint_chars(dst,
'"', 1);
1071 for (; *src; src++) {
1073 av_bprint_chars(dst,
'"', 1);
1074 av_bprint_chars(dst, *src, 1);
1077 av_bprint_chars(dst,
'"', 1);
1081 static const char *
none_escape_str(AVBPrint *dst,
const char *src,
const char sep,
void *log_ctx)
1087 const AVClass *
class;
1093 const char * (*escape_str)(AVBPrint *dst,
const char *src,
const char sep,
void *log_ctx);
1100 #define OFFSET(x) offsetof(CompactContext, x)
1103 {
"item_sep",
"set item separator",
OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=
"|"}, 0, 0 },
1104 {
"s",
"set item separator",
OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=
"|"}, 0, 0 },
1105 {
"nokey",
"force no key printing",
OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1106 {
"nk",
"force no key printing",
OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1107 {
"escape",
"set escape mode",
OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str=
"c"}, 0, 0 },
1108 {
"e",
"set escape mode",
OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str=
"c"}, 0, 0 },
1109 {
"print_section",
"print section name",
OFFSET(
print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1121 av_log(wctx, AV_LOG_ERROR,
"Item separator '%s' specified, but must contain a single character\n",
1123 return AVERROR(EINVAL);
1131 av_log(wctx, AV_LOG_ERROR,
"Unknown escape mode '%s'\n", compact->
escape_mode_str);
1132 return AVERROR(EINVAL);
1184 if (!compact->
nokey)
1186 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1188 av_bprint_finalize(&buf, NULL);
1196 if (!compact->
nokey)
1210 .priv_class = &compact_class,
1216 #define OFFSET(x) offsetof(CompactContext, x)
1219 {
"item_sep",
"set item separator",
OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=
","}, 0, 0 },
1220 {
"s",
"set item separator",
OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=
","}, 0, 0 },
1221 {
"nokey",
"force no key printing",
OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1222 {
"nk",
"force no key printing",
OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1223 {
"escape",
"set escape mode",
OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str=
"csv"}, 0, 0 },
1224 {
"e",
"set escape mode",
OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str=
"csv"}, 0, 0 },
1225 {
"print_section",
"print section name",
OFFSET(
print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1241 .priv_class = &csv_class,
1247 const AVClass *
class;
1254 #define OFFSET(x) offsetof(FlatContext, x)
1257 {
"sep_char",
"set separator",
OFFSET(sep_str), AV_OPT_TYPE_STRING, {.str=
"."}, 0, 0 },
1258 {
"s",
"set separator",
OFFSET(sep_str), AV_OPT_TYPE_STRING, {.str=
"."}, 0, 0 },
1259 {
"hierarchical",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1260 {
"h",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1270 if (strlen(flat->
sep_str) != 1) {
1271 av_log(wctx, AV_LOG_ERROR,
"Item separator '%s' specified, but must contain a single character\n",
1273 return AVERROR(EINVAL);
1284 for (p = src; *p; p++) {
1285 if (!((*p >=
'0' && *p <=
'9') ||
1286 (*p >=
'a' && *p <=
'z') ||
1287 (*p >=
'A' && *p <=
'Z')))
1288 av_bprint_chars(dst,
'_', 1);
1290 av_bprint_chars(dst, *p, 1);
1299 for (p = src; *p; p++) {
1301 case '\n': av_bprintf(dst,
"%s",
"\\n");
break;
1302 case '\r': av_bprintf(dst,
"%s",
"\\r");
break;
1303 case '\\': av_bprintf(dst,
"%s",
"\\\\");
break;
1304 case '"': av_bprintf(dst,
"%s",
"\\\"");
break;
1305 case '`': av_bprintf(dst,
"%s",
"\\`");
break;
1306 case '$': av_bprintf(dst,
"%s",
"\\$");
break;
1307 default: av_bprint_chars(dst, *p, 1);
break;
1322 av_bprint_clear(buf);
1323 if (!parent_section)
1334 av_bprintf(buf,
"%d%s", n, flat->
sep_str);
1350 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1352 av_bprint_clear(&buf);
1354 av_bprint_finalize(&buf, NULL);
1365 .priv_class = &flat_class,
1371 const AVClass *
class;
1376 #define OFFSET(x) offsetof(INIContext, x)
1379 {
"hierarchical",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1380 {
"h",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1391 while ((c = src[i++])) {
1393 case '\b': av_bprintf(dst,
"%s",
"\\b");
break;
1394 case '\f': av_bprintf(dst,
"%s",
"\\f");
break;
1395 case '\n': av_bprintf(dst,
"%s",
"\\n");
break;
1396 case '\r': av_bprintf(dst,
"%s",
"\\r");
break;
1397 case '\t': av_bprintf(dst,
"%s",
"\\t");
break;
1401 case ':' : av_bprint_chars(dst,
'\\', 1);
1403 if ((
unsigned char)c < 32)
1404 av_bprintf(dst,
"\\x00%02x", c & 0xff);
1406 av_bprint_chars(dst, c, 1);
1421 av_bprint_clear(buf);
1422 if (!parent_section) {
1433 av_bprintf(buf,
"%s%s", buf->str[0] ?
"." :
"", wctx->
section[wctx->
level]->
name);
1438 av_bprintf(buf,
".%d", n);
1450 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1452 av_bprint_clear(&buf);
1454 av_bprint_finalize(&buf, NULL);
1469 .priv_class = &ini_class,
1475 const AVClass *
class;
1482 #define OFFSET(x) offsetof(JSONContext, x)
1485 {
"compact",
"enable compact output",
OFFSET(compact), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1486 {
"c",
"enable compact output",
OFFSET(compact), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1504 static const char json_escape[] = {
'"',
'\\',
'\b',
'\f',
'\n',
'\r',
'\t', 0};
1505 static const char json_subst[] = {
'"',
'\\',
'b',
'f',
'n',
'r',
't', 0};
1508 for (p = src; *p; p++) {
1509 char *s = strchr(json_escape, *p);
1511 av_bprint_chars(dst,
'\\', 1);
1512 av_bprint_chars(dst, json_subst[s - json_escape], 1);
1513 }
else if ((
unsigned char)*p < 32) {
1514 av_bprintf(dst,
"\\u00%02x", *p & 0xff);
1516 av_bprint_chars(dst, *p, 1);
1522 #define JSON_INDENT() av_log(NULL, AV_LOG_STDERR, "%*c", json->indent_level * 4, ' ')
1539 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1558 av_bprint_finalize(&buf, NULL);
1567 if (wctx->
level == 0) {
1585 const char *key,
const char *value)
1589 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1591 av_bprint_clear(&buf);
1593 av_bprint_finalize(&buf, NULL);
1621 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1623 av_bprint_finalize(&buf, NULL);
1635 .priv_class = &json_class,
1641 const AVClass *
class;
1649 #define OFFSET(x) offsetof(XMLContext, x)
1652 {
"fully_qualified",
"specify if the output should be fully qualified",
OFFSET(fully_qualified), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1653 {
"q",
"specify if the output should be fully qualified",
OFFSET(fully_qualified), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1654 {
"xsd_strict",
"ensure that the output is XSD compliant",
OFFSET(xsd_strict), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1655 {
"x",
"ensure that the output is XSD compliant",
OFFSET(xsd_strict), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1667 #define CHECK_COMPLIANCE(opt, opt_name) \
1669 av_log(wctx, AV_LOG_ERROR, \
1670 "XSD-compliant output selected but option '%s' was selected, XML output may be non-compliant.\n" \
1671 "You need to disable such option with '-no%s'\n", opt_name, opt_name); \
1672 return AVERROR(EINVAL); \
1682 #define XML_INDENT() av_log(NULL, AV_LOG_STDERR, "%*c", xml->indent_level * 4, ' ')
1691 if (wctx->
level == 0) {
1692 const char *qual =
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
1693 "xmlns:ffprobe=\"http://www.ffmpeg.org/schema/ffprobe\" "
1694 "xsi:schemaLocation=\"http://www.ffmpeg.org/schema/ffprobe ffprobe.xsd\"";
1696 av_log(NULL,
AV_LOG_STDERR,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
1729 if (wctx->
level == 0) {
1749 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1753 av_bprint_escape(&buf, key, NULL,
1754 AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
1757 av_bprint_clear(&buf);
1759 av_bprint_escape(&buf, value, NULL,
1760 AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
1766 av_bprint_escape(&buf, value, NULL,
1767 AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
1771 av_bprint_finalize(&buf, NULL);
1790 .priv_class = &xml_class,
1805 #define print_fmt(k, f, ...) do { \
1806 av_bprint_clear(&pbuf); \
1807 av_bprintf(&pbuf, f, __VA_ARGS__); \
1808 writer_print_string(w, k, pbuf.str, 0); \
1811 #define print_int(k, v) writer_print_integer(w, k, v)
1812 #define print_q(k, v, s) writer_print_rational(w, k, v, s)
1813 #define print_str(k, v) writer_print_string(w, k, v, 0)
1814 #define print_str_opt(k, v) writer_print_string(w, k, v, PRINT_STRING_OPT)
1815 #define print_str_validate(k, v) writer_print_string(w, k, v, PRINT_STRING_VALIDATE)
1816 #define print_time(k, v, tb) writer_print_time(w, k, v, tb, 0)
1817 #define print_ts(k, v) writer_print_ts(w, k, v, 0)
1818 #define print_duration_time(k, v, tb) writer_print_time(w, k, v, tb, 1)
1819 #define print_duration_ts(k, v) writer_print_ts(w, k, v, 1)
1820 #define print_val(k, v, u) do { \
1821 struct unit_value uv; \
1824 writer_print_string(w, k, value_string(val_str, sizeof(val_str), uv), 0); \
1827 #define print_section_header(s) writer_print_section_header(w, s)
1828 #define print_section_footer(s) writer_print_section_footer(w, s)
1830 #define REALLOCZ_ARRAY_STREAM(ptr, cur_n, new_n) \
1832 ret = av_reallocp_array(&(ptr), (new_n), sizeof(*(ptr))); \
1835 memset( (ptr) + (cur_n), 0, ((new_n) - (cur_n)) * sizeof(*(ptr)) ); \
1840 AVDictionaryEntry *tag = NULL;
1847 while ((tag = av_dict_get(tags,
"", tag, AV_DICT_IGNORE_SUFFIX))) {
1860 print_int(
"application version", metadata->application_version);
1861 print_int(
"num_windows", metadata->num_windows);
1862 for (
int n = 1; n < metadata->num_windows; n++) {
1863 const AVHDRPlusColorTransformParams *params = &metadata->params[n];
1864 print_q(
"window_upper_left_corner_x",
1865 params->window_upper_left_corner_x,
'/');
1866 print_q(
"window_upper_left_corner_y",
1867 params->window_upper_left_corner_y,
'/');
1868 print_q(
"window_lower_right_corner_x",
1869 params->window_lower_right_corner_x,
'/');
1870 print_q(
"window_lower_right_corner_y",
1871 params->window_lower_right_corner_y,
'/');
1872 print_q(
"window_upper_left_corner_x",
1873 params->window_upper_left_corner_x,
'/');
1874 print_q(
"window_upper_left_corner_y",
1875 params->window_upper_left_corner_y,
'/');
1877 params->center_of_ellipse_x ) ;
1879 params->center_of_ellipse_y );
1881 params->rotation_angle);
1882 print_int(
"semimajor_axis_internal_ellipse",
1883 params->semimajor_axis_internal_ellipse);
1884 print_int(
"semimajor_axis_external_ellipse",
1885 params->semimajor_axis_external_ellipse);
1886 print_int(
"semiminor_axis_external_ellipse",
1887 params->semiminor_axis_external_ellipse);
1889 params->overlap_process_option);
1891 print_q(
"targeted_system_display_maximum_luminance",
1892 metadata->targeted_system_display_maximum_luminance,
'/');
1893 if (metadata->targeted_system_display_actual_peak_luminance_flag) {
1894 print_int(
"num_rows_targeted_system_display_actual_peak_luminance",
1895 metadata->num_rows_targeted_system_display_actual_peak_luminance);
1896 print_int(
"num_cols_targeted_system_display_actual_peak_luminance",
1897 metadata->num_cols_targeted_system_display_actual_peak_luminance);
1898 for (
int i = 0; i < metadata->num_rows_targeted_system_display_actual_peak_luminance; i++) {
1899 for (
int j = 0; j < metadata->num_cols_targeted_system_display_actual_peak_luminance; j++) {
1900 print_q(
"targeted_system_display_actual_peak_luminance",
1901 metadata->targeted_system_display_actual_peak_luminance[i][j],
'/');
1905 for (
int n = 0; n < metadata->num_windows; n++) {
1906 const AVHDRPlusColorTransformParams *params = &metadata->params[n];
1907 for (
int i = 0; i < 3; i++) {
1908 print_q(
"maxscl",params->maxscl[i],
'/');
1911 params->average_maxrgb,
'/');
1912 print_int(
"num_distribution_maxrgb_percentiles",
1913 params->num_distribution_maxrgb_percentiles);
1914 for (
int i = 0; i < params->num_distribution_maxrgb_percentiles; i++) {
1915 print_int(
"distribution_maxrgb_percentage",
1916 params->distribution_maxrgb[i].percentage);
1917 print_q(
"distribution_maxrgb_percentile",
1918 params->distribution_maxrgb[i].percentile,
'/');
1920 print_q(
"fraction_bright_pixels",
1921 params->fraction_bright_pixels,
'/');
1923 if (metadata->mastering_display_actual_peak_luminance_flag) {
1924 print_int(
"num_rows_mastering_display_actual_peak_luminance",
1925 metadata->num_rows_mastering_display_actual_peak_luminance);
1926 print_int(
"num_cols_mastering_display_actual_peak_luminance",
1927 metadata->num_cols_mastering_display_actual_peak_luminance);
1928 for (
int i = 0; i < metadata->num_rows_mastering_display_actual_peak_luminance; i++) {
1929 for (
int j = 0; j < metadata->num_cols_mastering_display_actual_peak_luminance; j++) {
1930 print_q(
"mastering_display_actual_peak_luminance",
1931 metadata->mastering_display_actual_peak_luminance[i][j],
'/');
1936 for (
int n = 0; n < metadata->num_windows; n++) {
1937 const AVHDRPlusColorTransformParams *params = &metadata->params[n];
1938 if (params->tone_mapping_flag) {
1939 print_q(
"knee_point_x", params->knee_point_x,
'/');
1940 print_q(
"knee_point_y", params->knee_point_y,
'/');
1942 params->num_bezier_curve_anchors );
1943 for (
int i = 0; i < params->num_bezier_curve_anchors; i++) {
1944 print_q(
"bezier_curve_anchors",
1945 params->bezier_curve_anchors[i],
'/');
1948 if (params->color_saturation_mapping_flag) {
1949 print_q(
"color_saturation_weight",
1950 params->color_saturation_weight,
'/');
1956 AVCodecParameters *par,
1957 const AVPacketSideData *side_data,
1965 for (i = 0; i < nb_side_data; i++) {
1966 const AVPacketSideData *sd = &side_data[i];
1967 const char *
name = av_packet_side_data_name(sd->type);
1971 if (sd->type == AV_PKT_DATA_DISPLAYMATRIX && sd->size >= 9*4) {
1973 print_int(
"rotation", av_display_rotation_get((int32_t *)sd->data));
1974 }
else if (sd->type == AV_PKT_DATA_STEREO3D) {
1975 const AVStereo3D *stereo = (AVStereo3D *)sd->data;
1976 print_str(
"type", av_stereo3d_type_name(stereo->type));
1977 print_int(
"inverted", !!(stereo->flags & AV_STEREO3D_FLAG_INVERT));
1978 }
else if (sd->type == AV_PKT_DATA_SPHERICAL) {
1979 const AVSphericalMapping *spherical = (AVSphericalMapping *)sd->data;
1980 print_str(
"projection", av_spherical_projection_name(spherical->projection));
1981 if (spherical->projection == AV_SPHERICAL_CUBEMAP) {
1982 print_int(
"padding", spherical->padding);
1983 }
else if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR_TILE) {
1985 av_spherical_tile_bounds(spherical, par->width, par->height,
1993 print_int(
"yaw", (
double) spherical->yaw / (1 << 16));
1994 print_int(
"pitch", (
double) spherical->pitch / (1 << 16));
1995 print_int(
"roll", (
double) spherical->roll / (1 << 16));
1996 }
else if (sd->type == AV_PKT_DATA_SKIP_SAMPLES && sd->size == 10) {
1997 print_int(
"skip_samples", AV_RL32(sd->data));
1998 print_int(
"discard_padding", AV_RL32(sd->data + 4));
1999 print_int(
"skip_reason", AV_RL8(sd->data + 8));
2000 print_int(
"discard_reason", AV_RL8(sd->data + 9));
2001 }
else if (sd->type == AV_PKT_DATA_MASTERING_DISPLAY_METADATA) {
2002 AVMasteringDisplayMetadata *metadata = (AVMasteringDisplayMetadata *)sd->data;
2004 if (metadata->has_primaries) {
2005 print_q(
"red_x", metadata->display_primaries[0][0],
'/');
2006 print_q(
"red_y", metadata->display_primaries[0][1],
'/');
2007 print_q(
"green_x", metadata->display_primaries[1][0],
'/');
2008 print_q(
"green_y", metadata->display_primaries[1][1],
'/');
2009 print_q(
"blue_x", metadata->display_primaries[2][0],
'/');
2010 print_q(
"blue_y", metadata->display_primaries[2][1],
'/');
2012 print_q(
"white_point_x", metadata->white_point[0],
'/');
2013 print_q(
"white_point_y", metadata->white_point[1],
'/');
2016 if (metadata->has_luminance) {
2017 print_q(
"min_luminance", metadata->min_luminance,
'/');
2018 print_q(
"max_luminance", metadata->max_luminance,
'/');
2020 }
else if (sd->type == AV_PKT_DATA_CONTENT_LIGHT_LEVEL) {
2021 AVContentLightMetadata *metadata = (AVContentLightMetadata *)sd->data;
2022 print_int(
"max_content", metadata->MaxCLL);
2023 print_int(
"max_average", metadata->MaxFALL);
2024 }
else if (sd->type == AV_PKT_DATA_DOVI_CONF) {
2025 AVDOVIDecoderConfigurationRecord *dovi = (AVDOVIDecoderConfigurationRecord *)sd->data;
2026 print_int(
"dv_version_major", dovi->dv_version_major);
2027 print_int(
"dv_version_minor", dovi->dv_version_minor);
2028 print_int(
"dv_profile", dovi->dv_profile);
2030 print_int(
"rpu_present_flag", dovi->rpu_present_flag);
2031 print_int(
"el_present_flag", dovi->el_present_flag);
2032 print_int(
"bl_present_flag", dovi->bl_present_flag);
2033 print_int(
"dv_bl_signal_compatibility_id", dovi->dv_bl_signal_compatibility_id);
2034 }
else if (sd->type == AV_PKT_DATA_AUDIO_SERVICE_TYPE) {
2035 enum AVAudioServiceType *t = (
enum AVAudioServiceType *)sd->data;
2037 }
else if (sd->type == AV_PKT_DATA_MPEGTS_STREAM_ID) {
2039 }
else if (sd->type == AV_PKT_DATA_CPB_PROPERTIES) {
2040 const AVCPBProperties *prop = (AVCPBProperties *)sd->data;
2041 print_int(
"max_bitrate", prop->max_bitrate);
2042 print_int(
"min_bitrate", prop->min_bitrate);
2043 print_int(
"avg_bitrate", prop->avg_bitrate);
2044 print_int(
"buffer_size", prop->buffer_size);
2045 print_int(
"vbv_delay", prop->vbv_delay);
2046 }
else if (sd->type == AV_PKT_DATA_WEBVTT_IDENTIFIER ||
2047 sd->type == AV_PKT_DATA_WEBVTT_SETTINGS) {
2059 const char *val = av_color_range_name(color_range);
2060 if (!val || color_range == AVCOL_RANGE_UNSPECIFIED) {
2069 const char *val = av_color_space_name(color_space);
2070 if (!val || color_space == AVCOL_SPC_UNSPECIFIED) {
2079 const char *val = av_color_primaries_name(color_primaries);
2080 if (!val || color_primaries == AVCOL_PRI_UNSPECIFIED) {
2089 const char *val = av_color_transfer_name(color_trc);
2090 if (!val || color_trc == AVCOL_TRC_UNSPECIFIED) {
2099 const char *val = av_chroma_location_name(chroma_location);
2100 if (!val || chroma_location == AVCHROMA_LOC_UNSPECIFIED) {
2162 AVStream *st = ifile->
streams[pkt->stream_index].
st;
2166 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2170 s = av_get_media_type_string(st->codecpar->codec_type);
2173 print_int(
"stream_index", pkt->stream_index);
2175 print_time(
"pts_time", pkt->pts, &st->time_base);
2177 print_time(
"dts_time", pkt->dts, &st->time_base);
2181 if (pkt->pos != -1)
print_fmt (
"pos",
"%"PRId64, pkt->pos);
2183 print_fmt(
"flags",
"%c%c", pkt->flags & AV_PKT_FLAG_KEY ?
'K' :
'_',
2184 pkt->flags & AV_PKT_FLAG_DISCARD ?
'D' :
'_');
2186 if (pkt->side_data_elems) {
2188 const uint8_t *side_metadata;
2190 side_metadata = av_packet_get_side_data(pkt, AV_PKT_DATA_STRINGS_METADATA, &size);
2192 AVDictionary *dict = NULL;
2193 if (av_packet_unpack_dictionary(side_metadata, size, &dict) >= 0)
2195 av_dict_free(&dict);
2208 av_bprint_finalize(&pbuf, NULL);
2213 AVFormatContext *fmt_ctx)
2217 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2223 print_time(
"pts_time", sub->pts, &AV_TIME_BASE_Q);
2225 print_int (
"start_display_time", sub->start_display_time);
2226 print_int (
"end_display_time", sub->end_display_time);
2227 print_int (
"num_rects", sub->num_rects);
2231 av_bprint_finalize(&pbuf, NULL);
2236 AVFormatContext *fmt_ctx)
2243 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2247 s = av_get_media_type_string(stream->codecpar->codec_type);
2250 print_int(
"stream_index", stream->index);
2251 print_int(
"key_frame", frame->key_frame);
2253 print_time(
"pts_time", frame->pts, &stream->time_base);
2254 print_ts (
"pkt_dts", frame->pkt_dts);
2255 print_time(
"pkt_dts_time", frame->pkt_dts, &stream->time_base);
2256 print_ts (
"best_effort_timestamp", frame->best_effort_timestamp);
2257 print_time(
"best_effort_timestamp_time", frame->best_effort_timestamp, &stream->time_base);
2260 if (frame->pkt_pos != -1)
print_fmt (
"pkt_pos",
"%"PRId64, frame->pkt_pos);
2265 switch (stream->codecpar->codec_type) {
2268 case AVMEDIA_TYPE_VIDEO:
2271 s = av_get_pix_fmt_name(frame->format);
2274 sar = av_guess_sample_aspect_ratio(fmt_ctx, stream, frame);
2276 print_q(
"sample_aspect_ratio", sar,
':');
2280 print_fmt(
"pict_type",
"%c", av_get_picture_type_char(frame->pict_type));
2281 print_int(
"coded_picture_number", frame->coded_picture_number);
2282 print_int(
"display_picture_number", frame->display_picture_number);
2283 print_int(
"interlaced_frame", frame->interlaced_frame);
2284 print_int(
"top_field_first", frame->top_field_first);
2285 print_int(
"repeat_pict", frame->repeat_pict);
2294 case AVMEDIA_TYPE_AUDIO:
2295 s = av_get_sample_fmt_name(frame->format);
2298 print_int(
"nb_samples", frame->nb_samples);
2300 if (frame->channel_layout) {
2301 av_bprint_clear(&pbuf);
2302 av_bprint_channel_layout(&pbuf, frame->channels,
2303 frame->channel_layout);
2313 if (frame->nb_side_data) {
2315 for (i = 0; i < frame->nb_side_data; i++) {
2316 AVFrameSideData *sd = frame->side_data[i];
2320 name = av_frame_side_data_name(sd->type);
2322 if (sd->type == AV_FRAME_DATA_DISPLAYMATRIX && sd->size >= 9*4) {
2324 print_int(
"rotation", av_display_rotation_get((int32_t *)sd->data));
2325 }
else if (sd->type == AV_FRAME_DATA_GOP_TIMECODE && sd->size >= 8) {
2326 char tcbuf[AV_TIMECODE_STR_SIZE];
2327 av_timecode_make_mpeg_tc_string(tcbuf, *(int64_t *)(sd->data));
2329 }
else if (sd->type == AV_FRAME_DATA_S12M_TIMECODE && sd->size == 16) {
2330 uint32_t *tc = (uint32_t*)sd->data;
2331 int m = FFMIN(tc[0],3);
2333 for (
int j = 1; j <= m ; j++) {
2334 char tcbuf[AV_TIMECODE_STR_SIZE];
2335 av_timecode_make_smpte_tc_string2(tcbuf, stream->avg_frame_rate, tc[j], 0, 0);
2341 }
else if (sd->type == AV_FRAME_DATA_MASTERING_DISPLAY_METADATA) {
2342 AVMasteringDisplayMetadata *metadata = (AVMasteringDisplayMetadata *)sd->data;
2344 if (metadata->has_primaries) {
2345 print_q(
"red_x", metadata->display_primaries[0][0],
'/');
2346 print_q(
"red_y", metadata->display_primaries[0][1],
'/');
2347 print_q(
"green_x", metadata->display_primaries[1][0],
'/');
2348 print_q(
"green_y", metadata->display_primaries[1][1],
'/');
2349 print_q(
"blue_x", metadata->display_primaries[2][0],
'/');
2350 print_q(
"blue_y", metadata->display_primaries[2][1],
'/');
2352 print_q(
"white_point_x", metadata->white_point[0],
'/');
2353 print_q(
"white_point_y", metadata->white_point[1],
'/');
2356 if (metadata->has_luminance) {
2357 print_q(
"min_luminance", metadata->min_luminance,
'/');
2358 print_q(
"max_luminance", metadata->max_luminance,
'/');
2360 }
else if (sd->type == AV_FRAME_DATA_DYNAMIC_HDR_PLUS) {
2361 AVDynamicHDRPlus *metadata = (AVDynamicHDRPlus *)sd->data;
2363 }
else if (sd->type == AV_FRAME_DATA_CONTENT_LIGHT_LEVEL) {
2364 AVContentLightMetadata *metadata = (AVContentLightMetadata *)sd->data;
2365 print_int(
"max_content", metadata->MaxCLL);
2366 print_int(
"max_average", metadata->MaxFALL);
2367 }
else if (sd->type == AV_FRAME_DATA_ICC_PROFILE) {
2368 AVDictionaryEntry *tag = av_dict_get(sd->metadata,
"name", NULL, AV_DICT_MATCH_CASE);
2380 av_bprint_finalize(&pbuf, NULL);
2386 AVFrame *frame, AVPacket *pkt,
2389 AVFormatContext *fmt_ctx = ifile->
fmt_ctx;
2390 AVCodecContext *dec_ctx = ifile->
streams[pkt->stream_index].
dec_ctx;
2391 AVCodecParameters *par = ifile->
streams[pkt->stream_index].
st->codecpar;
2393 int ret = 0, got_frame = 0;
2396 if (dec_ctx && dec_ctx->codec) {
2397 switch (par->codec_type) {
2398 case AVMEDIA_TYPE_VIDEO:
2399 case AVMEDIA_TYPE_AUDIO:
2401 ret = avcodec_send_packet(dec_ctx, pkt);
2402 if (ret == AVERROR(EAGAIN)) {
2404 }
else if (ret >= 0 || ret == AVERROR_EOF) {
2410 ret = avcodec_receive_frame(dec_ctx, frame);
2413 }
else if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
2419 case AVMEDIA_TYPE_SUBTITLE:
2421 ret = avcodec_decode_subtitle2(dec_ctx, &sub, &got_frame, pkt);
2434 int is_sub = (par->codec_type == AVMEDIA_TYPE_SUBTITLE);
2444 avsubtitle_free(&sub);
2447 return got_frame || *packet_new;
2452 av_log(log_ctx, log_level,
"id:%d", interval->
id);
2455 av_log(log_ctx, log_level,
" start:%s%s", interval->
start_is_offset ?
"+" :
"",
2456 av_ts2timestr(interval->
start, &AV_TIME_BASE_Q));
2458 av_log(log_ctx, log_level,
" start:N/A");
2462 av_log(log_ctx, log_level,
" end:%s", interval->
end_is_offset ?
"+" :
"");
2464 av_log(log_ctx, log_level,
"#%"PRId64, interval->
end);
2466 av_log(log_ctx, log_level,
"%s", av_ts2timestr(interval->
end, &AV_TIME_BASE_Q));
2468 av_log(log_ctx, log_level,
" end:N/A");
2471 av_log(log_ctx, log_level,
"\n");
2477 AVFormatContext *fmt_ctx = ifile->
fmt_ctx;
2478 AVPacket *pkt = NULL;
2479 AVFrame *frame = NULL;
2480 int ret = 0, i = 0, frame_count = 0;
2481 int64_t start = -INT64_MAX, end = interval->
end;
2484 av_log(NULL, AV_LOG_VERBOSE,
"Processing read interval ");
2490 if (*cur_ts == AV_NOPTS_VALUE) {
2491 av_log(NULL, AV_LOG_ERROR,
2492 "Could not seek to relative position since current "
2493 "timestamp is not defined\n");
2494 ret = AVERROR(EINVAL);
2497 target = *cur_ts + interval->
start;
2499 target = interval->
start;
2502 av_log(NULL, AV_LOG_VERBOSE,
"Seeking to read interval start point %s\n",
2503 av_ts2timestr(target, &AV_TIME_BASE_Q));
2504 if ((ret = avformat_seek_file(fmt_ctx, -1, -INT64_MAX, target, INT64_MAX, 0)) < 0) {
2505 av_log(NULL, AV_LOG_ERROR,
"Could not seek to position %"PRId64
": %s\n",
2506 interval->
start, av_err2str(ret));
2511 frame = av_frame_alloc();
2513 ret = AVERROR(ENOMEM);
2516 pkt = av_packet_alloc();
2518 ret = AVERROR(ENOMEM);
2521 while (!av_read_frame(fmt_ctx, pkt)) {
2529 AVRational tb = ifile->
streams[pkt->stream_index].
st->time_base;
2531 if (pkt->pts != AV_NOPTS_VALUE)
2532 *cur_ts = av_rescale_q(pkt->pts, tb, AV_TIME_BASE_Q);
2534 if (!has_start && *cur_ts != AV_NOPTS_VALUE) {
2540 end = start + interval->
end;
2545 if (frame_count >= interval->
end)
2547 }
else if (has_end && *cur_ts != AV_NOPTS_VALUE && *cur_ts >= end) {
2559 while (
process_frame(w, ifile, frame, pkt, &packet_new) > 0);
2562 av_packet_unref(pkt);
2564 av_packet_unref(pkt);
2566 for (i = 0; i < fmt_ctx->nb_streams; i++) {
2567 pkt->stream_index = i;
2573 av_frame_free(&frame);
2574 av_packet_free(&pkt);
2576 av_log(NULL, AV_LOG_ERROR,
"Could not read packets in interval ");
2584 AVFormatContext *fmt_ctx = ifile->
fmt_ctx;
2586 int64_t cur_ts = fmt_ctx->start_time;
2604 AVStream *stream =
ist->st;
2605 AVCodecParameters *par;
2606 AVCodecContext *dec_ctx;
2609 AVRational sar, dar;
2611 const AVCodecDescriptor *cd;
2613 const char *profile = NULL;
2615 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2621 par = stream->codecpar;
2622 dec_ctx =
ist->dec_ctx;
2623 if ((cd = avcodec_descriptor_get(par->codec_id))) {
2627 cd->long_name ? cd->long_name :
"unknown");
2636 if (!
do_bitexact && (profile = avcodec_profile_name(par->codec_id, par->profile)))
2639 if (par->profile != FF_PROFILE_UNKNOWN) {
2640 char profile_num[12];
2641 snprintf(profile_num,
sizeof(profile_num),
"%d", par->profile);
2647 s = av_get_media_type_string(par->codec_type);
2652 print_str(
"codec_tag_string", av_fourcc2str(par->codec_tag));
2653 print_fmt(
"codec_tag",
"0x%04"PRIx32, par->codec_tag);
2655 switch (par->codec_type) {
2656 case AVMEDIA_TYPE_VIDEO:
2660 print_int(
"coded_width", dec_ctx->coded_width);
2661 print_int(
"coded_height", dec_ctx->coded_height);
2662 print_int(
"closed_captions", !!(dec_ctx->properties & FF_CODEC_PROPERTY_CLOSED_CAPTIONS));
2664 print_int(
"has_b_frames", par->video_delay);
2665 sar = av_guess_sample_aspect_ratio(fmt_ctx, stream, NULL);
2667 print_q(
"sample_aspect_ratio", sar,
':');
2668 av_reduce(&dar.num, &dar.den,
2669 par->width * sar.num,
2670 par->height * sar.den,
2672 print_q(
"display_aspect_ratio", dar,
':');
2677 s = av_get_pix_fmt_name(par->format);
2688 if (par->field_order == AV_FIELD_PROGRESSIVE)
2689 print_str(
"field_order",
"progressive");
2690 else if (par->field_order == AV_FIELD_TT)
2692 else if (par->field_order == AV_FIELD_BB)
2694 else if (par->field_order == AV_FIELD_TB)
2696 else if (par->field_order == AV_FIELD_BT)
2705 case AVMEDIA_TYPE_AUDIO:
2706 s = av_get_sample_fmt_name(par->format);
2712 if (par->channel_layout) {
2713 av_bprint_clear(&pbuf);
2714 av_bprint_channel_layout(&pbuf, par->channels, par->channel_layout);
2720 print_int(
"bits_per_sample", av_get_bits_per_sample(par->codec_id));
2723 case AVMEDIA_TYPE_SUBTITLE:
2735 if (dec_ctx && dec_ctx->codec && dec_ctx->codec->priv_class &&
show_private_data) {
2736 const AVOption *opt = NULL;
2737 while ((opt = av_opt_next(dec_ctx->priv_data,opt))) {
2739 if (!(opt->flags & AV_OPT_FLAG_EXPORT))
continue;
2740 if (av_opt_get(dec_ctx->priv_data, opt->name, 0, &str) >= 0) {
2747 if (fmt_ctx->iformat->flags & AVFMT_SHOW_IDS)
print_fmt (
"id",
"0x%x", stream->id);
2749 print_q(
"r_frame_rate", stream->r_frame_rate,
'/');
2750 print_q(
"avg_frame_rate", stream->avg_frame_rate,
'/');
2751 print_q(
"time_base", stream->time_base,
'/');
2752 print_ts (
"start_pts", stream->start_time);
2753 print_time(
"start_time", stream->start_time, &stream->time_base);
2754 print_ts (
"duration_ts", stream->duration);
2755 print_time(
"duration", stream->duration, &stream->time_base);
2758 if (dec_ctx && dec_ctx->rc_max_rate > 0)
2762 if (dec_ctx && dec_ctx->bits_per_raw_sample > 0)
print_fmt(
"bits_per_raw_sample",
"%d", dec_ctx->bits_per_raw_sample);
2764 if (stream->nb_frames)
print_fmt (
"nb_frames",
"%"PRId64, stream->nb_frames);
2772 par->extradata_size);
2774 if (par->extradata_size > 0) {
2776 par->extradata_size);
2780 #define PRINT_DISPOSITION(flagname, name) do { \
2781 print_int(name, !!(stream->disposition & AV_DISPOSITION_##flagname)); \
2809 if (stream->nb_side_data) {
2816 av_bprint_finalize(&pbuf, NULL);
2824 AVFormatContext *fmt_ctx = ifile->
fmt_ctx;
2841 AVFormatContext *fmt_ctx = ifile->
fmt_ctx;
2846 print_int(
"program_num", program->program_num);
2847 print_int(
"nb_streams", program->nb_stream_indexes);
2850 print_ts(
"start_pts", program->start_time);
2851 print_time(
"start_time", program->start_time, &AV_TIME_BASE_Q);
2852 print_ts(
"end_pts", program->end_time);
2853 print_time(
"end_time", program->end_time, &AV_TIME_BASE_Q);
2860 for (i = 0; i < program->nb_stream_indexes; i++) {
2862 ret =
show_stream(w, fmt_ctx, program->stream_index[i], &ifile->
streams[program->stream_index[i]], 1);
2876 AVFormatContext *fmt_ctx = ifile->
fmt_ctx;
2880 for (i = 0; i < fmt_ctx->nb_programs; i++) {
2881 AVProgram *program = fmt_ctx->programs[i];
2894 AVFormatContext *fmt_ctx = ifile->
fmt_ctx;
2898 for (i = 0; i < fmt_ctx->nb_chapters; i++) {
2899 AVChapter *chapter = fmt_ctx->chapters[i];
2903 print_q (
"time_base", chapter->time_base,
'/');
2905 print_time(
"start_time", chapter->start, &chapter->time_base);
2907 print_time(
"end_time", chapter->end, &chapter->time_base);
2919 AVFormatContext *fmt_ctx = ifile->
fmt_ctx;
2921 int64_t size = fmt_ctx->pb ? avio_size(fmt_ctx->pb) : -1;
2926 print_int(
"nb_streams", fmt_ctx->nb_streams);
2927 print_int(
"nb_programs", fmt_ctx->nb_programs);
2928 print_str(
"format_name", fmt_ctx->iformat->name);
2930 if (fmt_ctx->iformat->long_name)
print_str (
"format_long_name", fmt_ctx->iformat->long_name);
2933 print_time(
"start_time", fmt_ctx->start_time, &AV_TIME_BASE_Q);
2934 print_time(
"duration", fmt_ctx->duration, &AV_TIME_BASE_Q);
2939 print_int(
"probe_score", fmt_ctx->probe_score);
2951 const char *errbuf_ptr = errbuf;
2953 if (av_strerror(err, errbuf,
sizeof(errbuf)) < 0)
2954 errbuf_ptr = strerror(AVUNERROR(err));
2965 AVFormatContext *fmt_ctx = NULL;
2966 AVDictionaryEntry *t = NULL;
2967 int scan_all_pmts_set = 0;
2969 fmt_ctx = avformat_alloc_context();
2975 if (!av_dict_get(
format_opts,
"scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
2976 av_dict_set(&
format_opts,
"scan_all_pmts",
"1", AV_DICT_DONT_OVERWRITE);
2977 scan_all_pmts_set = 1;
2979 if ((err = avformat_open_input(&fmt_ctx, filename,
2984 if (print_filename) {
2985 av_freep(&fmt_ctx->url);
2986 fmt_ctx->url = av_strdup(print_filename);
2989 if (scan_all_pmts_set)
2990 av_dict_set(&
format_opts,
"scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
2991 while ((t = av_dict_get(
format_opts,
"", t, AV_DICT_IGNORE_SUFFIX)))
2992 av_log(NULL, AV_LOG_WARNING,
"Option %s skipped - not known to demuxer.\n", t->key);
2996 int orig_nb_streams = fmt_ctx->nb_streams;
2998 err = avformat_find_stream_info(fmt_ctx, opts);
3000 for (i = 0; i < orig_nb_streams; i++)
3001 av_dict_free(&opts[i]);
3010 av_dump_format(fmt_ctx, 0, filename, 0);
3012 ifile->
streams = av_mallocz_array(fmt_ctx->nb_streams,
3019 for (i = 0; i < fmt_ctx->nb_streams; i++) {
3021 AVStream *stream = fmt_ctx->streams[i];
3022 const AVCodec *codec;
3026 if (stream->codecpar->codec_id == AV_CODEC_ID_PROBE) {
3027 av_log(NULL, AV_LOG_WARNING,
3028 "Failed to probe codec for input stream %d\n",
3033 codec = avcodec_find_decoder(stream->codecpar->codec_id);
3035 av_log(NULL, AV_LOG_WARNING,
3036 "Unsupported codec with id %d for input stream %d\n",
3037 stream->codecpar->codec_id, stream->index);
3042 fmt_ctx, stream, codec);
3044 ist->dec_ctx = avcodec_alloc_context3(codec);
3048 err = avcodec_parameters_to_context(
ist->dec_ctx, stream->codecpar);
3059 ist->dec_ctx->pkt_timebase = stream->time_base;
3061 if (avcodec_open2(
ist->dec_ctx, codec, &opts) < 0) {
3062 av_log(NULL, AV_LOG_WARNING,
"Could not open codec for input stream %d\n",
3067 if ((t = av_dict_get(opts,
"", NULL, AV_DICT_IGNORE_SUFFIX))) {
3068 av_log(NULL, AV_LOG_ERROR,
"Option %s for input stream %d not found\n",
3069 t->key, stream->index);
3070 return AVERROR_OPTION_NOT_FOUND;
3090 avformat_close_input(&ifile->
fmt_ctx);
3094 const char *print_filename)
3107 #define CHECK_END if (ret < 0) goto end
3114 for (i = 0; i < ifile.
fmt_ctx->nb_streams; i++) {
3116 ret = avformat_match_stream_specifier(ifile.
fmt_ctx,
3127 ifile.
fmt_ctx->streams[i]->discard = AVDISCARD_ALL;
3176 av_log(NULL, AV_LOG_INFO,
"Simple multimedia streams analyzer\n");
3177 av_log(NULL, AV_LOG_INFO,
"usage: %s [OPTIONS] [INPUT_FILE]\n",
program_name);
3178 av_log(NULL, AV_LOG_INFO,
"\n");
3184 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
3188 print_fmt(
"copyright",
"Copyright (c) %d-%d the FFmpeg developers",
3191 print_str(
"configuration", FFMPEG_CONFIGURATION);
3194 av_bprint_finalize(&pbuf, NULL);
3197 #define SHOW_LIB_VERSION(libname, LIBNAME) \
3199 if (CONFIG_##LIBNAME) { \
3200 unsigned int version = libname##_version(); \
3201 writer_print_section_header(w, SECTION_ID_LIBRARY_VERSION); \
3202 print_str("name", "lib" #libname); \
3203 print_int("major", LIB##LIBNAME##_VERSION_MAJOR); \
3204 print_int("minor", LIB##LIBNAME##_VERSION_MINOR); \
3205 print_int("micro", LIB##LIBNAME##_VERSION_MICRO); \
3206 print_int("version", version); \
3207 print_str("ident", LIB##LIBNAME##_IDENT); \
3208 writer_print_section_footer(w); \
3225 #define PRINT_PIX_FMT_FLAG(flagname, name) \
3227 print_int(name, !!(pixdesc->flags & AV_PIX_FMT_FLAG_##flagname)); \
3232 const AVPixFmtDescriptor *pixdesc = NULL;
3236 while ((pixdesc = av_pix_fmt_desc_next(pixdesc))) {
3239 print_int(
"nb_components", pixdesc->nb_components);
3240 if ((pixdesc->nb_components >= 3) && !(pixdesc->flags & AV_PIX_FMT_FLAG_RGB)) {
3241 print_int (
"log2_chroma_w", pixdesc->log2_chroma_w);
3242 print_int (
"log2_chroma_h", pixdesc->log2_chroma_h);
3247 n = av_get_bits_per_pixel(pixdesc);
3263 for (i = 0; i < pixdesc->nb_components; i++) {
3266 print_int(
"bit_depth", pixdesc->comp[i].depth);
3287 static int opt_format(
void *optctx,
const char *opt,
const char *arg)
3289 iformat = av_find_input_format(arg);
3291 av_log(NULL, AV_LOG_ERROR,
"Unknown input format: %s\n", arg);
3292 return AVERROR(EINVAL);
3317 for (i = 0; i < FF_ARRAY_ELEMS(
sections); i++) {
3321 av_log(NULL, AV_LOG_DEBUG,
3322 "'%s' matches section with unique name '%s'\n", section_name,
3333 const char *p = arg;
3337 AVDictionary *entries = NULL;
3338 char *section_name = av_get_token(&p,
"=:");
3341 if (!section_name) {
3342 av_log(NULL, AV_LOG_ERROR,
3343 "Missing section name for option '%s'\n", opt);
3344 return AVERROR(EINVAL);
3349 while (*p && *p !=
':') {
3350 char *entry = av_get_token(&p,
",:");
3353 av_log(NULL, AV_LOG_VERBOSE,
3354 "Adding '%s' to the entries to show in section '%s'\n",
3355 entry, section_name);
3356 av_dict_set(&entries, entry,
"", AV_DICT_DONT_STRDUP_KEY);
3366 av_log(NULL, AV_LOG_ERROR,
"No match for section '%s'\n", section_name);
3367 ret = AVERROR(EINVAL);
3369 av_dict_free(&entries);
3370 av_free(section_name);
3383 char *buf = av_asprintf(
"format=%s", arg);
3387 return AVERROR(ENOMEM);
3389 av_log(NULL, AV_LOG_WARNING,
3390 "Option '%s' is deprecated, use '-show_entries format=%s' instead\n",
3400 av_log(NULL, AV_LOG_ERROR,
3401 "Argument '%s' provided as input filename, but '%s' was already specified.\n",
3405 if (!strcmp(arg,
"-"))
3441 char *next, *p, *spec = av_strdup(interval_spec);
3443 return AVERROR(ENOMEM);
3446 av_log(NULL, AV_LOG_ERROR,
"Invalid empty interval specification\n");
3447 ret = AVERROR(EINVAL);
3452 next = strchr(spec,
'%');
3467 ret = av_parse_time(&interval->
start, p, 1);
3469 av_log(NULL, AV_LOG_ERROR,
"Invalid interval start specification '%s'\n", p);
3494 lli = strtoll(p, &tail, 10);
3495 if (*tail || lli < 0) {
3496 av_log(NULL, AV_LOG_ERROR,
3497 "Invalid or negative value '%s' for duration number of frames\n", p);
3500 interval->
end = lli;
3503 ret = av_parse_time(&us, p, 1);
3505 av_log(NULL, AV_LOG_ERROR,
"Invalid interval end/duration specification '%s'\n", p);
3522 char *p, *spec = av_strdup(intervals_spec);
3524 return AVERROR(ENOMEM);
3527 for (n = 0, p = spec; *p; p++)
3534 ret = AVERROR(ENOMEM);
3541 for (i = 0; p; i++) {
3545 next = strchr(p,
',');
3552 av_log(NULL, AV_LOG_ERROR,
"Error parsing read interval #%d '%s'\n",
3556 av_log(NULL, AV_LOG_VERBOSE,
"Parsed log interval ");
3572 static int opt_pretty(
void *optctx,
const char *opt,
const char *arg)
3601 "W.. = Section is a wrapper (contains other sections, no local entries)\n"
3602 ".A. = Section contains an array of elements of the same type\n"
3603 "..V = Section may contain a variable number of fields with variable keys\n"
3604 "FLAGS NAME/UNIQUE_NAME\n"
3617 #define DEFINE_OPT_SHOW_SECTION(section, target_section_id) \
3618 static int opt_show_##section(void *optctx, const char *opt, const char *arg) \
3620 mark_section_show_entries(SECTION_ID_##target_section_id, 1, NULL); \
3647 #define SET_DO_SHOW(id, varname) do { \
3648 if (check_section_show_entries(SECTION_ID_##id)) \
3649 do_show_##varname = 1; \
3719 char _program_name[] =
"ffprobe";
3738 {
"bsfs",
OPT_EXIT, { .func_arg =
show_bsfs },
"show available bit stream filters" },
3747 {
"report", 0, { .func_arg =
opt_report },
"generate a report" },
3748 {
"max_alloc",
HAS_ARG, { .func_arg =
opt_max_alloc },
"set maximum size of a single allocated block",
"bytes" },
3755 "list sources of the input device",
"device" },
3757 "list sinks of the output device",
"device" },
3764 "use binary prefixes for byte units" },
3766 "use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units" },
3768 "prettify the format of displayed values, make it more human readable" },
3770 "set the output printing format (available formats are: default, compact, csv, flat, ini, json, xml)",
"format" },
3773 {
"sections",
OPT_EXIT, {.func_arg =
opt_sections},
"print sections structure and section information, and exit" },
3776 {
"show_error", 0, { .func_arg = &opt_show_error },
"show probing error" },
3777 {
"show_format", 0, { .func_arg = &opt_show_format },
"show format/container info" },
3778 {
"show_frames", 0, { .func_arg = &opt_show_frames },
"show frames info" },
3780 "show a particular entry from the format/container info",
"entry" },
3782 "show a set of specified entries",
"entry_list" },
3786 {
"show_packets", 0, { .func_arg = &opt_show_packets },
"show packets info" },
3787 {
"show_programs", 0, { .func_arg = &opt_show_programs },
"show programs info" },
3788 {
"show_streams", 0, { .func_arg = &opt_show_streams },
"show streams info" },
3789 {
"show_chapters", 0, { .func_arg = &opt_show_chapters },
"show chapters info" },
3792 {
"show_program_version", 0, { .func_arg = &opt_show_program_version },
"show ffprobe version" },
3793 {
"show_library_versions", 0, { .func_arg = &opt_show_library_versions },
"show library versions" },
3794 {
"show_versions", 0, { .func_arg = &
opt_show_versions },
"show program and library versions" },
3795 {
"show_pixel_formats", 0, { .func_arg = &opt_show_pixel_formats },
"show pixel format descriptions" },
3805 "read and decode the streams to fill missing information with heuristics" },
3812 char *w_name = NULL, *w_args = NULL;
3816 if (savedCode == 0) {
3823 ret = pthread_mutex_init(&log_mutex, NULL);
3828 av_log_set_flags(AV_LOG_SKIP_REPEATED);
3833 avformat_network_init();
3835 avdevice_register_all();
3852 SET_DO_SHOW(PIXEL_FORMAT_FLAGS, pixel_format_flags);
3853 SET_DO_SHOW(PIXEL_FORMAT_COMPONENTS, pixel_format_components);
3857 SET_DO_SHOW(STREAM_DISPOSITION, stream_disposition);
3858 SET_DO_SHOW(PROGRAM_STREAM_DISPOSITION, stream_disposition);
3869 av_log(NULL, AV_LOG_ERROR,
3870 "-bitexact and -show_program_version or -show_library_versions "
3871 "options are incompatible\n");
3872 ret = AVERROR(EINVAL);
3881 ret = AVERROR(ENOMEM);
3886 av_log(NULL, AV_LOG_ERROR,
3887 "No name specified for the output format\n");
3888 ret = AVERROR(EINVAL);
3895 if (ret == AVERROR(EINVAL)) {
3897 av_log(NULL, AV_LOG_ERROR,
3898 "Unknown hash algorithm '%s'\nKnown algorithms:",
3900 for (i = 0; (n = av_hash_names(i)); i++)
3901 av_log(NULL, AV_LOG_ERROR,
" %s", n);
3902 av_log(NULL, AV_LOG_ERROR,
"\n");
3910 av_log(NULL, AV_LOG_ERROR,
"Unknown output format with name '%s'\n", w_name);
3911 ret = AVERROR(EINVAL);
3933 av_log(NULL, AV_LOG_ERROR,
"You have to specify one input file.\n");
3934 av_log(NULL, AV_LOG_ERROR,
"Use -h to get full help or, even better, run 'man %s'.\n",
program_name);
3935 ret = AVERROR(EINVAL);
3955 av_hash_freep(&
hash);
3958 for (i = 0; i < FF_ARRAY_ELEMS(
sections); i++)
3961 avformat_network_deinit();