00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00026 #include "config.h"
00027 #include "version.h"
00028
00029 #include <string.h>
00030
00031 #include "libavformat/avformat.h"
00032 #include "libavcodec/avcodec.h"
00033 #include "libavutil/avassert.h"
00034 #include "libavutil/avstring.h"
00035 #include "libavutil/bprint.h"
00036 #include "libavutil/opt.h"
00037 #include "libavutil/pixdesc.h"
00038 #include "libavutil/dict.h"
00039 #include "libavutil/libm.h"
00040 #include "libavutil/timecode.h"
00041 #include "libavdevice/avdevice.h"
00042 #include "libswscale/swscale.h"
00043 #include "libswresample/swresample.h"
00044 #include "libpostproc/postprocess.h"
00045 #include "cmdutils.h"
00046
00047 const char program_name[] = "ffprobe";
00048 const int program_birth_year = 2007;
00049
00050 static int do_bitexact = 0;
00051 static int do_count_frames = 0;
00052 static int do_count_packets = 0;
00053 static int do_read_frames = 0;
00054 static int do_read_packets = 0;
00055 static int do_show_error = 0;
00056 static int do_show_format = 0;
00057 static int do_show_frames = 0;
00058 static int do_show_packets = 0;
00059 static int do_show_streams = 0;
00060 static int do_show_stream_disposition = 0;
00061 static int do_show_data = 0;
00062 static int do_show_program_version = 0;
00063 static int do_show_library_versions = 0;
00064
00065 static int show_value_unit = 0;
00066 static int use_value_prefix = 0;
00067 static int use_byte_value_binary_prefix = 0;
00068 static int use_value_sexagesimal_format = 0;
00069 static int show_private_data = 1;
00070
00071 static char *print_format;
00072 static char *stream_specifier;
00073
00074
00075
00076 #define SECTION_MAX_NB_CHILDREN 10
00077
00078 struct section {
00079 int id;
00080 const char *name;
00081
00082 #define SECTION_FLAG_IS_WRAPPER 1
00083 #define SECTION_FLAG_IS_ARRAY 2
00084 #define SECTION_FLAG_HAS_VARIABLE_FIELDS 4
00085
00086 int flags;
00087 int children_ids[SECTION_MAX_NB_CHILDREN+1];
00088 const char *element_name;
00089 const char *unique_name;
00090 AVDictionary *entries_to_show;
00091 int show_all_entries;
00092 };
00093
00094 typedef enum {
00095 SECTION_ID_NONE = -1,
00096 SECTION_ID_ERROR,
00097 SECTION_ID_FORMAT,
00098 SECTION_ID_FORMAT_TAGS,
00099 SECTION_ID_FRAME,
00100 SECTION_ID_FRAMES,
00101 SECTION_ID_FRAME_TAGS,
00102 SECTION_ID_LIBRARY_VERSION,
00103 SECTION_ID_LIBRARY_VERSIONS,
00104 SECTION_ID_PACKET,
00105 SECTION_ID_PACKETS,
00106 SECTION_ID_PACKETS_AND_FRAMES,
00107 SECTION_ID_PROGRAM_VERSION,
00108 SECTION_ID_ROOT,
00109 SECTION_ID_STREAM,
00110 SECTION_ID_STREAM_DISPOSITION,
00111 SECTION_ID_STREAMS,
00112 SECTION_ID_STREAM_TAGS,
00113 } SectionID;
00114
00115 static struct section sections[] = {
00116 [SECTION_ID_ERROR] = { SECTION_ID_ERROR, "error", 0, { -1 } },
00117 [SECTION_ID_FORMAT] = { SECTION_ID_FORMAT, "format", 0, { SECTION_ID_FORMAT_TAGS, -1 } },
00118 [SECTION_ID_FORMAT_TAGS] = { SECTION_ID_FORMAT_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "format_tags" },
00119 [SECTION_ID_FRAMES] = { SECTION_ID_FRAMES, "frames", SECTION_FLAG_IS_ARRAY, { SECTION_ID_FRAME, -1 } },
00120 [SECTION_ID_FRAME] = { SECTION_ID_FRAME, "frame", 0, { SECTION_ID_FRAME_TAGS, -1 } },
00121 [SECTION_ID_FRAME_TAGS] = { SECTION_ID_FRAME_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "frame_tags" },
00122 [SECTION_ID_LIBRARY_VERSIONS] = { SECTION_ID_LIBRARY_VERSIONS, "library_versions", SECTION_FLAG_IS_ARRAY, { SECTION_ID_LIBRARY_VERSION, -1 } },
00123 [SECTION_ID_LIBRARY_VERSION] = { SECTION_ID_LIBRARY_VERSION, "library_version", 0, { -1 } },
00124 [SECTION_ID_PACKETS] = { SECTION_ID_PACKETS, "packets", SECTION_FLAG_IS_ARRAY, { SECTION_ID_PACKET, -1} },
00125 [SECTION_ID_PACKETS_AND_FRAMES] = { SECTION_ID_PACKETS_AND_FRAMES, "packets_and_frames", SECTION_FLAG_IS_ARRAY, { SECTION_ID_PACKET, -1} },
00126 [SECTION_ID_PACKET] = { SECTION_ID_PACKET, "packet", 0, { -1 } },
00127 [SECTION_ID_PROGRAM_VERSION] = { SECTION_ID_PROGRAM_VERSION, "program_version", 0, { -1 } },
00128 [SECTION_ID_ROOT] = { SECTION_ID_ROOT, "root", SECTION_FLAG_IS_WRAPPER,
00129 { SECTION_ID_FORMAT, SECTION_ID_FRAMES, SECTION_ID_STREAMS, SECTION_ID_PACKETS,
00130 SECTION_ID_ERROR, SECTION_ID_PROGRAM_VERSION, SECTION_ID_LIBRARY_VERSIONS, -1} },
00131 [SECTION_ID_STREAMS] = { SECTION_ID_STREAMS, "streams", SECTION_FLAG_IS_ARRAY, { SECTION_ID_STREAM, -1 } },
00132 [SECTION_ID_STREAM] = { SECTION_ID_STREAM, "stream", 0, { SECTION_ID_STREAM_DISPOSITION, SECTION_ID_STREAM_TAGS, -1 } },
00133 [SECTION_ID_STREAM_DISPOSITION] = { SECTION_ID_STREAM_DISPOSITION, "disposition", 0, { -1 }, .unique_name = "stream_disposition" },
00134 [SECTION_ID_STREAM_TAGS] = { SECTION_ID_STREAM_TAGS, "tags", SECTION_FLAG_HAS_VARIABLE_FIELDS, { -1 }, .element_name = "tag", .unique_name = "stream_tags" },
00135 };
00136
00137 static const OptionDef *options;
00138
00139
00140 static const char *input_filename;
00141 static AVInputFormat *iformat = NULL;
00142
00143 static const char *const binary_unit_prefixes [] = { "", "Ki", "Mi", "Gi", "Ti", "Pi" };
00144 static const char *const decimal_unit_prefixes[] = { "", "K" , "M" , "G" , "T" , "P" };
00145
00146 static const char unit_second_str[] = "s" ;
00147 static const char unit_hertz_str[] = "Hz" ;
00148 static const char unit_byte_str[] = "byte" ;
00149 static const char unit_bit_per_second_str[] = "bit/s";
00150
00151 static uint64_t *nb_streams_packets;
00152 static uint64_t *nb_streams_frames;
00153 static int *selected_streams;
00154
00155 static void exit_program(void)
00156 {
00157 int i;
00158 for (i = 0; i < FF_ARRAY_ELEMS(sections); i++)
00159 av_dict_free(&(sections[i].entries_to_show));
00160 }
00161
00162 struct unit_value {
00163 union { double d; long long int i; } val;
00164 const char *unit;
00165 };
00166
00167 static char *value_string(char *buf, int buf_size, struct unit_value uv)
00168 {
00169 double vald;
00170 long long int vali;
00171 int show_float = 0;
00172
00173 if (uv.unit == unit_second_str) {
00174 vald = uv.val.d;
00175 show_float = 1;
00176 } else {
00177 vald = vali = uv.val.i;
00178 }
00179
00180 if (uv.unit == unit_second_str && use_value_sexagesimal_format) {
00181 double secs;
00182 int hours, mins;
00183 secs = vald;
00184 mins = (int)secs / 60;
00185 secs = secs - mins * 60;
00186 hours = mins / 60;
00187 mins %= 60;
00188 snprintf(buf, buf_size, "%d:%02d:%09.6f", hours, mins, secs);
00189 } else {
00190 const char *prefix_string = "";
00191
00192 if (use_value_prefix && vald > 1) {
00193 long long int index;
00194
00195 if (uv.unit == unit_byte_str && use_byte_value_binary_prefix) {
00196 index = (long long int) (log2(vald)) / 10;
00197 index = av_clip(index, 0, FF_ARRAY_ELEMS(binary_unit_prefixes) - 1);
00198 vald /= exp2(index * 10);
00199 prefix_string = binary_unit_prefixes[index];
00200 } else {
00201 index = (long long int) (log10(vald)) / 3;
00202 index = av_clip(index, 0, FF_ARRAY_ELEMS(decimal_unit_prefixes) - 1);
00203 vald /= pow(10, index * 3);
00204 prefix_string = decimal_unit_prefixes[index];
00205 }
00206 }
00207
00208 if (show_float || (use_value_prefix && vald != (long long int)vald))
00209 snprintf(buf, buf_size, "%f", vald);
00210 else
00211 snprintf(buf, buf_size, "%lld", vali);
00212 av_strlcatf(buf, buf_size, "%s%s%s", *prefix_string || show_value_unit ? " " : "",
00213 prefix_string, show_value_unit ? uv.unit : "");
00214 }
00215
00216 return buf;
00217 }
00218
00219
00220
00221 typedef struct WriterContext WriterContext;
00222
00223 #define WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS 1
00224 #define WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER 2
00225
00226 typedef struct Writer {
00227 const AVClass *priv_class;
00228 int priv_size;
00229 const char *name;
00230
00231 int (*init) (WriterContext *wctx);
00232 void (*uninit)(WriterContext *wctx);
00233
00234 void (*print_section_header)(WriterContext *wctx);
00235 void (*print_section_footer)(WriterContext *wctx);
00236 void (*print_integer) (WriterContext *wctx, const char *, long long int);
00237 void (*print_rational) (WriterContext *wctx, AVRational *q, char *sep);
00238 void (*print_string) (WriterContext *wctx, const char *, const char *);
00239 int flags;
00240 } Writer;
00241
00242 #define SECTION_MAX_NB_LEVELS 10
00243
00244 struct WriterContext {
00245 const AVClass *class;
00246 const Writer *writer;
00247 char *name;
00248 void *priv;
00249
00250 const struct section *sections;
00251 int nb_sections;
00252
00253 int level;
00254
00256 unsigned int nb_item[SECTION_MAX_NB_LEVELS];
00257
00259 const struct section *section[SECTION_MAX_NB_LEVELS];
00260 AVBPrint section_pbuf[SECTION_MAX_NB_LEVELS];
00261
00262
00263 unsigned int nb_section_packet;
00264 unsigned int nb_section_frame;
00265 unsigned int nb_section_packet_frame;
00266 };
00267
00268 static const char *writer_get_name(void *p)
00269 {
00270 WriterContext *wctx = p;
00271 return wctx->writer->name;
00272 }
00273
00274 static const AVClass writer_class = {
00275 "Writer",
00276 writer_get_name,
00277 NULL,
00278 LIBAVUTIL_VERSION_INT,
00279 };
00280
00281 static void writer_close(WriterContext **wctx)
00282 {
00283 int i;
00284
00285 if (!*wctx)
00286 return;
00287
00288 if ((*wctx)->writer->uninit)
00289 (*wctx)->writer->uninit(*wctx);
00290 for (i = 0; i < SECTION_MAX_NB_LEVELS; i++)
00291 av_bprint_finalize(&(*wctx)->section_pbuf[i], NULL);
00292 if ((*wctx)->writer->priv_class)
00293 av_opt_free((*wctx)->priv);
00294 av_freep(&((*wctx)->priv));
00295 av_freep(wctx);
00296 }
00297
00298 static int writer_open(WriterContext **wctx, const Writer *writer, const char *args,
00299 const struct section *sections, int nb_sections)
00300 {
00301 int i, ret = 0;
00302
00303 if (!(*wctx = av_malloc(sizeof(WriterContext)))) {
00304 ret = AVERROR(ENOMEM);
00305 goto fail;
00306 }
00307
00308 if (!((*wctx)->priv = av_mallocz(writer->priv_size))) {
00309 ret = AVERROR(ENOMEM);
00310 goto fail;
00311 }
00312
00313 (*wctx)->class = &writer_class;
00314 (*wctx)->writer = writer;
00315 (*wctx)->level = -1;
00316 (*wctx)->sections = sections;
00317 (*wctx)->nb_sections = nb_sections;
00318
00319 if (writer->priv_class) {
00320 void *priv_ctx = (*wctx)->priv;
00321 *((const AVClass **)priv_ctx) = writer->priv_class;
00322 av_opt_set_defaults(priv_ctx);
00323
00324 if (args &&
00325 (ret = av_set_options_string(priv_ctx, args, "=", ":")) < 0)
00326 goto fail;
00327 }
00328
00329 for (i = 0; i < SECTION_MAX_NB_LEVELS; i++)
00330 av_bprint_init(&(*wctx)->section_pbuf[i], 1, AV_BPRINT_SIZE_UNLIMITED);
00331
00332 if ((*wctx)->writer->init)
00333 ret = (*wctx)->writer->init(*wctx);
00334 if (ret < 0)
00335 goto fail;
00336
00337 return 0;
00338
00339 fail:
00340 writer_close(wctx);
00341 return ret;
00342 }
00343
00344 static inline void writer_print_section_header(WriterContext *wctx,
00345 int section_id)
00346 {
00347 int parent_section_id;
00348 wctx->level++;
00349 av_assert0(wctx->level < SECTION_MAX_NB_LEVELS);
00350 parent_section_id = wctx->level ?
00351 (wctx->section[wctx->level-1])->id : SECTION_ID_NONE;
00352
00353 wctx->nb_item[wctx->level] = 0;
00354 wctx->section[wctx->level] = &wctx->sections[section_id];
00355
00356 if (section_id == SECTION_ID_PACKETS_AND_FRAMES) {
00357 wctx->nb_section_packet = wctx->nb_section_frame =
00358 wctx->nb_section_packet_frame = 0;
00359 } else if (parent_section_id == SECTION_ID_PACKETS_AND_FRAMES) {
00360 wctx->nb_section_packet_frame = section_id == SECTION_ID_PACKET ?
00361 wctx->nb_section_packet : wctx->nb_section_frame;
00362 }
00363
00364 if (wctx->writer->print_section_header)
00365 wctx->writer->print_section_header(wctx);
00366 }
00367
00368 static inline void writer_print_section_footer(WriterContext *wctx)
00369 {
00370 int section_id = wctx->section[wctx->level]->id;
00371 int parent_section_id = wctx->level ?
00372 wctx->section[wctx->level-1]->id : SECTION_ID_NONE;
00373
00374 if (parent_section_id != SECTION_ID_NONE)
00375 wctx->nb_item[wctx->level-1]++;
00376 if (parent_section_id == SECTION_ID_PACKETS_AND_FRAMES) {
00377 if (section_id == SECTION_ID_PACKET) wctx->nb_section_packet++;
00378 else wctx->nb_section_frame++;
00379 }
00380 if (wctx->writer->print_section_footer)
00381 wctx->writer->print_section_footer(wctx);
00382 wctx->level--;
00383 }
00384
00385 static inline void writer_print_integer(WriterContext *wctx,
00386 const char *key, long long int val)
00387 {
00388 const struct section *section = wctx->section[wctx->level];
00389
00390 if (section->show_all_entries || av_dict_get(section->entries_to_show, key, NULL, 0)) {
00391 wctx->writer->print_integer(wctx, key, val);
00392 wctx->nb_item[wctx->level]++;
00393 }
00394 }
00395
00396 static inline void writer_print_string(WriterContext *wctx,
00397 const char *key, const char *val, int opt)
00398 {
00399 const struct section *section = wctx->section[wctx->level];
00400
00401 if (opt && !(wctx->writer->flags & WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS))
00402 return;
00403
00404 if (section->show_all_entries || av_dict_get(section->entries_to_show, key, NULL, 0)) {
00405 wctx->writer->print_string(wctx, key, val);
00406 wctx->nb_item[wctx->level]++;
00407 }
00408 }
00409
00410 static inline void writer_print_rational(WriterContext *wctx,
00411 const char *key, AVRational q, char sep)
00412 {
00413 AVBPrint buf;
00414 av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC);
00415 av_bprintf(&buf, "%d%c%d", q.num, sep, q.den);
00416 writer_print_string(wctx, key, buf.str, 0);
00417 }
00418
00419 static void writer_print_time(WriterContext *wctx, const char *key,
00420 int64_t ts, const AVRational *time_base, int is_duration)
00421 {
00422 char buf[128];
00423
00424 if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
00425 writer_print_string(wctx, key, "N/A", 1);
00426 } else {
00427 double d = ts * av_q2d(*time_base);
00428 struct unit_value uv;
00429 uv.val.d = d;
00430 uv.unit = unit_second_str;
00431 value_string(buf, sizeof(buf), uv);
00432 writer_print_string(wctx, key, buf, 0);
00433 }
00434 }
00435
00436 static void writer_print_ts(WriterContext *wctx, const char *key, int64_t ts, int is_duration)
00437 {
00438 if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
00439 writer_print_string(wctx, key, "N/A", 1);
00440 } else {
00441 writer_print_integer(wctx, key, ts);
00442 }
00443 }
00444
00445 static void writer_print_data(WriterContext *wctx, const char *name,
00446 uint8_t *data, int size)
00447 {
00448 AVBPrint bp;
00449 int offset = 0, l, i;
00450
00451 av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
00452 av_bprintf(&bp, "\n");
00453 while (size) {
00454 av_bprintf(&bp, "%08x: ", offset);
00455 l = FFMIN(size, 16);
00456 for (i = 0; i < l; i++) {
00457 av_bprintf(&bp, "%02x", data[i]);
00458 if (i & 1)
00459 av_bprintf(&bp, " ");
00460 }
00461 av_bprint_chars(&bp, ' ', 41 - 2 * i - i / 2);
00462 for (i = 0; i < l; i++)
00463 av_bprint_chars(&bp, data[i] - 32U < 95 ? data[i] : '.', 1);
00464 av_bprintf(&bp, "\n");
00465 offset += l;
00466 data += l;
00467 size -= l;
00468 }
00469 writer_print_string(wctx, name, bp.str, 0);
00470 av_bprint_finalize(&bp, NULL);
00471 }
00472
00473 #define MAX_REGISTERED_WRITERS_NB 64
00474
00475 static const Writer *registered_writers[MAX_REGISTERED_WRITERS_NB + 1];
00476
00477 static int writer_register(const Writer *writer)
00478 {
00479 static int next_registered_writer_idx = 0;
00480
00481 if (next_registered_writer_idx == MAX_REGISTERED_WRITERS_NB)
00482 return AVERROR(ENOMEM);
00483
00484 registered_writers[next_registered_writer_idx++] = writer;
00485 return 0;
00486 }
00487
00488 static const Writer *writer_get_by_name(const char *name)
00489 {
00490 int i;
00491
00492 for (i = 0; registered_writers[i]; i++)
00493 if (!strcmp(registered_writers[i]->name, name))
00494 return registered_writers[i];
00495
00496 return NULL;
00497 }
00498
00499
00500
00501
00502 #define DEFINE_WRITER_CLASS(name) \
00503 static const char *name##_get_name(void *ctx) \
00504 { \
00505 return #name ; \
00506 } \
00507 static const AVClass name##_class = { \
00508 #name, \
00509 name##_get_name, \
00510 name##_options \
00511 }
00512
00513
00514
00515 typedef struct DefaultContext {
00516 const AVClass *class;
00517 int nokey;
00518 int noprint_wrappers;
00519 int nested_section[SECTION_MAX_NB_LEVELS];
00520 } DefaultContext;
00521
00522 #define OFFSET(x) offsetof(DefaultContext, x)
00523
00524 static const AVOption default_options[] = {
00525 { "noprint_wrappers", "do not print headers and footers", OFFSET(noprint_wrappers), AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
00526 { "nw", "do not print headers and footers", OFFSET(noprint_wrappers), AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
00527 { "nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
00528 { "nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
00529 {NULL},
00530 };
00531
00532 DEFINE_WRITER_CLASS(default);
00533
00534
00535 static inline char *upcase_string(char *dst, size_t dst_size, const char *src)
00536 {
00537 int i;
00538 for (i = 0; src[i] && i < dst_size-1; i++)
00539 dst[i] = av_toupper(src[i]);
00540 dst[i] = 0;
00541 return dst;
00542 }
00543
00544 static void default_print_section_header(WriterContext *wctx)
00545 {
00546 DefaultContext *def = wctx->priv;
00547 char buf[32];
00548 const struct section *section = wctx->section[wctx->level];
00549 const struct section *parent_section = wctx->level ?
00550 wctx->section[wctx->level-1] : NULL;
00551
00552 av_bprint_clear(&wctx->section_pbuf[wctx->level]);
00553 if (parent_section &&
00554 !(parent_section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY))) {
00555 def->nested_section[wctx->level] = 1;
00556 av_bprintf(&wctx->section_pbuf[wctx->level], "%s%s:",
00557 wctx->section_pbuf[wctx->level-1].str,
00558 upcase_string(buf, sizeof(buf),
00559 av_x_if_null(section->element_name, section->name)));
00560 }
00561
00562 if (def->noprint_wrappers || def->nested_section[wctx->level])
00563 return;
00564
00565 if (!(section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY)))
00566 printf("[%s]\n", upcase_string(buf, sizeof(buf), section->name));
00567 }
00568
00569 static void default_print_section_footer(WriterContext *wctx)
00570 {
00571 DefaultContext *def = wctx->priv;
00572 const struct section *section = wctx->section[wctx->level];
00573 char buf[32];
00574
00575 if (def->noprint_wrappers || def->nested_section[wctx->level])
00576 return;
00577
00578 if (!(section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY)))
00579 printf("[/%s]\n", upcase_string(buf, sizeof(buf), section->name));
00580 }
00581
00582 static void default_print_str(WriterContext *wctx, const char *key, const char *value)
00583 {
00584 DefaultContext *def = wctx->priv;
00585
00586 if (!def->nokey)
00587 printf("%s%s=", wctx->section_pbuf[wctx->level].str, key);
00588 printf("%s\n", value);
00589 }
00590
00591 static void default_print_int(WriterContext *wctx, const char *key, long long int value)
00592 {
00593 DefaultContext *def = wctx->priv;
00594
00595 if (!def->nokey)
00596 printf("%s%s=", wctx->section_pbuf[wctx->level].str, key);
00597 printf("%lld\n", value);
00598 }
00599
00600 static const Writer default_writer = {
00601 .name = "default",
00602 .priv_size = sizeof(DefaultContext),
00603 .print_section_header = default_print_section_header,
00604 .print_section_footer = default_print_section_footer,
00605 .print_integer = default_print_int,
00606 .print_string = default_print_str,
00607 .flags = WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS,
00608 .priv_class = &default_class,
00609 };
00610
00611
00612
00616 static const char *c_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
00617 {
00618 const char *p;
00619
00620 for (p = src; *p; p++) {
00621 switch (*p) {
00622 case '\b': av_bprintf(dst, "%s", "\\b"); break;
00623 case '\f': av_bprintf(dst, "%s", "\\f"); break;
00624 case '\n': av_bprintf(dst, "%s", "\\n"); break;
00625 case '\r': av_bprintf(dst, "%s", "\\r"); break;
00626 case '\\': av_bprintf(dst, "%s", "\\\\"); break;
00627 default:
00628 if (*p == sep)
00629 av_bprint_chars(dst, '\\', 1);
00630 av_bprint_chars(dst, *p, 1);
00631 }
00632 }
00633 return dst->str;
00634 }
00635
00639 static const char *csv_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
00640 {
00641 char meta_chars[] = { sep, '"', '\n', '\r', '\0' };
00642 int needs_quoting = !!src[strcspn(src, meta_chars)];
00643
00644 if (needs_quoting)
00645 av_bprint_chars(dst, '\"', 1);
00646
00647 for (; *src; src++) {
00648 if (*src == '"')
00649 av_bprint_chars(dst, '\"', 1);
00650 av_bprint_chars(dst, *src, 1);
00651 }
00652 if (needs_quoting)
00653 av_bprint_chars(dst, '\"', 1);
00654 return dst->str;
00655 }
00656
00657 static const char *none_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
00658 {
00659 return src;
00660 }
00661
00662 typedef struct CompactContext {
00663 const AVClass *class;
00664 char *item_sep_str;
00665 char item_sep;
00666 int nokey;
00667 int print_section;
00668 char *escape_mode_str;
00669 const char * (*escape_str)(AVBPrint *dst, const char *src, const char sep, void *log_ctx);
00670 int nested_section[SECTION_MAX_NB_LEVELS];
00671 } CompactContext;
00672
00673 #undef OFFSET
00674 #define OFFSET(x) offsetof(CompactContext, x)
00675
00676 static const AVOption compact_options[]= {
00677 {"item_sep", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str="|"}, CHAR_MIN, CHAR_MAX },
00678 {"s", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str="|"}, CHAR_MIN, CHAR_MAX },
00679 {"nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
00680 {"nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
00681 {"escape", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="c"}, CHAR_MIN, CHAR_MAX },
00682 {"e", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="c"}, CHAR_MIN, CHAR_MAX },
00683 {"print_section", "print section name", OFFSET(print_section), AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
00684 {"p", "print section name", OFFSET(print_section), AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
00685 {NULL},
00686 };
00687
00688 DEFINE_WRITER_CLASS(compact);
00689
00690 static av_cold int compact_init(WriterContext *wctx)
00691 {
00692 CompactContext *compact = wctx->priv;
00693
00694 if (strlen(compact->item_sep_str) != 1) {
00695 av_log(wctx, AV_LOG_ERROR, "Item separator '%s' specified, but must contain a single character\n",
00696 compact->item_sep_str);
00697 return AVERROR(EINVAL);
00698 }
00699 compact->item_sep = compact->item_sep_str[0];
00700
00701 if (!strcmp(compact->escape_mode_str, "none")) compact->escape_str = none_escape_str;
00702 else if (!strcmp(compact->escape_mode_str, "c" )) compact->escape_str = c_escape_str;
00703 else if (!strcmp(compact->escape_mode_str, "csv" )) compact->escape_str = csv_escape_str;
00704 else {
00705 av_log(wctx, AV_LOG_ERROR, "Unknown escape mode '%s'\n", compact->escape_mode_str);
00706 return AVERROR(EINVAL);
00707 }
00708
00709 return 0;
00710 }
00711
00712 static void compact_print_section_header(WriterContext *wctx)
00713 {
00714 CompactContext *compact = wctx->priv;
00715 const struct section *section = wctx->section[wctx->level];
00716 const struct section *parent_section = wctx->level ?
00717 wctx->section[wctx->level-1] : NULL;
00718
00719 av_bprint_clear(&wctx->section_pbuf[wctx->level]);
00720 if (parent_section &&
00721 !(parent_section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY))) {
00722 compact->nested_section[wctx->level] = 1;
00723 av_bprintf(&wctx->section_pbuf[wctx->level], "%s%s:",
00724 wctx->section_pbuf[wctx->level-1].str,
00725 (char *)av_x_if_null(section->element_name, section->name));
00726 wctx->nb_item[wctx->level] = wctx->nb_item[wctx->level-1];
00727 } else if (compact->print_section &&
00728 !(section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY)))
00729 printf("%s%c", section->name, compact->item_sep);
00730 }
00731
00732 static void compact_print_section_footer(WriterContext *wctx)
00733 {
00734 CompactContext *compact = wctx->priv;
00735
00736 if (!compact->nested_section[wctx->level] &&
00737 !(wctx->section[wctx->level]->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY)))
00738 printf("\n");
00739 }
00740
00741 static void compact_print_str(WriterContext *wctx, const char *key, const char *value)
00742 {
00743 CompactContext *compact = wctx->priv;
00744 AVBPrint buf;
00745
00746 if (wctx->nb_item[wctx->level]) printf("%c", compact->item_sep);
00747 if (!compact->nokey)
00748 printf("%s%s=", wctx->section_pbuf[wctx->level].str, key);
00749 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
00750 printf("%s", compact->escape_str(&buf, value, compact->item_sep, wctx));
00751 av_bprint_finalize(&buf, NULL);
00752 }
00753
00754 static void compact_print_int(WriterContext *wctx, const char *key, long long int value)
00755 {
00756 CompactContext *compact = wctx->priv;
00757
00758 if (wctx->nb_item[wctx->level]) printf("%c", compact->item_sep);
00759 if (!compact->nokey)
00760 printf("%s%s=", wctx->section_pbuf[wctx->level].str, key);
00761 printf("%lld", value);
00762 }
00763
00764 static const Writer compact_writer = {
00765 .name = "compact",
00766 .priv_size = sizeof(CompactContext),
00767 .init = compact_init,
00768 .print_section_header = compact_print_section_header,
00769 .print_section_footer = compact_print_section_footer,
00770 .print_integer = compact_print_int,
00771 .print_string = compact_print_str,
00772 .flags = WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS,
00773 .priv_class = &compact_class,
00774 };
00775
00776
00777
00778 #undef OFFSET
00779 #define OFFSET(x) offsetof(CompactContext, x)
00780
00781 static const AVOption csv_options[] = {
00782 {"item_sep", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=","}, CHAR_MIN, CHAR_MAX },
00783 {"s", "set item separator", OFFSET(item_sep_str), AV_OPT_TYPE_STRING, {.str=","}, CHAR_MIN, CHAR_MAX },
00784 {"nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
00785 {"nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
00786 {"escape", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="csv"}, CHAR_MIN, CHAR_MAX },
00787 {"e", "set escape mode", OFFSET(escape_mode_str), AV_OPT_TYPE_STRING, {.str="csv"}, CHAR_MIN, CHAR_MAX },
00788 {"print_section", "print section name", OFFSET(print_section), AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
00789 {"p", "print section name", OFFSET(print_section), AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
00790 {NULL},
00791 };
00792
00793 DEFINE_WRITER_CLASS(csv);
00794
00795 static const Writer csv_writer = {
00796 .name = "csv",
00797 .priv_size = sizeof(CompactContext),
00798 .init = compact_init,
00799 .print_section_header = compact_print_section_header,
00800 .print_section_footer = compact_print_section_footer,
00801 .print_integer = compact_print_int,
00802 .print_string = compact_print_str,
00803 .flags = WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS,
00804 .priv_class = &csv_class,
00805 };
00806
00807
00808
00809 typedef struct FlatContext {
00810 const AVClass *class;
00811 const char *sep_str;
00812 char sep;
00813 int hierarchical;
00814 } FlatContext;
00815
00816 #undef OFFSET
00817 #define OFFSET(x) offsetof(FlatContext, x)
00818
00819 static const AVOption flat_options[]= {
00820 {"sep_char", "set separator", OFFSET(sep_str), AV_OPT_TYPE_STRING, {.str="."}, CHAR_MIN, CHAR_MAX },
00821 {"s", "set separator", OFFSET(sep_str), AV_OPT_TYPE_STRING, {.str="."}, CHAR_MIN, CHAR_MAX },
00822 {"hierarchical", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
00823 {"h", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
00824 {NULL},
00825 };
00826
00827 DEFINE_WRITER_CLASS(flat);
00828
00829 static av_cold int flat_init(WriterContext *wctx)
00830 {
00831 FlatContext *flat = wctx->priv;
00832
00833 if (strlen(flat->sep_str) != 1) {
00834 av_log(wctx, AV_LOG_ERROR, "Item separator '%s' specified, but must contain a single character\n",
00835 flat->sep_str);
00836 return AVERROR(EINVAL);
00837 }
00838 flat->sep = flat->sep_str[0];
00839
00840 return 0;
00841 }
00842
00843 static const char *flat_escape_key_str(AVBPrint *dst, const char *src, const char sep)
00844 {
00845 const char *p;
00846
00847 for (p = src; *p; p++) {
00848 if (!((*p >= '0' && *p <= '9') ||
00849 (*p >= 'a' && *p <= 'z') ||
00850 (*p >= 'A' && *p <= 'Z')))
00851 av_bprint_chars(dst, '_', 1);
00852 else
00853 av_bprint_chars(dst, *p, 1);
00854 }
00855 return dst->str;
00856 }
00857
00858 static const char *flat_escape_value_str(AVBPrint *dst, const char *src)
00859 {
00860 const char *p;
00861
00862 for (p = src; *p; p++) {
00863 switch (*p) {
00864 case '\n': av_bprintf(dst, "%s", "\\n"); break;
00865 case '\r': av_bprintf(dst, "%s", "\\r"); break;
00866 case '\\': av_bprintf(dst, "%s", "\\\\"); break;
00867 case '"': av_bprintf(dst, "%s", "\\\""); break;
00868 case '`': av_bprintf(dst, "%s", "\\`"); break;
00869 case '$': av_bprintf(dst, "%s", "\\$"); break;
00870 default: av_bprint_chars(dst, *p, 1); break;
00871 }
00872 }
00873 return dst->str;
00874 }
00875
00876 static void flat_print_section_header(WriterContext *wctx)
00877 {
00878 FlatContext *flat = wctx->priv;
00879 AVBPrint *buf = &wctx->section_pbuf[wctx->level];
00880 const struct section *section = wctx->section[wctx->level];
00881 const struct section *parent_section = wctx->level ?
00882 wctx->section[wctx->level-1] : NULL;
00883
00884
00885 av_bprint_clear(buf);
00886 if (!parent_section)
00887 return;
00888 av_bprintf(buf, "%s", wctx->section_pbuf[wctx->level-1].str);
00889
00890 if (flat->hierarchical ||
00891 !(section->flags & (SECTION_FLAG_IS_ARRAY|SECTION_FLAG_IS_WRAPPER))) {
00892 av_bprintf(buf, "%s%s", wctx->section[wctx->level]->name, flat->sep_str);
00893
00894 if (parent_section->flags & SECTION_FLAG_IS_ARRAY) {
00895 int n = parent_section->id == SECTION_ID_PACKETS_AND_FRAMES ?
00896 wctx->nb_section_packet_frame : wctx->nb_item[wctx->level-1];
00897 av_bprintf(buf, "%d%s", n, flat->sep_str);
00898 }
00899 }
00900 }
00901
00902 static void flat_print_int(WriterContext *wctx, const char *key, long long int value)
00903 {
00904 printf("%s%s=%lld\n", wctx->section_pbuf[wctx->level].str, key, value);
00905 }
00906
00907 static void flat_print_str(WriterContext *wctx, const char *key, const char *value)
00908 {
00909 FlatContext *flat = wctx->priv;
00910 AVBPrint buf;
00911
00912 printf("%s", wctx->section_pbuf[wctx->level].str);
00913 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
00914 printf("%s=", flat_escape_key_str(&buf, key, flat->sep));
00915 av_bprint_clear(&buf);
00916 printf("\"%s\"\n", flat_escape_value_str(&buf, value));
00917 av_bprint_finalize(&buf, NULL);
00918 }
00919
00920 static const Writer flat_writer = {
00921 .name = "flat",
00922 .priv_size = sizeof(FlatContext),
00923 .init = flat_init,
00924 .print_section_header = flat_print_section_header,
00925 .print_integer = flat_print_int,
00926 .print_string = flat_print_str,
00927 .flags = WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS|WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER,
00928 .priv_class = &flat_class,
00929 };
00930
00931
00932
00933 typedef struct {
00934 const AVClass *class;
00935 int hierarchical;
00936 } INIContext;
00937
00938 #undef OFFSET
00939 #define OFFSET(x) offsetof(INIContext, x)
00940
00941 static const AVOption ini_options[] = {
00942 {"hierarchical", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
00943 {"h", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_INT, {.i64=1}, 0, 1 },
00944 {NULL},
00945 };
00946
00947 DEFINE_WRITER_CLASS(ini);
00948
00949 static char *ini_escape_str(AVBPrint *dst, const char *src)
00950 {
00951 int i = 0;
00952 char c = 0;
00953
00954 while (c = src[i++]) {
00955 switch (c) {
00956 case '\b': av_bprintf(dst, "%s", "\\b"); break;
00957 case '\f': av_bprintf(dst, "%s", "\\f"); break;
00958 case '\n': av_bprintf(dst, "%s", "\\n"); break;
00959 case '\r': av_bprintf(dst, "%s", "\\r"); break;
00960 case '\t': av_bprintf(dst, "%s", "\\t"); break;
00961 case '\\':
00962 case '#' :
00963 case '=' :
00964 case ':' : av_bprint_chars(dst, '\\', 1);
00965 default:
00966 if ((unsigned char)c < 32)
00967 av_bprintf(dst, "\\x00%02x", c & 0xff);
00968 else
00969 av_bprint_chars(dst, c, 1);
00970 break;
00971 }
00972 }
00973 return dst->str;
00974 }
00975
00976 static void ini_print_section_header(WriterContext *wctx)
00977 {
00978 INIContext *ini = wctx->priv;
00979 AVBPrint *buf = &wctx->section_pbuf[wctx->level];
00980 const struct section *section = wctx->section[wctx->level];
00981 const struct section *parent_section = wctx->level ?
00982 wctx->section[wctx->level-1] : NULL;
00983
00984 av_bprint_clear(buf);
00985 if (!parent_section) {
00986 printf("# ffprobe output\n\n");
00987 return;
00988 }
00989
00990 if (wctx->nb_item[wctx->level-1])
00991 printf("\n");
00992
00993 av_bprintf(buf, "%s", wctx->section_pbuf[wctx->level-1].str);
00994 if (ini->hierarchical ||
00995 !(section->flags & (SECTION_FLAG_IS_ARRAY|SECTION_FLAG_IS_WRAPPER))) {
00996 av_bprintf(buf, "%s%s", buf->str[0] ? "." : "", wctx->section[wctx->level]->name);
00997
00998 if (parent_section->flags & SECTION_FLAG_IS_ARRAY) {
00999 int n = parent_section->id == SECTION_ID_PACKETS_AND_FRAMES ?
01000 wctx->nb_section_packet_frame : wctx->nb_item[wctx->level-1];
01001 av_bprintf(buf, ".%d", n);
01002 }
01003 }
01004
01005 if (!(section->flags & (SECTION_FLAG_IS_ARRAY|SECTION_FLAG_IS_WRAPPER)))
01006 printf("[%s]\n", buf->str);
01007 }
01008
01009 static void ini_print_str(WriterContext *wctx, const char *key, const char *value)
01010 {
01011 AVBPrint buf;
01012
01013 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
01014 printf("%s=", ini_escape_str(&buf, key));
01015 av_bprint_clear(&buf);
01016 printf("%s\n", ini_escape_str(&buf, value));
01017 av_bprint_finalize(&buf, NULL);
01018 }
01019
01020 static void ini_print_int(WriterContext *wctx, const char *key, long long int value)
01021 {
01022 printf("%s=%lld\n", key, value);
01023 }
01024
01025 static const Writer ini_writer = {
01026 .name = "ini",
01027 .priv_size = sizeof(INIContext),
01028 .print_section_header = ini_print_section_header,
01029 .print_integer = ini_print_int,
01030 .print_string = ini_print_str,
01031 .flags = WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS|WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER,
01032 .priv_class = &ini_class,
01033 };
01034
01035
01036
01037 typedef struct {
01038 const AVClass *class;
01039 int indent_level;
01040 int compact;
01041 const char *item_sep, *item_start_end;
01042 } JSONContext;
01043
01044 #undef OFFSET
01045 #define OFFSET(x) offsetof(JSONContext, x)
01046
01047 static const AVOption json_options[]= {
01048 { "compact", "enable compact output", OFFSET(compact), AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
01049 { "c", "enable compact output", OFFSET(compact), AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
01050 { NULL }
01051 };
01052
01053 DEFINE_WRITER_CLASS(json);
01054
01055 static av_cold int json_init(WriterContext *wctx)
01056 {
01057 JSONContext *json = wctx->priv;
01058
01059 json->item_sep = json->compact ? ", " : ",\n";
01060 json->item_start_end = json->compact ? " " : "\n";
01061
01062 return 0;
01063 }
01064
01065 static const char *json_escape_str(AVBPrint *dst, const char *src, void *log_ctx)
01066 {
01067 static const char json_escape[] = {'"', '\\', '\b', '\f', '\n', '\r', '\t', 0};
01068 static const char json_subst[] = {'"', '\\', 'b', 'f', 'n', 'r', 't', 0};
01069 const char *p;
01070
01071 for (p = src; *p; p++) {
01072 char *s = strchr(json_escape, *p);
01073 if (s) {
01074 av_bprint_chars(dst, '\\', 1);
01075 av_bprint_chars(dst, json_subst[s - json_escape], 1);
01076 } else if ((unsigned char)*p < 32) {
01077 av_bprintf(dst, "\\u00%02x", *p & 0xff);
01078 } else {
01079 av_bprint_chars(dst, *p, 1);
01080 }
01081 }
01082 return dst->str;
01083 }
01084
01085 #define JSON_INDENT() printf("%*c", json->indent_level * 4, ' ')
01086
01087 static void json_print_section_header(WriterContext *wctx)
01088 {
01089 JSONContext *json = wctx->priv;
01090 AVBPrint buf;
01091 const struct section *section = wctx->section[wctx->level];
01092 const struct section *parent_section = wctx->level ?
01093 wctx->section[wctx->level-1] : NULL;
01094
01095 if (wctx->level && wctx->nb_item[wctx->level-1])
01096 printf(",\n");
01097
01098 if (section->flags & SECTION_FLAG_IS_WRAPPER) {
01099 printf("{\n");
01100 json->indent_level++;
01101 } else {
01102 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
01103 json_escape_str(&buf, section->name, wctx);
01104 JSON_INDENT();
01105
01106 json->indent_level++;
01107 if (section->flags & SECTION_FLAG_IS_ARRAY) {
01108 printf("\"%s\": [\n", buf.str);
01109 } else if (parent_section && !(parent_section->flags & SECTION_FLAG_IS_ARRAY)) {
01110 printf("\"%s\": {%s", buf.str, json->item_start_end);
01111 } else {
01112 printf("{%s", json->item_start_end);
01113
01114
01115 if (parent_section && parent_section->id == SECTION_ID_PACKETS_AND_FRAMES) {
01116 if (!json->compact)
01117 JSON_INDENT();
01118 printf("\"type\": \"%s\"%s", section->name, json->item_sep);
01119 }
01120 }
01121 av_bprint_finalize(&buf, NULL);
01122 }
01123 }
01124
01125 static void json_print_section_footer(WriterContext *wctx)
01126 {
01127 JSONContext *json = wctx->priv;
01128 const struct section *section = wctx->section[wctx->level];
01129
01130 if (wctx->level == 0) {
01131 json->indent_level--;
01132 printf("\n}\n");
01133 } else if (section->flags & SECTION_FLAG_IS_ARRAY) {
01134 printf("\n");
01135 json->indent_level--;
01136 JSON_INDENT();
01137 printf("]");
01138 } else {
01139 printf("%s", json->item_start_end);
01140 json->indent_level--;
01141 if (!json->compact)
01142 JSON_INDENT();
01143 printf("}");
01144 }
01145 }
01146
01147 static inline void json_print_item_str(WriterContext *wctx,
01148 const char *key, const char *value)
01149 {
01150 AVBPrint buf;
01151
01152 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
01153 printf("\"%s\":", json_escape_str(&buf, key, wctx));
01154 av_bprint_clear(&buf);
01155 printf(" \"%s\"", json_escape_str(&buf, value, wctx));
01156 av_bprint_finalize(&buf, NULL);
01157 }
01158
01159 static void json_print_str(WriterContext *wctx, const char *key, const char *value)
01160 {
01161 JSONContext *json = wctx->priv;
01162
01163 if (wctx->nb_item[wctx->level])
01164 printf("%s", json->item_sep);
01165 if (!json->compact)
01166 JSON_INDENT();
01167 json_print_item_str(wctx, key, value);
01168 }
01169
01170 static void json_print_int(WriterContext *wctx, const char *key, long long int value)
01171 {
01172 JSONContext *json = wctx->priv;
01173 AVBPrint buf;
01174
01175 if (wctx->nb_item[wctx->level])
01176 printf("%s", json->item_sep);
01177 if (!json->compact)
01178 JSON_INDENT();
01179
01180 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
01181 printf("\"%s\": %lld", json_escape_str(&buf, key, wctx), value);
01182 av_bprint_finalize(&buf, NULL);
01183 }
01184
01185 static const Writer json_writer = {
01186 .name = "json",
01187 .priv_size = sizeof(JSONContext),
01188 .init = json_init,
01189 .print_section_header = json_print_section_header,
01190 .print_section_footer = json_print_section_footer,
01191 .print_integer = json_print_int,
01192 .print_string = json_print_str,
01193 .flags = WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER,
01194 .priv_class = &json_class,
01195 };
01196
01197
01198
01199 typedef struct {
01200 const AVClass *class;
01201 int within_tag;
01202 int indent_level;
01203 int fully_qualified;
01204 int xsd_strict;
01205 } XMLContext;
01206
01207 #undef OFFSET
01208 #define OFFSET(x) offsetof(XMLContext, x)
01209
01210 static const AVOption xml_options[] = {
01211 {"fully_qualified", "specify if the output should be fully qualified", OFFSET(fully_qualified), AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
01212 {"q", "specify if the output should be fully qualified", OFFSET(fully_qualified), AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
01213 {"xsd_strict", "ensure that the output is XSD compliant", OFFSET(xsd_strict), AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
01214 {"x", "ensure that the output is XSD compliant", OFFSET(xsd_strict), AV_OPT_TYPE_INT, {.i64=0}, 0, 1 },
01215 {NULL},
01216 };
01217
01218 DEFINE_WRITER_CLASS(xml);
01219
01220 static av_cold int xml_init(WriterContext *wctx)
01221 {
01222 XMLContext *xml = wctx->priv;
01223
01224 if (xml->xsd_strict) {
01225 xml->fully_qualified = 1;
01226 #define CHECK_COMPLIANCE(opt, opt_name) \
01227 if (opt) { \
01228 av_log(wctx, AV_LOG_ERROR, \
01229 "XSD-compliant output selected but option '%s' was selected, XML output may be non-compliant.\n" \
01230 "You need to disable such option with '-no%s'\n", opt_name, opt_name); \
01231 return AVERROR(EINVAL); \
01232 }
01233 CHECK_COMPLIANCE(show_private_data, "private");
01234 CHECK_COMPLIANCE(show_value_unit, "unit");
01235 CHECK_COMPLIANCE(use_value_prefix, "prefix");
01236
01237 if (do_show_frames && do_show_packets) {
01238 av_log(wctx, AV_LOG_ERROR,
01239 "Interleaved frames and packets are not allowed in XSD. "
01240 "Select only one between the -show_frames and the -show_packets options.\n");
01241 return AVERROR(EINVAL);
01242 }
01243 }
01244
01245 return 0;
01246 }
01247
01248 static const char *xml_escape_str(AVBPrint *dst, const char *src, void *log_ctx)
01249 {
01250 const char *p;
01251
01252 for (p = src; *p; p++) {
01253 switch (*p) {
01254 case '&' : av_bprintf(dst, "%s", "&"); break;
01255 case '<' : av_bprintf(dst, "%s", "<"); break;
01256 case '>' : av_bprintf(dst, "%s", ">"); break;
01257 case '\"': av_bprintf(dst, "%s", """); break;
01258 case '\'': av_bprintf(dst, "%s", "'"); break;
01259 default: av_bprint_chars(dst, *p, 1);
01260 }
01261 }
01262
01263 return dst->str;
01264 }
01265
01266 #define XML_INDENT() printf("%*c", xml->indent_level * 4, ' ')
01267
01268 static void xml_print_section_header(WriterContext *wctx)
01269 {
01270 XMLContext *xml = wctx->priv;
01271 const struct section *section = wctx->section[wctx->level];
01272 const struct section *parent_section = wctx->level ?
01273 wctx->section[wctx->level-1] : NULL;
01274
01275 if (wctx->level == 0) {
01276 const char *qual = " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' "
01277 "xmlns:ffprobe='http://www.ffmpeg.org/schema/ffprobe' "
01278 "xsi:schemaLocation='http://www.ffmpeg.org/schema/ffprobe ffprobe.xsd'";
01279
01280 printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
01281 printf("<%sffprobe%s>\n",
01282 xml->fully_qualified ? "ffprobe:" : "",
01283 xml->fully_qualified ? qual : "");
01284 return;
01285 }
01286
01287 if (xml->within_tag) {
01288 xml->within_tag = 0;
01289 printf(">\n");
01290 }
01291 if (section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS) {
01292 xml->indent_level++;
01293 } else {
01294 if (parent_section && (parent_section->flags & SECTION_FLAG_IS_WRAPPER) &&
01295 wctx->level && wctx->nb_item[wctx->level-1])
01296 printf("\n");
01297 xml->indent_level++;
01298
01299 if (section->flags & SECTION_FLAG_IS_ARRAY) {
01300 XML_INDENT(); printf("<%s>\n", section->name);
01301 } else {
01302 XML_INDENT(); printf("<%s ", section->name);
01303 xml->within_tag = 1;
01304 }
01305 }
01306 }
01307
01308 static void xml_print_section_footer(WriterContext *wctx)
01309 {
01310 XMLContext *xml = wctx->priv;
01311 const struct section *section = wctx->section[wctx->level];
01312
01313 if (wctx->level == 0) {
01314 printf("</%sffprobe>\n", xml->fully_qualified ? "ffprobe:" : "");
01315 } else if (xml->within_tag) {
01316 xml->within_tag = 0;
01317 printf("/>\n");
01318 xml->indent_level--;
01319 } else if (section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS) {
01320 xml->indent_level--;
01321 } else {
01322 XML_INDENT(); printf("</%s>\n", section->name);
01323 xml->indent_level--;
01324 }
01325 }
01326
01327 static void xml_print_str(WriterContext *wctx, const char *key, const char *value)
01328 {
01329 AVBPrint buf;
01330 XMLContext *xml = wctx->priv;
01331 const struct section *section = wctx->section[wctx->level];
01332
01333 av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
01334
01335 if (section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS) {
01336 XML_INDENT();
01337 printf("<%s key=\"%s\"",
01338 section->element_name, xml_escape_str(&buf, key, wctx));
01339 av_bprint_clear(&buf);
01340 printf(" value=\"%s\"/>\n", xml_escape_str(&buf, value, wctx));
01341 } else {
01342 if (wctx->nb_item[wctx->level])
01343 printf(" ");
01344 printf("%s=\"%s\"", key, xml_escape_str(&buf, value, wctx));
01345 }
01346
01347 av_bprint_finalize(&buf, NULL);
01348 }
01349
01350 static void xml_print_int(WriterContext *wctx, const char *key, long long int value)
01351 {
01352 if (wctx->nb_item[wctx->level])
01353 printf(" ");
01354 printf("%s=\"%lld\"", key, value);
01355 }
01356
01357 static Writer xml_writer = {
01358 .name = "xml",
01359 .priv_size = sizeof(XMLContext),
01360 .init = xml_init,
01361 .print_section_header = xml_print_section_header,
01362 .print_section_footer = xml_print_section_footer,
01363 .print_integer = xml_print_int,
01364 .print_string = xml_print_str,
01365 .flags = WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER,
01366 .priv_class = &xml_class,
01367 };
01368
01369 static void writer_register_all(void)
01370 {
01371 static int initialized;
01372
01373 if (initialized)
01374 return;
01375 initialized = 1;
01376
01377 writer_register(&default_writer);
01378 writer_register(&compact_writer);
01379 writer_register(&csv_writer);
01380 writer_register(&flat_writer);
01381 writer_register(&ini_writer);
01382 writer_register(&json_writer);
01383 writer_register(&xml_writer);
01384 }
01385
01386 #define print_fmt(k, f, ...) do { \
01387 av_bprint_clear(&pbuf); \
01388 av_bprintf(&pbuf, f, __VA_ARGS__); \
01389 writer_print_string(w, k, pbuf.str, 0); \
01390 } while (0)
01391
01392 #define print_int(k, v) writer_print_integer(w, k, v)
01393 #define print_q(k, v, s) writer_print_rational(w, k, v, s)
01394 #define print_str(k, v) writer_print_string(w, k, v, 0)
01395 #define print_str_opt(k, v) writer_print_string(w, k, v, 1)
01396 #define print_time(k, v, tb) writer_print_time(w, k, v, tb, 0)
01397 #define print_ts(k, v) writer_print_ts(w, k, v, 0)
01398 #define print_duration_time(k, v, tb) writer_print_time(w, k, v, tb, 1)
01399 #define print_duration_ts(k, v) writer_print_ts(w, k, v, 1)
01400 #define print_val(k, v, u) do { \
01401 struct unit_value uv; \
01402 uv.val.i = v; \
01403 uv.unit = u; \
01404 writer_print_string(w, k, value_string(val_str, sizeof(val_str), uv), 0); \
01405 } while (0)
01406
01407 #define print_section_header(s) writer_print_section_header(w, s)
01408 #define print_section_footer(s) writer_print_section_footer(w, s)
01409
01410 static inline void show_tags(WriterContext *wctx, AVDictionary *tags, int section_id)
01411 {
01412 AVDictionaryEntry *tag = NULL;
01413
01414 if (!tags)
01415 return;
01416 writer_print_section_header(wctx, section_id);
01417 while ((tag = av_dict_get(tags, "", tag, AV_DICT_IGNORE_SUFFIX)))
01418 writer_print_string(wctx, tag->key, tag->value, 0);
01419 writer_print_section_footer(wctx);
01420 }
01421
01422 static void show_packet(WriterContext *w, AVFormatContext *fmt_ctx, AVPacket *pkt, int packet_idx)
01423 {
01424 char val_str[128];
01425 AVStream *st = fmt_ctx->streams[pkt->stream_index];
01426 AVBPrint pbuf;
01427 const char *s;
01428
01429 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
01430
01431 writer_print_section_header(w, SECTION_ID_PACKET);
01432
01433 s = av_get_media_type_string(st->codec->codec_type);
01434 if (s) print_str ("codec_type", s);
01435 else print_str_opt("codec_type", "unknown");
01436 print_int("stream_index", pkt->stream_index);
01437 print_ts ("pts", pkt->pts);
01438 print_time("pts_time", pkt->pts, &st->time_base);
01439 print_ts ("dts", pkt->dts);
01440 print_time("dts_time", pkt->dts, &st->time_base);
01441 print_duration_ts("duration", pkt->duration);
01442 print_duration_time("duration_time", pkt->duration, &st->time_base);
01443 print_duration_ts("convergence_duration", pkt->convergence_duration);
01444 print_duration_time("convergence_duration_time", pkt->convergence_duration, &st->time_base);
01445 print_val("size", pkt->size, unit_byte_str);
01446 if (pkt->pos != -1) print_fmt ("pos", "%"PRId64, pkt->pos);
01447 else print_str_opt("pos", "N/A");
01448 print_fmt("flags", "%c", pkt->flags & AV_PKT_FLAG_KEY ? 'K' : '_');
01449 if (do_show_data)
01450 writer_print_data(w, "data", pkt->data, pkt->size);
01451 writer_print_section_footer(w);
01452
01453 av_bprint_finalize(&pbuf, NULL);
01454 fflush(stdout);
01455 }
01456
01457 static void show_frame(WriterContext *w, AVFrame *frame, AVStream *stream,
01458 AVFormatContext *fmt_ctx)
01459 {
01460 AVBPrint pbuf;
01461 const char *s;
01462
01463 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
01464
01465 writer_print_section_header(w, SECTION_ID_FRAME);
01466
01467 s = av_get_media_type_string(stream->codec->codec_type);
01468 if (s) print_str ("media_type", s);
01469 else print_str_opt("media_type", "unknown");
01470 print_int("key_frame", frame->key_frame);
01471 print_ts ("pkt_pts", frame->pkt_pts);
01472 print_time("pkt_pts_time", frame->pkt_pts, &stream->time_base);
01473 print_ts ("pkt_dts", frame->pkt_dts);
01474 print_time("pkt_dts_time", frame->pkt_dts, &stream->time_base);
01475 print_duration_ts ("pkt_duration", frame->pkt_duration);
01476 print_duration_time("pkt_duration_time", frame->pkt_duration, &stream->time_base);
01477 if (frame->pkt_pos != -1) print_fmt ("pkt_pos", "%"PRId64, frame->pkt_pos);
01478 else print_str_opt("pkt_pos", "N/A");
01479 if (frame->pkt_size != -1) print_fmt ("pkt_size", "%d", av_frame_get_pkt_size(frame));
01480 else print_str_opt("pkt_size", "N/A");
01481
01482 switch (stream->codec->codec_type) {
01483 AVRational sar;
01484
01485 case AVMEDIA_TYPE_VIDEO:
01486 print_int("width", frame->width);
01487 print_int("height", frame->height);
01488 s = av_get_pix_fmt_name(frame->format);
01489 if (s) print_str ("pix_fmt", s);
01490 else print_str_opt("pix_fmt", "unknown");
01491 sar = av_guess_sample_aspect_ratio(fmt_ctx, stream, frame);
01492 if (sar.num) {
01493 print_q("sample_aspect_ratio", sar, ':');
01494 } else {
01495 print_str_opt("sample_aspect_ratio", "N/A");
01496 }
01497 print_fmt("pict_type", "%c", av_get_picture_type_char(frame->pict_type));
01498 print_int("coded_picture_number", frame->coded_picture_number);
01499 print_int("display_picture_number", frame->display_picture_number);
01500 print_int("interlaced_frame", frame->interlaced_frame);
01501 print_int("top_field_first", frame->top_field_first);
01502 print_int("repeat_pict", frame->repeat_pict);
01503 print_int("reference", frame->reference);
01504 break;
01505
01506 case AVMEDIA_TYPE_AUDIO:
01507 s = av_get_sample_fmt_name(frame->format);
01508 if (s) print_str ("sample_fmt", s);
01509 else print_str_opt("sample_fmt", "unknown");
01510 print_int("nb_samples", frame->nb_samples);
01511 print_int("channels", av_frame_get_channels(frame));
01512 if (av_frame_get_channel_layout(frame)) {
01513 av_bprint_clear(&pbuf);
01514 av_bprint_channel_layout(&pbuf, av_frame_get_channels(frame),
01515 av_frame_get_channel_layout(frame));
01516 print_str ("channel_layout", pbuf.str);
01517 } else
01518 print_str_opt("channel_layout", "unknown");
01519 break;
01520 }
01521 show_tags(w, av_frame_get_metadata(frame), SECTION_ID_FRAME_TAGS);
01522
01523 writer_print_section_footer(w);
01524
01525 av_bprint_finalize(&pbuf, NULL);
01526 fflush(stdout);
01527 }
01528
01529 static av_always_inline int process_frame(WriterContext *w,
01530 AVFormatContext *fmt_ctx,
01531 AVFrame *frame, AVPacket *pkt)
01532 {
01533 AVCodecContext *dec_ctx = fmt_ctx->streams[pkt->stream_index]->codec;
01534 int ret = 0, got_frame = 0;
01535
01536 avcodec_get_frame_defaults(frame);
01537 if (dec_ctx->codec) {
01538 switch (dec_ctx->codec_type) {
01539 case AVMEDIA_TYPE_VIDEO:
01540 ret = avcodec_decode_video2(dec_ctx, frame, &got_frame, pkt);
01541 break;
01542
01543 case AVMEDIA_TYPE_AUDIO:
01544 ret = avcodec_decode_audio4(dec_ctx, frame, &got_frame, pkt);
01545 break;
01546 }
01547 }
01548
01549 if (ret < 0)
01550 return ret;
01551 ret = FFMIN(ret, pkt->size);
01552 pkt->data += ret;
01553 pkt->size -= ret;
01554 if (got_frame) {
01555 nb_streams_frames[pkt->stream_index]++;
01556 if (do_show_frames)
01557 show_frame(w, frame, fmt_ctx->streams[pkt->stream_index], fmt_ctx);
01558 }
01559 return got_frame;
01560 }
01561
01562 static void read_packets(WriterContext *w, AVFormatContext *fmt_ctx)
01563 {
01564 AVPacket pkt, pkt1;
01565 AVFrame frame;
01566 int i = 0;
01567
01568 av_init_packet(&pkt);
01569
01570 while (!av_read_frame(fmt_ctx, &pkt)) {
01571 if (selected_streams[pkt.stream_index]) {
01572 if (do_read_packets) {
01573 if (do_show_packets)
01574 show_packet(w, fmt_ctx, &pkt, i++);
01575 nb_streams_packets[pkt.stream_index]++;
01576 }
01577 if (do_read_frames) {
01578 pkt1 = pkt;
01579 while (pkt1.size && process_frame(w, fmt_ctx, &frame, &pkt1) > 0);
01580 }
01581 }
01582 av_free_packet(&pkt);
01583 }
01584 av_init_packet(&pkt);
01585 pkt.data = NULL;
01586 pkt.size = 0;
01587
01588 for (i = 0; i < fmt_ctx->nb_streams; i++) {
01589 pkt.stream_index = i;
01590 if (do_read_frames)
01591 while (process_frame(w, fmt_ctx, &frame, &pkt) > 0);
01592 }
01593 }
01594
01595 static void show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_idx)
01596 {
01597 AVStream *stream = fmt_ctx->streams[stream_idx];
01598 AVCodecContext *dec_ctx;
01599 const AVCodec *dec;
01600 char val_str[128];
01601 const char *s;
01602 AVRational sar, dar;
01603 AVBPrint pbuf;
01604
01605 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
01606
01607 writer_print_section_header(w, SECTION_ID_STREAM);
01608
01609 print_int("index", stream->index);
01610
01611 if ((dec_ctx = stream->codec)) {
01612 const char *profile = NULL;
01613 dec = dec_ctx->codec;
01614 if (dec) {
01615 print_str("codec_name", dec->name);
01616 if (!do_bitexact) {
01617 if (dec->long_name) print_str ("codec_long_name", dec->long_name);
01618 else print_str_opt("codec_long_name", "unknown");
01619 }
01620 } else {
01621 print_str_opt("codec_name", "unknown");
01622 if (!do_bitexact) {
01623 print_str_opt("codec_long_name", "unknown");
01624 }
01625 }
01626
01627 if (dec && (profile = av_get_profile_name(dec, dec_ctx->profile)))
01628 print_str("profile", profile);
01629 else
01630 print_str_opt("profile", "unknown");
01631
01632 s = av_get_media_type_string(dec_ctx->codec_type);
01633 if (s) print_str ("codec_type", s);
01634 else print_str_opt("codec_type", "unknown");
01635 print_q("codec_time_base", dec_ctx->time_base, '/');
01636
01637
01638 av_get_codec_tag_string(val_str, sizeof(val_str), dec_ctx->codec_tag);
01639 print_str("codec_tag_string", val_str);
01640 print_fmt("codec_tag", "0x%04x", dec_ctx->codec_tag);
01641
01642 switch (dec_ctx->codec_type) {
01643 case AVMEDIA_TYPE_VIDEO:
01644 print_int("width", dec_ctx->width);
01645 print_int("height", dec_ctx->height);
01646 print_int("has_b_frames", dec_ctx->has_b_frames);
01647 sar = av_guess_sample_aspect_ratio(fmt_ctx, stream, NULL);
01648 if (sar.den) {
01649 print_q("sample_aspect_ratio", sar, ':');
01650 av_reduce(&dar.num, &dar.den,
01651 dec_ctx->width * sar.num,
01652 dec_ctx->height * sar.den,
01653 1024*1024);
01654 print_q("display_aspect_ratio", dar, ':');
01655 } else {
01656 print_str_opt("sample_aspect_ratio", "N/A");
01657 print_str_opt("display_aspect_ratio", "N/A");
01658 }
01659 s = av_get_pix_fmt_name(dec_ctx->pix_fmt);
01660 if (s) print_str ("pix_fmt", s);
01661 else print_str_opt("pix_fmt", "unknown");
01662 print_int("level", dec_ctx->level);
01663 if (dec_ctx->timecode_frame_start >= 0) {
01664 char tcbuf[AV_TIMECODE_STR_SIZE];
01665 av_timecode_make_mpeg_tc_string(tcbuf, dec_ctx->timecode_frame_start);
01666 print_str("timecode", tcbuf);
01667 } else {
01668 print_str_opt("timecode", "N/A");
01669 }
01670 break;
01671
01672 case AVMEDIA_TYPE_AUDIO:
01673 s = av_get_sample_fmt_name(dec_ctx->sample_fmt);
01674 if (s) print_str ("sample_fmt", s);
01675 else print_str_opt("sample_fmt", "unknown");
01676 print_val("sample_rate", dec_ctx->sample_rate, unit_hertz_str);
01677 print_int("channels", dec_ctx->channels);
01678 print_int("bits_per_sample", av_get_bits_per_sample(dec_ctx->codec_id));
01679 break;
01680 }
01681 } else {
01682 print_str_opt("codec_type", "unknown");
01683 }
01684 if (dec_ctx->codec && dec_ctx->codec->priv_class && show_private_data) {
01685 const AVOption *opt = NULL;
01686 while (opt = av_opt_next(dec_ctx->priv_data,opt)) {
01687 uint8_t *str;
01688 if (opt->flags) continue;
01689 if (av_opt_get(dec_ctx->priv_data, opt->name, 0, &str) >= 0) {
01690 print_str(opt->name, str);
01691 av_free(str);
01692 }
01693 }
01694 }
01695
01696 if (fmt_ctx->iformat->flags & AVFMT_SHOW_IDS) print_fmt ("id", "0x%x", stream->id);
01697 else print_str_opt("id", "N/A");
01698 print_q("r_frame_rate", stream->r_frame_rate, '/');
01699 print_q("avg_frame_rate", stream->avg_frame_rate, '/');
01700 print_q("time_base", stream->time_base, '/');
01701 print_ts ("start_pts", stream->start_time);
01702 print_time("start_time", stream->start_time, &stream->time_base);
01703 print_ts ("duration_ts", stream->duration);
01704 print_time("duration", stream->duration, &stream->time_base);
01705 if (dec_ctx->bit_rate > 0) print_val ("bit_rate", dec_ctx->bit_rate, unit_bit_per_second_str);
01706 else print_str_opt("bit_rate", "N/A");
01707 if (stream->nb_frames) print_fmt ("nb_frames", "%"PRId64, stream->nb_frames);
01708 else print_str_opt("nb_frames", "N/A");
01709 if (nb_streams_frames[stream_idx]) print_fmt ("nb_read_frames", "%"PRIu64, nb_streams_frames[stream_idx]);
01710 else print_str_opt("nb_read_frames", "N/A");
01711 if (nb_streams_packets[stream_idx]) print_fmt ("nb_read_packets", "%"PRIu64, nb_streams_packets[stream_idx]);
01712 else print_str_opt("nb_read_packets", "N/A");
01713 if (do_show_data)
01714 writer_print_data(w, "extradata", dec_ctx->extradata,
01715 dec_ctx->extradata_size);
01716
01717
01718 #define PRINT_DISPOSITION(flagname, name) do { \
01719 print_int(name, !!(stream->disposition & AV_DISPOSITION_##flagname)); \
01720 } while (0)
01721
01722 if (do_show_stream_disposition) {
01723 writer_print_section_header(w, SECTION_ID_STREAM_DISPOSITION);
01724 PRINT_DISPOSITION(DEFAULT, "default");
01725 PRINT_DISPOSITION(DUB, "dub");
01726 PRINT_DISPOSITION(ORIGINAL, "original");
01727 PRINT_DISPOSITION(COMMENT, "comment");
01728 PRINT_DISPOSITION(LYRICS, "lyrics");
01729 PRINT_DISPOSITION(KARAOKE, "karaoke");
01730 PRINT_DISPOSITION(FORCED, "forced");
01731 PRINT_DISPOSITION(HEARING_IMPAIRED, "hearing_impaired");
01732 PRINT_DISPOSITION(VISUAL_IMPAIRED, "visual_impaired");
01733 PRINT_DISPOSITION(CLEAN_EFFECTS, "clean_effects");
01734 PRINT_DISPOSITION(ATTACHED_PIC, "attached_pic");
01735 writer_print_section_footer(w);
01736 }
01737
01738 show_tags(w, stream->metadata, SECTION_ID_STREAM_TAGS);
01739
01740 writer_print_section_footer(w);
01741 av_bprint_finalize(&pbuf, NULL);
01742 fflush(stdout);
01743 }
01744
01745 static void show_streams(WriterContext *w, AVFormatContext *fmt_ctx)
01746 {
01747 int i;
01748 writer_print_section_header(w, SECTION_ID_STREAMS);
01749 for (i = 0; i < fmt_ctx->nb_streams; i++)
01750 if (selected_streams[i])
01751 show_stream(w, fmt_ctx, i);
01752 writer_print_section_footer(w);
01753 }
01754
01755 static void show_format(WriterContext *w, AVFormatContext *fmt_ctx)
01756 {
01757 char val_str[128];
01758 int64_t size = fmt_ctx->pb ? avio_size(fmt_ctx->pb) : -1;
01759
01760 writer_print_section_header(w, SECTION_ID_FORMAT);
01761 print_str("filename", fmt_ctx->filename);
01762 print_int("nb_streams", fmt_ctx->nb_streams);
01763 print_str("format_name", fmt_ctx->iformat->name);
01764 if (!do_bitexact) {
01765 if (fmt_ctx->iformat->long_name) print_str ("format_long_name", fmt_ctx->iformat->long_name);
01766 else print_str_opt("format_long_name", "unknown");
01767 }
01768 print_time("start_time", fmt_ctx->start_time, &AV_TIME_BASE_Q);
01769 print_time("duration", fmt_ctx->duration, &AV_TIME_BASE_Q);
01770 if (size >= 0) print_val ("size", size, unit_byte_str);
01771 else print_str_opt("size", "N/A");
01772 if (fmt_ctx->bit_rate > 0) print_val ("bit_rate", fmt_ctx->bit_rate, unit_bit_per_second_str);
01773 else print_str_opt("bit_rate", "N/A");
01774 show_tags(w, fmt_ctx->metadata, SECTION_ID_FORMAT_TAGS);
01775
01776 writer_print_section_footer(w);
01777 fflush(stdout);
01778 }
01779
01780 static void show_error(WriterContext *w, int err)
01781 {
01782 char errbuf[128];
01783 const char *errbuf_ptr = errbuf;
01784
01785 if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)
01786 errbuf_ptr = strerror(AVUNERROR(err));
01787
01788 writer_print_section_header(w, SECTION_ID_ERROR);
01789 print_int("code", err);
01790 print_str("string", errbuf_ptr);
01791 writer_print_section_footer(w);
01792 }
01793
01794 static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename)
01795 {
01796 int err, i;
01797 AVFormatContext *fmt_ctx = NULL;
01798 AVDictionaryEntry *t;
01799
01800 if ((err = avformat_open_input(&fmt_ctx, filename,
01801 iformat, &format_opts)) < 0) {
01802 print_error(filename, err);
01803 return err;
01804 }
01805 if ((t = av_dict_get(format_opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
01806 av_log(NULL, AV_LOG_ERROR, "Option %s not found.\n", t->key);
01807 return AVERROR_OPTION_NOT_FOUND;
01808 }
01809
01810
01811
01812 if ((err = avformat_find_stream_info(fmt_ctx, NULL)) < 0) {
01813 print_error(filename, err);
01814 return err;
01815 }
01816
01817 av_dump_format(fmt_ctx, 0, filename, 0);
01818
01819
01820 for (i = 0; i < fmt_ctx->nb_streams; i++) {
01821 AVStream *stream = fmt_ctx->streams[i];
01822 AVCodec *codec;
01823
01824 if (stream->codec->codec_id == AV_CODEC_ID_PROBE) {
01825 av_log(NULL, AV_LOG_ERROR,
01826 "Failed to probe codec for input stream %d\n",
01827 stream->index);
01828 } else if (!(codec = avcodec_find_decoder(stream->codec->codec_id))) {
01829 av_log(NULL, AV_LOG_ERROR,
01830 "Unsupported codec with id %d for input stream %d\n",
01831 stream->codec->codec_id, stream->index);
01832 } else if (avcodec_open2(stream->codec, codec, NULL) < 0) {
01833 av_log(NULL, AV_LOG_ERROR, "Error while opening codec for input stream %d\n",
01834 stream->index);
01835 }
01836 }
01837
01838 *fmt_ctx_ptr = fmt_ctx;
01839 return 0;
01840 }
01841
01842 static void close_input_file(AVFormatContext **ctx_ptr)
01843 {
01844 int i;
01845 AVFormatContext *fmt_ctx = *ctx_ptr;
01846
01847
01848 for (i = 0; i < fmt_ctx->nb_streams; i++)
01849 if (fmt_ctx->streams[i]->codec->codec_id != AV_CODEC_ID_NONE)
01850 avcodec_close(fmt_ctx->streams[i]->codec);
01851
01852 avformat_close_input(ctx_ptr);
01853 }
01854
01855 static int probe_file(WriterContext *wctx, const char *filename)
01856 {
01857 AVFormatContext *fmt_ctx;
01858 int ret, i;
01859 int section_id;
01860
01861 do_read_frames = do_show_frames || do_count_frames;
01862 do_read_packets = do_show_packets || do_count_packets;
01863
01864 ret = open_input_file(&fmt_ctx, filename);
01865 if (ret >= 0) {
01866 nb_streams_frames = av_calloc(fmt_ctx->nb_streams, sizeof(*nb_streams_frames));
01867 nb_streams_packets = av_calloc(fmt_ctx->nb_streams, sizeof(*nb_streams_packets));
01868 selected_streams = av_calloc(fmt_ctx->nb_streams, sizeof(*selected_streams));
01869
01870 for (i = 0; i < fmt_ctx->nb_streams; i++) {
01871 if (stream_specifier) {
01872 ret = avformat_match_stream_specifier(fmt_ctx,
01873 fmt_ctx->streams[i],
01874 stream_specifier);
01875 if (ret < 0)
01876 goto end;
01877 else
01878 selected_streams[i] = ret;
01879 } else {
01880 selected_streams[i] = 1;
01881 }
01882 }
01883
01884 if (do_read_frames || do_read_packets) {
01885 if (do_show_frames && do_show_packets &&
01886 wctx->writer->flags & WRITER_FLAG_PUT_PACKETS_AND_FRAMES_IN_SAME_CHAPTER)
01887 section_id = SECTION_ID_PACKETS_AND_FRAMES;
01888 else if (do_show_packets && !do_show_frames)
01889 section_id = SECTION_ID_PACKETS;
01890 else
01891 section_id = SECTION_ID_FRAMES;
01892 if (do_show_frames || do_show_packets)
01893 writer_print_section_header(wctx, section_id);
01894 read_packets(wctx, fmt_ctx);
01895 if (do_show_frames || do_show_packets)
01896 writer_print_section_footer(wctx);
01897 }
01898 if (do_show_streams)
01899 show_streams(wctx, fmt_ctx);
01900 if (do_show_format)
01901 show_format(wctx, fmt_ctx);
01902
01903 end:
01904 close_input_file(&fmt_ctx);
01905 av_freep(&nb_streams_frames);
01906 av_freep(&nb_streams_packets);
01907 av_freep(&selected_streams);
01908 }
01909 return ret;
01910 }
01911
01912 static void show_usage(void)
01913 {
01914 av_log(NULL, AV_LOG_INFO, "Simple multimedia streams analyzer\n");
01915 av_log(NULL, AV_LOG_INFO, "usage: %s [OPTIONS] [INPUT_FILE]\n", program_name);
01916 av_log(NULL, AV_LOG_INFO, "\n");
01917 }
01918
01919 static void ffprobe_show_program_version(WriterContext *w)
01920 {
01921 AVBPrint pbuf;
01922 av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
01923
01924 writer_print_section_header(w, SECTION_ID_PROGRAM_VERSION);
01925 print_str("version", FFMPEG_VERSION);
01926 print_fmt("copyright", "Copyright (c) %d-%d the FFmpeg developers",
01927 program_birth_year, this_year);
01928 print_str("build_date", __DATE__);
01929 print_str("build_time", __TIME__);
01930 print_str("compiler_ident", CC_IDENT);
01931 print_str("configuration", FFMPEG_CONFIGURATION);
01932 writer_print_section_footer(w);
01933
01934 av_bprint_finalize(&pbuf, NULL);
01935 }
01936
01937 #define SHOW_LIB_VERSION(libname, LIBNAME) \
01938 do { \
01939 if (CONFIG_##LIBNAME) { \
01940 unsigned int version = libname##_version(); \
01941 writer_print_section_header(w, SECTION_ID_LIBRARY_VERSION); \
01942 print_str("name", "lib" #libname); \
01943 print_int("major", LIB##LIBNAME##_VERSION_MAJOR); \
01944 print_int("minor", LIB##LIBNAME##_VERSION_MINOR); \
01945 print_int("micro", LIB##LIBNAME##_VERSION_MICRO); \
01946 print_int("version", version); \
01947 print_str("ident", LIB##LIBNAME##_IDENT); \
01948 writer_print_section_footer(w); \
01949 } \
01950 } while (0)
01951
01952 static void ffprobe_show_library_versions(WriterContext *w)
01953 {
01954 writer_print_section_header(w, SECTION_ID_LIBRARY_VERSIONS);
01955 SHOW_LIB_VERSION(avutil, AVUTIL);
01956 SHOW_LIB_VERSION(avcodec, AVCODEC);
01957 SHOW_LIB_VERSION(avformat, AVFORMAT);
01958 SHOW_LIB_VERSION(avdevice, AVDEVICE);
01959 SHOW_LIB_VERSION(avfilter, AVFILTER);
01960 SHOW_LIB_VERSION(swscale, SWSCALE);
01961 SHOW_LIB_VERSION(swresample, SWRESAMPLE);
01962 SHOW_LIB_VERSION(postproc, POSTPROC);
01963 writer_print_section_footer(w);
01964 }
01965
01966 static int opt_format(void *optctx, const char *opt, const char *arg)
01967 {
01968 iformat = av_find_input_format(arg);
01969 if (!iformat) {
01970 av_log(NULL, AV_LOG_ERROR, "Unknown input format: %s\n", arg);
01971 return AVERROR(EINVAL);
01972 }
01973 return 0;
01974 }
01975
01976 static inline void mark_section_show_entries(SectionID section_id,
01977 int show_all_entries, AVDictionary *entries)
01978 {
01979 struct section *section = §ions[section_id];
01980
01981 section->show_all_entries = show_all_entries;
01982 if (show_all_entries) {
01983 SectionID *id;
01984 for (id = section->children_ids; *id != -1; id++)
01985 mark_section_show_entries(*id, show_all_entries, entries);
01986 } else {
01987 av_dict_copy(§ion->entries_to_show, entries, 0);
01988 }
01989 }
01990
01991 static int match_section(const char *section_name,
01992 int show_all_entries, AVDictionary *entries)
01993 {
01994 int i, ret = 0;
01995
01996 for (i = 0; i < FF_ARRAY_ELEMS(sections); i++) {
01997 const struct section *section = §ions[i];
01998 if (!strcmp(section_name, section->name) ||
01999 (section->unique_name && !strcmp(section_name, section->unique_name))) {
02000 av_log(NULL, AV_LOG_DEBUG,
02001 "'%s' matches section with unique name '%s'\n", section_name,
02002 (char *)av_x_if_null(section->unique_name, section->name));
02003 ret++;
02004 mark_section_show_entries(section->id, show_all_entries, entries);
02005 }
02006 }
02007 return ret;
02008 }
02009
02010 static int opt_show_entries(void *optctx, const char *opt, const char *arg)
02011 {
02012 const char *p = arg;
02013 int ret = 0;
02014
02015 while (*p) {
02016 AVDictionary *entries = NULL;
02017 char *section_name = av_get_token(&p, "=:");
02018 int show_all_entries = 0;
02019
02020 if (!section_name) {
02021 av_log(NULL, AV_LOG_ERROR,
02022 "Missing section name for option '%s'\n", opt);
02023 return AVERROR(EINVAL);
02024 }
02025
02026 if (*p == '=') {
02027 p++;
02028 while (*p && *p != ':') {
02029 char *entry = av_get_token(&p, ",:");
02030 if (!entry)
02031 break;
02032 av_log(NULL, AV_LOG_VERBOSE,
02033 "Adding '%s' to the entries to show in section '%s'\n",
02034 entry, section_name);
02035 av_dict_set(&entries, entry, "", AV_DICT_DONT_STRDUP_KEY);
02036 if (*p == ',')
02037 p++;
02038 }
02039 } else {
02040 show_all_entries = 1;
02041 }
02042
02043 ret = match_section(section_name, show_all_entries, entries);
02044 if (ret == 0) {
02045 av_log(NULL, AV_LOG_ERROR, "No match for section '%s'\n", section_name);
02046 ret = AVERROR(EINVAL);
02047 }
02048 av_dict_free(&entries);
02049 av_free(section_name);
02050
02051 if (ret <= 0)
02052 break;
02053 if (*p)
02054 p++;
02055 }
02056
02057 return ret;
02058 }
02059
02060 static int opt_show_format_entry(void *optctx, const char *opt, const char *arg)
02061 {
02062 char *buf = av_asprintf("format=%s", arg);
02063 int ret;
02064
02065 av_log(NULL, AV_LOG_WARNING,
02066 "Option '%s' is deprecated, use '-show_entries format=%s' instead\n",
02067 opt, arg);
02068 ret = opt_show_entries(optctx, opt, buf);
02069 av_free(buf);
02070 return ret;
02071 }
02072
02073 static void opt_input_file(void *optctx, const char *arg)
02074 {
02075 if (input_filename) {
02076 av_log(NULL, AV_LOG_ERROR,
02077 "Argument '%s' provided as input filename, but '%s' was already specified.\n",
02078 arg, input_filename);
02079 exit(1);
02080 }
02081 if (!strcmp(arg, "-"))
02082 arg = "pipe:";
02083 input_filename = arg;
02084 }
02085
02086 static int opt_input_file_i(void *optctx, const char *opt, const char *arg)
02087 {
02088 opt_input_file(optctx, arg);
02089 return 0;
02090 }
02091
02092 void show_help_default(const char *opt, const char *arg)
02093 {
02094 av_log_set_callback(log_callback_help);
02095 show_usage();
02096 show_help_options(options, "Main options:", 0, 0, 0);
02097 printf("\n");
02098
02099 show_help_children(avformat_get_class(), AV_OPT_FLAG_DECODING_PARAM);
02100 }
02101
02102 static int opt_pretty(void *optctx, const char *opt, const char *arg)
02103 {
02104 show_value_unit = 1;
02105 use_value_prefix = 1;
02106 use_byte_value_binary_prefix = 1;
02107 use_value_sexagesimal_format = 1;
02108 return 0;
02109 }
02110
02111 static void print_section(SectionID id, int level)
02112 {
02113 const SectionID *pid;
02114 const struct section *section = §ions[id];
02115 printf("%c%c%c",
02116 section->flags & SECTION_FLAG_IS_WRAPPER ? 'W' : '.',
02117 section->flags & SECTION_FLAG_IS_ARRAY ? 'A' : '.',
02118 section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS ? 'V' : '.');
02119 printf("%*c %s", level * 4, ' ', section->name);
02120 if (section->unique_name)
02121 printf("/%s", section->unique_name);
02122 printf("\n");
02123
02124 for (pid = section->children_ids; *pid != -1; pid++)
02125 print_section(*pid, level+1);
02126 }
02127
02128 static int opt_sections(void *optctx, const char *opt, const char *arg)
02129 {
02130 printf("Sections:\n"
02131 "W.. = Section is a wrapper (contains other sections, no local entries)\n"
02132 ".A. = Section contains an array of elements of the same type\n"
02133 "..V = Section may contain a variable number of fields with variable keys\n"
02134 "FLAGS NAME/UNIQUE_NAME\n"
02135 "---\n");
02136 print_section(SECTION_ID_ROOT, 0);
02137 return 0;
02138 }
02139
02140 static int opt_show_versions(const char *opt, const char *arg)
02141 {
02142 mark_section_show_entries(SECTION_ID_PROGRAM_VERSION, 1, NULL);
02143 mark_section_show_entries(SECTION_ID_LIBRARY_VERSION, 1, NULL);
02144 return 0;
02145 }
02146
02147 #define DEFINE_OPT_SHOW_SECTION(section, target_section_id) \
02148 static int opt_show_##section(const char *opt, const char *arg) \
02149 { \
02150 mark_section_show_entries(SECTION_ID_##target_section_id, 1, NULL); \
02151 return 0; \
02152 }
02153
02154 DEFINE_OPT_SHOW_SECTION(error, ERROR);
02155 DEFINE_OPT_SHOW_SECTION(format, FORMAT);
02156 DEFINE_OPT_SHOW_SECTION(frames, FRAMES);
02157 DEFINE_OPT_SHOW_SECTION(library_versions, LIBRARY_VERSIONS);
02158 DEFINE_OPT_SHOW_SECTION(packets, PACKETS);
02159 DEFINE_OPT_SHOW_SECTION(program_version, PROGRAM_VERSION);
02160 DEFINE_OPT_SHOW_SECTION(streams, STREAMS);
02161
02162 static const OptionDef real_options[] = {
02163 #include "cmdutils_common_opts.h"
02164 { "f", HAS_ARG, {.func_arg = opt_format}, "force format", "format" },
02165 { "unit", OPT_BOOL, {&show_value_unit}, "show unit of the displayed values" },
02166 { "prefix", OPT_BOOL, {&use_value_prefix}, "use SI prefixes for the displayed values" },
02167 { "byte_binary_prefix", OPT_BOOL, {&use_byte_value_binary_prefix},
02168 "use binary prefixes for byte units" },
02169 { "sexagesimal", OPT_BOOL, {&use_value_sexagesimal_format},
02170 "use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units" },
02171 { "pretty", 0, {.func_arg = opt_pretty},
02172 "prettify the format of displayed values, make it more human readable" },
02173 { "print_format", OPT_STRING | HAS_ARG, {(void*)&print_format},
02174 "set the output printing format (available formats are: default, compact, csv, flat, ini, json, xml)", "format" },
02175 { "of", OPT_STRING | HAS_ARG, {(void*)&print_format}, "alias for -print_format", "format" },
02176 { "select_streams", OPT_STRING | HAS_ARG, {(void*)&stream_specifier}, "select the specified streams", "stream_specifier" },
02177 { "sections", OPT_EXIT, {.func_arg = opt_sections}, "print sections structure and section information, and exit" },
02178 { "show_data", OPT_BOOL, {(void*)&do_show_data}, "show packets data" },
02179 { "show_error", 0, {(void*)&opt_show_error}, "show probing error" },
02180 { "show_format", 0, {(void*)&opt_show_format}, "show format/container info" },
02181 { "show_frames", 0, {(void*)&opt_show_frames}, "show frames info" },
02182 { "show_format_entry", HAS_ARG, {.func_arg = opt_show_format_entry},
02183 "show a particular entry from the format/container info", "entry" },
02184 { "show_entries", HAS_ARG, {.func_arg = opt_show_entries},
02185 "show a set of specified entries", "entry_list" },
02186 { "show_packets", 0, {(void*)&opt_show_packets}, "show packets info" },
02187 { "show_streams", 0, {(void*)&opt_show_streams}, "show streams info" },
02188 { "count_frames", OPT_BOOL, {(void*)&do_count_frames}, "count the number of frames per stream" },
02189 { "count_packets", OPT_BOOL, {(void*)&do_count_packets}, "count the number of packets per stream" },
02190 { "show_program_version", 0, {(void*)&opt_show_program_version}, "show ffprobe version" },
02191 { "show_library_versions", 0, {(void*)&opt_show_library_versions}, "show library versions" },
02192 { "show_versions", 0, {(void*)&opt_show_versions}, "show program and library versions" },
02193 { "show_private_data", OPT_BOOL, {(void*)&show_private_data}, "show private data" },
02194 { "private", OPT_BOOL, {(void*)&show_private_data}, "same as show_private_data" },
02195 { "bitexact", OPT_BOOL, {&do_bitexact}, "force bitexact output" },
02196 { "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {.func_arg = opt_default}, "generic catch all option", "" },
02197 { "i", HAS_ARG, {.func_arg = opt_input_file_i}, "read specified file", "input_file"},
02198 { NULL, },
02199 };
02200
02201 static inline int check_section_show_entries(int section_id)
02202 {
02203 int *id;
02204 struct section *section = §ions[section_id];
02205 if (sections[section_id].show_all_entries || sections[section_id].entries_to_show)
02206 return 1;
02207 for (id = section->children_ids; *id != -1; id++)
02208 if (check_section_show_entries(*id))
02209 return 1;
02210 return 0;
02211 }
02212
02213 #define SET_DO_SHOW(id, varname) do { \
02214 if (check_section_show_entries(SECTION_ID_##id)) \
02215 do_show_##varname = 1; \
02216 } while (0)
02217
02218 int main(int argc, char **argv)
02219 {
02220 const Writer *w;
02221 WriterContext *wctx;
02222 char *buf;
02223 char *w_name = NULL, *w_args = NULL;
02224 int ret, i;
02225
02226 av_log_set_flags(AV_LOG_SKIP_REPEATED);
02227 atexit(exit_program);
02228
02229 options = real_options;
02230 parse_loglevel(argc, argv, options);
02231 av_register_all();
02232 avformat_network_init();
02233 init_opts();
02234 #if CONFIG_AVDEVICE
02235 avdevice_register_all();
02236 #endif
02237
02238 show_banner(argc, argv, options);
02239 parse_options(NULL, argc, argv, options, opt_input_file);
02240
02241
02242 SET_DO_SHOW(ERROR, error);
02243 SET_DO_SHOW(FORMAT, format);
02244 SET_DO_SHOW(FRAMES, frames);
02245 SET_DO_SHOW(LIBRARY_VERSIONS, library_versions);
02246 SET_DO_SHOW(PACKETS, packets);
02247 SET_DO_SHOW(PROGRAM_VERSION, program_version);
02248 SET_DO_SHOW(STREAMS, streams);
02249 SET_DO_SHOW(STREAM_DISPOSITION, stream_disposition);
02250
02251 if (do_bitexact && (do_show_program_version || do_show_library_versions)) {
02252 av_log(NULL, AV_LOG_ERROR,
02253 "-bitexact and -show_program_version or -show_library_versions "
02254 "options are incompatible\n");
02255 ret = AVERROR(EINVAL);
02256 goto end;
02257 }
02258
02259 writer_register_all();
02260
02261 if (!print_format)
02262 print_format = av_strdup("default");
02263 if (!print_format) {
02264 ret = AVERROR(ENOMEM);
02265 goto end;
02266 }
02267 w_name = av_strtok(print_format, "=", &buf);
02268 w_args = buf;
02269
02270 w = writer_get_by_name(w_name);
02271 if (!w) {
02272 av_log(NULL, AV_LOG_ERROR, "Unknown output format with name '%s'\n", w_name);
02273 ret = AVERROR(EINVAL);
02274 goto end;
02275 }
02276
02277 if ((ret = writer_open(&wctx, w, w_args,
02278 sections, FF_ARRAY_ELEMS(sections))) >= 0) {
02279 writer_print_section_header(wctx, SECTION_ID_ROOT);
02280
02281 if (do_show_program_version)
02282 ffprobe_show_program_version(wctx);
02283 if (do_show_library_versions)
02284 ffprobe_show_library_versions(wctx);
02285
02286 if (!input_filename &&
02287 ((do_show_format || do_show_streams || do_show_packets || do_show_error) ||
02288 (!do_show_program_version && !do_show_library_versions))) {
02289 show_usage();
02290 av_log(NULL, AV_LOG_ERROR, "You have to specify one input file.\n");
02291 av_log(NULL, AV_LOG_ERROR, "Use -h to get full help or, even better, run 'man %s'.\n", program_name);
02292 ret = AVERROR(EINVAL);
02293 } else if (input_filename) {
02294 ret = probe_file(wctx, input_filename);
02295 if (ret < 0 && do_show_error)
02296 show_error(wctx, ret);
02297 }
02298
02299 writer_print_section_footer(wctx);
02300 writer_close(&wctx);
02301 }
02302
02303 end:
02304 av_freep(&print_format);
02305
02306 uninit_opts();
02307 for (i = 0; i < FF_ARRAY_ELEMS(sections); i++)
02308 av_dict_free(&(sections[i].entries_to_show));
02309
02310 avformat_network_deinit();
02311
02312 return ret;
02313 }