[FFmpeg-devel] [PATCH 5/5] mp3enc: support for id3v2.3 tags using a per-muxer AVOption
Anton Khirnov
anton
Fri Jan 21 14:53:49 CET 2011
fixes issue2562.
---
libavformat/mp3enc.c | 39 ++++++++++++++++++++++++++++++++++-----
1 files changed, 34 insertions(+), 5 deletions(-)
diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c
index edd6619..b2681b4 100644
--- a/libavformat/mp3enc.c
+++ b/libavformat/mp3enc.c
@@ -24,6 +24,7 @@
#include "id3v1.h"
#include "id3v2.h"
#include "libavutil/intreadwrite.h"
+#include "libavutil/opt.h"
static int id3v1_set_string(AVFormatContext *s, const char *key,
uint8_t *buf, int buf_size)
@@ -142,6 +143,24 @@ AVOutputFormat mp2_muxer = {
#endif
#if CONFIG_MP3_MUXER
+typedef struct MP3Context {
+ const AVClass *class;
+ int id3v2_version;
+} MP3Context;
+
+static const AVOption options[] = {
+ { "id3v2_version", "Select ID3v2 version to write. Currently 3 and 4 are supported.",
+ offsetof(MP3Context, id3v2_version), FF_OPT_TYPE_INT, 4, 3, 4, AV_OPT_FLAG_ENCODING_PARAM},
+ { NULL },
+};
+
+static const AVClass mp3_muxer_class = {
+ "MP3 muxer",
+ av_default_item_name,
+ options,
+ LIBAVUTIL_VERSION_INT,
+};
+
static int id3v2_check_write_tag(AVFormatContext *s, AVMetadataTag *t, const char table[][4])
{
uint32_t tag;
@@ -157,16 +176,17 @@ static int id3v2_check_write_tag(AVFormatContext *s, AVMetadataTag *t, const cha
}
/**
- * Write an ID3v2.4 header at beginning of stream
+ * Write an ID3v2 header at beginning of stream
*/
static int mp3_write_header(struct AVFormatContext *s)
{
+ MP3Context *mp3 = s->priv_data;
AVMetadataTag *t = NULL;
int totlen = 0;
int64_t size_pos, cur_pos;
- put_be32(s->pb, MKBETAG('I', 'D', '3', 0x04)); /* ID3v2.4 */
+ put_be32(s->pb, MKBETAG('I', 'D', '3', mp3->id3v2_version));
put_byte(s->pb, 0);
put_byte(s->pb, 0); /* flags */
@@ -175,7 +195,9 @@ static int mp3_write_header(struct AVFormatContext *s)
put_be32(s->pb, 0);
ff_metadata_conv(&s->metadata, ff_id3v2_34_metadata_conv, NULL);
- ff_metadata_conv(&s->metadata, ff_id3v2_4_metadata_conv, NULL);
+ if (mp3->id3v2_version == 4)
+ ff_metadata_conv(&s->metadata, ff_id3v2_4_metadata_conv, NULL);
+
while ((t = av_metadata_get(s->metadata, "", t, AV_METADATA_IGNORE_SUFFIX))) {
int ret;
@@ -183,7 +205,13 @@ static int mp3_write_header(struct AVFormatContext *s)
totlen += ret;
continue;
}
- if ((ret = id3v2_check_write_tag(s, t, ff_id3v2_4_tags)) > 0) {
+ if (mp3->id3v2_version == 4 &&
+ (ret = id3v2_check_write_tag(s, t, ff_id3v2_4_tags)) > 0) {
+ totlen += ret;
+ continue;
+ }
+ if (mp3->id3v2_version == 3 &&
+ (ret = id3v2_check_write_tag(s, t, ff_id3v2_3_tags)) > 0) {
totlen += ret;
continue;
}
@@ -205,12 +233,13 @@ AVOutputFormat mp3_muxer = {
NULL_IF_CONFIG_SMALL("MPEG audio layer 3"),
"audio/x-mpeg",
"mp3",
- 0,
+ sizeof(MP3Context),
CODEC_ID_MP3,
CODEC_ID_NONE,
mp3_write_header,
mp3_write_packet,
mp3_write_trailer,
AVFMT_NOTIMESTAMPS,
+ .priv_class = &mp3_muxer_class,
};
#endif
--
1.7.2.3
More information about the ffmpeg-devel
mailing list