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