]> git.sesse.net Git - ffmpeg/blob - libavformat/dump.c
9f54bc3e8d52e728d41ee804fd63912cc0c8b08c
[ffmpeg] / libavformat / dump.c
1 /*
2  * Various pretty-printing functions for use within FFmpeg
3  * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
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  *
12  * FFmpeg is distributed in the hope that it will be useful,
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
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21
22 #include <stdio.h>
23 #include <stdint.h>
24
25 #include "libavutil/channel_layout.h"
26 #include "libavutil/display.h"
27 #include "libavutil/intreadwrite.h"
28 #include "libavutil/log.h"
29 #include "libavutil/mastering_display_metadata.h"
30 #include "libavutil/dovi_meta.h"
31 #include "libavutil/mathematics.h"
32 #include "libavutil/opt.h"
33 #include "libavutil/avstring.h"
34 #include "libavutil/replaygain.h"
35 #include "libavutil/spherical.h"
36 #include "libavutil/stereo3d.h"
37 #include "libavutil/timecode.h"
38
39 #include "avformat.h"
40 #include "internal.h"
41
42 #define HEXDUMP_PRINT(...)                                                    \
43     do {                                                                      \
44         if (!f)                                                               \
45             av_log(avcl, level, __VA_ARGS__);                                 \
46         else                                                                  \
47             fprintf(f, __VA_ARGS__);                                          \
48     } while (0)
49
50 static void hex_dump_internal(void *avcl, FILE *f, int level,
51                               const uint8_t *buf, int size)
52 {
53     int len, i, j, c;
54
55     for (i = 0; i < size; i += 16) {
56         len = size - i;
57         if (len > 16)
58             len = 16;
59         HEXDUMP_PRINT("%08x ", i);
60         for (j = 0; j < 16; j++) {
61             if (j < len)
62                 HEXDUMP_PRINT(" %02x", buf[i + j]);
63             else
64                 HEXDUMP_PRINT("   ");
65         }
66         HEXDUMP_PRINT(" ");
67         for (j = 0; j < len; j++) {
68             c = buf[i + j];
69             if (c < ' ' || c > '~')
70                 c = '.';
71             HEXDUMP_PRINT("%c", c);
72         }
73         HEXDUMP_PRINT("\n");
74     }
75 }
76
77 void av_hex_dump(FILE *f, const uint8_t *buf, int size)
78 {
79     hex_dump_internal(NULL, f, 0, buf, size);
80 }
81
82 void av_hex_dump_log(void *avcl, int level, const uint8_t *buf, int size)
83 {
84     hex_dump_internal(avcl, NULL, level, buf, size);
85 }
86
87 static void pkt_dump_internal(void *avcl, FILE *f, int level, const AVPacket *pkt,
88                               int dump_payload, AVRational time_base)
89 {
90     HEXDUMP_PRINT("stream #%d:\n", pkt->stream_index);
91     HEXDUMP_PRINT("  keyframe=%d\n", (pkt->flags & AV_PKT_FLAG_KEY) != 0);
92     HEXDUMP_PRINT("  duration=%0.3f\n", pkt->duration * av_q2d(time_base));
93     /* DTS is _always_ valid after av_read_frame() */
94     HEXDUMP_PRINT("  dts=");
95     if (pkt->dts == AV_NOPTS_VALUE)
96         HEXDUMP_PRINT("N/A");
97     else
98         HEXDUMP_PRINT("%0.3f", pkt->dts * av_q2d(time_base));
99     /* PTS may not be known if B-frames are present. */
100     HEXDUMP_PRINT("  pts=");
101     if (pkt->pts == AV_NOPTS_VALUE)
102         HEXDUMP_PRINT("N/A");
103     else
104         HEXDUMP_PRINT("%0.3f", pkt->pts * av_q2d(time_base));
105     HEXDUMP_PRINT("\n");
106     HEXDUMP_PRINT("  size=%d\n", pkt->size);
107     if (dump_payload)
108         hex_dump_internal(avcl, f, level, pkt->data, pkt->size);
109 }
110
111 void av_pkt_dump2(FILE *f, const AVPacket *pkt, int dump_payload, const AVStream *st)
112 {
113     pkt_dump_internal(NULL, f, 0, pkt, dump_payload, st->time_base);
114 }
115
116 void av_pkt_dump_log2(void *avcl, int level, const AVPacket *pkt, int dump_payload,
117                       const AVStream *st)
118 {
119     pkt_dump_internal(avcl, NULL, level, pkt, dump_payload, st->time_base);
120 }
121
122
123 static void print_fps(double d, const char *postfix)
124 {
125     uint64_t v = lrintf(d * 100);
126     if (!v)
127         av_log(NULL, AV_LOG_INFO, "%1.4f %s", d, postfix);
128     else if (v % 100)
129         av_log(NULL, AV_LOG_INFO, "%3.2f %s", d, postfix);
130     else if (v % (100 * 1000))
131         av_log(NULL, AV_LOG_INFO, "%1.0f %s", d, postfix);
132     else
133         av_log(NULL, AV_LOG_INFO, "%1.0fk %s", d / 1000, postfix);
134 }
135
136 static void dump_metadata(void *ctx, const AVDictionary *m, const char *indent)
137 {
138     if (m && !(av_dict_count(m) == 1 && av_dict_get(m, "language", NULL, 0))) {
139         const AVDictionaryEntry *tag = NULL;
140
141         av_log(ctx, AV_LOG_INFO, "%sMetadata:\n", indent);
142         while ((tag = av_dict_get(m, "", tag, AV_DICT_IGNORE_SUFFIX)))
143             if (strcmp("language", tag->key)) {
144                 const char *p = tag->value;
145                 av_log(ctx, AV_LOG_INFO,
146                        "%s  %-16s: ", indent, tag->key);
147                 while (*p) {
148                     char tmp[256];
149                     size_t len = strcspn(p, "\x8\xa\xb\xc\xd");
150                     av_strlcpy(tmp, p, FFMIN(sizeof(tmp), len+1));
151                     av_log(ctx, AV_LOG_INFO, "%s", tmp);
152                     p += len;
153                     if (*p == 0xd) av_log(ctx, AV_LOG_INFO, " ");
154                     if (*p == 0xa) av_log(ctx, AV_LOG_INFO, "\n%s  %-16s: ", indent, "");
155                     if (*p) p++;
156                 }
157                 av_log(ctx, AV_LOG_INFO, "\n");
158             }
159     }
160 }
161
162 /* param change side data*/
163 static void dump_paramchange(void *ctx, const AVPacketSideData *sd)
164 {
165     int size = sd->size;
166     const uint8_t *data = sd->data;
167     uint32_t flags, channels, sample_rate, width, height;
168     uint64_t layout;
169
170     if (!data || sd->size < 4)
171         goto fail;
172
173     flags = AV_RL32(data);
174     data += 4;
175     size -= 4;
176
177     if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT) {
178         if (size < 4)
179             goto fail;
180         channels = AV_RL32(data);
181         data += 4;
182         size -= 4;
183         av_log(ctx, AV_LOG_INFO, "channel count %"PRIu32", ", channels);
184     }
185     if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT) {
186         if (size < 8)
187             goto fail;
188         layout = AV_RL64(data);
189         data += 8;
190         size -= 8;
191         av_log(ctx, AV_LOG_INFO,
192                "channel layout: %s, ", av_get_channel_name(layout));
193     }
194     if (flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE) {
195         if (size < 4)
196             goto fail;
197         sample_rate = AV_RL32(data);
198         data += 4;
199         size -= 4;
200         av_log(ctx, AV_LOG_INFO, "sample_rate %"PRIu32", ", sample_rate);
201     }
202     if (flags & AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS) {
203         if (size < 8)
204             goto fail;
205         width = AV_RL32(data);
206         data += 4;
207         size -= 4;
208         height = AV_RL32(data);
209         data += 4;
210         size -= 4;
211         av_log(ctx, AV_LOG_INFO, "width %"PRIu32" height %"PRIu32, width, height);
212     }
213
214     return;
215 fail:
216     av_log(ctx, AV_LOG_ERROR, "unknown param\n");
217 }
218
219 /* replaygain side data*/
220 static void print_gain(void *ctx, const char *str, int32_t gain)
221 {
222     av_log(ctx, AV_LOG_INFO, "%s - ", str);
223     if (gain == INT32_MIN)
224         av_log(ctx, AV_LOG_INFO, "unknown");
225     else
226         av_log(ctx, AV_LOG_INFO, "%f", gain / 100000.0f);
227     av_log(ctx, AV_LOG_INFO, ", ");
228 }
229
230 static void print_peak(void *ctx, const char *str, uint32_t peak)
231 {
232     av_log(ctx, AV_LOG_INFO, "%s - ", str);
233     if (!peak)
234         av_log(ctx, AV_LOG_INFO, "unknown");
235     else
236         av_log(ctx, AV_LOG_INFO, "%f", (float) peak / UINT32_MAX);
237     av_log(ctx, AV_LOG_INFO, ", ");
238 }
239
240 static void dump_replaygain(void *ctx, const AVPacketSideData *sd)
241 {
242     const AVReplayGain *rg;
243
244     if (sd->size < sizeof(*rg)) {
245         av_log(ctx, AV_LOG_ERROR, "invalid data\n");
246         return;
247     }
248     rg = (const AVReplayGain *)sd->data;
249
250     print_gain(ctx, "track gain", rg->track_gain);
251     print_peak(ctx, "track peak", rg->track_peak);
252     print_gain(ctx, "album gain", rg->album_gain);
253     print_peak(ctx, "album peak", rg->album_peak);
254 }
255
256 static void dump_stereo3d(void *ctx, const AVPacketSideData *sd)
257 {
258     const AVStereo3D *stereo;
259
260     if (sd->size < sizeof(*stereo)) {
261         av_log(ctx, AV_LOG_ERROR, "invalid data\n");
262         return;
263     }
264
265     stereo = (const AVStereo3D *)sd->data;
266
267     av_log(ctx, AV_LOG_INFO, "%s", av_stereo3d_type_name(stereo->type));
268
269     if (stereo->flags & AV_STEREO3D_FLAG_INVERT)
270         av_log(ctx, AV_LOG_INFO, " (inverted)");
271 }
272
273 static void dump_audioservicetype(void *ctx, const AVPacketSideData *sd)
274 {
275     const enum AVAudioServiceType *ast = (const enum AVAudioServiceType *)sd->data;
276
277     if (sd->size < sizeof(*ast)) {
278         av_log(ctx, AV_LOG_ERROR, "invalid data\n");
279         return;
280     }
281
282     switch (*ast) {
283     case AV_AUDIO_SERVICE_TYPE_MAIN:
284         av_log(ctx, AV_LOG_INFO, "main");
285         break;
286     case AV_AUDIO_SERVICE_TYPE_EFFECTS:
287         av_log(ctx, AV_LOG_INFO, "effects");
288         break;
289     case AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED:
290         av_log(ctx, AV_LOG_INFO, "visually impaired");
291         break;
292     case AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED:
293         av_log(ctx, AV_LOG_INFO, "hearing impaired");
294         break;
295     case AV_AUDIO_SERVICE_TYPE_DIALOGUE:
296         av_log(ctx, AV_LOG_INFO, "dialogue");
297         break;
298     case AV_AUDIO_SERVICE_TYPE_COMMENTARY:
299         av_log(ctx, AV_LOG_INFO, "commentary");
300         break;
301     case AV_AUDIO_SERVICE_TYPE_EMERGENCY:
302         av_log(ctx, AV_LOG_INFO, "emergency");
303         break;
304     case AV_AUDIO_SERVICE_TYPE_VOICE_OVER:
305         av_log(ctx, AV_LOG_INFO, "voice over");
306         break;
307     case AV_AUDIO_SERVICE_TYPE_KARAOKE:
308         av_log(ctx, AV_LOG_INFO, "karaoke");
309         break;
310     default:
311         av_log(ctx, AV_LOG_WARNING, "unknown");
312         break;
313     }
314 }
315
316 static void dump_cpb(void *ctx, const AVPacketSideData *sd)
317 {
318     const AVCPBProperties *cpb = (const AVCPBProperties *)sd->data;
319
320     if (sd->size < sizeof(*cpb)) {
321         av_log(ctx, AV_LOG_ERROR, "invalid data\n");
322         return;
323     }
324
325     av_log(ctx, AV_LOG_INFO,
326            "bitrate max/min/avg: %"PRId64"/%"PRId64"/%"PRId64" buffer size: %"PRId64" ",
327            cpb->max_bitrate, cpb->min_bitrate, cpb->avg_bitrate,
328            cpb->buffer_size);
329     if (cpb->vbv_delay == UINT64_MAX)
330         av_log(ctx, AV_LOG_INFO, "vbv_delay: N/A");
331     else
332         av_log(ctx, AV_LOG_INFO, "vbv_delay: %"PRIu64"", cpb->vbv_delay);
333 }
334
335 static void dump_mastering_display_metadata(void *ctx, const AVPacketSideData *sd)
336 {
337     const AVMasteringDisplayMetadata *metadata =
338         (const AVMasteringDisplayMetadata *)sd->data;
339     av_log(ctx, AV_LOG_INFO, "Mastering Display Metadata, "
340            "has_primaries:%d has_luminance:%d "
341            "r(%5.4f,%5.4f) g(%5.4f,%5.4f) b(%5.4f %5.4f) wp(%5.4f, %5.4f) "
342            "min_luminance=%f, max_luminance=%f",
343            metadata->has_primaries, metadata->has_luminance,
344            av_q2d(metadata->display_primaries[0][0]),
345            av_q2d(metadata->display_primaries[0][1]),
346            av_q2d(metadata->display_primaries[1][0]),
347            av_q2d(metadata->display_primaries[1][1]),
348            av_q2d(metadata->display_primaries[2][0]),
349            av_q2d(metadata->display_primaries[2][1]),
350            av_q2d(metadata->white_point[0]), av_q2d(metadata->white_point[1]),
351            av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance));
352 }
353
354 static void dump_content_light_metadata(void *ctx, const AVPacketSideData *sd)
355 {
356     const AVContentLightMetadata *metadata =
357         (const AVContentLightMetadata *)sd->data;
358     av_log(ctx, AV_LOG_INFO, "Content Light Level Metadata, "
359            "MaxCLL=%d, MaxFALL=%d",
360            metadata->MaxCLL, metadata->MaxFALL);
361 }
362
363 static void dump_spherical(void *ctx, const AVCodecParameters *par,
364                            const AVPacketSideData *sd)
365 {
366     const AVSphericalMapping *spherical = (const AVSphericalMapping *)sd->data;
367     double yaw, pitch, roll;
368
369     if (sd->size < sizeof(*spherical)) {
370         av_log(ctx, AV_LOG_ERROR, "invalid data\n");
371         return;
372     }
373
374     av_log(ctx, AV_LOG_INFO, "%s ", av_spherical_projection_name(spherical->projection));
375
376     yaw = ((double)spherical->yaw) / (1 << 16);
377     pitch = ((double)spherical->pitch) / (1 << 16);
378     roll = ((double)spherical->roll) / (1 << 16);
379     av_log(ctx, AV_LOG_INFO, "(%f/%f/%f) ", yaw, pitch, roll);
380
381     if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR_TILE) {
382         size_t l, t, r, b;
383         av_spherical_tile_bounds(spherical, par->width, par->height,
384                                  &l, &t, &r, &b);
385         av_log(ctx, AV_LOG_INFO,
386                "[%"SIZE_SPECIFIER", %"SIZE_SPECIFIER", %"SIZE_SPECIFIER", %"SIZE_SPECIFIER"] ",
387                l, t, r, b);
388     } else if (spherical->projection == AV_SPHERICAL_CUBEMAP) {
389         av_log(ctx, AV_LOG_INFO, "[pad %"PRIu32"] ", spherical->padding);
390     }
391 }
392
393 static void dump_dovi_conf(void *ctx, const AVPacketSideData *sd)
394 {
395     const AVDOVIDecoderConfigurationRecord *dovi =
396         (const AVDOVIDecoderConfigurationRecord *)sd->data;
397
398     av_log(ctx, AV_LOG_INFO, "version: %d.%d, profile: %d, level: %d, "
399            "rpu flag: %d, el flag: %d, bl flag: %d, compatibility id: %d",
400            dovi->dv_version_major, dovi->dv_version_minor,
401            dovi->dv_profile, dovi->dv_level,
402            dovi->rpu_present_flag,
403            dovi->el_present_flag,
404            dovi->bl_present_flag,
405            dovi->dv_bl_signal_compatibility_id);
406 }
407
408 static void dump_s12m_timecode(void *ctx, const AVStream *st, const AVPacketSideData *sd)
409 {
410     const uint32_t *tc = (const uint32_t *)sd->data;
411
412     if ((sd->size != sizeof(uint32_t) * 4) || (tc[0] > 3)) {
413         av_log(ctx, AV_LOG_ERROR, "invalid data\n");
414         return;
415     }
416
417     for (int j = 1; j <= tc[0]; j++) {
418         char tcbuf[AV_TIMECODE_STR_SIZE];
419         av_timecode_make_smpte_tc_string2(tcbuf, st->avg_frame_rate, tc[j], 0, 0);
420         av_log(ctx, AV_LOG_INFO, "timecode - %s%s", tcbuf, j != tc[0] ? ", " : "");
421     }
422 }
423
424 static void dump_sidedata(void *ctx, const AVStream *st, const char *indent)
425 {
426     int i;
427
428     if (st->nb_side_data)
429         av_log(ctx, AV_LOG_INFO, "%sSide data:\n", indent);
430
431     for (i = 0; i < st->nb_side_data; i++) {
432         const AVPacketSideData *sd = &st->side_data[i];
433         av_log(ctx, AV_LOG_INFO, "%s  ", indent);
434
435         switch (sd->type) {
436         case AV_PKT_DATA_PALETTE:
437             av_log(ctx, AV_LOG_INFO, "palette");
438             break;
439         case AV_PKT_DATA_NEW_EXTRADATA:
440             av_log(ctx, AV_LOG_INFO, "new extradata");
441             break;
442         case AV_PKT_DATA_PARAM_CHANGE:
443             av_log(ctx, AV_LOG_INFO, "paramchange: ");
444             dump_paramchange(ctx, sd);
445             break;
446         case AV_PKT_DATA_H263_MB_INFO:
447             av_log(ctx, AV_LOG_INFO, "H.263 macroblock info");
448             break;
449         case AV_PKT_DATA_REPLAYGAIN:
450             av_log(ctx, AV_LOG_INFO, "replaygain: ");
451             dump_replaygain(ctx, sd);
452             break;
453         case AV_PKT_DATA_DISPLAYMATRIX:
454             av_log(ctx, AV_LOG_INFO, "displaymatrix: rotation of %.2f degrees",
455                    av_display_rotation_get((const int32_t *)sd->data));
456             break;
457         case AV_PKT_DATA_STEREO3D:
458             av_log(ctx, AV_LOG_INFO, "stereo3d: ");
459             dump_stereo3d(ctx, sd);
460             break;
461         case AV_PKT_DATA_AUDIO_SERVICE_TYPE:
462             av_log(ctx, AV_LOG_INFO, "audio service type: ");
463             dump_audioservicetype(ctx, sd);
464             break;
465         case AV_PKT_DATA_QUALITY_STATS:
466             av_log(ctx, AV_LOG_INFO, "quality factor: %"PRId32", pict_type: %c",
467                    AV_RL32(sd->data), av_get_picture_type_char(sd->data[4]));
468             break;
469         case AV_PKT_DATA_CPB_PROPERTIES:
470             av_log(ctx, AV_LOG_INFO, "cpb: ");
471             dump_cpb(ctx, sd);
472             break;
473         case AV_PKT_DATA_MASTERING_DISPLAY_METADATA:
474             dump_mastering_display_metadata(ctx, sd);
475             break;
476         case AV_PKT_DATA_SPHERICAL:
477             av_log(ctx, AV_LOG_INFO, "spherical: ");
478             dump_spherical(ctx, st->codecpar, sd);
479             break;
480         case AV_PKT_DATA_CONTENT_LIGHT_LEVEL:
481             dump_content_light_metadata(ctx, sd);
482             break;
483         case AV_PKT_DATA_ICC_PROFILE:
484             av_log(ctx, AV_LOG_INFO, "ICC Profile");
485             break;
486         case AV_PKT_DATA_DOVI_CONF:
487             av_log(ctx, AV_LOG_INFO, "DOVI configuration record: ");
488             dump_dovi_conf(ctx, sd);
489             break;
490         case AV_PKT_DATA_S12M_TIMECODE:
491             av_log(ctx, AV_LOG_INFO, "SMPTE ST 12-1:2014: ");
492             dump_s12m_timecode(ctx, st, sd);
493             break;
494         default:
495             av_log(ctx, AV_LOG_INFO, "unknown side data type %d "
496                    "(%"SIZE_SPECIFIER" bytes)", sd->type, sd->size);
497             break;
498         }
499
500         av_log(ctx, AV_LOG_INFO, "\n");
501     }
502 }
503
504 /* "user interface" functions */
505 static void dump_stream_format(const AVFormatContext *ic, int i,
506                                int index, int is_output)
507 {
508     char buf[256];
509     int flags = (is_output ? ic->oformat->flags : ic->iformat->flags);
510     const AVStream *st = ic->streams[i];
511     const AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL, 0);
512     const char *separator = ic->dump_separator;
513     AVCodecContext *avctx;
514     int ret;
515
516     avctx = avcodec_alloc_context3(NULL);
517     if (!avctx)
518         return;
519
520     ret = avcodec_parameters_to_context(avctx, st->codecpar);
521     if (ret < 0) {
522         avcodec_free_context(&avctx);
523         return;
524     }
525
526     // Fields which are missing from AVCodecParameters need to be taken from the AVCodecContext
527     avctx->properties   = st->internal->avctx->properties;
528     avctx->codec        = st->internal->avctx->codec;
529     avctx->qmin         = st->internal->avctx->qmin;
530     avctx->qmax         = st->internal->avctx->qmax;
531     avctx->coded_width  = st->internal->avctx->coded_width;
532     avctx->coded_height = st->internal->avctx->coded_height;
533
534     if (separator)
535         av_opt_set(avctx, "dump_separator", separator, 0);
536     avcodec_string(buf, sizeof(buf), avctx, is_output);
537     avcodec_free_context(&avctx);
538
539     av_log(NULL, AV_LOG_INFO, "  Stream #%d:%d", index, i);
540
541     /* the pid is an important information, so we display it */
542     /* XXX: add a generic system */
543     if (flags & AVFMT_SHOW_IDS)
544         av_log(NULL, AV_LOG_INFO, "[0x%x]", st->id);
545     if (lang)
546         av_log(NULL, AV_LOG_INFO, "(%s)", lang->value);
547     av_log(NULL, AV_LOG_DEBUG, ", %d, %d/%d", st->codec_info_nb_frames,
548            st->time_base.num, st->time_base.den);
549     av_log(NULL, AV_LOG_INFO, ": %s", buf);
550
551     if (st->sample_aspect_ratio.num &&
552         av_cmp_q(st->sample_aspect_ratio, st->codecpar->sample_aspect_ratio)) {
553         AVRational display_aspect_ratio;
554         av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
555                   st->codecpar->width  * (int64_t)st->sample_aspect_ratio.num,
556                   st->codecpar->height * (int64_t)st->sample_aspect_ratio.den,
557                   1024 * 1024);
558         av_log(NULL, AV_LOG_INFO, ", SAR %d:%d DAR %d:%d",
559                st->sample_aspect_ratio.num, st->sample_aspect_ratio.den,
560                display_aspect_ratio.num, display_aspect_ratio.den);
561     }
562
563     if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
564         int fps = st->avg_frame_rate.den && st->avg_frame_rate.num;
565         int tbr = st->r_frame_rate.den && st->r_frame_rate.num;
566         int tbn = st->time_base.den && st->time_base.num;
567         int tbc = 0;
568
569         if (fps || tbr || tbn || tbc)
570             av_log(NULL, AV_LOG_INFO, "%s", separator);
571
572         if (fps)
573             print_fps(av_q2d(st->avg_frame_rate), tbr || tbn || tbc ? "fps, " : "fps");
574         if (tbr)
575             print_fps(av_q2d(st->r_frame_rate), tbn || tbc ? "tbr, " : "tbr");
576         if (tbn)
577             print_fps(1 / av_q2d(st->time_base), tbc ? "tbn, " : "tbn");
578     }
579
580     if (st->disposition & AV_DISPOSITION_DEFAULT)
581         av_log(NULL, AV_LOG_INFO, " (default)");
582     if (st->disposition & AV_DISPOSITION_DUB)
583         av_log(NULL, AV_LOG_INFO, " (dub)");
584     if (st->disposition & AV_DISPOSITION_ORIGINAL)
585         av_log(NULL, AV_LOG_INFO, " (original)");
586     if (st->disposition & AV_DISPOSITION_COMMENT)
587         av_log(NULL, AV_LOG_INFO, " (comment)");
588     if (st->disposition & AV_DISPOSITION_LYRICS)
589         av_log(NULL, AV_LOG_INFO, " (lyrics)");
590     if (st->disposition & AV_DISPOSITION_KARAOKE)
591         av_log(NULL, AV_LOG_INFO, " (karaoke)");
592     if (st->disposition & AV_DISPOSITION_FORCED)
593         av_log(NULL, AV_LOG_INFO, " (forced)");
594     if (st->disposition & AV_DISPOSITION_HEARING_IMPAIRED)
595         av_log(NULL, AV_LOG_INFO, " (hearing impaired)");
596     if (st->disposition & AV_DISPOSITION_VISUAL_IMPAIRED)
597         av_log(NULL, AV_LOG_INFO, " (visual impaired)");
598     if (st->disposition & AV_DISPOSITION_CLEAN_EFFECTS)
599         av_log(NULL, AV_LOG_INFO, " (clean effects)");
600     if (st->disposition & AV_DISPOSITION_ATTACHED_PIC)
601         av_log(NULL, AV_LOG_INFO, " (attached pic)");
602     if (st->disposition & AV_DISPOSITION_TIMED_THUMBNAILS)
603         av_log(NULL, AV_LOG_INFO, " (timed thumbnails)");
604     if (st->disposition & AV_DISPOSITION_CAPTIONS)
605         av_log(NULL, AV_LOG_INFO, " (captions)");
606     if (st->disposition & AV_DISPOSITION_DESCRIPTIONS)
607         av_log(NULL, AV_LOG_INFO, " (descriptions)");
608     if (st->disposition & AV_DISPOSITION_METADATA)
609         av_log(NULL, AV_LOG_INFO, " (metadata)");
610     if (st->disposition & AV_DISPOSITION_DEPENDENT)
611         av_log(NULL, AV_LOG_INFO, " (dependent)");
612     if (st->disposition & AV_DISPOSITION_STILL_IMAGE)
613         av_log(NULL, AV_LOG_INFO, " (still image)");
614     av_log(NULL, AV_LOG_INFO, "\n");
615
616     dump_metadata(NULL, st->metadata, "    ");
617
618     dump_sidedata(NULL, st, "    ");
619 }
620
621 void av_dump_format(AVFormatContext *ic, int index,
622                     const char *url, int is_output)
623 {
624     int i;
625     uint8_t *printed = ic->nb_streams ? av_mallocz(ic->nb_streams) : NULL;
626     if (ic->nb_streams && !printed)
627         return;
628
629     av_log(NULL, AV_LOG_INFO, "%s #%d, %s, %s '%s':\n",
630            is_output ? "Output" : "Input",
631            index,
632            is_output ? ic->oformat->name : ic->iformat->name,
633            is_output ? "to" : "from", url);
634     dump_metadata(NULL, ic->metadata, "  ");
635
636     if (!is_output) {
637         av_log(NULL, AV_LOG_INFO, "  Duration: ");
638         if (ic->duration != AV_NOPTS_VALUE) {
639             int64_t hours, mins, secs, us;
640             int64_t duration = ic->duration + (ic->duration <= INT64_MAX - 5000 ? 5000 : 0);
641             secs  = duration / AV_TIME_BASE;
642             us    = duration % AV_TIME_BASE;
643             mins  = secs / 60;
644             secs %= 60;
645             hours = mins / 60;
646             mins %= 60;
647             av_log(NULL, AV_LOG_INFO, "%02"PRId64":%02"PRId64":%02"PRId64".%02"PRId64"", hours, mins, secs,
648                    (100 * us) / AV_TIME_BASE);
649         } else {
650             av_log(NULL, AV_LOG_INFO, "N/A");
651         }
652         if (ic->start_time != AV_NOPTS_VALUE) {
653             int secs, us;
654             av_log(NULL, AV_LOG_INFO, ", start: ");
655             secs = llabs(ic->start_time / AV_TIME_BASE);
656             us   = llabs(ic->start_time % AV_TIME_BASE);
657             av_log(NULL, AV_LOG_INFO, "%s%d.%06d",
658                    ic->start_time >= 0 ? "" : "-",
659                    secs,
660                    (int) av_rescale(us, 1000000, AV_TIME_BASE));
661         }
662         av_log(NULL, AV_LOG_INFO, ", bitrate: ");
663         if (ic->bit_rate)
664             av_log(NULL, AV_LOG_INFO, "%"PRId64" kb/s", ic->bit_rate / 1000);
665         else
666             av_log(NULL, AV_LOG_INFO, "N/A");
667         av_log(NULL, AV_LOG_INFO, "\n");
668     }
669
670     if (ic->nb_chapters)
671         av_log(NULL, AV_LOG_INFO, "  Chapters:\n");
672     for (i = 0; i < ic->nb_chapters; i++) {
673         const AVChapter *ch = ic->chapters[i];
674         av_log(NULL, AV_LOG_INFO, "    Chapter #%d:%d: ", index, i);
675         av_log(NULL, AV_LOG_INFO,
676                "start %f, ", ch->start * av_q2d(ch->time_base));
677         av_log(NULL, AV_LOG_INFO,
678                "end %f\n", ch->end * av_q2d(ch->time_base));
679
680         dump_metadata(NULL, ch->metadata, "      ");
681     }
682
683     if (ic->nb_programs) {
684         int j, k, total = 0;
685         for (j = 0; j < ic->nb_programs; j++) {
686             const AVProgram *program = ic->programs[j];
687             const AVDictionaryEntry *name = av_dict_get(program->metadata,
688                                                         "name", NULL, 0);
689             av_log(NULL, AV_LOG_INFO, "  Program %d %s\n", program->id,
690                    name ? name->value : "");
691             dump_metadata(NULL, program->metadata, "    ");
692             for (k = 0; k < program->nb_stream_indexes; k++) {
693                 dump_stream_format(ic, program->stream_index[k],
694                                    index, is_output);
695                 printed[program->stream_index[k]] = 1;
696             }
697             total += program->nb_stream_indexes;
698         }
699         if (total < ic->nb_streams)
700             av_log(NULL, AV_LOG_INFO, "  No Program\n");
701     }
702
703     for (i = 0; i < ic->nb_streams; i++)
704         if (!printed[i])
705             dump_stream_format(ic, i, index, is_output);
706
707     av_free(printed);
708 }