aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2012-02-08 23:58:17 +0000
committerPaul B Mahol <onemda@gmail.com>2012-07-29 01:28:12 +0000
commitbd93f96540f225b88f42eb25b464defb88d1fb7c (patch)
tree1a53160a6c4a66cde719b3a73990a2086efa2d4a /libavformat
parenta3a0774be823ba218f494d3a78de546599d600e2 (diff)
downloadffmpeg-bd93f96540f225b88f42eb25b464defb88d1fb7c.tar.gz
APE tag writer
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/Makefile2
-rw-r--r--libavformat/apetag.h5
-rw-r--r--libavformat/apetagenc.c69
3 files changed, 75 insertions, 1 deletions
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 6b88d908ff..d77c9ea5eb 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -357,7 +357,7 @@ OBJS-$(CONFIG_WTV_DEMUXER) += wtvdec.o wtv.o asfdec.o asf.o asfcry
avlanguage.o mpegts.o isom.o
OBJS-$(CONFIG_WTV_MUXER) += wtvenc.o wtv.o asf.o asfenc.o
OBJS-$(CONFIG_WV_DEMUXER) += wv.o apetag.o img2.o
-OBJS-$(CONFIG_WV_MUXER) += wvenc.o
+OBJS-$(CONFIG_WV_MUXER) += wvenc.o apetagenc.o
OBJS-$(CONFIG_XA_DEMUXER) += xa.o
OBJS-$(CONFIG_XBIN_DEMUXER) += bintext.o sauce.o
OBJS-$(CONFIG_XMV_DEMUXER) += xmv.o
diff --git a/libavformat/apetag.h b/libavformat/apetag.h
index 869fc4b3c0..7727921ca8 100644
--- a/libavformat/apetag.h
+++ b/libavformat/apetag.h
@@ -30,4 +30,9 @@
*/
void ff_ape_parse_tag(AVFormatContext *s);
+/**
+ * Write an APEv2 tag
+ */
+void ff_ape_write(AVFormatContext *s);
+
#endif /* AVFORMAT_APETAG_H */
diff --git a/libavformat/apetagenc.c b/libavformat/apetagenc.c
new file mode 100644
index 0000000000..3fbcad1e13
--- /dev/null
+++ b/libavformat/apetagenc.c
@@ -0,0 +1,69 @@
+/*
+ * APE tag writer
+ * Copyright (c) 2012 Paul B Mahol
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * 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.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * 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
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/dict.h"
+#include "avio_internal.h"
+#include "avformat.h"
+#include "apetag.h"
+
+#define APE_TAG_PREAMBLE "APETAGEX"
+#define APE_TAG_VERSION 2000
+#define APE_TAG_FOOTER_BYTES 32
+
+static int string_is_ascii(const uint8_t *str)
+{
+ while (*str && *str >= 0x20 && *str <= 0x7e ) str++;
+ return !*str;
+}
+
+void ff_ape_write(AVFormatContext *s)
+{
+ int64_t tag_bytes;
+ AVDictionaryEntry *t = NULL;
+ AVIOContext *pb = s->pb;
+ int tags = 0, vlen;
+
+ tag_bytes = avio_tell(s->pb);
+ while ((t = av_dict_get(s->metadata, "", t, AV_DICT_IGNORE_SUFFIX))) {
+ if (!string_is_ascii(t->key)) {
+ av_log(s, AV_LOG_WARNING, "Non ASCII keys are not allowed\n");
+ continue;
+ }
+
+ vlen = strlen(t->value);
+ avio_wl32(pb, vlen + 1);
+ avio_wl32(pb, 0); // flags
+ avio_put_str(pb, t->key);
+ avio_put_str(pb, t->value);
+ tags++;
+ }
+ tag_bytes = avio_tell(s->pb) - tag_bytes;
+
+ if (!tags)
+ return;
+
+ avio_write(pb, APE_TAG_PREAMBLE, 8);
+ avio_wl32(pb, APE_TAG_VERSION);
+ avio_wl32(pb, tag_bytes + APE_TAG_FOOTER_BYTES);
+ avio_wl32(pb, tags); // item count
+ avio_wl32(pb, 0); // global flags
+ ffio_fill(pb, 0, 8); // reserved
+}