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.

629 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_spherical(void *ctx, AVCodecParameters *par, AVPacketSideData *sd)
  309. {
  310. AVSphericalMapping *spherical = (AVSphericalMapping *)sd->data;
  311. double yaw, pitch, roll;
  312. if (sd->size < sizeof(*spherical)) {
  313. av_log(ctx, AV_LOG_INFO, "invalid data");
  314. return;
  315. }
  316. av_log(ctx, AV_LOG_INFO, "%s ", av_spherical_projection_name(spherical->projection));
  317. yaw = ((double)spherical->yaw) / (1 << 16);
  318. pitch = ((double)spherical->pitch) / (1 << 16);
  319. roll = ((double)spherical->roll) / (1 << 16);
  320. av_log(ctx, AV_LOG_INFO, "(%f/%f/%f) ", yaw, pitch, roll);
  321. if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR_TILE) {
  322. size_t l, t, r, b;
  323. av_spherical_tile_bounds(spherical, par->width, par->height,
  324. &l, &t, &r, &b);
  325. av_log(ctx, AV_LOG_INFO, "[%zu, %zu, %zu, %zu] ", l, t, r, b);
  326. } else if (spherical->projection == AV_SPHERICAL_CUBEMAP) {
  327. av_log(ctx, AV_LOG_INFO, "[pad %"PRIu32"] ", spherical->padding);
  328. }
  329. }
  330. static void dump_sidedata(void *ctx, AVStream *st, const char *indent)
  331. {
  332. int i;
  333. if (st->nb_side_data)
  334. av_log(ctx, AV_LOG_INFO, "%sSide data:\n", indent);
  335. for (i = 0; i < st->nb_side_data; i++) {
  336. AVPacketSideData sd = st->side_data[i];
  337. av_log(ctx, AV_LOG_INFO, "%s ", indent);
  338. switch (sd.type) {
  339. case AV_PKT_DATA_PALETTE:
  340. av_log(ctx, AV_LOG_INFO, "palette");
  341. break;
  342. case AV_PKT_DATA_NEW_EXTRADATA:
  343. av_log(ctx, AV_LOG_INFO, "new extradata");
  344. break;
  345. case AV_PKT_DATA_PARAM_CHANGE:
  346. av_log(ctx, AV_LOG_INFO, "paramchange: ");
  347. dump_paramchange(ctx, &sd);
  348. break;
  349. case AV_PKT_DATA_H263_MB_INFO:
  350. av_log(ctx, AV_LOG_INFO, "H.263 macroblock info");
  351. break;
  352. case AV_PKT_DATA_REPLAYGAIN:
  353. av_log(ctx, AV_LOG_INFO, "replaygain: ");
  354. dump_replaygain(ctx, &sd);
  355. break;
  356. case AV_PKT_DATA_DISPLAYMATRIX:
  357. av_log(ctx, AV_LOG_INFO, "displaymatrix: rotation of %.2f degrees",
  358. av_display_rotation_get((int32_t *)sd.data));
  359. break;
  360. case AV_PKT_DATA_STEREO3D:
  361. av_log(ctx, AV_LOG_INFO, "stereo3d: ");
  362. dump_stereo3d(ctx, &sd);
  363. break;
  364. case AV_PKT_DATA_AUDIO_SERVICE_TYPE:
  365. av_log(ctx, AV_LOG_INFO, "audio service type: ");
  366. dump_audioservicetype(ctx, &sd);
  367. break;
  368. case AV_PKT_DATA_QUALITY_STATS:
  369. av_log(ctx, AV_LOG_INFO, "quality factor: %"PRId32", pict_type: %c",
  370. AV_RL32(sd.data), av_get_picture_type_char(sd.data[4]));
  371. break;
  372. case AV_PKT_DATA_CPB_PROPERTIES:
  373. av_log(ctx, AV_LOG_INFO, "cpb: ");
  374. dump_cpb(ctx, &sd);
  375. break;
  376. case AV_PKT_DATA_MASTERING_DISPLAY_METADATA:
  377. dump_mastering_display_metadata(ctx, &sd);
  378. break;
  379. case AV_PKT_DATA_SPHERICAL:
  380. av_log(ctx, AV_LOG_INFO, "spherical: ");
  381. dump_spherical(ctx, st->codecpar, &sd);
  382. break;
  383. default:
  384. av_log(ctx, AV_LOG_INFO,
  385. "unknown side data type %d (%d bytes)", sd.type, sd.size);
  386. break;
  387. }
  388. av_log(ctx, AV_LOG_INFO, "\n");
  389. }
  390. }
  391. /* "user interface" functions */
  392. static void dump_stream_format(AVFormatContext *ic, int i,
  393. int index, int is_output)
  394. {
  395. char buf[256];
  396. int flags = (is_output ? ic->oformat->flags : ic->iformat->flags);
  397. AVStream *st = ic->streams[i];
  398. AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL, 0);
  399. char *separator = ic->dump_separator;
  400. AVCodecContext *avctx;
  401. int ret;
  402. avctx = avcodec_alloc_context3(NULL);
  403. if (!avctx)
  404. return;
  405. ret = avcodec_parameters_to_context(avctx, st->codecpar);
  406. if (ret < 0) {
  407. avcodec_free_context(&avctx);
  408. return;
  409. }
  410. // Fields which are missing from AVCodecParameters need to be taken from the AVCodecContext
  411. avctx->properties = st->codec->properties;
  412. avctx->codec = st->codec->codec;
  413. avctx->qmin = st->codec->qmin;
  414. avctx->qmax = st->codec->qmax;
  415. avctx->coded_width = st->codec->coded_width;
  416. avctx->coded_height = st->codec->coded_height;
  417. if (separator)
  418. av_opt_set(avctx, "dump_separator", separator, 0);
  419. avcodec_string(buf, sizeof(buf), avctx, is_output);
  420. avcodec_free_context(&avctx);
  421. av_log(NULL, AV_LOG_INFO, " Stream #%d:%d", index, i);
  422. /* the pid is an important information, so we display it */
  423. /* XXX: add a generic system */
  424. if (flags & AVFMT_SHOW_IDS)
  425. av_log(NULL, AV_LOG_INFO, "[0x%x]", st->id);
  426. if (lang)
  427. av_log(NULL, AV_LOG_INFO, "(%s)", lang->value);
  428. av_log(NULL, AV_LOG_DEBUG, ", %d, %d/%d", st->codec_info_nb_frames,
  429. st->time_base.num, st->time_base.den);
  430. av_log(NULL, AV_LOG_INFO, ": %s", buf);
  431. if (st->sample_aspect_ratio.num &&
  432. av_cmp_q(st->sample_aspect_ratio, st->codecpar->sample_aspect_ratio)) {
  433. AVRational display_aspect_ratio;
  434. av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
  435. st->codecpar->width * (int64_t)st->sample_aspect_ratio.num,
  436. st->codecpar->height * (int64_t)st->sample_aspect_ratio.den,
  437. 1024 * 1024);
  438. av_log(NULL, AV_LOG_INFO, ", SAR %d:%d DAR %d:%d",
  439. st->sample_aspect_ratio.num, st->sample_aspect_ratio.den,
  440. display_aspect_ratio.num, display_aspect_ratio.den);
  441. }
  442. if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
  443. int fps = st->avg_frame_rate.den && st->avg_frame_rate.num;
  444. int tbr = st->r_frame_rate.den && st->r_frame_rate.num;
  445. int tbn = st->time_base.den && st->time_base.num;
  446. int tbc = st->codec->time_base.den && st->codec->time_base.num;
  447. if (fps || tbr || tbn || tbc)
  448. av_log(NULL, AV_LOG_INFO, "%s", separator);
  449. if (fps)
  450. print_fps(av_q2d(st->avg_frame_rate), tbr || tbn || tbc ? "fps, " : "fps");
  451. if (tbr)
  452. print_fps(av_q2d(st->r_frame_rate), tbn || tbc ? "tbr, " : "tbr");
  453. if (tbn)
  454. print_fps(1 / av_q2d(st->time_base), tbc ? "tbn, " : "tbn");
  455. if (tbc)
  456. print_fps(1 / av_q2d(st->codec->time_base), "tbc");
  457. }
  458. if (st->disposition & AV_DISPOSITION_DEFAULT)
  459. av_log(NULL, AV_LOG_INFO, " (default)");
  460. if (st->disposition & AV_DISPOSITION_DUB)
  461. av_log(NULL, AV_LOG_INFO, " (dub)");
  462. if (st->disposition & AV_DISPOSITION_ORIGINAL)
  463. av_log(NULL, AV_LOG_INFO, " (original)");
  464. if (st->disposition & AV_DISPOSITION_COMMENT)
  465. av_log(NULL, AV_LOG_INFO, " (comment)");
  466. if (st->disposition & AV_DISPOSITION_LYRICS)
  467. av_log(NULL, AV_LOG_INFO, " (lyrics)");
  468. if (st->disposition & AV_DISPOSITION_KARAOKE)
  469. av_log(NULL, AV_LOG_INFO, " (karaoke)");
  470. if (st->disposition & AV_DISPOSITION_FORCED)
  471. av_log(NULL, AV_LOG_INFO, " (forced)");
  472. if (st->disposition & AV_DISPOSITION_HEARING_IMPAIRED)
  473. av_log(NULL, AV_LOG_INFO, " (hearing impaired)");
  474. if (st->disposition & AV_DISPOSITION_VISUAL_IMPAIRED)
  475. av_log(NULL, AV_LOG_INFO, " (visual impaired)");
  476. if (st->disposition & AV_DISPOSITION_CLEAN_EFFECTS)
  477. av_log(NULL, AV_LOG_INFO, " (clean effects)");
  478. av_log(NULL, AV_LOG_INFO, "\n");
  479. dump_metadata(NULL, st->metadata, " ");
  480. dump_sidedata(NULL, st, " ");
  481. }
  482. void av_dump_format(AVFormatContext *ic, int index,
  483. const char *url, int is_output)
  484. {
  485. int i;
  486. uint8_t *printed = ic->nb_streams ? av_mallocz(ic->nb_streams) : NULL;
  487. if (ic->nb_streams && !printed)
  488. return;
  489. av_log(NULL, AV_LOG_INFO, "%s #%d, %s, %s '%s':\n",
  490. is_output ? "Output" : "Input",
  491. index,
  492. is_output ? ic->oformat->name : ic->iformat->name,
  493. is_output ? "to" : "from", url);
  494. dump_metadata(NULL, ic->metadata, " ");
  495. if (!is_output) {
  496. av_log(NULL, AV_LOG_INFO, " Duration: ");
  497. if (ic->duration != AV_NOPTS_VALUE) {
  498. int hours, mins, secs, us;
  499. int64_t duration = ic->duration + (ic->duration <= INT64_MAX - 5000 ? 5000 : 0);
  500. secs = duration / AV_TIME_BASE;
  501. us = duration % AV_TIME_BASE;
  502. mins = secs / 60;
  503. secs %= 60;
  504. hours = mins / 60;
  505. mins %= 60;
  506. av_log(NULL, AV_LOG_INFO, "%02d:%02d:%02d.%02d", hours, mins, secs,
  507. (100 * us) / AV_TIME_BASE);
  508. } else {
  509. av_log(NULL, AV_LOG_INFO, "N/A");
  510. }
  511. if (ic->start_time != AV_NOPTS_VALUE) {
  512. int secs, us;
  513. av_log(NULL, AV_LOG_INFO, ", start: ");
  514. secs = llabs(ic->start_time / AV_TIME_BASE);
  515. us = llabs(ic->start_time % AV_TIME_BASE);
  516. av_log(NULL, AV_LOG_INFO, "%s%d.%06d",
  517. ic->start_time >= 0 ? "" : "-",
  518. secs,
  519. (int) av_rescale(us, 1000000, AV_TIME_BASE));
  520. }
  521. av_log(NULL, AV_LOG_INFO, ", bitrate: ");
  522. if (ic->bit_rate)
  523. av_log(NULL, AV_LOG_INFO, "%"PRId64" kb/s", (int64_t)ic->bit_rate / 1000);
  524. else
  525. av_log(NULL, AV_LOG_INFO, "N/A");
  526. av_log(NULL, AV_LOG_INFO, "\n");
  527. }
  528. for (i = 0; i < ic->nb_chapters; i++) {
  529. AVChapter *ch = ic->chapters[i];
  530. av_log(NULL, AV_LOG_INFO, " Chapter #%d:%d: ", index, i);
  531. av_log(NULL, AV_LOG_INFO,
  532. "start %f, ", ch->start * av_q2d(ch->time_base));
  533. av_log(NULL, AV_LOG_INFO,
  534. "end %f\n", ch->end * av_q2d(ch->time_base));
  535. dump_metadata(NULL, ch->metadata, " ");
  536. }
  537. if (ic->nb_programs) {
  538. int j, k, total = 0;
  539. for (j = 0; j < ic->nb_programs; j++) {
  540. AVDictionaryEntry *name = av_dict_get(ic->programs[j]->metadata,
  541. "name", NULL, 0);
  542. av_log(NULL, AV_LOG_INFO, " Program %d %s\n", ic->programs[j]->id,
  543. name ? name->value : "");
  544. dump_metadata(NULL, ic->programs[j]->metadata, " ");
  545. for (k = 0; k < ic->programs[j]->nb_stream_indexes; k++) {
  546. dump_stream_format(ic, ic->programs[j]->stream_index[k],
  547. index, is_output);
  548. printed[ic->programs[j]->stream_index[k]] = 1;
  549. }
  550. total += ic->programs[j]->nb_stream_indexes;
  551. }
  552. if (total < ic->nb_streams)
  553. av_log(NULL, AV_LOG_INFO, " No Program\n");
  554. }
  555. for (i = 0; i < ic->nb_streams; i++)
  556. if (!printed[i])
  557. dump_stream_format(ic, i, index, is_output);
  558. av_free(printed);
  559. }