[FFmpeg-devel] [PATCH 3/3] lavf/dump: use a writer.
Andriy Gelman
andriy.gelman at gmail.com
Fri Dec 27 18:48:04 EET 2019
On Fri, 27. Dec 14:24, Nicolas George wrote:
> Signed-off-by: Nicolas George <george at nsup.org>
> ---
> libavformat/avformat.h | 21 +++
> libavformat/dump.c | 297 +++++++++++++++++++++--------------------
> 2 files changed, 175 insertions(+), 143 deletions(-)
>
>
> Note: I chose flags instead of is_output because I intent do add new flags
> later, in particular AV_DUMP_FORMAT_NO_METADATA.
>
>
> diff --git a/libavformat/avformat.h b/libavformat/avformat.h
> index d4d9a3b06e..95a2c3ca33 100644
> --- a/libavformat/avformat.h
> +++ b/libavformat/avformat.h
> @@ -317,6 +317,7 @@
> #include "libavcodec/avcodec.h"
> #include "libavutil/dict.h"
> #include "libavutil/log.h"
> +#include "libavutil/writer.h"
>
> #include "avio.h"
> #include "libavformat/version.h"
> @@ -2894,6 +2895,26 @@ void av_dump_format(AVFormatContext *ic,
> const char *url,
> int is_output);
>
> +/**
> + * Write detailed information about the input or output format, such as
> + * duration, bitrate, streams, container, programs, metadata, side data,
> + * codec and time base, to an AVWriter.
> + *
> + * @param wr the writer where the format should be written
> + * @param ic the context to analyze
> + * @param index index of the stream to dump information about
> + * @param url the URL to print, such as source or destination file
> + * @param flags formatting flags, see below
> + */
> +void av_dump_format_to_writer(struct AVWriter wr,
> + AVFormatContext *ic, int index,
> + const char *url, unsigned flags);
> +
> +/**
> + * Flag to av_dump_format_to_writer():
> + * if set, the cotext is output; if unset, the context is input.
> + */
> +#define AV_DUMP_FORMAT_IS_OUTPUT 1
>
> #define AV_FRAME_FILENAME_FLAGS_MULTIPLE 1 ///< Allow multiple %d
>
> diff --git a/libavformat/dump.c b/libavformat/dump.c
> index fcf8bad63a..46ca9428b1 100644
> --- a/libavformat/dump.c
> +++ b/libavformat/dump.c
> @@ -33,6 +33,7 @@
> #include "libavutil/replaygain.h"
> #include "libavutil/spherical.h"
> #include "libavutil/stereo3d.h"
> +#include "libavutil/writer.h"
>
> #include "avformat.h"
>
> @@ -117,47 +118,47 @@ void av_pkt_dump_log2(void *avcl, int level, const AVPacket *pkt, int dump_paylo
> }
>
>
> -static void print_fps(double d, const char *postfix)
> +static void print_fps(AVWriter wr, double d, const char *postfix)
> {
> uint64_t v = lrintf(d * 100);
> if (!v)
> - av_log(NULL, AV_LOG_INFO, "%1.4f %s", d, postfix);
> + av_writer_printf(wr, "%1.4f %s", d, postfix);
> else if (v % 100)
> - av_log(NULL, AV_LOG_INFO, "%3.2f %s", d, postfix);
> + av_writer_printf(wr, "%3.2f %s", d, postfix);
> else if (v % (100 * 1000))
> - av_log(NULL, AV_LOG_INFO, "%1.0f %s", d, postfix);
> + av_writer_printf(wr, "%1.0f %s", d, postfix);
> else
> - av_log(NULL, AV_LOG_INFO, "%1.0fk %s", d / 1000, postfix);
> + av_writer_printf(wr, "%1.0fk %s", d / 1000, postfix);
> }
>
> -static void dump_metadata(void *ctx, AVDictionary *m, const char *indent)
> +static void dump_metadata(AVWriter wr, 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);
> + av_writer_printf(wr, "%sMetadata:\n", indent);
> while ((tag = av_dict_get(m, "", tag, AV_DICT_IGNORE_SUFFIX)))
> if (strcmp("language", tag->key)) {
> const char *p = tag->value;
> - av_log(ctx, AV_LOG_INFO,
> + av_writer_printf(wr,
> "%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);
> + av_writer_printf(wr, "%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 == 0xd) av_writer_printf(wr, " ");
> + if (*p == 0xa) av_writer_printf(wr, "\n%s %-16s: ", indent, "");
> if (*p) p++;
> }
> - av_log(ctx, AV_LOG_INFO, "\n");
> + av_writer_printf(wr, "\n");
> }
> }
> }
>
> /* param change side data*/
> -static void dump_paramchange(void *ctx, AVPacketSideData *sd)
> +static void dump_paramchange(AVWriter wr, AVPacketSideData *sd)
> {
> int size = sd->size;
> const uint8_t *data = sd->data;
> @@ -177,7 +178,7 @@ static void dump_paramchange(void *ctx, AVPacketSideData *sd)
> channels = AV_RL32(data);
> data += 4;
> size -= 4;
> - av_log(ctx, AV_LOG_INFO, "channel count %"PRIu32", ", channels);
> + av_writer_printf(wr, "channel count %"PRIu32", ", channels);
> }
> if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT) {
> if (size < 8)
> @@ -185,7 +186,7 @@ static void dump_paramchange(void *ctx, AVPacketSideData *sd)
> layout = AV_RL64(data);
> data += 8;
> size -= 8;
> - av_log(ctx, AV_LOG_INFO,
> + av_writer_printf(wr,
> "channel layout: %s, ", av_get_channel_name(layout));
> }
> if (flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE) {
> @@ -194,7 +195,7 @@ static void dump_paramchange(void *ctx, AVPacketSideData *sd)
> sample_rate = AV_RL32(data);
> data += 4;
> size -= 4;
> - av_log(ctx, AV_LOG_INFO, "sample_rate %"PRIu32", ", sample_rate);
> + av_writer_printf(wr, "sample_rate %"PRIu32", ", sample_rate);
> }
> if (flags & AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS) {
> if (size < 8)
> @@ -205,121 +206,121 @@ static void dump_paramchange(void *ctx, AVPacketSideData *sd)
> height = AV_RL32(data);
> data += 4;
> size -= 4;
> - av_log(ctx, AV_LOG_INFO, "width %"PRIu32" height %"PRIu32, width, height);
> + av_writer_printf(wr, "width %"PRIu32" height %"PRIu32, width, height);
> }
>
> return;
> fail:
> - av_log(ctx, AV_LOG_ERROR, "unknown param");
> + av_log_writer_log(wr, AV_LOG_ERROR, "unknown param");
> }
>
> /* replaygain side data*/
> -static void print_gain(void *ctx, const char *str, int32_t gain)
> +static void print_gain(AVWriter wr, const char *str, int32_t gain)
> {
> - av_log(ctx, AV_LOG_INFO, "%s - ", str);
> + av_writer_printf(wr, "%s - ", str);
> if (gain == INT32_MIN)
> - av_log(ctx, AV_LOG_INFO, "unknown");
> + av_writer_printf(wr, "unknown");
> else
> - av_log(ctx, AV_LOG_INFO, "%f", gain / 100000.0f);
> - av_log(ctx, AV_LOG_INFO, ", ");
> + av_writer_printf(wr, "%f", gain / 100000.0f);
> + av_writer_printf(wr, ", ");
> }
>
> -static void print_peak(void *ctx, const char *str, uint32_t peak)
> +static void print_peak(AVWriter wr, const char *str, uint32_t peak)
> {
> - av_log(ctx, AV_LOG_INFO, "%s - ", str);
> + av_writer_printf(wr, "%s - ", str);
> if (!peak)
> - av_log(ctx, AV_LOG_INFO, "unknown");
> + av_writer_printf(wr, "unknown");
> else
> - av_log(ctx, AV_LOG_INFO, "%f", (float) peak / UINT32_MAX);
> - av_log(ctx, AV_LOG_INFO, ", ");
> + av_writer_printf(wr, "%f", (float) peak / UINT32_MAX);
> + av_writer_printf(wr, ", ");
> }
>
> -static void dump_replaygain(void *ctx, AVPacketSideData *sd)
> +static void dump_replaygain(AVWriter wr, AVPacketSideData *sd)
> {
> AVReplayGain *rg;
>
> if (sd->size < sizeof(*rg)) {
> - av_log(ctx, AV_LOG_ERROR, "invalid data");
> + av_log_writer_log(wr, AV_LOG_ERROR, "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);
> + print_gain(wr, "track gain", rg->track_gain);
> + print_peak(wr, "track peak", rg->track_peak);
> + print_gain(wr, "album gain", rg->album_gain);
> + print_peak(wr, "album peak", rg->album_peak);
> }
>
> -static void dump_stereo3d(void *ctx, AVPacketSideData *sd)
> +static void dump_stereo3d(AVWriter wr, AVPacketSideData *sd)
> {
> AVStereo3D *stereo;
>
> if (sd->size < sizeof(*stereo)) {
> - av_log(ctx, AV_LOG_ERROR, "invalid data");
> + av_log_writer_log(wr, AV_LOG_ERROR, "invalid data");
> return;
> }
>
> stereo = (AVStereo3D *)sd->data;
>
> - av_log(ctx, AV_LOG_INFO, "%s", av_stereo3d_type_name(stereo->type));
> + av_writer_printf(wr, "%s", av_stereo3d_type_name(stereo->type));
>
> if (stereo->flags & AV_STEREO3D_FLAG_INVERT)
> - av_log(ctx, AV_LOG_INFO, " (inverted)");
> + av_writer_printf(wr, " (inverted)");
> }
>
> -static void dump_audioservicetype(void *ctx, AVPacketSideData *sd)
> +static void dump_audioservicetype(AVWriter wr, AVPacketSideData *sd)
> {
> enum AVAudioServiceType *ast = (enum AVAudioServiceType *)sd->data;
>
> if (sd->size < sizeof(*ast)) {
> - av_log(ctx, AV_LOG_ERROR, "invalid data");
> + av_log_writer_log(wr, AV_LOG_ERROR, "invalid data");
> return;
> }
>
> switch (*ast) {
> case AV_AUDIO_SERVICE_TYPE_MAIN:
> - av_log(ctx, AV_LOG_INFO, "main");
> + av_writer_printf(wr, "main");
> break;
> case AV_AUDIO_SERVICE_TYPE_EFFECTS:
> - av_log(ctx, AV_LOG_INFO, "effects");
> + av_writer_printf(wr, "effects");
> break;
> case AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED:
> - av_log(ctx, AV_LOG_INFO, "visually impaired");
> + av_writer_printf(wr, "visually impaired");
> break;
> case AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED:
> - av_log(ctx, AV_LOG_INFO, "hearing impaired");
> + av_writer_printf(wr, "hearing impaired");
> break;
> case AV_AUDIO_SERVICE_TYPE_DIALOGUE:
> - av_log(ctx, AV_LOG_INFO, "dialogue");
> + av_writer_printf(wr, "dialogue");
> break;
> case AV_AUDIO_SERVICE_TYPE_COMMENTARY:
> - av_log(ctx, AV_LOG_INFO, "commentary");
> + av_writer_printf(wr, "commentary");
> break;
> case AV_AUDIO_SERVICE_TYPE_EMERGENCY:
> - av_log(ctx, AV_LOG_INFO, "emergency");
> + av_writer_printf(wr, "emergency");
> break;
> case AV_AUDIO_SERVICE_TYPE_VOICE_OVER:
> - av_log(ctx, AV_LOG_INFO, "voice over");
> + av_writer_printf(wr, "voice over");
> break;
> case AV_AUDIO_SERVICE_TYPE_KARAOKE:
> - av_log(ctx, AV_LOG_INFO, "karaoke");
> + av_writer_printf(wr, "karaoke");
> break;
> default:
> - av_log(ctx, AV_LOG_WARNING, "unknown");
> + av_log_writer_log(wr, AV_LOG_WARNING, "unknown");
> break;
> }
> }
>
> -static void dump_cpb(void *ctx, AVPacketSideData *sd)
> +static void dump_cpb(AVWriter wr, AVPacketSideData *sd)
> {
> AVCPBProperties *cpb = (AVCPBProperties *)sd->data;
>
> if (sd->size < sizeof(*cpb)) {
> - av_log(ctx, AV_LOG_ERROR, "invalid data");
> + av_log_writer_log(wr, AV_LOG_ERROR, "invalid data");
> return;
> }
>
> - av_log(ctx, AV_LOG_INFO,
> + av_writer_printf(wr,
> #if FF_API_UNSANITIZED_BITRATES
> "bitrate max/min/avg: %d/%d/%d buffer size: %d ",
> #else
> @@ -328,14 +329,14 @@ static void dump_cpb(void *ctx, AVPacketSideData *sd)
> cpb->max_bitrate, cpb->min_bitrate, cpb->avg_bitrate,
> cpb->buffer_size);
> if (cpb->vbv_delay == UINT64_MAX)
> - av_log(ctx, AV_LOG_INFO, "vbv_delay: N/A");
> + av_writer_printf(wr, "vbv_delay: N/A");
> else
> - av_log(ctx, AV_LOG_INFO, "vbv_delay: %"PRIu64"", cpb->vbv_delay);
> + av_writer_printf(wr, "vbv_delay: %"PRIu64"", cpb->vbv_delay);
> }
>
> -static void dump_mastering_display_metadata(void *ctx, AVPacketSideData* sd) {
> +static void dump_mastering_display_metadata(AVWriter wr, AVPacketSideData* sd) {
> AVMasteringDisplayMetadata* metadata = (AVMasteringDisplayMetadata*)sd->data;
> - av_log(ctx, AV_LOG_INFO, "Mastering Display Metadata, "
> + av_writer_printf(wr, "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",
> @@ -350,114 +351,115 @@ static void dump_mastering_display_metadata(void *ctx, AVPacketSideData* sd) {
> av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance));
> }
>
> -static void dump_content_light_metadata(void *ctx, AVPacketSideData* sd)
> +static void dump_content_light_metadata(AVWriter wr, AVPacketSideData* sd)
> {
> AVContentLightMetadata* metadata = (AVContentLightMetadata*)sd->data;
> - av_log(ctx, AV_LOG_INFO, "Content Light Level Metadata, "
> + av_writer_printf(wr, "Content Light Level Metadata, "
> "MaxCLL=%d, MaxFALL=%d",
> metadata->MaxCLL, metadata->MaxFALL);
> }
>
> -static void dump_spherical(void *ctx, AVCodecParameters *par, AVPacketSideData *sd)
> +static void dump_spherical(AVWriter wr, AVCodecParameters *par, AVPacketSideData *sd)
> {
> AVSphericalMapping *spherical = (AVSphericalMapping *)sd->data;
> double yaw, pitch, roll;
>
> if (sd->size < sizeof(*spherical)) {
> - av_log(ctx, AV_LOG_ERROR, "invalid data");
> + av_log_writer_log(wr, AV_LOG_ERROR, "invalid data");
> return;
> }
>
> - av_log(ctx, AV_LOG_INFO, "%s ", av_spherical_projection_name(spherical->projection));
> + av_writer_printf(wr, "%s ", av_spherical_projection_name(spherical->projection));
>
> 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);
> + av_writer_printf(wr, "(%f/%f/%f) ", yaw, pitch, roll);
>
> 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);
> - av_log(ctx, AV_LOG_INFO,
> + av_writer_printf(wr,
> "[%"SIZE_SPECIFIER", %"SIZE_SPECIFIER", %"SIZE_SPECIFIER", %"SIZE_SPECIFIER"] ",
> l, t, r, b);
> } else if (spherical->projection == AV_SPHERICAL_CUBEMAP) {
> - av_log(ctx, AV_LOG_INFO, "[pad %"PRIu32"] ", spherical->padding);
> + av_writer_printf(wr, "[pad %"PRIu32"] ", spherical->padding);
> }
> }
>
> -static void dump_sidedata(void *ctx, AVStream *st, const char *indent)
> +static void dump_sidedata(AVWriter wr, AVStream *st, const char *indent)
> {
> int i;
>
> if (st->nb_side_data)
> - av_log(ctx, AV_LOG_INFO, "%sSide data:\n", indent);
> + av_writer_printf(wr, "%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);
> + av_writer_printf(wr, "%s ", indent);
>
> switch (sd.type) {
> case AV_PKT_DATA_PALETTE:
> - av_log(ctx, AV_LOG_INFO, "palette");
> + av_writer_printf(wr, "palette");
> break;
> case AV_PKT_DATA_NEW_EXTRADATA:
> - av_log(ctx, AV_LOG_INFO, "new extradata");
> + av_writer_printf(wr, "new extradata");
> break;
> case AV_PKT_DATA_PARAM_CHANGE:
> - av_log(ctx, AV_LOG_INFO, "paramchange: ");
> - dump_paramchange(ctx, &sd);
> + av_writer_printf(wr, "paramchange: ");
> + dump_paramchange(wr, &sd);
> break;
> case AV_PKT_DATA_H263_MB_INFO:
> - av_log(ctx, AV_LOG_INFO, "H.263 macroblock info");
> + av_writer_printf(wr, "H.263 macroblock info");
> break;
> case AV_PKT_DATA_REPLAYGAIN:
> - av_log(ctx, AV_LOG_INFO, "replaygain: ");
> - dump_replaygain(ctx, &sd);
> + av_writer_printf(wr, "replaygain: ");
> + dump_replaygain(wr, &sd);
> break;
> case AV_PKT_DATA_DISPLAYMATRIX:
> - av_log(ctx, AV_LOG_INFO, "displaymatrix: rotation of %.2f degrees",
> + av_writer_printf(wr, "displaymatrix: rotation of %.2f degrees",
> av_display_rotation_get((int32_t *)sd.data));
> break;
> case AV_PKT_DATA_STEREO3D:
> - av_log(ctx, AV_LOG_INFO, "stereo3d: ");
> - dump_stereo3d(ctx, &sd);
> + av_writer_printf(wr, "stereo3d: ");
> + dump_stereo3d(wr, &sd);
> break;
> case AV_PKT_DATA_AUDIO_SERVICE_TYPE:
> - av_log(ctx, AV_LOG_INFO, "audio service type: ");
> - dump_audioservicetype(ctx, &sd);
> + av_writer_printf(wr, "audio service type: ");
> + dump_audioservicetype(wr, &sd);
> break;
> case AV_PKT_DATA_QUALITY_STATS:
> - av_log(ctx, AV_LOG_INFO, "quality factor: %"PRId32", pict_type: %c",
> + av_writer_printf(wr, "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);
> + av_writer_printf(wr, "cpb: ");
> + dump_cpb(wr, &sd);
> break;
> case AV_PKT_DATA_MASTERING_DISPLAY_METADATA:
> - dump_mastering_display_metadata(ctx, &sd);
> + dump_mastering_display_metadata(wr, &sd);
> break;
> case AV_PKT_DATA_SPHERICAL:
> - av_log(ctx, AV_LOG_INFO, "spherical: ");
> - dump_spherical(ctx, st->codecpar, &sd);
> + av_writer_printf(wr, "spherical: ");
> + dump_spherical(wr, st->codecpar, &sd);
> break;
> case AV_PKT_DATA_CONTENT_LIGHT_LEVEL:
> - dump_content_light_metadata(ctx, &sd);
> + dump_content_light_metadata(wr, &sd);
> break;
> default:
> - av_log(ctx, AV_LOG_INFO,
> + av_writer_printf(wr,
> "unknown side data type %d (%d bytes)", sd.type, sd.size);
> break;
> }
>
> - av_log(ctx, AV_LOG_INFO, "\n");
> + av_writer_printf(wr, "\n");
> }
> }
>
> /* "user interface" functions */
> -static void dump_stream_format(AVFormatContext *ic, int i,
> +static void dump_stream_format(AVWriter wr,
> + AVFormatContext *ic, int i,
> int index, int is_output)
> {
> char buf[256];
> @@ -493,17 +495,17 @@ FF_ENABLE_DEPRECATION_WARNINGS
> avcodec_string(buf, sizeof(buf), avctx, is_output);
> avcodec_free_context(&avctx);
>
> - av_log(NULL, AV_LOG_INFO, " Stream #%d:%d", index, i);
> + av_writer_printf(wr, " Stream #%d:%d", index, i);
>
> /* 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);
> + av_writer_printf(wr, "[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,
> + av_writer_printf(wr, "(%s)", lang->value);
> + av_log_writer_log(wr, AV_LOG_DEBUG, ", %d, %d/%d", st->codec_info_nb_frames,
> st->time_base.num, st->time_base.den);
> - av_log(NULL, AV_LOG_INFO, ": %s", buf);
> + av_writer_printf(wr, ": %s", buf);
>
> if (st->sample_aspect_ratio.num &&
> av_cmp_q(st->sample_aspect_ratio, st->codecpar->sample_aspect_ratio)) {
> @@ -512,7 +514,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
> 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, ", SAR %d:%d DAR %d:%d",
> + av_writer_printf(wr, ", SAR %d:%d DAR %d:%d",
> st->sample_aspect_ratio.num, st->sample_aspect_ratio.den,
> display_aspect_ratio.num, display_aspect_ratio.den);
> }
> @@ -526,78 +528,80 @@ FF_DISABLE_DEPRECATION_WARNINGS
> FF_ENABLE_DEPRECATION_WARNINGS
>
> if (fps || tbr || tbn || tbc)
> - av_log(NULL, AV_LOG_INFO, "%s", separator);
> + av_writer_printf(wr, "%s", separator);
>
> if (fps)
> - print_fps(av_q2d(st->avg_frame_rate), tbr || tbn || tbc ? "fps, " : "fps");
> + print_fps(wr, 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");
> + print_fps(wr, av_q2d(st->r_frame_rate), tbn || tbc ? "tbr, " : "tbr");
> if (tbn)
> - print_fps(1 / av_q2d(st->time_base), tbc ? "tbn, " : "tbn");
> + print_fps(wr, 1 / av_q2d(st->time_base), tbc ? "tbn, " : "tbn");
> FF_DISABLE_DEPRECATION_WARNINGS
> if (tbc)
> - print_fps(1 / av_q2d(st->codec->time_base), "tbc");
> + print_fps(wr, 1 / av_q2d(st->codec->time_base), "tbc");
> FF_ENABLE_DEPRECATION_WARNINGS
> }
>
> if (st->disposition & AV_DISPOSITION_DEFAULT)
> - av_log(NULL, AV_LOG_INFO, " (default)");
> + av_writer_printf(wr, " (default)");
> if (st->disposition & AV_DISPOSITION_DUB)
> - av_log(NULL, AV_LOG_INFO, " (dub)");
> + av_writer_printf(wr, " (dub)");
> if (st->disposition & AV_DISPOSITION_ORIGINAL)
> - av_log(NULL, AV_LOG_INFO, " (original)");
> + av_writer_printf(wr, " (original)");
> if (st->disposition & AV_DISPOSITION_COMMENT)
> - av_log(NULL, AV_LOG_INFO, " (comment)");
> + av_writer_printf(wr, " (comment)");
> if (st->disposition & AV_DISPOSITION_LYRICS)
> - av_log(NULL, AV_LOG_INFO, " (lyrics)");
> + av_writer_printf(wr, " (lyrics)");
> if (st->disposition & AV_DISPOSITION_KARAOKE)
> - av_log(NULL, AV_LOG_INFO, " (karaoke)");
> + av_writer_printf(wr, " (karaoke)");
> if (st->disposition & AV_DISPOSITION_FORCED)
> - av_log(NULL, AV_LOG_INFO, " (forced)");
> + av_writer_printf(wr, " (forced)");
> if (st->disposition & AV_DISPOSITION_HEARING_IMPAIRED)
> - av_log(NULL, AV_LOG_INFO, " (hearing impaired)");
> + av_writer_printf(wr, " (hearing impaired)");
> if (st->disposition & AV_DISPOSITION_VISUAL_IMPAIRED)
> - av_log(NULL, AV_LOG_INFO, " (visual impaired)");
> + av_writer_printf(wr, " (visual impaired)");
> if (st->disposition & AV_DISPOSITION_CLEAN_EFFECTS)
> - av_log(NULL, AV_LOG_INFO, " (clean effects)");
> + av_writer_printf(wr, " (clean effects)");
> if (st->disposition & AV_DISPOSITION_ATTACHED_PIC)
> - av_log(NULL, AV_LOG_INFO, " (attached pic)");
> + av_writer_printf(wr, " (attached pic)");
> if (st->disposition & AV_DISPOSITION_TIMED_THUMBNAILS)
> - av_log(NULL, AV_LOG_INFO, " (timed thumbnails)");
> + av_writer_printf(wr, " (timed thumbnails)");
> if (st->disposition & AV_DISPOSITION_CAPTIONS)
> - av_log(NULL, AV_LOG_INFO, " (captions)");
> + av_writer_printf(wr, " (captions)");
> if (st->disposition & AV_DISPOSITION_DESCRIPTIONS)
> - av_log(NULL, AV_LOG_INFO, " (descriptions)");
> + av_writer_printf(wr, " (descriptions)");
> if (st->disposition & AV_DISPOSITION_METADATA)
> - av_log(NULL, AV_LOG_INFO, " (metadata)");
> + av_writer_printf(wr, " (metadata)");
> if (st->disposition & AV_DISPOSITION_DEPENDENT)
> - av_log(NULL, AV_LOG_INFO, " (dependent)");
> + av_writer_printf(wr, " (dependent)");
> if (st->disposition & AV_DISPOSITION_STILL_IMAGE)
> - av_log(NULL, AV_LOG_INFO, " (still image)");
> - av_log(NULL, AV_LOG_INFO, "\n");
> + av_writer_printf(wr, " (still image)");
> + av_writer_printf(wr, "\n");
>
> - dump_metadata(NULL, st->metadata, " ");
> + dump_metadata(wr, st->metadata, " ");
>
> - dump_sidedata(NULL, st, " ");
> + dump_sidedata(wr, st, " ");
> }
>
> -void av_dump_format(AVFormatContext *ic, int index,
> - const char *url, int is_output)
> +void av_dump_format_to_writer(AVWriter wr,
> + AVFormatContext *ic, int index,
> + const char *url, unsigned flags)
> {
> + int is_output = flags & AV_DUMP_FORMAT_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",
> + av_writer_printf(wr, "%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, " ");
> + dump_metadata(wr, ic->metadata, " ");
>
> if (!is_output) {
> - av_log(NULL, AV_LOG_INFO, " Duration: ");
> + av_writer_printf(wr, " Duration: ");
> if (ic->duration != AV_NOPTS_VALUE) {
> int hours, mins, secs, us;
> int64_t duration = ic->duration + (ic->duration <= INT64_MAX - 5000 ? 5000 : 0);
> @@ -607,38 +611,38 @@ void av_dump_format(AVFormatContext *ic, int index,
> secs %= 60;
> hours = mins / 60;
> mins %= 60;
> - av_log(NULL, AV_LOG_INFO, "%02d:%02d:%02d.%02d", hours, mins, secs,
> + av_writer_printf(wr, "%02d:%02d:%02d.%02d", hours, mins, secs,
> (100 * us) / AV_TIME_BASE);
> } else {
> - av_log(NULL, AV_LOG_INFO, "N/A");
> + av_writer_printf(wr, "N/A");
> }
> if (ic->start_time != AV_NOPTS_VALUE) {
> int secs, us;
> - av_log(NULL, AV_LOG_INFO, ", start: ");
> + av_writer_printf(wr, ", start: ");
> secs = llabs(ic->start_time / AV_TIME_BASE);
> us = llabs(ic->start_time % AV_TIME_BASE);
> - av_log(NULL, AV_LOG_INFO, "%s%d.%06d",
> + av_writer_printf(wr, "%s%d.%06d",
> ic->start_time >= 0 ? "" : "-",
> secs,
> (int) av_rescale(us, 1000000, AV_TIME_BASE));
> }
> - av_log(NULL, AV_LOG_INFO, ", bitrate: ");
> + av_writer_printf(wr, ", bitrate: ");
> if (ic->bit_rate)
> - av_log(NULL, AV_LOG_INFO, "%"PRId64" kb/s", ic->bit_rate / 1000);
> + av_writer_printf(wr, "%"PRId64" kb/s", ic->bit_rate / 1000);
> else
> - av_log(NULL, AV_LOG_INFO, "N/A");
> - av_log(NULL, AV_LOG_INFO, "\n");
> + av_writer_printf(wr, "N/A");
> + av_writer_printf(wr, "\n");
> }
>
> for (i = 0; i < ic->nb_chapters; i++) {
> AVChapter *ch = ic->chapters[i];
> - av_log(NULL, AV_LOG_INFO, " Chapter #%d:%d: ", index, i);
> - av_log(NULL, AV_LOG_INFO,
> + av_writer_printf(wr, " Chapter #%d:%d: ", index, i);
> + av_writer_printf(wr,
> "start %f, ", ch->start * av_q2d(ch->time_base));
> - av_log(NULL, AV_LOG_INFO,
> + av_writer_printf(wr,
> "end %f\n", ch->end * av_q2d(ch->time_base));
>
> - dump_metadata(NULL, ch->metadata, " ");
> + dump_metadata(wr, ch->metadata, " ");
> }
>
> if (ic->nb_programs) {
> @@ -646,23 +650,30 @@ void av_dump_format(AVFormatContext *ic, int index,
> 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,
> + av_writer_printf(wr, " Program %d %s\n", ic->programs[j]->id,
> name ? name->value : "");
> - dump_metadata(NULL, ic->programs[j]->metadata, " ");
> + dump_metadata(wr, 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],
> + dump_stream_format(wr, 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");
> + av_writer_printf(wr, " No Program\n");
> }
>
> for (i = 0; i < ic->nb_streams; i++)
> if (!printed[i])
> - dump_stream_format(ic, i, index, is_output);
> + dump_stream_format(wr, ic, i, index, is_output);
>
> av_free(printed);
> }
> +
> +void av_dump_format(AVFormatContext *ic, int index,
> + const char *url, int is_output)
> +{
> + av_dump_format_to_writer(av_log_writer(NULL), ic, index, url,
> + is_output ? AV_DUMP_FORMAT_IS_OUTPUT : 0);
> +}
> --
> 2.24.0
>
George,
The 3/3 patch fails to apply with git:
https://unofficial.patchwork-ffmpeg.org/project/FFmpeg/list/?series=68
--
Andriy
More information about the ffmpeg-devel
mailing list