[FFmpeg-devel] [PATCH] avformat: add dump_metadata_lines
Vittorio Giovara
vittorio.giovara at gmail.com
Wed Dec 10 03:17:31 CET 2014
On Tue, Dec 9, 2014 at 10:17 PM, wm4 <nfxjfg at googlemail.com> wrote:
> On Tue, 9 Dec 2014 14:10:22 +0100
> Michael Niedermayer <michaelni at gmx.at> wrote:
>
>> TODO: bump version, update APIChanges
>>
>> Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
>> ---
>> libavformat/avformat.h | 8 ++++++++
>> libavformat/dump.c | 24 ++++++++++++++++++------
>> libavformat/options_table.h | 1 +
>> 3 files changed, 27 insertions(+), 6 deletions(-)
>>
>> diff --git a/libavformat/avformat.h b/libavformat/avformat.h
>> index 2e54ed1..cbe3608 100644
>> --- a/libavformat/avformat.h
>> +++ b/libavformat/avformat.h
>> @@ -1616,6 +1616,14 @@ typedef struct AVFormatContext {
>> */
>> char *format_whitelist;
>>
>> + /**
>> + * Maximum number of lines per metadata tag to dump with av_log.
>> + * -1 means default
>> + * - encoding: unused
>> + * - decoding: set by user through AVOptions (NO direct access)
>> + */
>> + int dump_metadata_lines;
>> +
>> /*****************************************************************
>> * All fields below this line are not part of the public API. They
>> * may not be used outside of libavformat and can be changed and
>> diff --git a/libavformat/dump.c b/libavformat/dump.c
>> index 56b37ff..38286b8 100644
>> --- a/libavformat/dump.c
>> +++ b/libavformat/dump.c
>> @@ -126,7 +126,7 @@ static void print_fps(double d, const char *postfix)
>> av_log(NULL, AV_LOG_INFO, "%1.0fk %s", d / 1000, postfix);
>> }
>>
>> -static void dump_metadata(void *ctx, AVDictionary *m, const char *indent)
>> +static void dump_metadata(void *ctx, AVDictionary *m, const char *indent, int dump_metadata_lines_arg)
>> {
>> if (m && !(av_dict_count(m) == 1 && av_dict_get(m, "language", NULL, 0))) {
>> AVDictionaryEntry *tag = NULL;
>> @@ -135,16 +135,28 @@ static void dump_metadata(void *ctx, AVDictionary *m, const char *indent)
>> while ((tag = av_dict_get(m, "", tag, AV_DICT_IGNORE_SUFFIX)))
>> if (strcmp("language", tag->key)) {
>> const char *p = tag->value;
>> + int lines = 0;
>> + int dump_metadata_lines = dump_metadata_lines_arg;
>> + if (dump_metadata_lines == -1) {
>> + dump_metadata_lines = strcmp("comment", tag->key) ? 1 : 25;
>> + }
>> av_log(ctx, AV_LOG_INFO,
>> "%s %-16s: ", indent, tag->key);
>> while (*p) {
>> char tmp[256];
>> size_t len = strcspn(p, "\x8\xa\xb\xc\xd");
>> + if (lines >= dump_metadata_lines) {
>> + av_log(ctx, AV_LOG_INFO, "[%"SIZE_SPECIFIER" bytes ommited, use \'-dump_metadata_lines <max>\' to see more]", strlen(p));
>> + break;
>> + }
>> 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 == 0xa) {
>> + av_log(ctx, AV_LOG_INFO, "\n%s %-16s: ", indent, "");
>> + lines++;
>> + }
>> if (*p) p++;
>> }
>> av_log(ctx, AV_LOG_INFO, "\n");
>> @@ -420,7 +432,7 @@ static void dump_stream_format(AVFormatContext *ic, int i,
>> av_log(NULL, AV_LOG_INFO, " (clean effects)");
>> av_log(NULL, AV_LOG_INFO, "\n");
>>
>> - dump_metadata(NULL, st->metadata, " ");
>> + dump_metadata(NULL, st->metadata, " ", ic->dump_metadata_lines);
>>
>> dump_sidedata(NULL, st, " ");
>> }
>> @@ -438,7 +450,7 @@ void av_dump_format(AVFormatContext *ic, int index,
>> index,
>> is_output ? ic->oformat->name : ic->iformat->name,
>> is_output ? "to" : "from", url);
>> - dump_metadata(NULL, ic->metadata, " ");
>> + dump_metadata(NULL, ic->metadata, " ", ic->dump_metadata_lines);
>>
>> if (!is_output) {
>> av_log(NULL, AV_LOG_INFO, " Duration: ");
>> @@ -480,7 +492,7 @@ void av_dump_format(AVFormatContext *ic, int index,
>> av_log(NULL, AV_LOG_INFO,
>> "end %f\n", ch->end * av_q2d(ch->time_base));
>>
>> - dump_metadata(NULL, ch->metadata, " ");
>> + dump_metadata(NULL, ch->metadata, " ", ic->dump_metadata_lines);
>> }
>>
>> if (ic->nb_programs) {
>> @@ -490,7 +502,7 @@ void av_dump_format(AVFormatContext *ic, int index,
>> "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, " ");
>> + dump_metadata(NULL, ic->programs[j]->metadata, " ", ic->dump_metadata_lines);
>> for (k = 0; k < ic->programs[j]->nb_stream_indexes; k++) {
>> dump_stream_format(ic, ic->programs[j]->stream_index[k],
>> index, is_output);
>> diff --git a/libavformat/options_table.h b/libavformat/options_table.h
>> index 40f1e0a..75ddf9c 100644
>> --- a/libavformat/options_table.h
>> +++ b/libavformat/options_table.h
>> @@ -99,6 +99,7 @@ static const AVOption avformat_options[] = {
>> {"dump_separator", "set information dump field separator", OFFSET(dump_separator), AV_OPT_TYPE_STRING, {.str = ", "}, CHAR_MIN, CHAR_MAX, D|E},
>> {"codec_whitelist", "List of decoders that are allowed to be used", OFFSET(codec_whitelist), AV_OPT_TYPE_STRING, { .str = NULL }, CHAR_MIN, CHAR_MAX, D },
>> {"format_whitelist", "List of demuxers that are allowed to be used", OFFSET(format_whitelist), AV_OPT_TYPE_STRING, { .str = NULL }, CHAR_MIN, CHAR_MAX, D },
>> +{"dump_metadata_lines", "Maximum number of lines per metadata tag to dump with av_log", OFFSET(dump_metadata_lines), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, D },
>> {NULL},
>> };
>>
>
> Stuff liken this doesn't belong in a library. /nag
+1
--
Vittorio
More information about the ffmpeg-devel
mailing list