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.

726 lines
25KB

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