2014-04-15 14:08:58 +00:00
|
|
|
/*
|
2014-06-16 10:24:53 +00:00
|
|
|
* Various pretty-printing functions for use within FFmpeg
|
2014-06-16 10:39:44 +00:00
|
|
|
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
|
2014-04-15 14:08:58 +00:00
|
|
|
*
|
2014-06-16 10:24:53 +00:00
|
|
|
* This file is part of FFmpeg.
|
2014-04-15 14:08:58 +00:00
|
|
|
*
|
2014-06-16 10:24:53 +00:00
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2014-04-15 14:08:58 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2014-06-16 10:24:53 +00:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2014-04-15 14:08:58 +00:00
|
|
|
* 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
|
2014-06-16 10:24:53 +00:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2014-04-15 14:08:58 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2014-04-15 14:55:23 +00:00
|
|
|
#include "libavutil/channel_layout.h"
|
|
|
|
#include "libavutil/display.h"
|
|
|
|
#include "libavutil/intreadwrite.h"
|
2014-04-15 14:08:58 +00:00
|
|
|
#include "libavutil/log.h"
|
2016-03-01 01:20:17 +00:00
|
|
|
#include "libavutil/mastering_display_metadata.h"
|
2014-04-15 14:08:58 +00:00
|
|
|
#include "libavutil/mathematics.h"
|
2014-10-08 21:48:32 +00:00
|
|
|
#include "libavutil/opt.h"
|
2014-06-16 10:24:53 +00:00
|
|
|
#include "libavutil/avstring.h"
|
2014-04-15 14:55:23 +00:00
|
|
|
#include "libavutil/replaygain.h"
|
2016-11-11 22:37:43 +00:00
|
|
|
#include "libavutil/spherical.h"
|
2014-07-23 08:21:28 +00:00
|
|
|
#include "libavutil/stereo3d.h"
|
2014-04-15 14:08:58 +00:00
|
|
|
|
|
|
|
#include "avformat.h"
|
|
|
|
|
|
|
|
#define HEXDUMP_PRINT(...) \
|
|
|
|
do { \
|
|
|
|
if (!f) \
|
|
|
|
av_log(avcl, level, __VA_ARGS__); \
|
|
|
|
else \
|
|
|
|
fprintf(f, __VA_ARGS__); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
static void hex_dump_internal(void *avcl, FILE *f, int level,
|
|
|
|
const uint8_t *buf, int size)
|
|
|
|
{
|
|
|
|
int len, i, j, c;
|
|
|
|
|
|
|
|
for (i = 0; i < size; i += 16) {
|
|
|
|
len = size - i;
|
|
|
|
if (len > 16)
|
|
|
|
len = 16;
|
|
|
|
HEXDUMP_PRINT("%08x ", i);
|
|
|
|
for (j = 0; j < 16; j++) {
|
|
|
|
if (j < len)
|
|
|
|
HEXDUMP_PRINT(" %02x", buf[i + j]);
|
|
|
|
else
|
|
|
|
HEXDUMP_PRINT(" ");
|
|
|
|
}
|
|
|
|
HEXDUMP_PRINT(" ");
|
|
|
|
for (j = 0; j < len; j++) {
|
|
|
|
c = buf[i + j];
|
|
|
|
if (c < ' ' || c > '~')
|
|
|
|
c = '.';
|
|
|
|
HEXDUMP_PRINT("%c", c);
|
|
|
|
}
|
|
|
|
HEXDUMP_PRINT("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void av_hex_dump(FILE *f, const uint8_t *buf, int size)
|
|
|
|
{
|
|
|
|
hex_dump_internal(NULL, f, 0, buf, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void av_hex_dump_log(void *avcl, int level, const uint8_t *buf, int size)
|
|
|
|
{
|
|
|
|
hex_dump_internal(avcl, NULL, level, buf, size);
|
|
|
|
}
|
|
|
|
|
2014-06-16 10:24:53 +00:00
|
|
|
static void pkt_dump_internal(void *avcl, FILE *f, int level, const AVPacket *pkt,
|
2014-04-15 14:08:58 +00:00
|
|
|
int dump_payload, AVRational time_base)
|
|
|
|
{
|
|
|
|
HEXDUMP_PRINT("stream #%d:\n", pkt->stream_index);
|
|
|
|
HEXDUMP_PRINT(" keyframe=%d\n", (pkt->flags & AV_PKT_FLAG_KEY) != 0);
|
|
|
|
HEXDUMP_PRINT(" duration=%0.3f\n", pkt->duration * av_q2d(time_base));
|
|
|
|
/* DTS is _always_ valid after av_read_frame() */
|
|
|
|
HEXDUMP_PRINT(" dts=");
|
|
|
|
if (pkt->dts == AV_NOPTS_VALUE)
|
|
|
|
HEXDUMP_PRINT("N/A");
|
|
|
|
else
|
|
|
|
HEXDUMP_PRINT("%0.3f", pkt->dts * av_q2d(time_base));
|
|
|
|
/* PTS may not be known if B-frames are present. */
|
|
|
|
HEXDUMP_PRINT(" pts=");
|
|
|
|
if (pkt->pts == AV_NOPTS_VALUE)
|
|
|
|
HEXDUMP_PRINT("N/A");
|
|
|
|
else
|
|
|
|
HEXDUMP_PRINT("%0.3f", pkt->pts * av_q2d(time_base));
|
|
|
|
HEXDUMP_PRINT("\n");
|
|
|
|
HEXDUMP_PRINT(" size=%d\n", pkt->size);
|
|
|
|
if (dump_payload)
|
2016-03-05 17:10:00 +00:00
|
|
|
hex_dump_internal(avcl, f, level, pkt->data, pkt->size);
|
2014-04-15 14:08:58 +00:00
|
|
|
}
|
|
|
|
|
2014-06-16 10:24:53 +00:00
|
|
|
void av_pkt_dump2(FILE *f, const AVPacket *pkt, int dump_payload, const AVStream *st)
|
2014-04-15 14:08:58 +00:00
|
|
|
{
|
|
|
|
pkt_dump_internal(NULL, f, 0, pkt, dump_payload, st->time_base);
|
|
|
|
}
|
|
|
|
|
2014-06-16 10:24:53 +00:00
|
|
|
void av_pkt_dump_log2(void *avcl, int level, const AVPacket *pkt, int dump_payload,
|
|
|
|
const AVStream *st)
|
2014-04-15 14:08:58 +00:00
|
|
|
{
|
|
|
|
pkt_dump_internal(avcl, NULL, level, pkt, dump_payload, st->time_base);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void print_fps(double d, const char *postfix)
|
|
|
|
{
|
|
|
|
uint64_t v = lrintf(d * 100);
|
2015-04-03 19:07:06 +00:00
|
|
|
if (!v)
|
|
|
|
av_log(NULL, AV_LOG_INFO, "%1.4f %s", d, postfix);
|
|
|
|
else if (v % 100)
|
2014-09-26 13:37:40 +00:00
|
|
|
av_log(NULL, AV_LOG_INFO, "%3.2f %s", d, postfix);
|
2014-04-15 14:08:58 +00:00
|
|
|
else if (v % (100 * 1000))
|
2014-09-26 13:37:40 +00:00
|
|
|
av_log(NULL, AV_LOG_INFO, "%1.0f %s", d, postfix);
|
2014-04-15 14:08:58 +00:00
|
|
|
else
|
2014-09-26 13:37:40 +00:00
|
|
|
av_log(NULL, AV_LOG_INFO, "%1.0fk %s", d / 1000, postfix);
|
2014-04-15 14:08:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void dump_metadata(void *ctx, AVDictionary *m, const char *indent)
|
|
|
|
{
|
|
|
|
if (m && !(av_dict_count(m) == 1 && av_dict_get(m, "language", NULL, 0))) {
|
|
|
|
AVDictionaryEntry *tag = NULL;
|
|
|
|
|
|
|
|
av_log(ctx, AV_LOG_INFO, "%sMetadata:\n", indent);
|
|
|
|
while ((tag = av_dict_get(m, "", tag, AV_DICT_IGNORE_SUFFIX)))
|
2014-06-16 10:24:53 +00:00
|
|
|
if (strcmp("language", tag->key)) {
|
|
|
|
const char *p = tag->value;
|
2014-04-15 14:08:58 +00:00
|
|
|
av_log(ctx, AV_LOG_INFO,
|
2014-06-16 10:24:53 +00:00
|
|
|
"%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");
|
|
|
|
}
|
2014-04-15 14:08:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-15 14:55:23 +00:00
|
|
|
/* param change side data*/
|
|
|
|
static void dump_paramchange(void *ctx, AVPacketSideData *sd)
|
|
|
|
{
|
|
|
|
int size = sd->size;
|
|
|
|
const uint8_t *data = sd->data;
|
|
|
|
uint32_t flags, channels, sample_rate, width, height;
|
|
|
|
uint64_t layout;
|
|
|
|
|
|
|
|
if (!data || sd->size < 4)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
flags = AV_RL32(data);
|
|
|
|
data += 4;
|
|
|
|
size -= 4;
|
|
|
|
|
|
|
|
if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT) {
|
|
|
|
if (size < 4)
|
|
|
|
goto fail;
|
|
|
|
channels = AV_RL32(data);
|
|
|
|
data += 4;
|
|
|
|
size -= 4;
|
2014-07-26 12:11:18 +00:00
|
|
|
av_log(ctx, AV_LOG_INFO, "channel count %"PRIu32", ", channels);
|
2014-04-15 14:55:23 +00:00
|
|
|
}
|
|
|
|
if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT) {
|
|
|
|
if (size < 8)
|
|
|
|
goto fail;
|
|
|
|
layout = AV_RL64(data);
|
|
|
|
data += 8;
|
|
|
|
size -= 8;
|
|
|
|
av_log(ctx, AV_LOG_INFO,
|
|
|
|
"channel layout: %s, ", av_get_channel_name(layout));
|
|
|
|
}
|
|
|
|
if (flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE) {
|
|
|
|
if (size < 4)
|
|
|
|
goto fail;
|
|
|
|
sample_rate = AV_RL32(data);
|
|
|
|
data += 4;
|
|
|
|
size -= 4;
|
2014-07-26 12:11:18 +00:00
|
|
|
av_log(ctx, AV_LOG_INFO, "sample_rate %"PRIu32", ", sample_rate);
|
2014-04-15 14:55:23 +00:00
|
|
|
}
|
|
|
|
if (flags & AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS) {
|
|
|
|
if (size < 8)
|
|
|
|
goto fail;
|
|
|
|
width = AV_RL32(data);
|
|
|
|
data += 4;
|
|
|
|
size -= 4;
|
|
|
|
height = AV_RL32(data);
|
|
|
|
data += 4;
|
|
|
|
size -= 4;
|
2014-07-26 12:11:18 +00:00
|
|
|
av_log(ctx, AV_LOG_INFO, "width %"PRIu32" height %"PRIu32, width, height);
|
2014-04-15 14:55:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
fail:
|
|
|
|
av_log(ctx, AV_LOG_INFO, "unknown param");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* replaygain side data*/
|
|
|
|
static void print_gain(void *ctx, const char *str, int32_t gain)
|
|
|
|
{
|
|
|
|
av_log(ctx, AV_LOG_INFO, "%s - ", str);
|
|
|
|
if (gain == INT32_MIN)
|
|
|
|
av_log(ctx, AV_LOG_INFO, "unknown");
|
|
|
|
else
|
|
|
|
av_log(ctx, AV_LOG_INFO, "%f", gain / 100000.0f);
|
|
|
|
av_log(ctx, AV_LOG_INFO, ", ");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_peak(void *ctx, const char *str, uint32_t peak)
|
|
|
|
{
|
|
|
|
av_log(ctx, AV_LOG_INFO, "%s - ", str);
|
|
|
|
if (!peak)
|
|
|
|
av_log(ctx, AV_LOG_INFO, "unknown");
|
|
|
|
else
|
|
|
|
av_log(ctx, AV_LOG_INFO, "%f", (float) peak / UINT32_MAX);
|
|
|
|
av_log(ctx, AV_LOG_INFO, ", ");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dump_replaygain(void *ctx, AVPacketSideData *sd)
|
|
|
|
{
|
|
|
|
AVReplayGain *rg;
|
|
|
|
|
|
|
|
if (sd->size < sizeof(*rg)) {
|
|
|
|
av_log(ctx, AV_LOG_INFO, "invalid data");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
rg = (AVReplayGain*)sd->data;
|
|
|
|
|
|
|
|
print_gain(ctx, "track gain", rg->track_gain);
|
|
|
|
print_peak(ctx, "track peak", rg->track_peak);
|
|
|
|
print_gain(ctx, "album gain", rg->album_gain);
|
|
|
|
print_peak(ctx, "album peak", rg->album_peak);
|
|
|
|
}
|
|
|
|
|
2014-07-23 08:21:28 +00:00
|
|
|
static void dump_stereo3d(void *ctx, AVPacketSideData *sd)
|
|
|
|
{
|
|
|
|
AVStereo3D *stereo;
|
|
|
|
|
|
|
|
if (sd->size < sizeof(*stereo)) {
|
|
|
|
av_log(ctx, AV_LOG_INFO, "invalid data");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
stereo = (AVStereo3D *)sd->data;
|
|
|
|
|
2016-04-21 21:24:07 +00:00
|
|
|
av_log(ctx, AV_LOG_INFO, "%s", av_stereo3d_type_name(stereo->type));
|
2014-07-23 08:21:28 +00:00
|
|
|
|
|
|
|
if (stereo->flags & AV_STEREO3D_FLAG_INVERT)
|
|
|
|
av_log(ctx, AV_LOG_INFO, " (inverted)");
|
|
|
|
}
|
|
|
|
|
2015-05-01 14:33:50 +00:00
|
|
|
static void dump_audioservicetype(void *ctx, AVPacketSideData *sd)
|
|
|
|
{
|
|
|
|
enum AVAudioServiceType *ast = (enum AVAudioServiceType *)sd->data;
|
|
|
|
|
|
|
|
if (sd->size < sizeof(*ast)) {
|
|
|
|
av_log(ctx, AV_LOG_INFO, "invalid data");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (*ast) {
|
|
|
|
case AV_AUDIO_SERVICE_TYPE_MAIN:
|
|
|
|
av_log(ctx, AV_LOG_INFO, "main");
|
|
|
|
break;
|
|
|
|
case AV_AUDIO_SERVICE_TYPE_EFFECTS:
|
|
|
|
av_log(ctx, AV_LOG_INFO, "effects");
|
|
|
|
break;
|
|
|
|
case AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED:
|
|
|
|
av_log(ctx, AV_LOG_INFO, "visually impaired");
|
|
|
|
break;
|
|
|
|
case AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED:
|
|
|
|
av_log(ctx, AV_LOG_INFO, "hearing impaired");
|
|
|
|
break;
|
|
|
|
case AV_AUDIO_SERVICE_TYPE_DIALOGUE:
|
|
|
|
av_log(ctx, AV_LOG_INFO, "dialogue");
|
|
|
|
break;
|
|
|
|
case AV_AUDIO_SERVICE_TYPE_COMMENTARY:
|
|
|
|
av_log(ctx, AV_LOG_INFO, "comentary");
|
|
|
|
break;
|
|
|
|
case AV_AUDIO_SERVICE_TYPE_EMERGENCY:
|
|
|
|
av_log(ctx, AV_LOG_INFO, "emergency");
|
|
|
|
break;
|
|
|
|
case AV_AUDIO_SERVICE_TYPE_VOICE_OVER:
|
|
|
|
av_log(ctx, AV_LOG_INFO, "voice over");
|
|
|
|
break;
|
|
|
|
case AV_AUDIO_SERVICE_TYPE_KARAOKE:
|
|
|
|
av_log(ctx, AV_LOG_INFO, "karaoke");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
av_log(ctx, AV_LOG_WARNING, "unknown");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-02 14:34:04 +00:00
|
|
|
static void dump_cpb(void *ctx, AVPacketSideData *sd)
|
|
|
|
{
|
|
|
|
AVCPBProperties *cpb = (AVCPBProperties *)sd->data;
|
|
|
|
|
|
|
|
if (sd->size < sizeof(*cpb)) {
|
|
|
|
av_log(ctx, AV_LOG_INFO, "invalid data");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
av_log(ctx, AV_LOG_INFO,
|
|
|
|
"bitrate max/min/avg: %d/%d/%d buffer size: %d vbv_delay: %"PRId64,
|
|
|
|
cpb->max_bitrate, cpb->min_bitrate, cpb->avg_bitrate,
|
|
|
|
cpb->buffer_size,
|
|
|
|
cpb->vbv_delay);
|
|
|
|
}
|
|
|
|
|
2016-03-01 01:20:17 +00:00
|
|
|
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) "
|
2016-12-05 23:03:16 +00:00
|
|
|
"min_luminance=%f, max_luminance=%f",
|
2016-03-01 01:20:17 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2017-04-02 08:08:25 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-02-10 20:26:55 +00:00
|
|
|
static void dump_spherical(void *ctx, AVCodecParameters *par, AVPacketSideData *sd)
|
2016-11-11 22:37:43 +00:00
|
|
|
{
|
|
|
|
AVSphericalMapping *spherical = (AVSphericalMapping *)sd->data;
|
|
|
|
double yaw, pitch, roll;
|
|
|
|
|
|
|
|
if (sd->size < sizeof(*spherical)) {
|
|
|
|
av_log(ctx, AV_LOG_INFO, "invalid data");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-29 02:49:48 +00:00
|
|
|
av_log(ctx, AV_LOG_INFO, "%s ", av_spherical_projection_name(spherical->projection));
|
2016-11-11 22:37:43 +00:00
|
|
|
|
|
|
|
yaw = ((double)spherical->yaw) / (1 << 16);
|
|
|
|
pitch = ((double)spherical->pitch) / (1 << 16);
|
|
|
|
roll = ((double)spherical->roll) / (1 << 16);
|
|
|
|
av_log(ctx, AV_LOG_INFO, "(%f/%f/%f) ", yaw, pitch, roll);
|
2017-02-10 20:26:55 +00:00
|
|
|
|
|
|
|
if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR_TILE) {
|
|
|
|
size_t l, t, r, b;
|
|
|
|
av_spherical_tile_bounds(spherical, par->width, par->height,
|
|
|
|
&l, &t, &r, &b);
|
2017-12-17 17:03:47 +00:00
|
|
|
av_log(ctx, AV_LOG_INFO,
|
|
|
|
"[%"SIZE_SPECIFIER", %"SIZE_SPECIFIER", %"SIZE_SPECIFIER", %"SIZE_SPECIFIER"] ",
|
|
|
|
l, t, r, b);
|
2017-02-10 20:26:55 +00:00
|
|
|
} else if (spherical->projection == AV_SPHERICAL_CUBEMAP) {
|
2017-03-16 21:20:47 +00:00
|
|
|
av_log(ctx, AV_LOG_INFO, "[pad %"PRIu32"] ", spherical->padding);
|
2017-02-10 20:26:55 +00:00
|
|
|
}
|
2016-11-11 22:37:43 +00:00
|
|
|
}
|
|
|
|
|
2014-04-15 14:55:23 +00:00
|
|
|
static void dump_sidedata(void *ctx, AVStream *st, const char *indent)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (st->nb_side_data)
|
|
|
|
av_log(ctx, AV_LOG_INFO, "%sSide data:\n", indent);
|
|
|
|
|
|
|
|
for (i = 0; i < st->nb_side_data; i++) {
|
|
|
|
AVPacketSideData sd = st->side_data[i];
|
|
|
|
av_log(ctx, AV_LOG_INFO, "%s ", indent);
|
|
|
|
|
|
|
|
switch (sd.type) {
|
|
|
|
case AV_PKT_DATA_PALETTE:
|
|
|
|
av_log(ctx, AV_LOG_INFO, "palette");
|
|
|
|
break;
|
|
|
|
case AV_PKT_DATA_NEW_EXTRADATA:
|
|
|
|
av_log(ctx, AV_LOG_INFO, "new extradata");
|
|
|
|
break;
|
|
|
|
case AV_PKT_DATA_PARAM_CHANGE:
|
|
|
|
av_log(ctx, AV_LOG_INFO, "paramchange: ");
|
|
|
|
dump_paramchange(ctx, &sd);
|
|
|
|
break;
|
|
|
|
case AV_PKT_DATA_H263_MB_INFO:
|
2016-04-27 17:45:23 +00:00
|
|
|
av_log(ctx, AV_LOG_INFO, "H.263 macroblock info");
|
2014-04-15 14:55:23 +00:00
|
|
|
break;
|
|
|
|
case AV_PKT_DATA_REPLAYGAIN:
|
|
|
|
av_log(ctx, AV_LOG_INFO, "replaygain: ");
|
|
|
|
dump_replaygain(ctx, &sd);
|
|
|
|
break;
|
|
|
|
case AV_PKT_DATA_DISPLAYMATRIX:
|
|
|
|
av_log(ctx, AV_LOG_INFO, "displaymatrix: rotation of %.2f degrees",
|
|
|
|
av_display_rotation_get((int32_t *)sd.data));
|
|
|
|
break;
|
2014-07-23 08:21:28 +00:00
|
|
|
case AV_PKT_DATA_STEREO3D:
|
|
|
|
av_log(ctx, AV_LOG_INFO, "stereo3d: ");
|
|
|
|
dump_stereo3d(ctx, &sd);
|
|
|
|
break;
|
2015-05-01 14:33:50 +00:00
|
|
|
case AV_PKT_DATA_AUDIO_SERVICE_TYPE:
|
|
|
|
av_log(ctx, AV_LOG_INFO, "audio service type: ");
|
|
|
|
dump_audioservicetype(ctx, &sd);
|
|
|
|
break;
|
2015-07-21 11:23:29 +00:00
|
|
|
case AV_PKT_DATA_QUALITY_STATS:
|
2017-03-27 19:31:46 +00:00
|
|
|
av_log(ctx, AV_LOG_INFO, "quality factor: %"PRId32", pict_type: %c",
|
|
|
|
AV_RL32(sd.data), av_get_picture_type_char(sd.data[4]));
|
2015-07-15 17:41:21 +00:00
|
|
|
break;
|
2016-01-02 14:34:04 +00:00
|
|
|
case AV_PKT_DATA_CPB_PROPERTIES:
|
|
|
|
av_log(ctx, AV_LOG_INFO, "cpb: ");
|
|
|
|
dump_cpb(ctx, &sd);
|
|
|
|
break;
|
2016-03-01 01:20:17 +00:00
|
|
|
case AV_PKT_DATA_MASTERING_DISPLAY_METADATA:
|
|
|
|
dump_mastering_display_metadata(ctx, &sd);
|
|
|
|
break;
|
2016-11-11 22:37:43 +00:00
|
|
|
case AV_PKT_DATA_SPHERICAL:
|
|
|
|
av_log(ctx, AV_LOG_INFO, "spherical: ");
|
2017-02-10 20:26:55 +00:00
|
|
|
dump_spherical(ctx, st->codecpar, &sd);
|
2016-11-11 22:37:43 +00:00
|
|
|
break;
|
2017-04-02 08:08:25 +00:00
|
|
|
case AV_PKT_DATA_CONTENT_LIGHT_LEVEL:
|
|
|
|
dump_content_light_metadata(ctx, &sd);
|
|
|
|
break;
|
2014-04-15 14:55:23 +00:00
|
|
|
default:
|
2016-05-12 08:26:03 +00:00
|
|
|
av_log(ctx, AV_LOG_INFO,
|
2014-04-15 14:55:23 +00:00
|
|
|
"unknown side data type %d (%d bytes)", sd.type, sd.size);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
av_log(ctx, AV_LOG_INFO, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-15 14:08:58 +00:00
|
|
|
/* "user interface" functions */
|
|
|
|
static void dump_stream_format(AVFormatContext *ic, int i,
|
|
|
|
int index, int is_output)
|
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
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);
|
2014-10-08 21:48:32 +00:00
|
|
|
char *separator = ic->dump_separator;
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 18:42:52 +00:00
|
|
|
AVCodecContext *avctx;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
avctx = avcodec_alloc_context3(NULL);
|
|
|
|
if (!avctx)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ret = avcodec_parameters_to_context(avctx, st->codecpar);
|
|
|
|
if (ret < 0) {
|
|
|
|
avcodec_free_context(&avctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-30 12:00:53 +00:00
|
|
|
// Fields which are missing from AVCodecParameters need to be taken from the AVCodecContext
|
|
|
|
avctx->properties = st->codec->properties;
|
2016-06-03 20:26:00 +00:00
|
|
|
avctx->codec = st->codec->codec;
|
|
|
|
avctx->qmin = st->codec->qmin;
|
|
|
|
avctx->qmax = st->codec->qmax;
|
2016-06-05 02:11:11 +00:00
|
|
|
avctx->coded_width = st->codec->coded_width;
|
|
|
|
avctx->coded_height = st->codec->coded_height;
|
2016-05-30 12:00:53 +00:00
|
|
|
|
2016-04-10 19:58:15 +00:00
|
|
|
if (separator)
|
|
|
|
av_opt_set(avctx, "dump_separator", separator, 0);
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 18:42:52 +00:00
|
|
|
avcodec_string(buf, sizeof(buf), avctx, is_output);
|
|
|
|
avcodec_free_context(&avctx);
|
2014-04-15 14:08:58 +00:00
|
|
|
|
2014-06-16 10:24:53 +00:00
|
|
|
av_log(NULL, AV_LOG_INFO, " Stream #%d:%d", index, i);
|
2014-04-15 14:08:58 +00:00
|
|
|
|
|
|
|
/* the pid is an important information, so we display it */
|
|
|
|
/* XXX: add a generic system */
|
|
|
|
if (flags & AVFMT_SHOW_IDS)
|
|
|
|
av_log(NULL, AV_LOG_INFO, "[0x%x]", st->id);
|
|
|
|
if (lang)
|
|
|
|
av_log(NULL, AV_LOG_INFO, "(%s)", lang->value);
|
|
|
|
av_log(NULL, AV_LOG_DEBUG, ", %d, %d/%d", st->codec_info_nb_frames,
|
2014-06-24 05:39:35 +00:00
|
|
|
st->time_base.num, st->time_base.den);
|
2014-04-15 14:08:58 +00:00
|
|
|
av_log(NULL, AV_LOG_INFO, ": %s", buf);
|
|
|
|
|
2016-04-10 19:58:15 +00:00
|
|
|
if (st->sample_aspect_ratio.num &&
|
|
|
|
av_cmp_q(st->sample_aspect_ratio, st->codecpar->sample_aspect_ratio)) {
|
2014-04-15 14:08:58 +00:00
|
|
|
AVRational display_aspect_ratio;
|
|
|
|
av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
|
2016-04-10 19:58:15 +00:00
|
|
|
st->codecpar->width * (int64_t)st->sample_aspect_ratio.num,
|
|
|
|
st->codecpar->height * (int64_t)st->sample_aspect_ratio.den,
|
2014-04-15 14:08:58 +00:00
|
|
|
1024 * 1024);
|
2014-06-16 10:24:53 +00:00
|
|
|
av_log(NULL, AV_LOG_INFO, ", SAR %d:%d DAR %d:%d",
|
2014-04-15 14:08:58 +00:00
|
|
|
st->sample_aspect_ratio.num, st->sample_aspect_ratio.den,
|
|
|
|
display_aspect_ratio.num, display_aspect_ratio.den);
|
|
|
|
}
|
|
|
|
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 18:42:52 +00:00
|
|
|
if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
|
2014-09-26 13:37:40 +00:00
|
|
|
int fps = st->avg_frame_rate.den && st->avg_frame_rate.num;
|
2014-10-08 21:33:24 +00:00
|
|
|
int tbr = st->r_frame_rate.den && st->r_frame_rate.num;
|
2014-09-26 13:37:40 +00:00
|
|
|
int tbn = st->time_base.den && st->time_base.num;
|
2016-06-03 21:29:05 +00:00
|
|
|
int tbc = st->codec->time_base.den && st->codec->time_base.num;
|
2014-09-26 13:37:40 +00:00
|
|
|
|
2016-06-03 21:29:05 +00:00
|
|
|
if (fps || tbr || tbn || tbc)
|
2014-10-08 21:48:32 +00:00
|
|
|
av_log(NULL, AV_LOG_INFO, "%s", separator);
|
2014-10-08 21:33:24 +00:00
|
|
|
|
2014-09-26 13:37:40 +00:00
|
|
|
if (fps)
|
2016-06-03 21:29:05 +00:00
|
|
|
print_fps(av_q2d(st->avg_frame_rate), tbr || tbn || tbc ? "fps, " : "fps");
|
2014-10-08 21:33:24 +00:00
|
|
|
if (tbr)
|
2016-06-03 21:29:05 +00:00
|
|
|
print_fps(av_q2d(st->r_frame_rate), tbn || tbc ? "tbr, " : "tbr");
|
2014-09-26 13:37:40 +00:00
|
|
|
if (tbn)
|
2016-06-03 21:29:05 +00:00
|
|
|
print_fps(1 / av_q2d(st->time_base), tbc ? "tbn, " : "tbn");
|
|
|
|
if (tbc)
|
|
|
|
print_fps(1 / av_q2d(st->codec->time_base), "tbc");
|
2014-04-15 14:08:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (st->disposition & AV_DISPOSITION_DEFAULT)
|
|
|
|
av_log(NULL, AV_LOG_INFO, " (default)");
|
|
|
|
if (st->disposition & AV_DISPOSITION_DUB)
|
|
|
|
av_log(NULL, AV_LOG_INFO, " (dub)");
|
|
|
|
if (st->disposition & AV_DISPOSITION_ORIGINAL)
|
|
|
|
av_log(NULL, AV_LOG_INFO, " (original)");
|
|
|
|
if (st->disposition & AV_DISPOSITION_COMMENT)
|
|
|
|
av_log(NULL, AV_LOG_INFO, " (comment)");
|
|
|
|
if (st->disposition & AV_DISPOSITION_LYRICS)
|
|
|
|
av_log(NULL, AV_LOG_INFO, " (lyrics)");
|
|
|
|
if (st->disposition & AV_DISPOSITION_KARAOKE)
|
|
|
|
av_log(NULL, AV_LOG_INFO, " (karaoke)");
|
|
|
|
if (st->disposition & AV_DISPOSITION_FORCED)
|
|
|
|
av_log(NULL, AV_LOG_INFO, " (forced)");
|
|
|
|
if (st->disposition & AV_DISPOSITION_HEARING_IMPAIRED)
|
|
|
|
av_log(NULL, AV_LOG_INFO, " (hearing impaired)");
|
|
|
|
if (st->disposition & AV_DISPOSITION_VISUAL_IMPAIRED)
|
|
|
|
av_log(NULL, AV_LOG_INFO, " (visual impaired)");
|
|
|
|
if (st->disposition & AV_DISPOSITION_CLEAN_EFFECTS)
|
|
|
|
av_log(NULL, AV_LOG_INFO, " (clean effects)");
|
2018-02-23 21:38:20 +00:00
|
|
|
if (st->disposition & AV_DISPOSITION_DESCRIPTIONS)
|
|
|
|
av_log(NULL, AV_LOG_INFO, " (descriptions)");
|
2018-02-23 21:38:33 +00:00
|
|
|
if (st->disposition & AV_DISPOSITION_DEPENDENT)
|
|
|
|
av_log(NULL, AV_LOG_INFO, " (dependent)");
|
2018-05-15 18:26:07 +00:00
|
|
|
if (st->disposition & AV_DISPOSITION_STILL_IMAGE)
|
|
|
|
av_log(NULL, AV_LOG_INFO, " (still image)");
|
2014-04-15 14:08:58 +00:00
|
|
|
av_log(NULL, AV_LOG_INFO, "\n");
|
|
|
|
|
|
|
|
dump_metadata(NULL, st->metadata, " ");
|
2014-04-15 14:55:23 +00:00
|
|
|
|
|
|
|
dump_sidedata(NULL, st, " ");
|
2014-04-15 14:08:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void av_dump_format(AVFormatContext *ic, int index,
|
|
|
|
const char *url, int is_output)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
uint8_t *printed = ic->nb_streams ? av_mallocz(ic->nb_streams) : NULL;
|
|
|
|
if (ic->nb_streams && !printed)
|
|
|
|
return;
|
|
|
|
|
|
|
|
av_log(NULL, AV_LOG_INFO, "%s #%d, %s, %s '%s':\n",
|
|
|
|
is_output ? "Output" : "Input",
|
|
|
|
index,
|
|
|
|
is_output ? ic->oformat->name : ic->iformat->name,
|
|
|
|
is_output ? "to" : "from", url);
|
|
|
|
dump_metadata(NULL, ic->metadata, " ");
|
|
|
|
|
|
|
|
if (!is_output) {
|
|
|
|
av_log(NULL, AV_LOG_INFO, " Duration: ");
|
|
|
|
if (ic->duration != AV_NOPTS_VALUE) {
|
|
|
|
int hours, mins, secs, us;
|
2015-12-01 11:40:32 +00:00
|
|
|
int64_t duration = ic->duration + (ic->duration <= INT64_MAX - 5000 ? 5000 : 0);
|
2014-06-16 10:24:53 +00:00
|
|
|
secs = duration / AV_TIME_BASE;
|
|
|
|
us = duration % AV_TIME_BASE;
|
2014-04-15 14:08:58 +00:00
|
|
|
mins = secs / 60;
|
|
|
|
secs %= 60;
|
|
|
|
hours = mins / 60;
|
|
|
|
mins %= 60;
|
|
|
|
av_log(NULL, AV_LOG_INFO, "%02d:%02d:%02d.%02d", hours, mins, secs,
|
|
|
|
(100 * us) / AV_TIME_BASE);
|
|
|
|
} else {
|
|
|
|
av_log(NULL, AV_LOG_INFO, "N/A");
|
|
|
|
}
|
|
|
|
if (ic->start_time != AV_NOPTS_VALUE) {
|
|
|
|
int secs, us;
|
|
|
|
av_log(NULL, AV_LOG_INFO, ", start: ");
|
2016-04-13 04:49:27 +00:00
|
|
|
secs = llabs(ic->start_time / AV_TIME_BASE);
|
2015-06-30 13:38:46 +00:00
|
|
|
us = llabs(ic->start_time % AV_TIME_BASE);
|
2016-04-13 04:49:27 +00:00
|
|
|
av_log(NULL, AV_LOG_INFO, "%s%d.%06d",
|
|
|
|
ic->start_time >= 0 ? "" : "-",
|
|
|
|
secs,
|
|
|
|
(int) av_rescale(us, 1000000, AV_TIME_BASE));
|
2014-04-15 14:08:58 +00:00
|
|
|
}
|
|
|
|
av_log(NULL, AV_LOG_INFO, ", bitrate: ");
|
|
|
|
if (ic->bit_rate)
|
2017-08-28 23:33:47 +00:00
|
|
|
av_log(NULL, AV_LOG_INFO, "%"PRId64" kb/s", ic->bit_rate / 1000);
|
2014-04-15 14:08:58 +00:00
|
|
|
else
|
|
|
|
av_log(NULL, AV_LOG_INFO, "N/A");
|
|
|
|
av_log(NULL, AV_LOG_INFO, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ic->nb_chapters; i++) {
|
|
|
|
AVChapter *ch = ic->chapters[i];
|
2014-09-30 09:26:06 +00:00
|
|
|
av_log(NULL, AV_LOG_INFO, " Chapter #%d:%d: ", index, i);
|
2014-04-15 14:08:58 +00:00
|
|
|
av_log(NULL, AV_LOG_INFO,
|
|
|
|
"start %f, ", ch->start * av_q2d(ch->time_base));
|
|
|
|
av_log(NULL, AV_LOG_INFO,
|
|
|
|
"end %f\n", ch->end * av_q2d(ch->time_base));
|
|
|
|
|
|
|
|
dump_metadata(NULL, ch->metadata, " ");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ic->nb_programs) {
|
|
|
|
int j, k, total = 0;
|
|
|
|
for (j = 0; j < ic->nb_programs; j++) {
|
|
|
|
AVDictionaryEntry *name = av_dict_get(ic->programs[j]->metadata,
|
|
|
|
"name", NULL, 0);
|
|
|
|
av_log(NULL, AV_LOG_INFO, " Program %d %s\n", ic->programs[j]->id,
|
|
|
|
name ? name->value : "");
|
|
|
|
dump_metadata(NULL, ic->programs[j]->metadata, " ");
|
|
|
|
for (k = 0; k < ic->programs[j]->nb_stream_indexes; k++) {
|
|
|
|
dump_stream_format(ic, ic->programs[j]->stream_index[k],
|
|
|
|
index, is_output);
|
|
|
|
printed[ic->programs[j]->stream_index[k]] = 1;
|
|
|
|
}
|
|
|
|
total += ic->programs[j]->nb_stream_indexes;
|
|
|
|
}
|
|
|
|
if (total < ic->nb_streams)
|
|
|
|
av_log(NULL, AV_LOG_INFO, " No Program\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ic->nb_streams; i++)
|
|
|
|
if (!printed[i])
|
|
|
|
dump_stream_format(ic, i, index, is_output);
|
|
|
|
|
|
|
|
av_free(printed);
|
|
|
|
}
|