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.

699 lines
24KB

  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, AVDictionary *m, const char *indent)
  121. {
  122. if (m && !(av_dict_count(m) == 1 && av_dict_get(m, "language", NULL, 0))) {
  123. 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, 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");
  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, AVPacketSideData *sd)
  216. {
  217. AVReplayGain *rg;
  218. if (sd->size < sizeof(*rg)) {
  219. av_log(ctx, AV_LOG_ERROR, "invalid data");
  220. return;
  221. }
  222. rg = (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, AVPacketSideData *sd)
  229. {
  230. AVStereo3D *stereo;
  231. if (sd->size < sizeof(*stereo)) {
  232. av_log(ctx, AV_LOG_ERROR, "invalid data");
  233. return;
  234. }
  235. stereo = (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, AVPacketSideData *sd)
  241. {
  242. enum AVAudioServiceType *ast = (enum AVAudioServiceType *)sd->data;
  243. if (sd->size < sizeof(*ast)) {
  244. av_log(ctx, AV_LOG_ERROR, "invalid data");
  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, AVPacketSideData *sd)
  281. {
  282. AVCPBProperties *cpb = (AVCPBProperties *)sd->data;
  283. if (sd->size < sizeof(*cpb)) {
  284. av_log(ctx, AV_LOG_ERROR, "invalid data");
  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, AVPacketSideData* sd) {
  301. AVMasteringDisplayMetadata* metadata = (AVMasteringDisplayMetadata*)sd->data;
  302. av_log(ctx, AV_LOG_INFO, "Mastering Display Metadata, "
  303. "has_primaries:%d has_luminance:%d "
  304. "r(%5.4f,%5.4f) g(%5.4f,%5.4f) b(%5.4f %5.4f) wp(%5.4f, %5.4f) "
  305. "min_luminance=%f, max_luminance=%f",
  306. metadata->has_primaries, metadata->has_luminance,
  307. av_q2d(metadata->display_primaries[0][0]),
  308. av_q2d(metadata->display_primaries[0][1]),
  309. av_q2d(metadata->display_primaries[1][0]),
  310. av_q2d(metadata->display_primaries[1][1]),
  311. av_q2d(metadata->display_primaries[2][0]),
  312. av_q2d(metadata->display_primaries[2][1]),
  313. av_q2d(metadata->white_point[0]), av_q2d(metadata->white_point[1]),
  314. av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance));
  315. }
  316. static void dump_content_light_metadata(void *ctx, AVPacketSideData* sd)
  317. {
  318. AVContentLightMetadata* metadata = (AVContentLightMetadata*)sd->data;
  319. av_log(ctx, AV_LOG_INFO, "Content Light Level Metadata, "
  320. "MaxCLL=%d, MaxFALL=%d",
  321. metadata->MaxCLL, metadata->MaxFALL);
  322. }
  323. static void dump_spherical(void *ctx, AVCodecParameters *par, AVPacketSideData *sd)
  324. {
  325. AVSphericalMapping *spherical = (AVSphericalMapping *)sd->data;
  326. double yaw, pitch, roll;
  327. if (sd->size < sizeof(*spherical)) {
  328. av_log(ctx, AV_LOG_ERROR, "invalid data");
  329. return;
  330. }
  331. av_log(ctx, AV_LOG_INFO, "%s ", av_spherical_projection_name(spherical->projection));
  332. yaw = ((double)spherical->yaw) / (1 << 16);
  333. pitch = ((double)spherical->pitch) / (1 << 16);
  334. roll = ((double)spherical->roll) / (1 << 16);
  335. av_log(ctx, AV_LOG_INFO, "(%f/%f/%f) ", yaw, pitch, roll);
  336. if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR_TILE) {
  337. size_t l, t, r, b;
  338. av_spherical_tile_bounds(spherical, par->width, par->height,
  339. &l, &t, &r, &b);
  340. av_log(ctx, AV_LOG_INFO,
  341. "[%"SIZE_SPECIFIER", %"SIZE_SPECIFIER", %"SIZE_SPECIFIER", %"SIZE_SPECIFIER"] ",
  342. l, t, r, b);
  343. } else if (spherical->projection == AV_SPHERICAL_CUBEMAP) {
  344. av_log(ctx, AV_LOG_INFO, "[pad %"PRIu32"] ", spherical->padding);
  345. }
  346. }
  347. static void dump_dovi_conf(void *ctx, AVPacketSideData* sd)
  348. {
  349. AVDOVIDecoderConfigurationRecord *dovi = (AVDOVIDecoderConfigurationRecord *)sd->data;
  350. av_log(ctx, AV_LOG_INFO, "version: %d.%d, profile: %d, level: %d, "
  351. "rpu flag: %d, el flag: %d, bl flag: %d, compatibility id: %d",
  352. dovi->dv_version_major, dovi->dv_version_minor,
  353. dovi->dv_profile, dovi->dv_level,
  354. dovi->rpu_present_flag,
  355. dovi->el_present_flag,
  356. dovi->bl_present_flag,
  357. dovi->dv_bl_signal_compatibility_id);
  358. }
  359. static void dump_sidedata(void *ctx, AVStream *st, const char *indent)
  360. {
  361. int i;
  362. if (st->nb_side_data)
  363. av_log(ctx, AV_LOG_INFO, "%sSide data:\n", indent);
  364. for (i = 0; i < st->nb_side_data; i++) {
  365. AVPacketSideData sd = st->side_data[i];
  366. av_log(ctx, AV_LOG_INFO, "%s ", indent);
  367. switch (sd.type) {
  368. case AV_PKT_DATA_PALETTE:
  369. av_log(ctx, AV_LOG_INFO, "palette");
  370. break;
  371. case AV_PKT_DATA_NEW_EXTRADATA:
  372. av_log(ctx, AV_LOG_INFO, "new extradata");
  373. break;
  374. case AV_PKT_DATA_PARAM_CHANGE:
  375. av_log(ctx, AV_LOG_INFO, "paramchange: ");
  376. dump_paramchange(ctx, &sd);
  377. break;
  378. case AV_PKT_DATA_H263_MB_INFO:
  379. av_log(ctx, AV_LOG_INFO, "H.263 macroblock info");
  380. break;
  381. case AV_PKT_DATA_REPLAYGAIN:
  382. av_log(ctx, AV_LOG_INFO, "replaygain: ");
  383. dump_replaygain(ctx, &sd);
  384. break;
  385. case AV_PKT_DATA_DISPLAYMATRIX:
  386. av_log(ctx, AV_LOG_INFO, "displaymatrix: rotation of %.2f degrees",
  387. av_display_rotation_get((int32_t *)sd.data));
  388. break;
  389. case AV_PKT_DATA_STEREO3D:
  390. av_log(ctx, AV_LOG_INFO, "stereo3d: ");
  391. dump_stereo3d(ctx, &sd);
  392. break;
  393. case AV_PKT_DATA_AUDIO_SERVICE_TYPE:
  394. av_log(ctx, AV_LOG_INFO, "audio service type: ");
  395. dump_audioservicetype(ctx, &sd);
  396. break;
  397. case AV_PKT_DATA_QUALITY_STATS:
  398. av_log(ctx, AV_LOG_INFO, "quality factor: %"PRId32", pict_type: %c",
  399. AV_RL32(sd.data), av_get_picture_type_char(sd.data[4]));
  400. break;
  401. case AV_PKT_DATA_CPB_PROPERTIES:
  402. av_log(ctx, AV_LOG_INFO, "cpb: ");
  403. dump_cpb(ctx, &sd);
  404. break;
  405. case AV_PKT_DATA_MASTERING_DISPLAY_METADATA:
  406. dump_mastering_display_metadata(ctx, &sd);
  407. break;
  408. case AV_PKT_DATA_SPHERICAL:
  409. av_log(ctx, AV_LOG_INFO, "spherical: ");
  410. dump_spherical(ctx, st->codecpar, &sd);
  411. break;
  412. case AV_PKT_DATA_CONTENT_LIGHT_LEVEL:
  413. dump_content_light_metadata(ctx, &sd);
  414. break;
  415. case AV_PKT_DATA_ICC_PROFILE:
  416. av_log(ctx, AV_LOG_INFO, "ICC Profile");
  417. break;
  418. case AV_PKT_DATA_DOVI_CONF:
  419. av_log(ctx, AV_LOG_INFO, "DOVI configuration record: ");
  420. dump_dovi_conf(ctx, &sd);
  421. break;
  422. default:
  423. av_log(ctx, AV_LOG_INFO,
  424. "unknown side data type %d (%d bytes)", sd.type, sd.size);
  425. break;
  426. }
  427. av_log(ctx, AV_LOG_INFO, "\n");
  428. }
  429. }
  430. /* "user interface" functions */
  431. static void dump_stream_format(AVFormatContext *ic, int i,
  432. int index, int is_output)
  433. {
  434. char buf[256];
  435. int flags = (is_output ? ic->oformat->flags : ic->iformat->flags);
  436. AVStream *st = ic->streams[i];
  437. AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL, 0);
  438. char *separator = ic->dump_separator;
  439. AVCodecContext *avctx;
  440. int ret;
  441. avctx = avcodec_alloc_context3(NULL);
  442. if (!avctx)
  443. return;
  444. ret = avcodec_parameters_to_context(avctx, st->codecpar);
  445. if (ret < 0) {
  446. avcodec_free_context(&avctx);
  447. return;
  448. }
  449. #if FF_API_LAVF_AVCTX
  450. FF_DISABLE_DEPRECATION_WARNINGS
  451. // Fields which are missing from AVCodecParameters need to be taken from the AVCodecContext
  452. avctx->properties = st->codec->properties;
  453. avctx->codec = st->codec->codec;
  454. avctx->qmin = st->codec->qmin;
  455. avctx->qmax = st->codec->qmax;
  456. avctx->coded_width = st->codec->coded_width;
  457. avctx->coded_height = st->codec->coded_height;
  458. FF_ENABLE_DEPRECATION_WARNINGS
  459. #endif
  460. if (separator)
  461. av_opt_set(avctx, "dump_separator", separator, 0);
  462. avcodec_string(buf, sizeof(buf), avctx, is_output);
  463. avcodec_free_context(&avctx);
  464. av_log(NULL, AV_LOG_INFO, " Stream #%d:%d", index, i);
  465. /* the pid is an important information, so we display it */
  466. /* XXX: add a generic system */
  467. if (flags & AVFMT_SHOW_IDS)
  468. av_log(NULL, AV_LOG_INFO, "[0x%x]", st->id);
  469. if (lang)
  470. av_log(NULL, AV_LOG_INFO, "(%s)", lang->value);
  471. av_log(NULL, AV_LOG_DEBUG, ", %d, %d/%d", st->codec_info_nb_frames,
  472. st->time_base.num, st->time_base.den);
  473. av_log(NULL, AV_LOG_INFO, ": %s", buf);
  474. if (st->sample_aspect_ratio.num &&
  475. av_cmp_q(st->sample_aspect_ratio, st->codecpar->sample_aspect_ratio)) {
  476. AVRational display_aspect_ratio;
  477. av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
  478. st->codecpar->width * (int64_t)st->sample_aspect_ratio.num,
  479. st->codecpar->height * (int64_t)st->sample_aspect_ratio.den,
  480. 1024 * 1024);
  481. av_log(NULL, AV_LOG_INFO, ", SAR %d:%d DAR %d:%d",
  482. st->sample_aspect_ratio.num, st->sample_aspect_ratio.den,
  483. display_aspect_ratio.num, display_aspect_ratio.den);
  484. }
  485. if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
  486. int fps = st->avg_frame_rate.den && st->avg_frame_rate.num;
  487. int tbr = st->r_frame_rate.den && st->r_frame_rate.num;
  488. int tbn = st->time_base.den && st->time_base.num;
  489. #if FF_API_LAVF_AVCTX
  490. FF_DISABLE_DEPRECATION_WARNINGS
  491. int tbc = st->codec->time_base.den && st->codec->time_base.num;
  492. FF_ENABLE_DEPRECATION_WARNINGS
  493. #else
  494. int tbc = 0;
  495. #endif
  496. if (fps || tbr || tbn || tbc)
  497. av_log(NULL, AV_LOG_INFO, "%s", separator);
  498. if (fps)
  499. print_fps(av_q2d(st->avg_frame_rate), tbr || tbn || tbc ? "fps, " : "fps");
  500. if (tbr)
  501. print_fps(av_q2d(st->r_frame_rate), tbn || tbc ? "tbr, " : "tbr");
  502. if (tbn)
  503. print_fps(1 / av_q2d(st->time_base), tbc ? "tbn, " : "tbn");
  504. #if FF_API_LAVF_AVCTX
  505. FF_DISABLE_DEPRECATION_WARNINGS
  506. if (tbc)
  507. print_fps(1 / av_q2d(st->codec->time_base), "tbc");
  508. FF_ENABLE_DEPRECATION_WARNINGS
  509. #endif
  510. }
  511. if (st->disposition & AV_DISPOSITION_DEFAULT)
  512. av_log(NULL, AV_LOG_INFO, " (default)");
  513. if (st->disposition & AV_DISPOSITION_DUB)
  514. av_log(NULL, AV_LOG_INFO, " (dub)");
  515. if (st->disposition & AV_DISPOSITION_ORIGINAL)
  516. av_log(NULL, AV_LOG_INFO, " (original)");
  517. if (st->disposition & AV_DISPOSITION_COMMENT)
  518. av_log(NULL, AV_LOG_INFO, " (comment)");
  519. if (st->disposition & AV_DISPOSITION_LYRICS)
  520. av_log(NULL, AV_LOG_INFO, " (lyrics)");
  521. if (st->disposition & AV_DISPOSITION_KARAOKE)
  522. av_log(NULL, AV_LOG_INFO, " (karaoke)");
  523. if (st->disposition & AV_DISPOSITION_FORCED)
  524. av_log(NULL, AV_LOG_INFO, " (forced)");
  525. if (st->disposition & AV_DISPOSITION_HEARING_IMPAIRED)
  526. av_log(NULL, AV_LOG_INFO, " (hearing impaired)");
  527. if (st->disposition & AV_DISPOSITION_VISUAL_IMPAIRED)
  528. av_log(NULL, AV_LOG_INFO, " (visual impaired)");
  529. if (st->disposition & AV_DISPOSITION_CLEAN_EFFECTS)
  530. av_log(NULL, AV_LOG_INFO, " (clean effects)");
  531. if (st->disposition & AV_DISPOSITION_ATTACHED_PIC)
  532. av_log(NULL, AV_LOG_INFO, " (attached pic)");
  533. if (st->disposition & AV_DISPOSITION_TIMED_THUMBNAILS)
  534. av_log(NULL, AV_LOG_INFO, " (timed thumbnails)");
  535. if (st->disposition & AV_DISPOSITION_CAPTIONS)
  536. av_log(NULL, AV_LOG_INFO, " (captions)");
  537. if (st->disposition & AV_DISPOSITION_DESCRIPTIONS)
  538. av_log(NULL, AV_LOG_INFO, " (descriptions)");
  539. if (st->disposition & AV_DISPOSITION_METADATA)
  540. av_log(NULL, AV_LOG_INFO, " (metadata)");
  541. if (st->disposition & AV_DISPOSITION_DEPENDENT)
  542. av_log(NULL, AV_LOG_INFO, " (dependent)");
  543. if (st->disposition & AV_DISPOSITION_STILL_IMAGE)
  544. av_log(NULL, AV_LOG_INFO, " (still image)");
  545. av_log(NULL, AV_LOG_INFO, "\n");
  546. dump_metadata(NULL, st->metadata, " ");
  547. dump_sidedata(NULL, st, " ");
  548. }
  549. void av_dump_format(AVFormatContext *ic, int index,
  550. const char *url, int is_output)
  551. {
  552. int i;
  553. uint8_t *printed = ic->nb_streams ? av_mallocz(ic->nb_streams) : NULL;
  554. if (ic->nb_streams && !printed)
  555. return;
  556. av_log(NULL, AV_LOG_INFO, "%s #%d, %s, %s '%s':\n",
  557. is_output ? "Output" : "Input",
  558. index,
  559. is_output ? ic->oformat->name : ic->iformat->name,
  560. is_output ? "to" : "from", url);
  561. dump_metadata(NULL, ic->metadata, " ");
  562. if (!is_output) {
  563. av_log(NULL, AV_LOG_INFO, " Duration: ");
  564. if (ic->duration != AV_NOPTS_VALUE) {
  565. int64_t hours, mins, secs, us;
  566. int64_t duration = ic->duration + (ic->duration <= INT64_MAX - 5000 ? 5000 : 0);
  567. secs = duration / AV_TIME_BASE;
  568. us = duration % AV_TIME_BASE;
  569. mins = secs / 60;
  570. secs %= 60;
  571. hours = mins / 60;
  572. mins %= 60;
  573. av_log(NULL, AV_LOG_INFO, "%02"PRId64":%02"PRId64":%02"PRId64".%02"PRId64"", hours, mins, secs,
  574. (100 * us) / AV_TIME_BASE);
  575. } else {
  576. av_log(NULL, AV_LOG_INFO, "N/A");
  577. }
  578. if (ic->start_time != AV_NOPTS_VALUE) {
  579. int secs, us;
  580. av_log(NULL, AV_LOG_INFO, ", start: ");
  581. secs = llabs(ic->start_time / AV_TIME_BASE);
  582. us = llabs(ic->start_time % AV_TIME_BASE);
  583. av_log(NULL, AV_LOG_INFO, "%s%d.%06d",
  584. ic->start_time >= 0 ? "" : "-",
  585. secs,
  586. (int) av_rescale(us, 1000000, AV_TIME_BASE));
  587. }
  588. av_log(NULL, AV_LOG_INFO, ", bitrate: ");
  589. if (ic->bit_rate)
  590. av_log(NULL, AV_LOG_INFO, "%"PRId64" kb/s", ic->bit_rate / 1000);
  591. else
  592. av_log(NULL, AV_LOG_INFO, "N/A");
  593. av_log(NULL, AV_LOG_INFO, "\n");
  594. }
  595. for (i = 0; i < ic->nb_chapters; i++) {
  596. AVChapter *ch = ic->chapters[i];
  597. av_log(NULL, AV_LOG_INFO, " Chapter #%d:%d: ", index, i);
  598. av_log(NULL, AV_LOG_INFO,
  599. "start %f, ", ch->start * av_q2d(ch->time_base));
  600. av_log(NULL, AV_LOG_INFO,
  601. "end %f\n", ch->end * av_q2d(ch->time_base));
  602. dump_metadata(NULL, ch->metadata, " ");
  603. }
  604. if (ic->nb_programs) {
  605. int j, k, total = 0;
  606. for (j = 0; j < ic->nb_programs; j++) {
  607. AVDictionaryEntry *name = av_dict_get(ic->programs[j]->metadata,
  608. "name", NULL, 0);
  609. av_log(NULL, AV_LOG_INFO, " Program %d %s\n", ic->programs[j]->id,
  610. name ? name->value : "");
  611. dump_metadata(NULL, ic->programs[j]->metadata, " ");
  612. for (k = 0; k < ic->programs[j]->nb_stream_indexes; k++) {
  613. dump_stream_format(ic, ic->programs[j]->stream_index[k],
  614. index, is_output);
  615. printed[ic->programs[j]->stream_index[k]] = 1;
  616. }
  617. total += ic->programs[j]->nb_stream_indexes;
  618. }
  619. if (total < ic->nb_streams)
  620. av_log(NULL, AV_LOG_INFO, " No Program\n");
  621. }
  622. for (i = 0; i < ic->nb_streams; i++)
  623. if (!printed[i])
  624. dump_stream_format(ic, i, index, is_output);
  625. av_free(printed);
  626. }