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.

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