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/mastering_display_metadata.h"
46 #include "libavutil/opt.h"
47 #include "libavutil/pixdesc.h"
48 #include "libavutil/spherical.h"
49 #include "libavutil/stereo3d.h"
50 #include "libavutil/dict.h"
51 #include "libavutil/intreadwrite.h"
52 #include "libavutil/libm.h"
53 #include "libavutil/parseutils.h"
54 #include "libavutil/timecode.h"
55 #include "libavutil/timestamp.h"
56 #include "libavdevice/avdevice.h"
57 #include "libswscale/swscale.h"
58 #include "libswresample/swresample.h"
61 #include "libavutil/thread.h"
66 # ifdef pthread_mutex_lock
67 # undef pthread_mutex_lock
69 # define pthread_mutex_lock(a) do{}while(0)
70 # ifdef pthread_mutex_unlock
71 # undef pthread_mutex_unlock
73 # define pthread_mutex_unlock(a) do{}while(0)
140 #define SECTION_MAX_NB_CHILDREN 10
146 #define SECTION_FLAG_IS_WRAPPER 1
147 #define SECTION_FLAG_IS_ARRAY 2
148 #define SECTION_FLAG_HAS_VARIABLE_FIELDS 4
262 __thread
struct AVHashContext *
hash;
267 static const struct {
273 { 1.0, 1.0,
"",
"" },
274 { 1.024e3, 1e3,
"Ki",
"K" },
275 { 1.048576e6, 1e6,
"Mi",
"M" },
276 { 1.073741824e9, 1e9,
"Gi",
"G" },
277 { 1.099511627776e12, 1e12,
"Ti",
"T" },
278 { 1.125899906842624e15, 1e15,
"Pi",
"P" },
292 __thread pthread_mutex_t log_mutex;
306 static void log_callback(
void *ptr,
int level,
const char *fmt, va_list vl)
308 AVClass* avc = ptr ? *(AVClass **) ptr : NULL;
311 static int print_prefix = 1;
312 void *new_log_buffer;
315 av_log_default_callback(ptr, level, fmt, vl);
316 av_log_format_line(ptr, level, fmt, vl2, line,
sizeof(line), &print_prefix);
323 if (new_log_buffer) {
336 for (i=strlen(msg) - 1; i>=0 && msg[i] ==
'\n'; i--) {
339 if (avc && avc->parent_log_context_offset) {
340 AVClass** parent = *(AVClass ***) (((uint8_t *) ptr) +
341 avc->parent_log_context_offset);
342 if (parent && *parent) {
345 (*parent)->get_category ? (*parent)->get_category(parent) :(*parent)->category;
358 for (i = 0; i < FF_ARRAY_ELEMS(
sections); i++)
359 av_dict_free(&(
sections[i].entries_to_show));
362 pthread_mutex_destroy(&log_mutex);
367 union {
double d;
long long int i; }
val;
381 vald = vali = uv.
val.
i;
388 mins = (
int)secs / 60;
389 secs = secs - mins * 60;
392 snprintf(buf, buf_size,
"%d:%02d:%09.6f", hours, mins, secs);
394 const char *prefix_string =
"";
400 index = (
long long int) (log2(vald)) / 10;
401 index = av_clip(index, 0, FF_ARRAY_ELEMS(
si_prefixes) - 1);
405 index = (
long long int) (log10(vald)) / 3;
406 index = av_clip(index, 0, FF_ARRAY_ELEMS(
si_prefixes) - 1);
414 snprintf(buf, buf_size,
"%f", vald);
416 snprintf(buf, buf_size,
"%lld", vali);
417 av_strlcatf(buf, buf_size,
"%s%s%s", *prefix_string ||
show_value_unit ?
" " :
"",
428 #define WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS 1
429 #define WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER 2
454 #define SECTION_MAX_NB_LEVELS 10
457 const AVClass *
class;
490 #define OFFSET(x) offsetof(WriterContext, x)
493 {
"string_validation",
"set string validation mode",
495 {
"sv",
"set string validation mode",
500 {
"string_validation_replacement",
"set string validation replacement string",
OFFSET(string_validation_replacement), AV_OPT_TYPE_STRING, {.str=
""}},
501 {
"svr",
"set string validation replacement string",
OFFSET(string_validation_replacement), AV_OPT_TYPE_STRING, {.str=
"\xEF\xBF\xBD"}},
514 .class_name =
"Writer",
517 .version = LIBAVUTIL_VERSION_INT,
528 if ((*wctx)->writer->uninit)
529 (*wctx)->writer->uninit(*wctx);
531 av_bprint_finalize(&(*wctx)->section_pbuf[i], NULL);
532 if ((*wctx)->writer->priv_class)
533 av_opt_free((*wctx)->priv);
534 av_freep(&((*wctx)->priv));
539 static void bprint_bytes(AVBPrint *bp,
const uint8_t *ubuf,
size_t ubuf_size)
542 av_bprintf(bp,
"0X");
543 for (i = 0; i < ubuf_size; i++)
544 av_bprintf(bp,
"%02X", ubuf[i]);
554 ret = AVERROR(ENOMEM);
558 if (!((*wctx)->priv = av_mallocz(writer->
priv_size))) {
559 ret = AVERROR(ENOMEM);
564 (*wctx)->writer = writer;
567 (*wctx)->nb_sections = nb_sections;
569 av_opt_set_defaults(*wctx);
572 void *priv_ctx = (*wctx)->priv;
573 *((
const AVClass **)priv_ctx) = writer->
priv_class;
574 av_opt_set_defaults(priv_ctx);
579 AVDictionary *opts = NULL;
580 AVDictionaryEntry *opt = NULL;
582 if ((ret = av_dict_parse_string(&opts, args,
"=",
":", 0)) < 0) {
583 av_log(*wctx,
AV_LOG_ERROR,
"Failed to parse option string '%s' provided to writer context\n", args);
588 while ((opt = av_dict_get(opts,
"", opt, AV_DICT_IGNORE_SUFFIX))) {
589 if ((ret = av_opt_set(*wctx, opt->key, opt->value, AV_OPT_SEARCH_CHILDREN)) < 0) {
590 av_log(*wctx,
AV_LOG_ERROR,
"Failed to set option '%s' with value '%s' provided to writer context\n",
591 opt->key, opt->value);
602 const uint8_t *p = (*wctx)->string_validation_replacement;
603 const uint8_t *endp = p + strlen(p);
605 const uint8_t *p0 = p;
607 ret = av_utf8_decode(&code, &p, endp, (*wctx)->string_validation_utf8_flags);
610 av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
613 "Invalid UTF8 sequence %s found in string validation replace '%s'\n",
614 bp.str, (*wctx)->string_validation_replacement);
621 av_bprint_init(&(*wctx)->section_pbuf[i], 1, AV_BPRINT_SIZE_UNLIMITED);
623 if ((*wctx)->writer->init)
624 ret = (*wctx)->writer->init(*wctx);
638 int parent_section_id;
641 parent_section_id = wctx->
level ?
662 int parent_section_id = wctx->
level ?
677 const char *key,
long long int val)
689 const uint8_t *p, *endp;
691 int invalid_chars_nb = 0, ret = 0;
693 av_bprint_init(&dstbuf, 0, AV_BPRINT_SIZE_UNLIMITED);
695 endp = src + strlen(src);
696 for (p = (uint8_t *)src; *p;) {
699 const uint8_t *p0 = p;
703 av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
706 "Invalid UTF-8 sequence %s found in string '%s'\n", bp.str, src);
716 "Invalid UTF-8 sequence found in string '%s'\n", src);
717 ret = AVERROR_INVALIDDATA;
728 av_bprint_append_data(&dstbuf, p0, p-p0);
733 "%d invalid UTF-8 sequence(s) found in string '%s', replaced with '%s'\n",
738 av_bprint_finalize(&dstbuf, dstp);
742 #define PRINT_STRING_OPT 1
743 #define PRINT_STRING_VALIDATE 2
746 const char *key,
const char *val,
int flags)
757 char *key1 = NULL, *val1 = NULL;
759 if (ret < 0)
goto end;
761 if (ret < 0)
goto end;
766 "Invalid key=value string combination %s=%s in section %s\n",
782 const char *key, AVRational q,
char sep)
785 av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC);
786 av_bprintf(&buf,
"%d%c%d", q.num, sep, q.den);
791 int64_t ts,
const AVRational *time_base,
int is_duration)
795 if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
798 double d = ts * av_q2d(*time_base);
809 if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
817 uint8_t *data,
int size)
820 int offset = 0, l,
i;
822 av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
823 av_bprintf(&bp,
"\n");
825 av_bprintf(&bp,
"%08x: ", offset);
827 for (
i = 0;
i < l;
i++) {
828 av_bprintf(&bp,
"%02x", data[
i]);
830 av_bprintf(&bp,
" ");
832 av_bprint_chars(&bp,
' ', 41 - 2 *
i -
i / 2);
833 for (
i = 0;
i < l;
i++)
834 av_bprint_chars(&bp, data[
i] - 32U < 95 ? data[
i] :
'.', 1);
835 av_bprintf(&bp,
"\n");
841 av_bprint_finalize(&bp, NULL);
845 uint8_t *data,
int size)
847 char *p, buf[AV_HASH_MAX_SIZE * 2 + 64] = { 0 };
853 snprintf(buf,
sizeof(buf),
"%s:", av_hash_get_name(
hash));
854 p = buf + strlen(buf);
855 av_hash_final_hex(
hash, p, buf +
sizeof(buf) - p);
860 uint8_t *data,
int size,
const char *format,
861 int columns,
int bytes,
int offset_add)
864 int offset = 0, l,
i;
866 av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
867 av_bprintf(&bp,
"\n");
869 av_bprintf(&bp,
"%08x: ", offset);
870 l = FFMIN(
size, columns);
871 for (
i = 0;
i < l;
i++) {
872 if (bytes == 1) av_bprintf(&bp, format, *data);
873 else if (bytes == 2) av_bprintf(&bp, format, AV_RN16(data));
874 else if (bytes == 4) av_bprintf(&bp, format, AV_RN32(data));
878 av_bprintf(&bp,
"\n");
879 offset += offset_add;
882 av_bprint_finalize(&bp, NULL);
885 #define MAX_REGISTERED_WRITERS_NB 64
894 return AVERROR(ENOMEM);
914 #define DEFINE_WRITER_CLASS(name) \
915 static const char *name##_get_name(void *ctx) \
919 static const AVClass name##_class = { \
920 .class_name = #name, \
921 .item_name = name##_get_name, \
922 .option = name##_options \
928 const AVClass *
class;
935 #define OFFSET(x) offsetof(DefaultContext, x)
938 {
"noprint_wrappers",
"do not print headers and footers",
OFFSET(noprint_wrappers), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
939 {
"nw",
"do not print headers and footers",
OFFSET(noprint_wrappers), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
940 {
"nokey",
"force no key printing",
OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
941 {
"nk",
"force no key printing",
OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
948 static inline char *
upcase_string(
char *dst,
size_t dst_size,
const char *src)
951 for (i = 0; src[i] && i < dst_size-1; i++)
952 dst[i] = av_toupper(src[i]);
966 if (parent_section &&
1021 .priv_class = &default_class,
1029 static const char *
c_escape_str(AVBPrint *dst,
const char *src,
const char sep,
void *log_ctx)
1033 for (p = src; *p; p++) {
1035 case '\b': av_bprintf(dst,
"%s",
"\\b");
break;
1036 case '\f': av_bprintf(dst,
"%s",
"\\f");
break;
1037 case '\n': av_bprintf(dst,
"%s",
"\\n");
break;
1038 case '\r': av_bprintf(dst,
"%s",
"\\r");
break;
1039 case '\\': av_bprintf(dst,
"%s",
"\\\\");
break;
1042 av_bprint_chars(dst,
'\\', 1);
1043 av_bprint_chars(dst, *p, 1);
1052 static const char *
csv_escape_str(AVBPrint *dst,
const char *src,
const char sep,
void *log_ctx)
1054 char meta_chars[] = { sep,
'"',
'\n',
'\r',
'\0' };
1055 int needs_quoting = !!src[strcspn(src, meta_chars)];
1058 av_bprint_chars(dst,
'"', 1);
1060 for (; *src; src++) {
1062 av_bprint_chars(dst,
'"', 1);
1063 av_bprint_chars(dst, *src, 1);
1066 av_bprint_chars(dst,
'"', 1);
1070 static const char *
none_escape_str(AVBPrint *dst,
const char *src,
const char sep,
void *log_ctx)
1076 const AVClass *
class;
1082 const char * (*escape_str)(AVBPrint *dst,
const char *src,
const char sep,
void *log_ctx);
1089 #define OFFSET(x) offsetof(CompactContext, x)
1092 {
"item_sep",
"set item separator",
OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=
"|"}, CHAR_MIN, CHAR_MAX },
1093 {
"s",
"set item separator",
OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=
"|"}, CHAR_MIN, CHAR_MAX },
1094 {
"nokey",
"force no key printing",
OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1095 {
"nk",
"force no key printing",
OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1096 {
"escape",
"set escape mode",
OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str=
"c"}, CHAR_MIN, CHAR_MAX },
1097 {
"e",
"set escape mode",
OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str=
"c"}, CHAR_MIN, CHAR_MAX },
1098 {
"print_section",
"print section name",
OFFSET(
print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1110 av_log(wctx,
AV_LOG_ERROR,
"Item separator '%s' specified, but must contain a single character\n",
1112 return AVERROR(EINVAL);
1121 return AVERROR(EINVAL);
1173 if (!compact->
nokey)
1175 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1177 av_bprint_finalize(&buf, NULL);
1185 if (!compact->
nokey)
1199 .priv_class = &compact_class,
1205 #define OFFSET(x) offsetof(CompactContext, x)
1208 {
"item_sep",
"set item separator",
OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=
","}, CHAR_MIN, CHAR_MAX },
1209 {
"s",
"set item separator",
OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=
","}, CHAR_MIN, CHAR_MAX },
1210 {
"nokey",
"force no key printing",
OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1211 {
"nk",
"force no key printing",
OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1212 {
"escape",
"set escape mode",
OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str=
"csv"}, CHAR_MIN, CHAR_MAX },
1213 {
"e",
"set escape mode",
OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str=
"csv"}, CHAR_MIN, CHAR_MAX },
1214 {
"print_section",
"print section name",
OFFSET(
print_section), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1230 .priv_class = &csv_class,
1236 const AVClass *
class;
1243 #define OFFSET(x) offsetof(FlatContext, x)
1246 {
"sep_char",
"set separator",
OFFSET(sep_str), AV_OPT_TYPE_STRING, {.str=
"."}, CHAR_MIN, CHAR_MAX },
1247 {
"s",
"set separator",
OFFSET(sep_str), AV_OPT_TYPE_STRING, {.str=
"."}, CHAR_MIN, CHAR_MAX },
1248 {
"hierarchical",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1249 {
"h",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1259 if (strlen(flat->
sep_str) != 1) {
1260 av_log(wctx,
AV_LOG_ERROR,
"Item separator '%s' specified, but must contain a single character\n",
1262 return AVERROR(EINVAL);
1273 for (p = src; *p; p++) {
1274 if (!((*p >=
'0' && *p <=
'9') ||
1275 (*p >=
'a' && *p <=
'z') ||
1276 (*p >=
'A' && *p <=
'Z')))
1277 av_bprint_chars(dst,
'_', 1);
1279 av_bprint_chars(dst, *p, 1);
1288 for (p = src; *p; p++) {
1290 case '\n': av_bprintf(dst,
"%s",
"\\n");
break;
1291 case '\r': av_bprintf(dst,
"%s",
"\\r");
break;
1292 case '\\': av_bprintf(dst,
"%s",
"\\\\");
break;
1293 case '"': av_bprintf(dst,
"%s",
"\\\"");
break;
1294 case '`': av_bprintf(dst,
"%s",
"\\`");
break;
1295 case '$': av_bprintf(dst,
"%s",
"\\$");
break;
1296 default: av_bprint_chars(dst, *p, 1);
break;
1311 av_bprint_clear(buf);
1312 if (!parent_section)
1323 av_bprintf(buf,
"%d%s", n, flat->
sep_str);
1339 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1341 av_bprint_clear(&buf);
1343 av_bprint_finalize(&buf, NULL);
1354 .priv_class = &flat_class,
1360 const AVClass *
class;
1365 #define OFFSET(x) offsetof(INIContext, x)
1368 {
"hierarchical",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1369 {
"h",
"specify if the section specification should be hierarchical",
OFFSET(hierarchical), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1 },
1380 while ((c = src[i++])) {
1382 case '\b': av_bprintf(dst,
"%s",
"\\b");
break;
1383 case '\f': av_bprintf(dst,
"%s",
"\\f");
break;
1384 case '\n': av_bprintf(dst,
"%s",
"\\n");
break;
1385 case '\r': av_bprintf(dst,
"%s",
"\\r");
break;
1386 case '\t': av_bprintf(dst,
"%s",
"\\t");
break;
1390 case ':' : av_bprint_chars(dst,
'\\', 1);
1392 if ((
unsigned char)c < 32)
1393 av_bprintf(dst,
"\\x00%02x", c & 0xff);
1395 av_bprint_chars(dst, c, 1);
1410 av_bprint_clear(buf);
1411 if (!parent_section) {
1422 av_bprintf(buf,
"%s%s", buf->str[0] ?
"." :
"", wctx->
section[wctx->
level]->
name);
1427 av_bprintf(buf,
".%d", n);
1439 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1441 av_bprint_clear(&buf);
1443 av_bprint_finalize(&buf, NULL);
1458 .priv_class = &ini_class,
1464 const AVClass *
class;
1471 #define OFFSET(x) offsetof(JSONContext, x)
1474 {
"compact",
"enable compact output",
OFFSET(compact), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1475 {
"c",
"enable compact output",
OFFSET(compact), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1493 static const char json_escape[] = {
'"',
'\\',
'\b',
'\f',
'\n',
'\r',
'\t', 0};
1494 static const char json_subst[] = {
'"',
'\\',
'b',
'f',
'n',
'r',
't', 0};
1497 for (p = src; *p; p++) {
1498 char *s = strchr(json_escape, *p);
1500 av_bprint_chars(dst,
'\\', 1);
1501 av_bprint_chars(dst, json_subst[s - json_escape], 1);
1502 }
else if ((
unsigned char)*p < 32) {
1503 av_bprintf(dst,
"\\u00%02x", *p & 0xff);
1505 av_bprint_chars(dst, *p, 1);
1511 #define JSON_INDENT() av_log(NULL, AV_LOG_STDERR, "%*c", json->indent_level * 4, ' ')
1528 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1547 av_bprint_finalize(&buf, NULL);
1556 if (wctx->
level == 0) {
1574 const char *key,
const char *
value)
1578 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1580 av_bprint_clear(&buf);
1582 av_bprint_finalize(&buf, NULL);
1610 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1612 av_bprint_finalize(&buf, NULL);
1624 .priv_class = &json_class,
1630 const AVClass *
class;
1638 #define OFFSET(x) offsetof(XMLContext, x)
1641 {
"fully_qualified",
"specify if the output should be fully qualified",
OFFSET(fully_qualified), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1642 {
"q",
"specify if the output should be fully qualified",
OFFSET(fully_qualified), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1643 {
"xsd_strict",
"ensure that the output is XSD compliant",
OFFSET(xsd_strict), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1644 {
"x",
"ensure that the output is XSD compliant",
OFFSET(xsd_strict), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
1656 #define CHECK_COMPLIANCE(opt, opt_name) \
1658 av_log(wctx, AV_LOG_ERROR, \
1659 "XSD-compliant output selected but option '%s' was selected, XML output may be non-compliant.\n" \
1660 "You need to disable such option with '-no%s'\n", opt_name, opt_name); \
1661 return AVERROR(EINVAL); \
1669 "Interleaved frames and packets are not allowed in XSD. "
1670 "Select only one between the -show_frames and the -show_packets options.\n");
1671 return AVERROR(EINVAL);
1682 for (p = src; *p; p++) {
1684 case '&' : av_bprintf(dst,
"%s",
"&");
break;
1685 case '<' : av_bprintf(dst,
"%s",
"<");
break;
1686 case '>' : av_bprintf(dst,
"%s",
">");
break;
1687 case '"' : av_bprintf(dst,
"%s",
""");
break;
1688 case '\'': av_bprintf(dst,
"%s",
"'");
break;
1689 default: av_bprint_chars(dst, *p, 1);
1696 #define XML_INDENT() av_log(NULL, AV_LOG_STDERR, "%*c", xml->indent_level * 4, ' ')
1705 if (wctx->
level == 0) {
1706 const char *qual =
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' "
1707 "xmlns:ffprobe='http://www.ffmpeg.org/schema/ffprobe' "
1708 "xsi:schemaLocation='http://www.ffmpeg.org/schema/ffprobe ffprobe.xsd'";
1710 av_log(NULL,
AV_LOG_STDERR,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
1743 if (wctx->
level == 0) {
1763 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
1769 av_bprint_clear(&buf);
1777 av_bprint_finalize(&buf, NULL);
1796 .priv_class = &xml_class,
1811 #define print_fmt(k, f, ...) do { \
1812 av_bprint_clear(&pbuf); \
1813 av_bprintf(&pbuf, f, __VA_ARGS__); \
1814 writer_print_string(w, k, pbuf.str, 0); \
1817 #define print_int(k, v) writer_print_integer(w, k, v)
1818 #define print_q(k, v, s) writer_print_rational(w, k, v, s)
1819 #define print_str(k, v) writer_print_string(w, k, v, 0)
1820 #define print_str_opt(k, v) writer_print_string(w, k, v, PRINT_STRING_OPT)
1821 #define print_str_validate(k, v) writer_print_string(w, k, v, PRINT_STRING_VALIDATE)
1822 #define print_time(k, v, tb) writer_print_time(w, k, v, tb, 0)
1823 #define print_ts(k, v) writer_print_ts(w, k, v, 0)
1824 #define print_duration_time(k, v, tb) writer_print_time(w, k, v, tb, 1)
1825 #define print_duration_ts(k, v) writer_print_ts(w, k, v, 1)
1826 #define print_val(k, v, u) do { \
1827 struct unit_value uv; \
1830 writer_print_string(w, k, value_string(val_str, sizeof(val_str), uv), 0); \
1833 #define print_section_header(s) writer_print_section_header(w, s)
1834 #define print_section_footer(s) writer_print_section_footer(w, s)
1836 #define REALLOCZ_ARRAY_STREAM(ptr, cur_n, new_n) \
1838 ret = av_reallocp_array(&(ptr), (new_n), sizeof(*(ptr))); \
1841 memset( (ptr) + (cur_n), 0, ((new_n) - (cur_n)) * sizeof(*(ptr)) ); \
1846 AVDictionaryEntry *tag = NULL;
1853 while ((tag = av_dict_get(tags,
"", tag, AV_DICT_IGNORE_SUFFIX))) {
1863 AVCodecParameters *par,
1864 const AVPacketSideData *side_data,
1872 for (i = 0; i < nb_side_data; i++) {
1873 const AVPacketSideData *sd = &side_data[i];
1874 const char *
name = av_packet_side_data_name(sd->type);
1878 if (sd->type == AV_PKT_DATA_DISPLAYMATRIX && sd->size >= 9*4) {
1880 print_int(
"rotation", av_display_rotation_get((int32_t *)sd->data));
1881 }
else if (sd->type == AV_PKT_DATA_STEREO3D) {
1882 const AVStereo3D *stereo = (AVStereo3D *)sd->data;
1883 print_str(
"type", av_stereo3d_type_name(stereo->type));
1884 print_int(
"inverted", !!(stereo->flags & AV_STEREO3D_FLAG_INVERT));
1885 }
else if (sd->type == AV_PKT_DATA_SPHERICAL) {
1886 const AVSphericalMapping *spherical = (AVSphericalMapping *)sd->data;
1887 print_str(
"projection", av_spherical_projection_name(spherical->projection));
1888 if (spherical->projection == AV_SPHERICAL_CUBEMAP) {
1889 print_int(
"padding", spherical->padding);
1890 }
else if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR_TILE) {
1892 av_spherical_tile_bounds(spherical, par->width, par->height,
1900 print_int(
"yaw", (
double) spherical->yaw / (1 << 16));
1901 print_int(
"pitch", (
double) spherical->pitch / (1 << 16));
1902 print_int(
"roll", (
double) spherical->roll / (1 << 16));
1903 }
else if (sd->type == AV_PKT_DATA_SKIP_SAMPLES && sd->size == 10) {
1904 print_int(
"skip_samples", AV_RL32(sd->data));
1905 print_int(
"discard_padding", AV_RL32(sd->data + 4));
1906 print_int(
"skip_reason", AV_RL8(sd->data + 8));
1907 print_int(
"discard_reason", AV_RL8(sd->data + 9));
1908 }
else if (sd->type == AV_PKT_DATA_MASTERING_DISPLAY_METADATA) {
1909 AVMasteringDisplayMetadata *metadata = (AVMasteringDisplayMetadata *)sd->data;
1911 if (metadata->has_primaries) {
1912 print_q(
"red_x", metadata->display_primaries[0][0],
'/');
1913 print_q(
"red_y", metadata->display_primaries[0][1],
'/');
1914 print_q(
"green_x", metadata->display_primaries[1][0],
'/');
1915 print_q(
"green_y", metadata->display_primaries[1][1],
'/');
1916 print_q(
"blue_x", metadata->display_primaries[2][0],
'/');
1917 print_q(
"blue_y", metadata->display_primaries[2][1],
'/');
1919 print_q(
"white_point_x", metadata->white_point[0],
'/');
1920 print_q(
"white_point_y", metadata->white_point[1],
'/');
1923 if (metadata->has_luminance) {
1924 print_q(
"min_luminance", metadata->min_luminance,
'/');
1925 print_q(
"max_luminance", metadata->max_luminance,
'/');
1927 }
else if (sd->type == AV_PKT_DATA_CONTENT_LIGHT_LEVEL) {
1928 AVContentLightMetadata *metadata = (AVContentLightMetadata *)sd->data;
1929 print_int(
"max_content", metadata->MaxCLL);
1930 print_int(
"max_average", metadata->MaxFALL);
1939 const char *val = av_color_range_name(color_range);
1940 if (!val || color_range == AVCOL_RANGE_UNSPECIFIED) {
1949 const char *val = av_color_space_name(color_space);
1950 if (!val || color_space == AVCOL_SPC_UNSPECIFIED) {
1959 const char *val = av_color_primaries_name(color_primaries);
1960 if (!val || color_primaries == AVCOL_PRI_UNSPECIFIED) {
1969 const char *val = av_color_transfer_name(color_trc);
1970 if (!val || color_trc == AVCOL_TRC_UNSPECIFIED) {
1979 const char *val = av_chroma_location_name(chroma_location);
1980 if (!val || chroma_location == AVCHROMA_LOC_UNSPECIFIED) {
2042 AVStream *st = ifile->
streams[pkt->stream_index].
st;
2046 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2050 s = av_get_media_type_string(st->codecpar->codec_type);
2053 print_int(
"stream_index", pkt->stream_index);
2055 print_time(
"pts_time", pkt->pts, &st->time_base);
2057 print_time(
"dts_time", pkt->dts, &st->time_base);
2061 print_duration_time(
"convergence_duration_time", pkt->convergence_duration, &st->time_base);
2063 if (pkt->pos != -1)
print_fmt (
"pos",
"%"PRId64, pkt->pos);
2065 print_fmt(
"flags",
"%c%c", pkt->flags & AV_PKT_FLAG_KEY ?
'K' :
'_',
2066 pkt->flags & AV_PKT_FLAG_DISCARD ?
'D' :
'_');
2068 if (pkt->side_data_elems) {
2070 const uint8_t *side_metadata;
2072 side_metadata = av_packet_get_side_data(pkt, AV_PKT_DATA_STRINGS_METADATA, &
size);
2074 AVDictionary *dict = NULL;
2075 if (av_packet_unpack_dictionary(side_metadata,
size, &dict) >= 0)
2077 av_dict_free(&dict);
2090 av_bprint_finalize(&pbuf, NULL);
2095 AVFormatContext *fmt_ctx)
2099 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2105 print_time(
"pts_time", sub->pts, &AV_TIME_BASE_Q);
2107 print_int (
"start_display_time", sub->start_display_time);
2108 print_int (
"end_display_time", sub->end_display_time);
2109 print_int (
"num_rects", sub->num_rects);
2113 av_bprint_finalize(&pbuf, NULL);
2118 AVFormatContext *fmt_ctx)
2125 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2129 s = av_get_media_type_string(stream->codecpar->codec_type);
2132 print_int(
"stream_index", stream->index);
2133 print_int(
"key_frame", frame->key_frame);
2135 print_time(
"pkt_pts_time", frame->pts, &stream->time_base);
2136 print_ts (
"pkt_dts", frame->pkt_dts);
2137 print_time(
"pkt_dts_time", frame->pkt_dts, &stream->time_base);
2138 print_ts (
"best_effort_timestamp", frame->best_effort_timestamp);
2139 print_time(
"best_effort_timestamp_time", frame->best_effort_timestamp, &stream->time_base);
2142 if (frame->pkt_pos != -1)
print_fmt (
"pkt_pos",
"%"PRId64, frame->pkt_pos);
2147 switch (stream->codecpar->codec_type) {
2150 case AVMEDIA_TYPE_VIDEO:
2153 s = av_get_pix_fmt_name(frame->format);
2156 sar = av_guess_sample_aspect_ratio(fmt_ctx, stream, frame);
2158 print_q(
"sample_aspect_ratio", sar,
':');
2162 print_fmt(
"pict_type",
"%c", av_get_picture_type_char(frame->pict_type));
2163 print_int(
"coded_picture_number", frame->coded_picture_number);
2164 print_int(
"display_picture_number", frame->display_picture_number);
2165 print_int(
"interlaced_frame", frame->interlaced_frame);
2166 print_int(
"top_field_first", frame->top_field_first);
2167 print_int(
"repeat_pict", frame->repeat_pict);
2176 case AVMEDIA_TYPE_AUDIO:
2177 s = av_get_sample_fmt_name(frame->format);
2180 print_int(
"nb_samples", frame->nb_samples);
2182 if (frame->channel_layout) {
2183 av_bprint_clear(&pbuf);
2184 av_bprint_channel_layout(&pbuf, frame->channels,
2185 frame->channel_layout);
2195 if (frame->nb_side_data) {
2197 for (i = 0; i < frame->nb_side_data; i++) {
2198 AVFrameSideData *sd = frame->side_data[i];
2202 name = av_frame_side_data_name(sd->type);
2204 if (sd->type == AV_FRAME_DATA_DISPLAYMATRIX && sd->size >= 9*4) {
2206 print_int(
"rotation", av_display_rotation_get((int32_t *)sd->data));
2207 }
else if (sd->type == AV_FRAME_DATA_GOP_TIMECODE && sd->size >= 8) {
2208 char tcbuf[AV_TIMECODE_STR_SIZE];
2209 av_timecode_make_mpeg_tc_string(tcbuf, *(int64_t *)(sd->data));
2211 }
else if (sd->type == AV_FRAME_DATA_S12M_TIMECODE && sd->size == 16) {
2212 uint32_t *tc = (uint32_t*)sd->data;
2213 int m = FFMIN(tc[0],3);
2215 for (
int j = 1; j <= m ; j++) {
2216 char tcbuf[AV_TIMECODE_STR_SIZE];
2217 av_timecode_make_smpte_tc_string(tcbuf, tc[j], 0);
2223 }
else if (sd->type == AV_FRAME_DATA_MASTERING_DISPLAY_METADATA) {
2224 AVMasteringDisplayMetadata *metadata = (AVMasteringDisplayMetadata *)sd->data;
2226 if (metadata->has_primaries) {
2227 print_q(
"red_x", metadata->display_primaries[0][0],
'/');
2228 print_q(
"red_y", metadata->display_primaries[0][1],
'/');
2229 print_q(
"green_x", metadata->display_primaries[1][0],
'/');
2230 print_q(
"green_y", metadata->display_primaries[1][1],
'/');
2231 print_q(
"blue_x", metadata->display_primaries[2][0],
'/');
2232 print_q(
"blue_y", metadata->display_primaries[2][1],
'/');
2234 print_q(
"white_point_x", metadata->white_point[0],
'/');
2235 print_q(
"white_point_y", metadata->white_point[1],
'/');
2238 if (metadata->has_luminance) {
2239 print_q(
"min_luminance", metadata->min_luminance,
'/');
2240 print_q(
"max_luminance", metadata->max_luminance,
'/');
2242 }
else if (sd->type == AV_FRAME_DATA_CONTENT_LIGHT_LEVEL) {
2243 AVContentLightMetadata *metadata = (AVContentLightMetadata *)sd->data;
2244 print_int(
"max_content", metadata->MaxCLL);
2245 print_int(
"max_average", metadata->MaxFALL);
2246 }
else if (sd->type == AV_FRAME_DATA_ICC_PROFILE) {
2247 AVDictionaryEntry *tag = av_dict_get(sd->metadata,
"name", NULL, AV_DICT_MATCH_CASE);
2259 av_bprint_finalize(&pbuf, NULL);
2265 AVFrame *frame, AVPacket *pkt,
2268 AVFormatContext *fmt_ctx = ifile->
fmt_ctx;
2269 AVCodecContext *dec_ctx = ifile->
streams[pkt->stream_index].
dec_ctx;
2270 AVCodecParameters *par = ifile->
streams[pkt->stream_index].
st->codecpar;
2272 int ret = 0, got_frame = 0;
2275 if (dec_ctx && dec_ctx->codec) {
2276 switch (par->codec_type) {
2277 case AVMEDIA_TYPE_VIDEO:
2278 case AVMEDIA_TYPE_AUDIO:
2280 ret = avcodec_send_packet(dec_ctx, pkt);
2281 if (ret == AVERROR(EAGAIN)) {
2283 }
else if (ret >= 0 || ret == AVERROR_EOF) {
2289 ret = avcodec_receive_frame(dec_ctx, frame);
2292 }
else if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
2298 case AVMEDIA_TYPE_SUBTITLE:
2300 ret = avcodec_decode_subtitle2(dec_ctx, &sub, &got_frame, pkt);
2313 int is_sub = (par->codec_type == AVMEDIA_TYPE_SUBTITLE);
2323 avsubtitle_free(&sub);
2326 return got_frame || *packet_new;
2331 av_log(log_ctx, log_level,
"id:%d", interval->
id);
2334 av_log(log_ctx, log_level,
" start:%s%s", interval->
start_is_offset ?
"+" :
"",
2335 av_ts2timestr(interval->
start, &AV_TIME_BASE_Q));
2337 av_log(log_ctx, log_level,
" start:N/A");
2341 av_log(log_ctx, log_level,
" end:%s", interval->
end_is_offset ?
"+" :
"");
2343 av_log(log_ctx, log_level,
"#%"PRId64, interval->
end);
2345 av_log(log_ctx, log_level,
"%s", av_ts2timestr(interval->
end, &AV_TIME_BASE_Q));
2347 av_log(log_ctx, log_level,
" end:N/A");
2350 av_log(log_ctx, log_level,
"\n");
2356 AVFormatContext *fmt_ctx = ifile->
fmt_ctx;
2358 AVFrame *frame = NULL;
2359 int ret = 0, i = 0, frame_count = 0;
2360 int64_t start = -INT64_MAX, end = interval->
end;
2363 av_init_packet(&pkt);
2371 if (*cur_ts == AV_NOPTS_VALUE) {
2373 "Could not seek to relative position since current "
2374 "timestamp is not defined\n");
2375 ret = AVERROR(EINVAL);
2378 target = *cur_ts + interval->
start;
2380 target = interval->
start;
2383 av_log(NULL,
AV_LOG_VERBOSE,
"Seeking to read interval start point %s\n",
2384 av_ts2timestr(target, &AV_TIME_BASE_Q));
2385 if ((ret = avformat_seek_file(fmt_ctx, -1, -INT64_MAX, target, INT64_MAX, 0)) < 0) {
2386 av_log(NULL,
AV_LOG_ERROR,
"Could not seek to position %"PRId64
": %s\n",
2387 interval->
start, av_err2str(ret));
2392 frame = av_frame_alloc();
2394 ret = AVERROR(ENOMEM);
2397 while (!av_read_frame(fmt_ctx, &pkt)) {
2405 AVRational tb = ifile->
streams[pkt.stream_index].
st->time_base;
2407 if (pkt.pts != AV_NOPTS_VALUE)
2408 *cur_ts = av_rescale_q(pkt.pts, tb, AV_TIME_BASE_Q);
2410 if (!has_start && *cur_ts != AV_NOPTS_VALUE) {
2416 end = start + interval->
end;
2421 if (frame_count >= interval->
end)
2423 }
else if (has_end && *cur_ts != AV_NOPTS_VALUE && *cur_ts >= end) {
2435 while (
process_frame(w, ifile, frame, &pkt, &packet_new) > 0);
2438 av_packet_unref(&pkt);
2440 av_packet_unref(&pkt);
2442 for (i = 0; i < fmt_ctx->nb_streams; i++) {
2443 pkt.stream_index = i;
2445 while (
process_frame(w, ifile, frame, &pkt, &(
int){1}) > 0);
2449 av_frame_free(&frame);
2451 av_log(NULL,
AV_LOG_ERROR,
"Could not read packets in interval ");
2459 AVFormatContext *fmt_ctx = ifile->
fmt_ctx;
2461 int64_t cur_ts = fmt_ctx->start_time;
2479 AVStream *stream = ist->
st;
2480 AVCodecParameters *par;
2481 AVCodecContext *dec_ctx;
2484 AVRational sar, dar;
2486 const AVCodecDescriptor *cd;
2488 const char *profile = NULL;
2490 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
2496 par = stream->codecpar;
2498 if ((cd = avcodec_descriptor_get(par->codec_id))) {
2502 cd->long_name ? cd->long_name :
"unknown");
2511 if (!
do_bitexact && (profile = avcodec_profile_name(par->codec_id, par->profile)))
2514 if (par->profile != FF_PROFILE_UNKNOWN) {
2515 char profile_num[12];
2516 snprintf(profile_num,
sizeof(profile_num),
"%d", par->profile);
2522 s = av_get_media_type_string(par->codec_type);
2525 #if FF_API_LAVF_AVCTX
2527 print_q(
"codec_time_base", dec_ctx->time_base,
'/');
2531 print_str(
"codec_tag_string", av_fourcc2str(par->codec_tag));
2532 print_fmt(
"codec_tag",
"0x%04"PRIx32, par->codec_tag);
2534 switch (par->codec_type) {
2535 case AVMEDIA_TYPE_VIDEO:
2538 #if FF_API_LAVF_AVCTX
2540 print_int(
"coded_width", dec_ctx->coded_width);
2541 print_int(
"coded_height", dec_ctx->coded_height);
2544 print_int(
"has_b_frames", par->video_delay);
2545 sar = av_guess_sample_aspect_ratio(fmt_ctx, stream, NULL);
2547 print_q(
"sample_aspect_ratio", sar,
':');
2548 av_reduce(&dar.num, &dar.den,
2549 par->width * sar.num,
2550 par->height * sar.den,
2552 print_q(
"display_aspect_ratio", dar,
':');
2557 s = av_get_pix_fmt_name(par->format);
2568 if (par->field_order == AV_FIELD_PROGRESSIVE)
2569 print_str(
"field_order",
"progressive");
2570 else if (par->field_order == AV_FIELD_TT)
2572 else if (par->field_order == AV_FIELD_BB)
2574 else if (par->field_order == AV_FIELD_TB)
2576 else if (par->field_order == AV_FIELD_BT)
2581 #if FF_API_PRIVATE_OPT
2582 if (dec_ctx && dec_ctx->timecode_frame_start >= 0) {
2583 char tcbuf[AV_TIMECODE_STR_SIZE];
2584 av_timecode_make_mpeg_tc_string(tcbuf, dec_ctx->timecode_frame_start);
2594 case AVMEDIA_TYPE_AUDIO:
2595 s = av_get_sample_fmt_name(par->format);
2601 if (par->channel_layout) {
2602 av_bprint_clear(&pbuf);
2603 av_bprint_channel_layout(&pbuf, par->channels, par->channel_layout);
2609 print_int(
"bits_per_sample", av_get_bits_per_sample(par->codec_id));
2612 case AVMEDIA_TYPE_SUBTITLE:
2624 if (dec_ctx && dec_ctx->codec && dec_ctx->codec->priv_class &&
show_private_data) {
2625 const AVOption *opt = NULL;
2626 while ((opt = av_opt_next(dec_ctx->priv_data,opt))) {
2628 if (opt->flags)
continue;
2629 if (av_opt_get(dec_ctx->priv_data, opt->name, 0, &str) >= 0) {
2636 if (fmt_ctx->iformat->flags & AVFMT_SHOW_IDS)
print_fmt (
"id",
"0x%x", stream->id);
2638 print_q(
"r_frame_rate", stream->r_frame_rate,
'/');
2639 print_q(
"avg_frame_rate", stream->avg_frame_rate,
'/');
2640 print_q(
"time_base", stream->time_base,
'/');
2641 print_ts (
"start_pts", stream->start_time);
2642 print_time(
"start_time", stream->start_time, &stream->time_base);
2643 print_ts (
"duration_ts", stream->duration);
2644 print_time(
"duration", stream->duration, &stream->time_base);
2647 #if FF_API_LAVF_AVCTX
2651 if (dec_ctx && dec_ctx->bits_per_raw_sample > 0)
print_fmt(
"bits_per_raw_sample",
"%d", dec_ctx->bits_per_raw_sample);
2653 if (stream->nb_frames)
print_fmt (
"nb_frames",
"%"PRId64, stream->nb_frames);
2661 par->extradata_size);
2663 par->extradata_size);
2666 #define PRINT_DISPOSITION(flagname, name) do { \
2667 print_int(name, !!(stream->disposition & AV_DISPOSITION_##flagname)); \
2690 if (stream->nb_side_data) {
2697 av_bprint_finalize(&pbuf, NULL);
2705 AVFormatContext *fmt_ctx = ifile->
fmt_ctx;
2722 AVFormatContext *fmt_ctx = ifile->
fmt_ctx;
2727 print_int(
"program_num", program->program_num);
2728 print_int(
"nb_streams", program->nb_stream_indexes);
2731 print_ts(
"start_pts", program->start_time);
2732 print_time(
"start_time", program->start_time, &AV_TIME_BASE_Q);
2733 print_ts(
"end_pts", program->end_time);
2734 print_time(
"end_time", program->end_time, &AV_TIME_BASE_Q);
2741 for (i = 0; i < program->nb_stream_indexes; i++) {
2743 ret =
show_stream(w, fmt_ctx, program->stream_index[i], &ifile->
streams[program->stream_index[i]], 1);
2757 AVFormatContext *fmt_ctx = ifile->
fmt_ctx;
2761 for (i = 0; i < fmt_ctx->nb_programs; i++) {
2762 AVProgram *program = fmt_ctx->programs[i];
2775 AVFormatContext *fmt_ctx = ifile->
fmt_ctx;
2779 for (i = 0; i < fmt_ctx->nb_chapters; i++) {
2780 AVChapter *chapter = fmt_ctx->chapters[i];
2784 print_q (
"time_base", chapter->time_base,
'/');
2786 print_time(
"start_time", chapter->start, &chapter->time_base);
2788 print_time(
"end_time", chapter->end, &chapter->time_base);
2800 AVFormatContext *fmt_ctx = ifile->
fmt_ctx;
2802 int64_t
size = fmt_ctx->pb ? avio_size(fmt_ctx->pb) : -1;
2807 print_int(
"nb_streams", fmt_ctx->nb_streams);
2808 print_int(
"nb_programs", fmt_ctx->nb_programs);
2809 print_str(
"format_name", fmt_ctx->iformat->name);
2811 if (fmt_ctx->iformat->long_name)
print_str (
"format_long_name", fmt_ctx->iformat->long_name);
2814 print_time(
"start_time", fmt_ctx->start_time, &AV_TIME_BASE_Q);
2815 print_time(
"duration", fmt_ctx->duration, &AV_TIME_BASE_Q);
2820 print_int(
"probe_score", fmt_ctx->probe_score);
2832 const char *errbuf_ptr = errbuf;
2834 if (av_strerror(err, errbuf,
sizeof(errbuf)) < 0)
2835 errbuf_ptr = strerror(AVUNERROR(err));
2846 AVFormatContext *fmt_ctx = NULL;
2847 AVDictionaryEntry *t;
2848 int scan_all_pmts_set = 0;
2850 fmt_ctx = avformat_alloc_context();
2856 if (!av_dict_get(
format_opts,
"scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
2857 av_dict_set(&
format_opts,
"scan_all_pmts",
"1", AV_DICT_DONT_OVERWRITE);
2858 scan_all_pmts_set = 1;
2860 if ((err = avformat_open_input(&fmt_ctx, filename,
2866 if (scan_all_pmts_set)
2867 av_dict_set(&
format_opts,
"scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
2868 if ((t = av_dict_get(
format_opts,
"", NULL, AV_DICT_IGNORE_SUFFIX))) {
2869 av_log(NULL,
AV_LOG_ERROR,
"Option %s not found.\n", t->key);
2870 return AVERROR_OPTION_NOT_FOUND;
2875 int orig_nb_streams = fmt_ctx->nb_streams;
2877 err = avformat_find_stream_info(fmt_ctx, opts);
2879 for (i = 0; i < orig_nb_streams; i++)
2880 av_dict_free(&opts[i]);
2889 av_dump_format(fmt_ctx, 0, filename, 0);
2891 ifile->
streams = av_mallocz_array(fmt_ctx->nb_streams,
2898 for (i = 0; i < fmt_ctx->nb_streams; i++) {
2900 AVStream *stream = fmt_ctx->streams[i];
2905 if (stream->codecpar->codec_id == AV_CODEC_ID_PROBE) {
2907 "Failed to probe codec for input stream %d\n",
2912 codec = avcodec_find_decoder(stream->codecpar->codec_id);
2915 "Unsupported codec with id %d for input stream %d\n",
2916 stream->codecpar->codec_id, stream->index);
2921 fmt_ctx, stream, codec);
2923 ist->
dec_ctx = avcodec_alloc_context3(codec);
2927 err = avcodec_parameters_to_context(ist->
dec_ctx, stream->codecpar);
2938 ist->
dec_ctx->pkt_timebase = stream->time_base;
2939 ist->
dec_ctx->framerate = stream->avg_frame_rate;
2940 #if FF_API_LAVF_AVCTX
2941 ist->
dec_ctx->coded_width = stream->codec->coded_width;
2942 ist->
dec_ctx->coded_height = stream->codec->coded_height;
2945 if (avcodec_open2(ist->
dec_ctx, codec, &opts) < 0) {
2946 av_log(NULL,
AV_LOG_WARNING,
"Could not open codec for input stream %d\n",
2951 if ((t = av_dict_get(opts,
"", NULL, AV_DICT_IGNORE_SUFFIX))) {
2952 av_log(NULL,
AV_LOG_ERROR,
"Option %s for input stream %d not found\n",
2953 t->key, stream->index);
2954 return AVERROR_OPTION_NOT_FOUND;
2969 if (ifile->
streams[i].
st->codecpar->codec_id != AV_CODEC_ID_NONE)
2975 avformat_close_input(&ifile->
fmt_ctx);
2991 #define CHECK_END if (ret < 0) goto end
2998 for (i = 0; i < ifile.
fmt_ctx->nb_streams; i++) {
3000 ret = avformat_match_stream_specifier(ifile.
fmt_ctx,
3011 ifile.
fmt_ctx->streams[i]->discard = AVDISCARD_ALL;
3060 av_log(NULL,
AV_LOG_INFO,
"Simple multimedia streams analyzer\n");
3068 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
3072 print_fmt(
"copyright",
"Copyright (c) %d-%d the FFmpeg developers",
3075 print_str(
"configuration", FFMPEG_CONFIGURATION);
3078 av_bprint_finalize(&pbuf, NULL);
3081 #define SHOW_LIB_VERSION(libname, LIBNAME) \
3083 if (CONFIG_##LIBNAME) { \
3084 unsigned int version = libname##_version(); \
3085 writer_print_section_header(w, SECTION_ID_LIBRARY_VERSION); \
3086 print_str("name", "lib" #libname); \
3087 print_int("major", LIB##LIBNAME##_VERSION_MAJOR); \
3088 print_int("minor", LIB##LIBNAME##_VERSION_MINOR); \
3089 print_int("micro", LIB##LIBNAME##_VERSION_MICRO); \
3090 print_int("version", version); \
3091 print_str("ident", LIB##LIBNAME##_IDENT); \
3092 writer_print_section_footer(w); \
3109 #define PRINT_PIX_FMT_FLAG(flagname, name) \
3111 print_int(name, !!(pixdesc->flags & AV_PIX_FMT_FLAG_##flagname)); \
3116 const AVPixFmtDescriptor *pixdesc = NULL;
3120 while ((pixdesc = av_pix_fmt_desc_next(pixdesc))) {
3123 print_int(
"nb_components", pixdesc->nb_components);
3124 if ((pixdesc->nb_components >= 3) && !(pixdesc->flags & AV_PIX_FMT_FLAG_RGB)) {
3125 print_int (
"log2_chroma_w", pixdesc->log2_chroma_w);
3126 print_int (
"log2_chroma_h", pixdesc->log2_chroma_h);
3131 n = av_get_bits_per_pixel(pixdesc);
3142 #if FF_API_PSEUDOPAL
3150 for (i = 0; i < pixdesc->nb_components; i++) {
3153 print_int(
"bit_depth", pixdesc->comp[i].depth);
3163 static int opt_format(
void *optctx,
const char *opt,
const char *arg)
3165 iformat = av_find_input_format(arg);
3167 av_log(NULL,
AV_LOG_ERROR,
"Unknown input format: %s\n", arg);
3168 return AVERROR(EINVAL);
3193 for (i = 0; i < FF_ARRAY_ELEMS(
sections); i++) {
3198 "'%s' matches section with unique name '%s'\n", section_name,
3209 const char *p = arg;
3213 AVDictionary *entries = NULL;
3214 char *section_name = av_get_token(&p,
"=:");
3217 if (!section_name) {
3219 "Missing section name for option '%s'\n", opt);
3220 return AVERROR(EINVAL);
3225 while (*p && *p !=
':') {
3226 char *entry = av_get_token(&p,
",:");
3230 "Adding '%s' to the entries to show in section '%s'\n",
3231 entry, section_name);
3232 av_dict_set(&entries, entry,
"", AV_DICT_DONT_STRDUP_KEY);
3242 av_log(NULL,
AV_LOG_ERROR,
"No match for section '%s'\n", section_name);
3243 ret = AVERROR(EINVAL);
3245 av_dict_free(&entries);
3246 av_free(section_name);
3259 char *buf = av_asprintf(
"format=%s", arg);
3263 return AVERROR(ENOMEM);
3266 "Option '%s' is deprecated, use '-show_entries format=%s' instead\n",
3277 "Argument '%s' provided as input filename, but '%s' was already specified.\n",
3281 if (!strcmp(arg,
"-"))
3311 char *next, *p, *spec = av_strdup(interval_spec);
3313 return AVERROR(ENOMEM);
3316 av_log(NULL,
AV_LOG_ERROR,
"Invalid empty interval specification\n");
3317 ret = AVERROR(EINVAL);
3322 next = strchr(spec,
'%');
3337 ret = av_parse_time(&interval->
start, p, 1);
3339 av_log(NULL,
AV_LOG_ERROR,
"Invalid interval start specification '%s'\n", p);
3364 lli = strtoll(p, &tail, 10);
3365 if (*tail || lli < 0) {
3367 "Invalid or negative value '%s' for duration number of frames\n", p);
3370 interval->
end = lli;
3373 ret = av_parse_time(&us, p, 1);
3375 av_log(NULL,
AV_LOG_ERROR,
"Invalid interval end/duration specification '%s'\n", p);
3392 char *p, *spec = av_strdup(intervals_spec);
3394 return AVERROR(ENOMEM);
3397 for (n = 0, p = spec; *p; p++)
3404 ret = AVERROR(ENOMEM);
3411 for (i = 0; p; i++) {
3415 next = strchr(p,
',');
3422 av_log(NULL,
AV_LOG_ERROR,
"Error parsing read interval #%d '%s'\n",
3442 static int opt_pretty(
void *optctx,
const char *opt,
const char *arg)
3471 "W.. = Section is a wrapper (contains other sections, no local entries)\n"
3472 ".A. = Section contains an array of elements of the same type\n"
3473 "..V = Section may contain a variable number of fields with variable keys\n"
3474 "FLAGS NAME/UNIQUE_NAME\n"
3487 #define DEFINE_OPT_SHOW_SECTION(section, target_section_id) \
3488 static int opt_show_##section(void *optctx, const char *opt, const char *arg) \
3490 mark_section_show_entries(SECTION_ID_##target_section_id, 1, NULL); \
3517 #define SET_DO_SHOW(id, varname) do { \
3518 if (check_section_show_entries(SECTION_ID_##id)) \
3519 do_show_##varname = 1; \
3587 char _program_name[] =
"ffprobe";
3606 {
"bsfs",
OPT_EXIT, { .func_arg =
show_bsfs },
"show available bit stream filters" },
3615 {
"report", 0, { .func_arg =
opt_report },
"generate a report" },
3616 {
"max_alloc",
HAS_ARG, { .func_arg =
opt_max_alloc },
"set maximum size of a single allocated block",
"bytes" },
3622 "list sources of the input device",
"device" },
3624 "list sinks of the output device",
"device" },
3631 "use binary prefixes for byte units" },
3633 "use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units" },
3635 "prettify the format of displayed values, make it more human readable" },
3637 "set the output printing format (available formats are: default, compact, csv, flat, ini, json, xml)",
"format" },
3640 {
"sections",
OPT_EXIT, {.func_arg =
opt_sections},
"print sections structure and section information, and exit" },
3643 {
"show_error", 0, { .func_arg = &opt_show_error },
"show probing error" },
3644 {
"show_format", 0, { .func_arg = &opt_show_format },
"show format/container info" },
3645 {
"show_frames", 0, { .func_arg = &opt_show_frames },
"show frames info" },
3647 "show a particular entry from the format/container info",
"entry" },
3649 "show a set of specified entries",
"entry_list" },
3653 {
"show_packets", 0, { .func_arg = &opt_show_packets },
"show packets info" },
3654 {
"show_programs", 0, { .func_arg = &opt_show_programs },
"show programs info" },
3655 {
"show_streams", 0, { .func_arg = &opt_show_streams },
"show streams info" },
3656 {
"show_chapters", 0, { .func_arg = &opt_show_chapters },
"show chapters info" },
3659 {
"show_program_version", 0, { .func_arg = &opt_show_program_version },
"show ffprobe version" },
3660 {
"show_library_versions", 0, { .func_arg = &opt_show_library_versions },
"show library versions" },
3661 {
"show_versions", 0, { .func_arg = &
opt_show_versions },
"show program and library versions" },
3662 {
"show_pixel_formats", 0, { .func_arg = &opt_show_pixel_formats },
"show pixel format descriptions" },
3670 "read and decode the streams to fill missing information with heuristics" },
3677 char *w_name = NULL, *w_args = NULL;
3681 if (savedCode == 0) {
3688 ret = pthread_mutex_init(&log_mutex, NULL);
3693 av_log_set_flags(AV_LOG_SKIP_REPEATED);
3698 avformat_network_init();
3701 avdevice_register_all();
3718 SET_DO_SHOW(PIXEL_FORMAT_FLAGS, pixel_format_flags);
3719 SET_DO_SHOW(PIXEL_FORMAT_COMPONENTS, pixel_format_components);
3723 SET_DO_SHOW(STREAM_DISPOSITION, stream_disposition);
3724 SET_DO_SHOW(PROGRAM_STREAM_DISPOSITION, stream_disposition);
3736 "-bitexact and -show_program_version or -show_library_versions "
3737 "options are incompatible\n");
3738 ret = AVERROR(EINVAL);
3747 ret = AVERROR(ENOMEM);
3753 "No name specified for the output format\n");
3754 ret = AVERROR(EINVAL);
3761 if (ret == AVERROR(EINVAL)) {
3764 "Unknown hash algorithm '%s'\nKnown algorithms:",
3766 for (i = 0; (n = av_hash_names(i)); i++)
3776 av_log(NULL,
AV_LOG_ERROR,
"Unknown output format with name '%s'\n", w_name);
3777 ret = AVERROR(EINVAL);
3799 av_log(NULL,
AV_LOG_ERROR,
"You have to specify one input file.\n");
3801 ret = AVERROR(EINVAL);
3821 av_hash_freep(&
hash);
3824 for (i = 0; i < FF_ARRAY_ELEMS(
sections); i++)
3827 avformat_network_deinit();