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