You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

648 lines
22KB

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