diff options
Diffstat (limited to 'libavformat/dump.c')
-rw-r--r-- | libavformat/dump.c | 146 |
1 files changed, 105 insertions, 41 deletions
diff --git a/libavformat/dump.c b/libavformat/dump.c index 7514aee..77043e3 100644 --- a/libavformat/dump.c +++ b/libavformat/dump.c @@ -1,20 +1,21 @@ /* - * Various pretty-printing functions for use within Libav + * Various pretty-printing functions for use within FFmpeg + * Copyright (c) 2000, 2001, 2002 Fabrice Bellard * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -25,7 +26,10 @@ #include "libavutil/display.h" #include "libavutil/intreadwrite.h" #include "libavutil/log.h" +#include "libavutil/mastering_display_metadata.h" #include "libavutil/mathematics.h" +#include "libavutil/opt.h" +#include "libavutil/avstring.h" #include "libavutil/replaygain.h" #include "libavutil/spherical.h" #include "libavutil/stereo3d.h" @@ -77,7 +81,7 @@ void av_hex_dump_log(void *avcl, int level, const uint8_t *buf, int size) hex_dump_internal(avcl, NULL, level, buf, size); } -static void pkt_dump_internal(void *avcl, FILE *f, int level, AVPacket *pkt, +static void pkt_dump_internal(void *avcl, FILE *f, int level, const AVPacket *pkt, int dump_payload, AVRational time_base) { HEXDUMP_PRINT("stream #%d:\n", pkt->stream_index); @@ -98,16 +102,16 @@ static void pkt_dump_internal(void *avcl, FILE *f, int level, AVPacket *pkt, HEXDUMP_PRINT("\n"); HEXDUMP_PRINT(" size=%d\n", pkt->size); if (dump_payload) - av_hex_dump(f, pkt->data, pkt->size); + hex_dump_internal(avcl, f, level, pkt->data, pkt->size); } -void av_pkt_dump2(FILE *f, AVPacket *pkt, int dump_payload, AVStream *st) +void av_pkt_dump2(FILE *f, const AVPacket *pkt, int dump_payload, const AVStream *st) { pkt_dump_internal(NULL, f, 0, pkt, dump_payload, st->time_base); } -void av_pkt_dump_log2(void *avcl, int level, AVPacket *pkt, int dump_payload, - AVStream *st) +void av_pkt_dump_log2(void *avcl, int level, const AVPacket *pkt, int dump_payload, + const AVStream *st) { pkt_dump_internal(avcl, NULL, level, pkt, dump_payload, st->time_base); } @@ -116,7 +120,9 @@ void av_pkt_dump_log2(void *avcl, int level, AVPacket *pkt, int dump_payload, static void print_fps(double d, const char *postfix) { uint64_t v = lrintf(d * 100); - if (v % 100) + if (!v) + av_log(NULL, AV_LOG_INFO, "%1.4f %s", d, postfix); + else if (v % 100) av_log(NULL, AV_LOG_INFO, "%3.2f %s", d, postfix); else if (v % (100 * 1000)) av_log(NULL, AV_LOG_INFO, "%1.0f %s", d, postfix); @@ -131,9 +137,22 @@ static void dump_metadata(void *ctx, AVDictionary *m, const char *indent) av_log(ctx, AV_LOG_INFO, "%sMetadata:\n", indent); while ((tag = av_dict_get(m, "", tag, AV_DICT_IGNORE_SUFFIX))) - if (strcmp("language", tag->key)) + if (strcmp("language", tag->key)) { + const char *p = tag->value; av_log(ctx, AV_LOG_INFO, - "%s %-16s: %s\n", indent, tag->key, tag->value); + "%s %-16s: ", indent, tag->key); + while (*p) { + char tmp[256]; + size_t len = strcspn(p, "\x8\xa\xb\xc\xd"); + av_strlcpy(tmp, p, FFMIN(sizeof(tmp), len+1)); + av_log(ctx, AV_LOG_INFO, "%s", tmp); + p += len; + if (*p == 0xd) av_log(ctx, AV_LOG_INFO, " "); + if (*p == 0xa) av_log(ctx, AV_LOG_INFO, "\n%s %-16s: ", indent, ""); + if (*p) p++; + } + av_log(ctx, AV_LOG_INFO, "\n"); + } } } @@ -307,6 +326,31 @@ static void dump_cpb(void *ctx, AVPacketSideData *sd) cpb->vbv_delay); } +static void dump_mastering_display_metadata(void *ctx, AVPacketSideData* sd) { + AVMasteringDisplayMetadata* metadata = (AVMasteringDisplayMetadata*)sd->data; + av_log(ctx, AV_LOG_INFO, "Mastering Display Metadata, " + "has_primaries:%d has_luminance:%d " + "r(%5.4f,%5.4f) g(%5.4f,%5.4f) b(%5.4f %5.4f) wp(%5.4f, %5.4f) " + "min_luminance=%f, max_luminance=%f", + metadata->has_primaries, metadata->has_luminance, + av_q2d(metadata->display_primaries[0][0]), + av_q2d(metadata->display_primaries[0][1]), + av_q2d(metadata->display_primaries[1][0]), + av_q2d(metadata->display_primaries[1][1]), + av_q2d(metadata->display_primaries[2][0]), + av_q2d(metadata->display_primaries[2][1]), + av_q2d(metadata->white_point[0]), av_q2d(metadata->white_point[1]), + av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance)); +} + +static void dump_content_light_metadata(void *ctx, AVPacketSideData* sd) +{ + AVContentLightMetadata* metadata = (AVContentLightMetadata*)sd->data; + av_log(ctx, AV_LOG_INFO, "Content Light Level Metadata, " + "MaxCLL=%d, MaxFALL=%d", + metadata->MaxCLL, metadata->MaxFALL); +} + static void dump_spherical(void *ctx, AVCodecParameters *par, AVPacketSideData *sd) { AVSphericalMapping *spherical = (AVSphericalMapping *)sd->data; @@ -317,16 +361,7 @@ static void dump_spherical(void *ctx, AVCodecParameters *par, AVPacketSideData * return; } - if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR) - av_log(ctx, AV_LOG_INFO, "equirectangular "); - else if (spherical->projection == AV_SPHERICAL_CUBEMAP) - av_log(ctx, AV_LOG_INFO, "cubemap "); - else if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR_TILE) - av_log(ctx, AV_LOG_INFO, "tiled equirectangular "); - else { - av_log(ctx, AV_LOG_WARNING, "unknown"); - return; - } + av_log(ctx, AV_LOG_INFO, "%s ", av_spherical_projection_name(spherical->projection)); yaw = ((double)spherical->yaw) / (1 << 16); pitch = ((double)spherical->pitch) / (1 << 16); @@ -339,7 +374,7 @@ static void dump_spherical(void *ctx, AVCodecParameters *par, AVPacketSideData * &l, &t, &r, &b); av_log(ctx, AV_LOG_INFO, "[%zu, %zu, %zu, %zu] ", l, t, r, b); } else if (spherical->projection == AV_SPHERICAL_CUBEMAP) { - av_log(ctx, AV_LOG_INFO, "[pad %zu] ", spherical->padding); + av_log(ctx, AV_LOG_INFO, "[pad %"PRIu32"] ", spherical->padding); } } @@ -384,19 +419,26 @@ static void dump_sidedata(void *ctx, AVStream *st, const char *indent) av_log(ctx, AV_LOG_INFO, "audio service type: "); dump_audioservicetype(ctx, &sd); break; - case AV_PKT_DATA_QUALITY_FACTOR: - av_log(ctx, AV_LOG_INFO, "quality factor: %d", *(int *)sd.data); + case AV_PKT_DATA_QUALITY_STATS: + av_log(ctx, AV_LOG_INFO, "quality factor: %"PRId32", pict_type: %c", + AV_RL32(sd.data), av_get_picture_type_char(sd.data[4])); break; case AV_PKT_DATA_CPB_PROPERTIES: av_log(ctx, AV_LOG_INFO, "cpb: "); dump_cpb(ctx, &sd); break; + case AV_PKT_DATA_MASTERING_DISPLAY_METADATA: + dump_mastering_display_metadata(ctx, &sd); + break; case AV_PKT_DATA_SPHERICAL: av_log(ctx, AV_LOG_INFO, "spherical: "); dump_spherical(ctx, st->codecpar, &sd); break; + case AV_PKT_DATA_CONTENT_LIGHT_LEVEL: + dump_content_light_metadata(ctx, &sd); + break; default: - av_log(ctx, AV_LOG_WARNING, + av_log(ctx, AV_LOG_INFO, "unknown side data type %d (%d bytes)", sd.type, sd.size); break; } @@ -413,6 +455,7 @@ static void dump_stream_format(AVFormatContext *ic, int i, int flags = (is_output ? ic->oformat->flags : ic->iformat->flags); AVStream *st = ic->streams[i]; AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL, 0); + char *separator = ic->dump_separator; AVCodecContext *avctx; int ret; @@ -426,6 +469,16 @@ static void dump_stream_format(AVFormatContext *ic, int i, return; } + // Fields which are missing from AVCodecParameters need to be taken from the AVCodecContext + avctx->properties = st->codec->properties; + avctx->codec = st->codec->codec; + avctx->qmin = st->codec->qmin; + avctx->qmax = st->codec->qmax; + avctx->coded_width = st->codec->coded_width; + avctx->coded_height = st->codec->coded_height; + + if (separator) + av_opt_set(avctx, "dump_separator", separator, 0); avcodec_string(buf, sizeof(buf), avctx, is_output); avcodec_free_context(&avctx); @@ -441,27 +494,35 @@ static void dump_stream_format(AVFormatContext *ic, int i, st->time_base.num, st->time_base.den); av_log(NULL, AV_LOG_INFO, ": %s", buf); - if (st->sample_aspect_ratio.num) { + if (st->sample_aspect_ratio.num && + av_cmp_q(st->sample_aspect_ratio, st->codecpar->sample_aspect_ratio)) { AVRational display_aspect_ratio; av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den, - st->codecpar->width * st->sample_aspect_ratio.num, - st->codecpar->height * st->sample_aspect_ratio.den, + st->codecpar->width * (int64_t)st->sample_aspect_ratio.num, + st->codecpar->height * (int64_t)st->sample_aspect_ratio.den, 1024 * 1024); - av_log(NULL, AV_LOG_INFO, ", PAR %d:%d DAR %d:%d", + av_log(NULL, AV_LOG_INFO, ", SAR %d:%d DAR %d:%d", st->sample_aspect_ratio.num, st->sample_aspect_ratio.den, display_aspect_ratio.num, display_aspect_ratio.den); } if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { int fps = st->avg_frame_rate.den && st->avg_frame_rate.num; + int tbr = st->r_frame_rate.den && st->r_frame_rate.num; int tbn = st->time_base.den && st->time_base.num; + int tbc = st->codec->time_base.den && st->codec->time_base.num; + + if (fps || tbr || tbn || tbc) + av_log(NULL, AV_LOG_INFO, "%s", separator); - if (fps || tbn) - av_log(NULL, AV_LOG_INFO, "\n "); if (fps) - print_fps(av_q2d(st->avg_frame_rate), tbn ? "fps, " : "fps"); + print_fps(av_q2d(st->avg_frame_rate), tbr || tbn || tbc ? "fps, " : "fps"); + if (tbr) + print_fps(av_q2d(st->r_frame_rate), tbn || tbc ? "tbr, " : "tbr"); if (tbn) - print_fps(1 / av_q2d(st->time_base), "tbn"); + print_fps(1 / av_q2d(st->time_base), tbc ? "tbn, " : "tbn"); + if (tbc) + print_fps(1 / av_q2d(st->codec->time_base), "tbc"); } if (st->disposition & AV_DISPOSITION_DEFAULT) @@ -510,8 +571,9 @@ void av_dump_format(AVFormatContext *ic, int index, av_log(NULL, AV_LOG_INFO, " Duration: "); if (ic->duration != AV_NOPTS_VALUE) { int hours, mins, secs, us; - secs = ic->duration / AV_TIME_BASE; - us = ic->duration % AV_TIME_BASE; + int64_t duration = ic->duration + (ic->duration <= INT64_MAX - 5000 ? 5000 : 0); + secs = duration / AV_TIME_BASE; + us = duration % AV_TIME_BASE; mins = secs / 60; secs %= 60; hours = mins / 60; @@ -524,14 +586,16 @@ void av_dump_format(AVFormatContext *ic, int index, if (ic->start_time != AV_NOPTS_VALUE) { int secs, us; av_log(NULL, AV_LOG_INFO, ", start: "); - secs = ic->start_time / AV_TIME_BASE; + secs = llabs(ic->start_time / AV_TIME_BASE); us = llabs(ic->start_time % AV_TIME_BASE); - av_log(NULL, AV_LOG_INFO, "%d.%06d", - secs, (int) av_rescale(us, 1000000, AV_TIME_BASE)); + av_log(NULL, AV_LOG_INFO, "%s%d.%06d", + ic->start_time >= 0 ? "" : "-", + secs, + (int) av_rescale(us, 1000000, AV_TIME_BASE)); } av_log(NULL, AV_LOG_INFO, ", bitrate: "); if (ic->bit_rate) - av_log(NULL, AV_LOG_INFO, "%d kb/s", ic->bit_rate / 1000); + av_log(NULL, AV_LOG_INFO, "%"PRId64" kb/s", ic->bit_rate / 1000); else av_log(NULL, AV_LOG_INFO, "N/A"); av_log(NULL, AV_LOG_INFO, "\n"); |