avprobe: Print a user-friendly version of the display matrix
[libav.git] / avtools / avprobe.c
CommitLineData
336ce917 1/*
9e12f0bf 2 * avprobe : Simple Media Prober based on the Libav libraries
336ce917
SS
3 * Copyright (c) 2007-2010 Stefano Sabatini
4 *
2912e87a 5 * This file is part of Libav.
336ce917 6 *
2912e87a 7 * Libav is free software; you can redistribute it and/or
336ce917
SS
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
2912e87a 12 * Libav is distributed in the hope that it will be useful,
336ce917
SS
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
2912e87a 18 * License along with Libav; if not, write to the Free Software
336ce917
SS
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
6ce98ea4
SS
22#include "config.h"
23
336ce917
SS
24#include "libavformat/avformat.h"
25#include "libavcodec/avcodec.h"
efa7f420 26#include "libavutil/avstring.h"
709e1c91 27#include "libavutil/display.h"
41d0eb1c 28#include "libavutil/opt.h"
336ce917 29#include "libavutil/pixdesc.h"
2fb6acd9 30#include "libavutil/spherical.h"
8e757716 31#include "libavutil/stereo3d.h"
d2d67e42 32#include "libavutil/dict.h"
0af85d57 33#include "libavutil/libm.h"
6ce98ea4 34#include "libavdevice/avdevice.h"
336ce917
SS
35#include "cmdutils.h"
36
567d6d5f
AK
37typedef struct InputStream {
38 AVStream *st;
ba357e98
AK
39
40 AVCodecContext *dec_ctx;
567d6d5f
AK
41} InputStream;
42
c9478410
AK
43typedef struct InputFile {
44 AVFormatContext *fmt_ctx;
567d6d5f
AK
45
46 InputStream *streams;
47 int nb_streams;
c9478410
AK
48} InputFile;
49
9e12f0bf 50const char program_name[] = "avprobe";
336ce917
SS
51const int program_birth_year = 2007;
52
53static int do_show_format = 0;
08354bf4 54static AVDictionary *fmt_entries_to_show = NULL;
d8947523 55static int nb_fmt_entries_to_show;
530bbe96 56static int do_show_packets = 0;
336ce917 57static int do_show_streams = 0;
7d308bf8
VG
58static AVDictionary *stream_entries_to_show = NULL;
59static int nb_stream_entries_to_show;
60
61/* key used to print when probe_{int,str}(NULL, ..) is invoked */
62static const char *header_key;
336ce917
SS
63
64static int show_value_unit = 0;
65static int use_value_prefix = 0;
66static int use_byte_value_binary_prefix = 0;
67static int use_value_sexagesimal_format = 0;
68
69/* globals */
dcb7ef54 70static const OptionDef *options;
336ce917 71
41ed7ab4 72/* avprobe context */
336ce917 73static const char *input_filename;
1be784a2 74static AVInputFormat *iformat = NULL;
336ce917 75
b0f29db5
AC
76static const char *const binary_unit_prefixes [] = { "", "Ki", "Mi", "Gi", "Ti", "Pi" };
77static const char *const decimal_unit_prefixes[] = { "", "K" , "M" , "G" , "T" , "P" };
336ce917 78
b0f29db5
AC
79static const char unit_second_str[] = "s" ;
80static const char unit_hertz_str[] = "Hz" ;
81static const char unit_byte_str[] = "byte" ;
82static const char unit_bit_per_second_str[] = "bit/s";
336ce917 83
636ced8e 84static void avprobe_cleanup(int ret)
dad09ff9 85{
08354bf4 86 av_dict_free(&fmt_entries_to_show);
7d308bf8 87 av_dict_free(&stream_entries_to_show);
dad09ff9
AK
88}
89
3a8c95f7
LB
90/*
91 * The output is structured in array and objects that might contain items
92 * Array could require the objects within to not be named.
93 * Object could require the items within to be named.
94 *
95 * For flat representation the name of each section is saved on prefix so it
96 * can be rendered in order to represent nested structures (e.g. array of
97 * objects for the packets list).
98 *
99 * Within an array each element can need an unique identifier or an index.
100 *
101 * Nesting level is accounted separately.
102 */
103
104typedef enum {
105 ARRAY,
106 OBJECT
a4baf96a 107} PrintElementType;
3a8c95f7 108
bf704132 109typedef struct PrintElement {
3a8c95f7 110 const char *name;
a4baf96a 111 PrintElementType type;
3a8c95f7
LB
112 int64_t index;
113 int64_t nb_elems;
a4baf96a 114} PrintElement;
3a8c95f7 115
bf704132 116typedef struct PrintContext {
a4baf96a 117 PrintElement *prefix;
3a8c95f7 118 int level;
52899558
LB
119 void (*print_header)(void);
120 void (*print_footer)(void);
121
3080b049
MS
122 void (*print_array_header) (const char *name, int plain_values);
123 void (*print_array_footer) (const char *name, int plain_values);
52899558
LB
124 void (*print_object_header)(const char *name);
125 void (*print_object_footer)(const char *name);
126
127 void (*print_integer) (const char *key, int64_t value);
128 void (*print_string) (const char *key, const char *value);
a4baf96a 129} PrintContext;
3a8c95f7
LB
130
131static AVIOContext *probe_out = NULL;
a4baf96a 132static PrintContext octx;
0d242a77 133#define AVP_INDENT() avio_printf(probe_out, "%*c", octx.level * 2, ' ')
c31f6b1d 134#define CONV_FP(x,fp) ((double) (x)) / (1 << fp)
3a8c95f7
LB
135
136/*
137 * Default format, INI
138 *
139 * - all key and values are utf8
140 * - '.' is the subgroup separator
141 * - newlines and the following characters are escaped
142 * - '\' is the escape character
143 * - '#' is the comment
144 * - '=' is the key/value separators
145 * - ':' is not used but usually parsed as key/value separator
146 */
147
148static void ini_print_header(void)
149{
150 avio_printf(probe_out, "# avprobe output\n\n");
151}
152static void ini_print_footer(void)
153{
154 avio_w8(probe_out, '\n');
155}
156
157static void ini_escape_print(const char *s)
158{
159 int i = 0;
160 char c = 0;
161
162 while (c = s[i++]) {
163 switch (c) {
164 case '\r': avio_printf(probe_out, "%s", "\\r"); break;
165 case '\n': avio_printf(probe_out, "%s", "\\n"); break;
166 case '\f': avio_printf(probe_out, "%s", "\\f"); break;
167 case '\b': avio_printf(probe_out, "%s", "\\b"); break;
168 case '\t': avio_printf(probe_out, "%s", "\\t"); break;
169 case '\\':
170 case '#' :
171 case '=' :
172 case ':' : avio_w8(probe_out, '\\');
173 default:
174 if ((unsigned char)c < 32)
175 avio_printf(probe_out, "\\x00%02x", c & 0xff);
176 else
177 avio_w8(probe_out, c);
178 break;
179 }
180 }
181}
182
3080b049 183static void ini_print_array_header(const char *name, int plain_values)
3a8c95f7 184{
3080b049
MS
185 if (!plain_values) {
186 /* Add a new line if we create a new full group */
187 if (octx.prefix[octx.level -1].nb_elems)
188 avio_printf(probe_out, "\n");
189 } else {
190 ini_escape_print(name);
191 avio_w8(probe_out, '=');
192 }
193}
194
195static void ini_print_array_footer(const char *name, int plain_values)
196{
197 if (plain_values)
3a8c95f7
LB
198 avio_printf(probe_out, "\n");
199}
200
201static void ini_print_object_header(const char *name)
202{
203 int i;
a4baf96a 204 PrintElement *el = octx.prefix + octx.level -1;
3a8c95f7
LB
205
206 if (el->nb_elems)
207 avio_printf(probe_out, "\n");
208
209 avio_printf(probe_out, "[");
210
211 for (i = 1; i < octx.level; i++) {
212 el = octx.prefix + i;
213 avio_printf(probe_out, "%s.", el->name);
214 if (el->index >= 0)
215 avio_printf(probe_out, "%"PRId64".", el->index);
216 }
217
218 avio_printf(probe_out, "%s", name);
aeb23fc4 219 if (el->type == ARRAY)
3a8c95f7
LB
220 avio_printf(probe_out, ".%"PRId64"", el->nb_elems);
221 avio_printf(probe_out, "]\n");
222}
223
224static void ini_print_integer(const char *key, int64_t value)
225{
3080b049
MS
226 if (key) {
227 ini_escape_print(key);
228 avio_printf(probe_out, "=%"PRId64"\n", value);
229 } else {
230 if (octx.prefix[octx.level -1].nb_elems)
231 avio_printf(probe_out, ",");
232 avio_printf(probe_out, "%"PRId64, value);
233 }
3a8c95f7
LB
234}
235
236
237static void ini_print_string(const char *key, const char *value)
238{
f821b2ea
VG
239 if (key) {
240 ini_escape_print(key);
241 avio_printf(probe_out, "=%s\n", value);
242 } else {
243 if (octx.prefix[octx.level -1].nb_elems)
244 avio_printf(probe_out, ",");
245 avio_printf(probe_out, "%s", value);
246 }
3a8c95f7
LB
247}
248
249/*
0d242a77
LB
250 * Alternate format, JSON
251 */
252
253static void json_print_header(void)
254{
255 avio_printf(probe_out, "{");
256}
257static void json_print_footer(void)
258{
259 avio_printf(probe_out, "}\n");
260}
261
3080b049 262static void json_print_array_header(const char *name, int plain_values)
0d242a77
LB
263{
264 if (octx.prefix[octx.level -1].nb_elems)
265 avio_printf(probe_out, ",\n");
266 AVP_INDENT();
267 avio_printf(probe_out, "\"%s\" : ", name);
268 avio_printf(probe_out, "[\n");
269}
270
3080b049 271static void json_print_array_footer(const char *name, int plain_values)
0d242a77
LB
272{
273 avio_printf(probe_out, "\n");
274 AVP_INDENT();
275 avio_printf(probe_out, "]");
276}
277
278static void json_print_object_header(const char *name)
279{
280 if (octx.prefix[octx.level -1].nb_elems)
281 avio_printf(probe_out, ",\n");
282 AVP_INDENT();
283 if (octx.prefix[octx.level -1].type == OBJECT)
284 avio_printf(probe_out, "\"%s\" : ", name);
285 avio_printf(probe_out, "{\n");
286}
287
288static void json_print_object_footer(const char *name)
289{
290 avio_printf(probe_out, "\n");
291 AVP_INDENT();
292 avio_printf(probe_out, "}");
293}
294
295static void json_print_integer(const char *key, int64_t value)
296{
3080b049
MS
297 if (key) {
298 if (octx.prefix[octx.level -1].nb_elems)
299 avio_printf(probe_out, ",\n");
300 AVP_INDENT();
301 avio_printf(probe_out, "\"%s\" : ", key);
302 } else {
303 if (octx.prefix[octx.level -1].nb_elems)
304 avio_printf(probe_out, ", ");
305 else
306 AVP_INDENT();
307 }
308 avio_printf(probe_out, "%"PRId64, value);
0d242a77
LB
309}
310
311static void json_escape_print(const char *s)
312{
313 int i = 0;
314 char c = 0;
315
316 while (c = s[i++]) {
317 switch (c) {
318 case '\r': avio_printf(probe_out, "%s", "\\r"); break;
319 case '\n': avio_printf(probe_out, "%s", "\\n"); break;
320 case '\f': avio_printf(probe_out, "%s", "\\f"); break;
321 case '\b': avio_printf(probe_out, "%s", "\\b"); break;
322 case '\t': avio_printf(probe_out, "%s", "\\t"); break;
323 case '\\':
324 case '"' : avio_w8(probe_out, '\\');
325 default:
326 if ((unsigned char)c < 32)
327 avio_printf(probe_out, "\\u00%02x", c & 0xff);
328 else
329 avio_w8(probe_out, c);
330 break;
331 }
332 }
333}
334
335static void json_print_string(const char *key, const char *value)
336{
f821b2ea
VG
337 if (key) {
338 if (octx.prefix[octx.level -1].nb_elems)
339 avio_printf(probe_out, ",\n");
340 AVP_INDENT();
341 avio_w8(probe_out, '\"');
342 json_escape_print(key);
343 avio_printf(probe_out, "\" : \"");
344 json_escape_print(value);
345 avio_w8(probe_out, '\"');
346 } else {
347 if (octx.prefix[octx.level -1].nb_elems)
348 avio_printf(probe_out, ", ");
349 else
350 AVP_INDENT();
351 avio_w8(probe_out, '\"');
352 json_escape_print(value);
353 avio_w8(probe_out, '\"');
354 }
0d242a77
LB
355}
356
357/*
8271f55b
AK
358 * old-style pseudo-INI
359 */
360static void old_print_object_header(const char *name)
361{
362 char *str, *p;
363
364 if (!strcmp(name, "tags"))
365 return;
366
367 str = p = av_strdup(name);
b1306823
VG
368 if (!str)
369 return;
8271f55b 370 while (*p) {
efa7f420 371 *p = av_toupper(*p);
8271f55b
AK
372 p++;
373 }
374
375 avio_printf(probe_out, "[%s]\n", str);
376 av_freep(&str);
377}
378
379static void old_print_object_footer(const char *name)
380{
381 char *str, *p;
382
383 if (!strcmp(name, "tags"))
384 return;
385
386 str = p = av_strdup(name);
b1306823
VG
387 if (!str)
388 return;
8271f55b 389 while (*p) {
efa7f420 390 *p = av_toupper(*p);
8271f55b
AK
391 p++;
392 }
393
394 avio_printf(probe_out, "[/%s]\n", str);
395 av_freep(&str);
396}
397
398static void old_print_string(const char *key, const char *value)
399{
400 if (!strcmp(octx.prefix[octx.level - 1].name, "tags"))
401 avio_printf(probe_out, "TAG:");
402 ini_print_string(key, value);
403}
404
405/*
3a8c95f7
LB
406 * Simple Formatter for single entries.
407 */
408
409static void show_format_entry_integer(const char *key, int64_t value)
410{
411 if (key && av_dict_get(fmt_entries_to_show, key, NULL, 0)) {
412 if (nb_fmt_entries_to_show > 1)
413 avio_printf(probe_out, "%s=", key);
414 avio_printf(probe_out, "%"PRId64"\n", value);
415 }
416}
417
418static void show_format_entry_string(const char *key, const char *value)
419{
420 if (key && av_dict_get(fmt_entries_to_show, key, NULL, 0)) {
421 if (nb_fmt_entries_to_show > 1)
422 avio_printf(probe_out, "%s=", key);
423 avio_printf(probe_out, "%s\n", value);
424 }
425}
426
7d308bf8
VG
427static void show_stream_entry_header(const char *key, int value)
428{
429 header_key = key;
430}
431
432static void show_stream_entry_footer(const char *key, int value)
433{
434 header_key = NULL;
435}
436
437static void show_stream_entry_integer(const char *key, int64_t value)
438{
439 if (!key)
440 key = header_key;
441
442 if (key && av_dict_get(stream_entries_to_show, key, NULL, 0)) {
443 if (nb_stream_entries_to_show > 1)
444 avio_printf(probe_out, "%s=", key);
445 avio_printf(probe_out, "%"PRId64"\n", value);
446 }
447}
448
449static void show_stream_entry_string(const char *key, const char *value)
450{
451 if (key && av_dict_get(stream_entries_to_show, key, NULL, 0)) {
452 if (nb_stream_entries_to_show > 1)
453 avio_printf(probe_out, "%s=", key);
454 avio_printf(probe_out, "%s\n", value);
455 }
456}
457
3a8c95f7
LB
458static void probe_group_enter(const char *name, int type)
459{
460 int64_t count = -1;
461
462 octx.prefix =
a4baf96a 463 av_realloc(octx.prefix, sizeof(PrintElement) * (octx.level + 1));
3a8c95f7
LB
464
465 if (!octx.prefix || !name) {
466 fprintf(stderr, "Out of memory\n");
636ced8e 467 exit_program(1);
3a8c95f7
LB
468 }
469
470 if (octx.level) {
a4baf96a 471 PrintElement *parent = octx.prefix + octx.level -1;
3a8c95f7
LB
472 if (parent->type == ARRAY)
473 count = parent->nb_elems;
474 parent->nb_elems++;
475 }
476
a4baf96a 477 octx.prefix[octx.level++] = (PrintElement){name, type, count, 0};
3a8c95f7
LB
478}
479
480static void probe_group_leave(void)
481{
482 --octx.level;
483}
484
485static void probe_header(void)
486{
52899558
LB
487 if (octx.print_header)
488 octx.print_header();
3a8c95f7
LB
489 probe_group_enter("root", OBJECT);
490}
491
492static void probe_footer(void)
493{
52899558
LB
494 if (octx.print_footer)
495 octx.print_footer();
3a8c95f7
LB
496 probe_group_leave();
497}
498
499
3080b049 500static void probe_array_header(const char *name, int plain_values)
3a8c95f7 501{
52899558 502 if (octx.print_array_header)
3080b049 503 octx.print_array_header(name, plain_values);
3a8c95f7
LB
504
505 probe_group_enter(name, ARRAY);
506}
507
3080b049 508static void probe_array_footer(const char *name, int plain_values)
3a8c95f7
LB
509{
510 probe_group_leave();
52899558 511 if (octx.print_array_footer)
3080b049 512 octx.print_array_footer(name, plain_values);
3a8c95f7
LB
513}
514
515static void probe_object_header(const char *name)
516{
52899558
LB
517 if (octx.print_object_header)
518 octx.print_object_header(name);
3a8c95f7
LB
519
520 probe_group_enter(name, OBJECT);
521}
522
523static void probe_object_footer(const char *name)
524{
525 probe_group_leave();
52899558
LB
526 if (octx.print_object_footer)
527 octx.print_object_footer(name);
3a8c95f7
LB
528}
529
530static void probe_int(const char *key, int64_t value)
531{
52899558 532 octx.print_integer(key, value);
3a8c95f7
LB
533 octx.prefix[octx.level -1].nb_elems++;
534}
535
536static void probe_str(const char *key, const char *value)
537{
52899558 538 octx.print_string(key, value);
3a8c95f7
LB
539 octx.prefix[octx.level -1].nb_elems++;
540}
541
542static void probe_dict(AVDictionary *dict, const char *name)
543{
544 AVDictionaryEntry *entry = NULL;
545 if (!dict)
546 return;
547 probe_object_header(name);
548 while ((entry = av_dict_get(dict, "", entry, AV_DICT_IGNORE_SUFFIX))) {
549 probe_str(entry->key, entry->value);
550 }
551 probe_object_footer(name);
552}
553
336ce917
SS
554static char *value_string(char *buf, int buf_size, double val, const char *unit)
555{
556 if (unit == unit_second_str && use_value_sexagesimal_format) {
557 double secs;
558 int hours, mins;
559 secs = val;
560 mins = (int)secs / 60;
561 secs = secs - mins * 60;
562 hours = mins / 60;
563 mins %= 60;
564 snprintf(buf, buf_size, "%d:%02d:%09.6f", hours, mins, secs);
565 } else if (use_value_prefix) {
566 const char *prefix_string;
567 int index;
568
569 if (unit == unit_byte_str && use_byte_value_binary_prefix) {
d752509b 570 index = (int) log2(val) / 10;
0184bbe2
GN
571 index = av_clip(index, 0, FF_ARRAY_ELEMS(binary_unit_prefixes) - 1);
572 val /= pow(2, index * 10);
336ce917
SS
573 prefix_string = binary_unit_prefixes[index];
574 } else {
575 index = (int) (log10(val)) / 3;
0184bbe2
GN
576 index = av_clip(index, 0, FF_ARRAY_ELEMS(decimal_unit_prefixes) - 1);
577 val /= pow(10, index * 3);
336ce917
SS
578 prefix_string = decimal_unit_prefixes[index];
579 }
beb33fca
LB
580 snprintf(buf, buf_size, "%.*f%s%s",
581 index ? 3 : 0, val,
582 prefix_string,
0184bbe2 583 show_value_unit ? unit : "");
336ce917 584 } else {
beb33fca 585 snprintf(buf, buf_size, "%f%s", val, show_value_unit ? unit : "");
336ce917
SS
586 }
587
588 return buf;
589}
590
0184bbe2
GN
591static char *time_value_string(char *buf, int buf_size, int64_t val,
592 const AVRational *time_base)
336ce917
SS
593{
594 if (val == AV_NOPTS_VALUE) {
595 snprintf(buf, buf_size, "N/A");
596 } else {
597 value_string(buf, buf_size, val * av_q2d(*time_base), unit_second_str);
598 }
599
600 return buf;
601}
602
3a8c95f7 603static char *ts_value_string(char *buf, int buf_size, int64_t ts)
530bbe96
SS
604{
605 if (ts == AV_NOPTS_VALUE) {
606 snprintf(buf, buf_size, "N/A");
607 } else {
608 snprintf(buf, buf_size, "%"PRId64, ts);
609 }
610
611 return buf;
612}
613
3a8c95f7
LB
614static char *rational_string(char *buf, int buf_size, const char *sep,
615 const AVRational *rat)
616{
617 snprintf(buf, buf_size, "%d%s%d", rat->num, sep, rat->den);
618 return buf;
619}
620
621static char *tag_string(char *buf, int buf_size, int tag)
622{
623 snprintf(buf, buf_size, "0x%04x", tag);
624 return buf;
625}
626
c55f2ae2
LB
627static char *unknown_string(char *buf, int buf_size, int val)
628{
629 snprintf(buf, buf_size, "Unknown (%d)", val);
630 return buf;
631}
632
530bbe96
SS
633static void show_packet(AVFormatContext *fmt_ctx, AVPacket *pkt)
634{
635 char val_str[128];
636 AVStream *st = fmt_ctx->streams[pkt->stream_index];
637
3a8c95f7 638 probe_object_header("packet");
ba357e98 639 probe_str("codec_type", media_type_string(st->codecpar->codec_type));
3a8c95f7
LB
640 probe_int("stream_index", pkt->stream_index);
641 probe_str("pts", ts_value_string(val_str, sizeof(val_str), pkt->pts));
642 probe_str("pts_time", time_value_string(val_str, sizeof(val_str),
643 pkt->pts, &st->time_base));
644 probe_str("dts", ts_value_string(val_str, sizeof(val_str), pkt->dts));
645 probe_str("dts_time", time_value_string(val_str, sizeof(val_str),
646 pkt->dts, &st->time_base));
647 probe_str("duration", ts_value_string(val_str, sizeof(val_str),
648 pkt->duration));
649 probe_str("duration_time", time_value_string(val_str, sizeof(val_str),
650 pkt->duration,
651 &st->time_base));
652 probe_str("size", value_string(val_str, sizeof(val_str),
653 pkt->size, unit_byte_str));
654 probe_int("pos", pkt->pos);
655 probe_str("flags", pkt->flags & AV_PKT_FLAG_KEY ? "K" : "_");
656 probe_object_footer("packet");
530bbe96
SS
657}
658
c9478410 659static void show_packets(InputFile *ifile)
530bbe96 660{
c9478410 661 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
530bbe96
SS
662 AVPacket pkt;
663
664 av_init_packet(&pkt);
3080b049 665 probe_array_header("packets", 0);
f0ca6ffa 666 while (!av_read_frame(fmt_ctx, &pkt)) {
530bbe96 667 show_packet(fmt_ctx, &pkt);
f0ca6ffa
LB
668 av_packet_unref(&pkt);
669 }
3080b049 670 probe_array_footer("packets", 0);
530bbe96
SS
671}
672
ba357e98 673static void show_stream(InputFile *ifile, InputStream *ist)
336ce917 674{
c9478410 675 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
ba357e98
AK
676 AVStream *stream = ist->st;
677 AVCodecParameters *par;
336ce917 678 AVCodecContext *dec_ctx;
168a443d 679 const AVCodecDescriptor *codec_desc;
b1d22dc5 680 const char *profile;
336ce917 681 char val_str[128];
dda20a6e 682 AVRational display_aspect_ratio, *sar = NULL;
b7f1010c 683 const AVPixFmtDescriptor *desc;
c55f2ae2 684 const char *val;
336ce917 685
3a8c95f7 686 probe_object_header("stream");
336ce917 687
3a8c95f7 688 probe_int("index", stream->index);
336ce917 689
ba357e98
AK
690 par = stream->codecpar;
691 dec_ctx = ist->dec_ctx;
692 codec_desc = avcodec_descriptor_get(par->codec_id);
168a443d
AK
693 if (codec_desc) {
694 probe_str("codec_name", codec_desc->name);
695 probe_str("codec_long_name", codec_desc->long_name);
e7188a1a
AK
696 } else {
697 probe_str("codec_name", "unknown");
698 }
336ce917 699
ba357e98 700 probe_str("codec_type", media_type_string(par->codec_type));
e7188a1a
AK
701
702 /* print AVI/FourCC tag */
ba357e98 703 av_get_codec_tag_string(val_str, sizeof(val_str), par->codec_tag);
e7188a1a
AK
704 probe_str("codec_tag_string", val_str);
705 probe_str("codec_tag", tag_string(val_str, sizeof(val_str),
ba357e98 706 par->codec_tag));
e7188a1a
AK
707
708 /* print profile, if there is one */
ba357e98 709 profile = avcodec_profile_name(par->codec_id, par->profile);
168a443d 710 if (profile)
e7188a1a
AK
711 probe_str("profile", profile);
712
ba357e98 713 switch (par->codec_type) {
e7188a1a 714 case AVMEDIA_TYPE_VIDEO:
ba357e98
AK
715 probe_int("width", par->width);
716 probe_int("height", par->height);
717 if (dec_ctx) {
718 probe_int("coded_width", dec_ctx->coded_width);
719 probe_int("coded_height", dec_ctx->coded_height);
720 probe_int("has_b_frames", dec_ctx->has_b_frames);
721 }
722 if (dec_ctx && dec_ctx->sample_aspect_ratio.num)
e7188a1a 723 sar = &dec_ctx->sample_aspect_ratio;
ba357e98
AK
724 else if (par->sample_aspect_ratio.num)
725 sar = &par->sample_aspect_ratio;
e7188a1a
AK
726 else if (stream->sample_aspect_ratio.num)
727 sar = &stream->sample_aspect_ratio;
728
729 if (sar) {
730 probe_str("sample_aspect_ratio",
731 rational_string(val_str, sizeof(val_str), ":", sar));
732 av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
ba357e98 733 par->width * sar->num, par->height * sar->den,
e7188a1a
AK
734 1024*1024);
735 probe_str("display_aspect_ratio",
736 rational_string(val_str, sizeof(val_str), ":",
737 &display_aspect_ratio));
336ce917 738 }
ba357e98 739 desc = av_pix_fmt_desc_get(par->format);
e7188a1a 740 probe_str("pix_fmt", desc ? desc->name : "unknown");
ba357e98 741 probe_int("level", par->level);
e7188a1a 742
c55f2ae2
LB
743 val = av_color_range_name(par->color_range);
744 if (!val)
745 val = unknown_string(val_str, sizeof(val_str), par->color_range);
746 probe_str("color_range", val);
747
748 val = av_color_space_name(par->color_space);
749 if (!val)
750 val = unknown_string(val_str, sizeof(val_str), par->color_space);
751 probe_str("color_space", val);
752
753 val = av_color_transfer_name(par->color_trc);
754 if (!val)
755 val = unknown_string(val_str, sizeof(val_str), par->color_trc);
756 probe_str("color_trc", val);
757
758 val = av_color_primaries_name(par->color_primaries);
759 if (!val)
760 val = unknown_string(val_str, sizeof(val_str), par->color_primaries);
761 probe_str("color_pri", val);
762
763 val = av_chroma_location_name(par->chroma_location);
764 if (!val)
765 val = unknown_string(val_str, sizeof(val_str), par->chroma_location);
766 probe_str("chroma_loc", val);
e7188a1a
AK
767 break;
768
769 case AVMEDIA_TYPE_AUDIO:
770 probe_str("sample_rate",
771 value_string(val_str, sizeof(val_str),
ba357e98 772 par->sample_rate,
e7188a1a 773 unit_hertz_str));
ba357e98 774 probe_int("channels", par->channels);
e7188a1a 775 probe_int("bits_per_sample",
ba357e98 776 av_get_bits_per_sample(par->codec_id));
e7188a1a 777 break;
336ce917
SS
778 }
779
780 if (fmt_ctx->iformat->flags & AVFMT_SHOW_IDS)
3a8c95f7 781 probe_int("id", stream->id);
3a8c95f7
LB
782 probe_str("avg_frame_rate",
783 rational_string(val_str, sizeof(val_str), "/",
784 &stream->avg_frame_rate));
ba357e98
AK
785
786 if (par->bit_rate)
89a4465b
JG
787 probe_str("bit_rate",
788 value_string(val_str, sizeof(val_str),
ba357e98 789 par->bit_rate, unit_bit_per_second_str));
3a8c95f7
LB
790 probe_str("time_base",
791 rational_string(val_str, sizeof(val_str), "/",
792 &stream->time_base));
793 probe_str("start_time",
794 time_value_string(val_str, sizeof(val_str),
795 stream->start_time, &stream->time_base));
796 probe_str("duration",
797 time_value_string(val_str, sizeof(val_str),
798 stream->duration, &stream->time_base));
0a6a282a 799 if (stream->nb_frames)
3a8c95f7 800 probe_int("nb_frames", stream->nb_frames);
336ce917 801
3a8c95f7 802 probe_dict(stream->metadata, "tags");
336ce917 803
709e1c91
MS
804 if (stream->nb_side_data) {
805 int i, j;
8e757716 806
709e1c91
MS
807 probe_object_header("sidedata");
808 for (i = 0; i < stream->nb_side_data; i++) {
809 const AVPacketSideData* sd = &stream->side_data[i];
8e757716 810 AVStereo3D *stereo;
2fb6acd9 811 AVSphericalMapping *spherical;
8e757716 812
709e1c91
MS
813 switch (sd->type) {
814 case AV_PKT_DATA_DISPLAYMATRIX:
815 probe_object_header("displaymatrix");
816 probe_array_header("matrix", 1);
817 for (j = 0; j < 9; j++)
818 probe_int(NULL, ((int32_t *)sd->data)[j]);
819 probe_array_footer("matrix", 1);
c31f6b1d
VG
820 probe_array_header("matrix_str", 1);
821 for (j = 0; j < 9; j++) {
822 char buf[32];
823 int fp = (j == 2 || j == 5 || j == 8) ? 30 : 16;
824 int32_t val = ((int32_t *)sd->data)[j];
825 value_string(buf, sizeof(buf), CONV_FP(val, fp), "");
826 probe_str(NULL, buf);
827 }
828 probe_array_footer("matrix_str", 1);
709e1c91
MS
829 probe_int("rotation",
830 av_display_rotation_get((int32_t *)sd->data));
831 probe_object_footer("displaymatrix");
832 break;
8e757716
VG
833 case AV_PKT_DATA_STEREO3D:
834 stereo = (AVStereo3D *)sd->data;
835 probe_object_header("stereo3d");
836 probe_str("type", av_stereo3d_type_name(stereo->type));
837 probe_int("inverted",
838 !!(stereo->flags & AV_STEREO3D_FLAG_INVERT));
839 probe_object_footer("stereo3d");
840 break;
2fb6acd9
VG
841 case AV_PKT_DATA_SPHERICAL:
842 spherical = (AVSphericalMapping *)sd->data;
843 probe_object_header("spherical");
c7bf98d4 844 probe_str("projection", av_spherical_projection_name(spherical->projection));
2fb6acd9 845
c7bf98d4 846 if (spherical->projection == AV_SPHERICAL_CUBEMAP) {
6bce6aa1
VG
847 probe_int("padding", spherical->padding);
848 } else if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR_TILE) {
849 size_t l, t, r, b;
850 av_spherical_tile_bounds(spherical, par->width, par->height,
851 &l, &t, &r, &b);
6bce6aa1
VG
852 probe_object_header("bounding");
853 probe_int("left", l);
854 probe_int("top", t);
855 probe_int("right", r);
856 probe_int("bottom", b);
857 probe_object_footer("bounding");
c7bf98d4 858 }
2fb6acd9
VG
859
860 probe_object_header("orientation");
861 probe_int("yaw", (double) spherical->yaw / (1 << 16));
862 probe_int("pitch", (double) spherical->pitch / (1 << 16));
863 probe_int("roll", (double) spherical->roll / (1 << 16));
864 probe_object_footer("orientation");
865
866 probe_object_footer("spherical");
867 break;
709e1c91
MS
868 }
869 }
870 probe_object_footer("sidedata");
871 }
872
3a8c95f7 873 probe_object_footer("stream");
08354bf4
RB
874}
875
c9478410 876static void show_format(InputFile *ifile)
336ce917 877{
c9478410 878 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
336ce917 879 char val_str[128];
136ee32d 880 int64_t size = fmt_ctx->pb ? avio_size(fmt_ctx->pb) : -1;
336ce917 881
3a8c95f7
LB
882 probe_object_header("format");
883 probe_str("filename", fmt_ctx->filename);
884 probe_int("nb_streams", fmt_ctx->nb_streams);
885 probe_str("format_name", fmt_ctx->iformat->name);
886 probe_str("format_long_name", fmt_ctx->iformat->long_name);
887 probe_str("start_time",
08354bf4
RB
888 time_value_string(val_str, sizeof(val_str),
889 fmt_ctx->start_time, &AV_TIME_BASE_Q));
3a8c95f7 890 probe_str("duration",
08354bf4
RB
891 time_value_string(val_str, sizeof(val_str),
892 fmt_ctx->duration, &AV_TIME_BASE_Q));
3a8c95f7 893 probe_str("size",
08354bf4
RB
894 size >= 0 ? value_string(val_str, sizeof(val_str),
895 size, unit_byte_str)
0184bbe2 896 : "unknown");
3a8c95f7 897 probe_str("bit_rate",
08354bf4
RB
898 value_string(val_str, sizeof(val_str),
899 fmt_ctx->bit_rate, unit_bit_per_second_str));
0184bbe2 900
3a8c95f7 901 probe_dict(fmt_ctx->metadata, "tags");
336ce917 902
3a8c95f7 903 probe_object_footer("format");
336ce917
SS
904}
905
c9478410 906static int open_input_file(InputFile *ifile, const char *filename)
336ce917
SS
907{
908 int err, i;
e0518705
AK
909 AVFormatContext *fmt_ctx = NULL;
910 AVDictionaryEntry *t;
336ce917 911
0184bbe2
GN
912 if ((err = avformat_open_input(&fmt_ctx, filename,
913 iformat, &format_opts)) < 0) {
336ce917
SS
914 print_error(filename, err);
915 return err;
916 }
e0518705
AK
917 if ((t = av_dict_get(format_opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
918 av_log(NULL, AV_LOG_ERROR, "Option %s not found.\n", t->key);
919 return AVERROR_OPTION_NOT_FOUND;
920 }
921
336ce917
SS
922
923 /* fill the streams in the format context */
c960e67a 924 if ((err = avformat_find_stream_info(fmt_ctx, NULL)) < 0) {
336ce917
SS
925 print_error(filename, err);
926 return err;
927 }
928
610219a5 929 av_dump_format(fmt_ctx, 0, filename, 0);
336ce917 930
567d6d5f
AK
931 ifile->streams = av_mallocz_array(fmt_ctx->nb_streams,
932 sizeof(*ifile->streams));
933 if (!ifile->streams)
934 exit(1);
935 ifile->nb_streams = fmt_ctx->nb_streams;
936
336ce917
SS
937 /* bind a decoder to each input stream */
938 for (i = 0; i < fmt_ctx->nb_streams; i++) {
567d6d5f 939 InputStream *ist = &ifile->streams[i];
336ce917
SS
940 AVStream *stream = fmt_ctx->streams[i];
941 AVCodec *codec;
942
567d6d5f
AK
943 ist->st = stream;
944
ba357e98 945 if (stream->codecpar->codec_id == AV_CODEC_ID_PROBE) {
503f2feb
AC
946 fprintf(stderr, "Failed to probe codec for input stream %d\n",
947 stream->index);
ba357e98
AK
948 continue;
949 }
950
951 codec = avcodec_find_decoder(stream->codecpar->codec_id);
952 if (!codec) {
0184bbe2
GN
953 fprintf(stderr,
954 "Unsupported codec with id %d for input stream %d\n",
ba357e98
AK
955 stream->codecpar->codec_id, stream->index);
956 continue;
957 }
958
959 ist->dec_ctx = avcodec_alloc_context3(codec);
960 if (!ist->dec_ctx)
961 exit(1);
962
963 err = avcodec_parameters_to_context(ist->dec_ctx, stream->codecpar);
964 if (err < 0)
965 exit(1);
966
967 err = avcodec_open2(ist->dec_ctx, NULL, NULL);
968 if (err < 0) {
336ce917
SS
969 fprintf(stderr, "Error while opening codec for input stream %d\n",
970 stream->index);
ba357e98
AK
971 exit(1);
972
336ce917
SS
973 }
974 }
975
c9478410 976 ifile->fmt_ctx = fmt_ctx;
336ce917
SS
977 return 0;
978}
979
c9478410 980static void close_input_file(InputFile *ifile)
093c50a4
JG
981{
982 int i;
093c50a4
JG
983
984 /* close decoder for each stream */
ba357e98
AK
985 for (i = 0; i < ifile->nb_streams; i++) {
986 InputStream *ist = &ifile->streams[i];
093c50a4 987
ba357e98 988 avcodec_free_context(&ist->dec_ctx);
093c50a4 989 }
567d6d5f
AK
990
991 av_freep(&ifile->streams);
992 ifile->nb_streams = 0;
993
c9478410 994 avformat_close_input(&ifile->fmt_ctx);
093c50a4
JG
995}
996
336ce917
SS
997static int probe_file(const char *filename)
998{
c9478410 999 InputFile ifile;
336ce917
SS
1000 int ret, i;
1001
c9478410
AK
1002 ret = open_input_file(&ifile, filename);
1003 if (ret < 0)
336ce917
SS
1004 return ret;
1005
3a8c95f7 1006 if (do_show_format)
c9478410 1007 show_format(&ifile);
530bbe96 1008
3a8c95f7 1009 if (do_show_streams) {
3080b049 1010 probe_array_header("streams", 0);
ba357e98
AK
1011 for (i = 0; i < ifile.nb_streams; i++)
1012 show_stream(&ifile, &ifile.streams[i]);
3080b049 1013 probe_array_footer("streams", 0);
3a8c95f7 1014 }
336ce917 1015
3a8c95f7 1016 if (do_show_packets)
c9478410 1017 show_packets(&ifile);
336ce917 1018
c9478410 1019 close_input_file(&ifile);
336ce917
SS
1020 return 0;
1021}
1022
1023static void show_usage(void)
1024{
1025 printf("Simple multimedia streams analyzer\n");
9e12f0bf 1026 printf("usage: %s [OPTIONS] [INPUT_FILE]\n", program_name);
336ce917
SS
1027 printf("\n");
1028}
1029
11d957fb 1030static int opt_format(void *optctx, const char *opt, const char *arg)
1be784a2
SS
1031{
1032 iformat = av_find_input_format(arg);
1033 if (!iformat) {
1034 fprintf(stderr, "Unknown input format: %s\n", arg);
26513856 1035 return AVERROR(EINVAL);
1be784a2 1036 }
26513856 1037 return 0;
1be784a2
SS
1038}
1039
11d957fb 1040static int opt_output_format(void *optctx, const char *opt, const char *arg)
0d242a77
LB
1041{
1042
1043 if (!strcmp(arg, "json")) {
52899558
LB
1044 octx.print_header = json_print_header;
1045 octx.print_footer = json_print_footer;
1046 octx.print_array_header = json_print_array_header;
1047 octx.print_array_footer = json_print_array_footer;
1048 octx.print_object_header = json_print_object_header;
1049 octx.print_object_footer = json_print_object_footer;
1050
1051 octx.print_integer = json_print_integer;
1052 octx.print_string = json_print_string;
d30acfa9 1053 } else if (!strcmp(arg, "ini")) {
52899558
LB
1054 octx.print_header = ini_print_header;
1055 octx.print_footer = ini_print_footer;
1056 octx.print_array_header = ini_print_array_header;
3080b049 1057 octx.print_array_footer = ini_print_array_footer;
52899558 1058 octx.print_object_header = ini_print_object_header;
0d242a77 1059
52899558
LB
1060 octx.print_integer = ini_print_integer;
1061 octx.print_string = ini_print_string;
8271f55b 1062 } else if (!strcmp(arg, "old")) {
52899558
LB
1063 octx.print_header = NULL;
1064 octx.print_object_header = old_print_object_header;
1065 octx.print_object_footer = old_print_object_footer;
8271f55b 1066
52899558 1067 octx.print_string = old_print_string;
0d242a77
LB
1068 } else {
1069 av_log(NULL, AV_LOG_ERROR, "Unsupported formatter %s\n", arg);
70026be8 1070 return AVERROR(EINVAL);
0d242a77 1071 }
70026be8 1072 return 0;
0d242a77
LB
1073}
1074
11d957fb 1075static int opt_show_format_entry(void *optctx, const char *opt, const char *arg)
08354bf4
RB
1076{
1077 do_show_format = 1;
d8947523 1078 nb_fmt_entries_to_show++;
52899558
LB
1079 octx.print_header = NULL;
1080 octx.print_footer = NULL;
1081 octx.print_array_header = NULL;
1082 octx.print_array_footer = NULL;
1083 octx.print_object_header = NULL;
1084 octx.print_object_footer = NULL;
1085
1086 octx.print_integer = show_format_entry_integer;
1087 octx.print_string = show_format_entry_string;
08354bf4
RB
1088 av_dict_set(&fmt_entries_to_show, arg, "", 0);
1089 return 0;
1090}
1091
7d308bf8
VG
1092static int opt_show_stream_entry(void *optctx, const char *opt, const char *arg)
1093{
68f8db61
VG
1094 const char *p = arg;
1095
7d308bf8
VG
1096 do_show_streams = 1;
1097 nb_stream_entries_to_show++;
1098 octx.print_header = NULL;
1099 octx.print_footer = NULL;
1100 octx.print_array_header = show_stream_entry_header;
1101 octx.print_array_footer = show_stream_entry_footer;
1102 octx.print_object_header = NULL;
1103 octx.print_object_footer = NULL;
1104
1105 octx.print_integer = show_stream_entry_integer;
1106 octx.print_string = show_stream_entry_string;
68f8db61
VG
1107
1108 while (*p) {
1109 char *val = av_get_token(&p, ",");
1110 if (!val)
1111 return AVERROR(ENOMEM);
1112
1113 av_dict_set(&stream_entries_to_show, val, "", 0);
1114
1115 av_free(val);
1116 if (*p)
1117 p++;
1118 }
1119
7d308bf8
VG
1120 return 0;
1121}
1122
7cc8d638 1123static void opt_input_file(void *optctx, const char *arg)
336ce917 1124{
c8c0ac6b 1125 if (input_filename) {
0184bbe2
GN
1126 fprintf(stderr,
1127 "Argument '%s' provided as input filename, but '%s' was already specified.\n",
58621b8d 1128 arg, input_filename);
636ced8e 1129 exit_program(1);
c8c0ac6b 1130 }
912dd63e
SS
1131 if (!strcmp(arg, "-"))
1132 arg = "pipe:";
1133 input_filename = arg;
336ce917
SS
1134}
1135
a3ad68d3 1136void show_help_default(const char *opt, const char *arg)
336ce917 1137{
6afd569e 1138 av_log_set_callback(log_callback_help);
336ce917 1139 show_usage();
f9fada27 1140 show_help_options(options, "Main options:", 0, 0, 0);
336ce917 1141 printf("\n");
7a6cd995 1142 show_help_children(avformat_get_class(), AV_OPT_FLAG_DECODING_PARAM);
336ce917
SS
1143}
1144
11d957fb 1145static int opt_pretty(void *optctx, const char *opt, const char *arg)
336ce917
SS
1146{
1147 show_value_unit = 1;
1148 use_value_prefix = 1;
1149 use_byte_value_binary_prefix = 1;
1150 use_value_sexagesimal_format = 1;
b42be2d5 1151 return 0;
336ce917
SS
1152}
1153
dcb7ef54 1154static const OptionDef real_options[] = {
122de16d 1155 CMDUTILS_COMMON_OPTIONS
b42be2d5
MS
1156 { "f", HAS_ARG, {.func_arg = opt_format}, "force format", "format" },
1157 { "of", HAS_ARG, {.func_arg = opt_output_format}, "output the document either as ini or json", "output_format" },
1158 { "unit", OPT_BOOL, {&show_value_unit},
0184bbe2 1159 "show unit of the displayed values" },
b42be2d5 1160 { "prefix", OPT_BOOL, {&use_value_prefix},
0184bbe2 1161 "use SI prefixes for the displayed values" },
b42be2d5 1162 { "byte_binary_prefix", OPT_BOOL, {&use_byte_value_binary_prefix},
336ce917 1163 "use binary prefixes for byte units" },
b42be2d5 1164 { "sexagesimal", OPT_BOOL, {&use_value_sexagesimal_format},
336ce917 1165 "use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units" },
b42be2d5 1166 { "pretty", 0, {.func_arg = opt_pretty},
336ce917 1167 "prettify the format of displayed values, make it more human readable" },
b42be2d5
MS
1168 { "show_format", OPT_BOOL, {&do_show_format} , "show format/container info" },
1169 { "show_format_entry", HAS_ARG, {.func_arg = opt_show_format_entry},
08354bf4 1170 "show a particular entry from the format/container info", "entry" },
b42be2d5
MS
1171 { "show_packets", OPT_BOOL, {&do_show_packets}, "show packets info" },
1172 { "show_streams", OPT_BOOL, {&do_show_streams}, "show streams info" },
7d308bf8 1173 { "show_stream_entry", HAS_ARG, {.func_arg = opt_show_stream_entry},
68f8db61 1174 "show a particular entry from all streams (comma separated)", "entry" },
b42be2d5 1175 { "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {.func_arg = opt_default},
0184bbe2 1176 "generic catch all option", "" },
336ce917
SS
1177 { NULL, },
1178};
1179
3a8c95f7
LB
1180static int probe_buf_write(void *opaque, uint8_t *buf, int buf_size)
1181{
1182 printf("%.*s", buf_size, buf);
1183 return 0;
1184}
1185
1186#define AVP_BUFFSIZE 4096
1187
336ce917
SS
1188int main(int argc, char **argv)
1189{
6afd569e 1190 int ret;
6135c3b6 1191 uint8_t *buffer = av_malloc(AVP_BUFFSIZE);
3a8c95f7
LB
1192
1193 if (!buffer)
1194 exit(1);
6afd569e 1195
636ced8e 1196 register_exit(avprobe_cleanup);
5e3f9979 1197
dcb7ef54 1198 options = real_options;
182cbe43 1199 parse_loglevel(argc, argv, options);
336ce917 1200 av_register_all();
776f2bb9 1201 avformat_network_init();
c558122e 1202 init_opts();
6ce98ea4
SS
1203#if CONFIG_AVDEVICE
1204 avdevice_register_all();
1205#endif
336ce917
SS
1206
1207 show_banner();
43b50e62
LB
1208
1209 octx.print_header = ini_print_header;
1210 octx.print_footer = ini_print_footer;
1211
1212 octx.print_array_header = ini_print_array_header;
3080b049 1213 octx.print_array_footer = ini_print_array_footer;
43b50e62
LB
1214 octx.print_object_header = ini_print_object_header;
1215
1216 octx.print_integer = ini_print_integer;
1217 octx.print_string = ini_print_string;
1218
7cc8d638 1219 parse_options(NULL, argc, argv, options, opt_input_file);
336ce917
SS
1220
1221 if (!input_filename) {
1222 show_usage();
1223 fprintf(stderr, "You have to specify one input file.\n");
0184bbe2
GN
1224 fprintf(stderr,
1225 "Use -h to get full help or, even better, run 'man %s'.\n",
1226 program_name);
636ced8e 1227 exit_program(1);
336ce917
SS
1228 }
1229
3a8c95f7
LB
1230 probe_out = avio_alloc_context(buffer, AVP_BUFFSIZE, 1, NULL, NULL,
1231 probe_buf_write, NULL);
1232 if (!probe_out)
636ced8e 1233 exit_program(1);
6afd569e 1234
3a8c95f7
LB
1235 probe_header();
1236 ret = probe_file(input_filename);
1237 probe_footer();
1238 avio_flush(probe_out);
6f554521 1239 avio_context_free(&probe_out);
5efd9128 1240 av_freep(&buffer);
95f80293 1241 uninit_opts();
776f2bb9
MS
1242 avformat_network_deinit();
1243
6afd569e 1244 return ret;
336ce917 1245}