From a119c64e38bd9bfc5c3c94b70b321619c6fabac9 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 16 Oct 2012 09:53:39 +0200 Subject: [PATCH 1/2] avconv: fix disabling auto mappings with -map_metadata CC: libav-stable@libav.org --- avconv_opt.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/avconv_opt.c b/avconv_opt.c index 058d5a3779..79444eb6f3 100644 --- a/avconv_opt.c +++ b/avconv_opt.c @@ -326,6 +326,10 @@ static int copy_metadata(char *outspec, char *inspec, AVFormatContext *oc, AVFor if (type_in == 'c' || type_out == 'c') o->metadata_chapters_manual = 1; + /* ic is NULL when just disabling automatic mappings */ + if (!ic) + return 0; + #define METADATA_CHECK_INDEX(index, nb_elems, desc)\ if ((index) < 0 || (index) >= (nb_elems)) {\ av_log(NULL, AV_LOG_FATAL, "Invalid %s index %d while processing metadata maps.\n",\ @@ -1410,13 +1414,13 @@ loop_end: char *p; int in_file_index = strtol(o->metadata_map[i].u.str, &p, 0); - if (in_file_index < 0) - continue; if (in_file_index >= nb_input_files) { av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d while processing metadata maps\n", in_file_index); exit(1); } - copy_metadata(o->metadata_map[i].specifier, *p ? p + 1 : p, oc, input_files[in_file_index]->ctx, o); + copy_metadata(o->metadata_map[i].specifier, *p ? p + 1 : p, oc, + in_file_index >= 0 ? + input_files[in_file_index]->ctx : NULL, o); } /* copy chapters */ From 71e92414bfd79e56ea6fff174a665ff7b9b86e68 Mon Sep 17 00:00:00 2001 From: Victor Vasiliev Date: Fri, 25 Nov 2011 23:29:12 +0400 Subject: [PATCH 2/2] lavf: move RIFF INFO tag writing from avienc to riff It will be useful in the wav muxer. Signed-off-by: Anton Khirnov --- libavformat/avienc.c | 24 ++---------------------- libavformat/riff.c | 32 +++++++++++++++++++++++++++++++- libavformat/riff.h | 12 +++++++++++- 3 files changed, 44 insertions(+), 24 deletions(-) diff --git a/libavformat/avienc.c b/libavformat/avienc.c index fa6321200e..9d1f5102a1 100644 --- a/libavformat/avienc.c +++ b/libavformat/avienc.c @@ -105,19 +105,6 @@ static char* avi_stream2fourcc(char* tag, int index, enum AVMediaType type) return tag; } -static void avi_write_info_tag(AVIOContext *pb, const char *tag, const char *str) -{ - int len = strlen(str); - if (len > 0) { - len++; - ffio_wfourcc(pb, tag); - avio_wl32(pb, len); - avio_put_str(pb, str); - if (len & 1) - avio_w8(pb, 0); - } -} - static int avi_write_counters(AVFormatContext* s, int riff_id) { AVIOContext *pb = s->pb; @@ -300,7 +287,7 @@ static int avi_write_header(AVFormatContext *s) } ff_end_tag(pb, strf); if ((t = av_dict_get(s->streams[i]->metadata, "title", NULL, 0))) { - avi_write_info_tag(s->pb, "strn", t->value); + ff_riff_write_info_tag(s->pb, "strn", t->value); t = NULL; } } @@ -377,14 +364,7 @@ static int avi_write_header(AVFormatContext *s) ff_end_tag(pb, list1); - list2 = ff_start_tag(pb, "LIST"); - ffio_wfourcc(pb, "INFO"); - ff_metadata_conv(&s->metadata, ff_riff_info_conv, NULL); - for (i = 0; *ff_riff_tags[i]; i++) { - if ((t = av_dict_get(s->metadata, ff_riff_tags[i], NULL, AV_DICT_MATCH_CASE))) - avi_write_info_tag(s->pb, t->key, t->value); - } - ff_end_tag(pb, list2); + ff_riff_write_info(s); /* some padding for easier tag editing */ list2 = ff_start_tag(pb, "JUNK"); diff --git a/libavformat/riff.c b/libavformat/riff.c index 2539b23134..3d805d8884 100644 --- a/libavformat/riff.c +++ b/libavformat/riff.c @@ -1,5 +1,5 @@ /* - * RIFF codec tags + * RIFF common functions and data * Copyright (c) 2000 Fabrice Bellard * * This file is part of Libav. @@ -708,3 +708,33 @@ int ff_read_riff_info(AVFormatContext *s, int64_t size) return 0; } + +void ff_riff_write_info_tag(AVIOContext *pb, const char *tag, const char *str) +{ + int len = strlen(str); + if (len > 0) { + len++; + ffio_wfourcc(pb, tag); + avio_wl32(pb, len); + avio_put_str(pb, str); + if (len & 1) + avio_w8(pb, 0); + } +} + +void ff_riff_write_info(AVFormatContext *s) +{ + AVIOContext *pb = s->pb; + int i; + int64_t list_pos; + AVDictionaryEntry *t = NULL; + + list_pos = ff_start_tag(pb, "LIST"); + ffio_wfourcc(pb, "INFO"); + ff_metadata_conv(&s->metadata, ff_riff_info_conv, NULL); + for (i = 0; *ff_riff_tags[i]; i++) { + if ((t = av_dict_get(s->metadata, ff_riff_tags[i], NULL, AV_DICT_MATCH_CASE))) + ff_riff_write_info_tag(s->pb, t->key, t->value); + } + ff_end_tag(pb, list_pos); +} diff --git a/libavformat/riff.h b/libavformat/riff.h index 42a28d17c9..167d8fc49b 100644 --- a/libavformat/riff.h +++ b/libavformat/riff.h @@ -1,5 +1,5 @@ /* - * RIFF codec tags + * RIFF common functions and data * copyright (c) 2000 Fabrice Bellard * * This file is part of Libav. @@ -60,4 +60,14 @@ void ff_parse_specific_params(AVCodecContext *stream, int *au_rate, int *au_ssiz int ff_read_riff_info(AVFormatContext *s, int64_t size); +/** + * Write all recognized RIFF tags from s->metadata + */ +void ff_riff_write_info(AVFormatContext *s); + +/** + * Write a single RIFF info tag + */ +void ff_riff_write_info_tag(AVIOContext *pb, const char *tag, const char *str); + #endif /* AVFORMAT_RIFF_H */