[FFmpeg-devel] [PATCH v3 09/25] avcodec/metaenc, metadec: added an encoder/decoder for timed metadata

Erkki Seppälä erkki.seppala.ext at nokia.com
Mon Sep 19 16:25:32 EEST 2016


It has the codec id AV_CODEC_ID_META and type of AVMEDIA_TYPE_DATA.

This codec basically passes the data forward and is used for referring
timed meta data tracks by a codec. It is useful for dealing with the
metadata in a similar way as other kinds of codecs.

Signed-off-by: Erkki Seppälä <erkki.seppala.ext at nokia.com>
Signed-off-by: OZOPlayer <OZOPL at nokia.com>
---
 configure               |  4 ++--
 libavcodec/Makefile     |  2 ++
 libavcodec/allcodecs.c  |  3 +++
 libavcodec/avcodec.h    |  1 +
 libavcodec/codec_desc.c |  8 +++++++
 libavcodec/metadec.c    | 59 +++++++++++++++++++++++++++++++++++++++++++++++++
 libavcodec/metaenc.c    | 58 ++++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 133 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/metadec.c
 create mode 100644 libavcodec/metaenc.c

diff --git a/configure b/configure
index 9b92426..ded5452 100755
--- a/configure
+++ b/configure
@@ -2848,11 +2848,11 @@ matroska_demuxer_select="iso_media riffdec"
 matroska_demuxer_suggest="bzlib lzo zlib"
 matroska_muxer_select="iso_media riffenc"
 mmf_muxer_select="riffenc"
-mov_demuxer_select="iso_media riffdec"
+mov_demuxer_select="iso_media riffdec meta_decoder"
 mov_demuxer_suggest="zlib"
 mov_muxer_select="iso_media riffenc rtpenc_chain"
 mp3_demuxer_select="mpegaudio_parser"
-mp4_muxer_select="mov_muxer"
+mp4_muxer_select="mov_muxer meta_encoder"
 mpegts_demuxer_select="iso_media"
 mpegts_muxer_select="adts_muxer latm_muxer"
 mpegtsraw_demuxer_select="mpegts_demuxer"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index a6e79ce..534f201 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -757,6 +757,8 @@ OBJS-$(CONFIG_ADPCM_VIMA_DECODER)         += vima.o adpcm_data.o
 OBJS-$(CONFIG_ADPCM_XA_DECODER)           += adpcm.o adpcm_data.o
 OBJS-$(CONFIG_ADPCM_YAMAHA_DECODER)       += adpcm.o adpcm_data.o
 OBJS-$(CONFIG_ADPCM_YAMAHA_ENCODER)       += adpcmenc.o adpcm_data.o
+OBJS-$(CONFIG_META_ENCODER)               += metaenc.o
+OBJS-$(CONFIG_META_DECODER)               += metadec.o
 
 # hardware accelerators
 OBJS-$(CONFIG_D3D11VA)                    += dxva2.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 4c6b94e..30d0243 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -687,4 +687,7 @@ void avcodec_register_all(void)
     REGISTER_PARSER(VP3,                vp3);
     REGISTER_PARSER(VP8,                vp8);
     REGISTER_PARSER(VP9,                vp9);
+
+    /* data, meta data */
+    REGISTER_ENCDEC(META,               meta);
 }
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 3be54d4..4219a9f 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -639,6 +639,7 @@ enum AVCodecID {
     AV_CODEC_ID_DVD_NAV,
     AV_CODEC_ID_TIMED_ID3,
     AV_CODEC_ID_BIN_DATA,
+    AV_CODEC_ID_META,
 
 
     AV_CODEC_ID_PROBE = 0x19000, ///< codec_id is not known (like AV_CODEC_ID_NONE) but lavf should attempt to identify it
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 24948ca..e85b51d 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -2965,6 +2965,14 @@ static const AVCodecDescriptor codec_descriptors[] = {
         .mime_types= MT("application/octet-stream"),
     },
 
+    {
+        .id        = AV_CODEC_ID_META,
+        .type      = AVMEDIA_TYPE_DATA,
+        .name      = "meta_data",
+        .long_name = NULL_IF_CONFIG_SMALL("binary data"),
+        .mime_types= MT("application/octet-stream"),
+    },
+
     /* deprecated codec ids */
 };
 
diff --git a/libavcodec/metadec.c b/libavcodec/metadec.c
new file mode 100644
index 0000000..2c1d461
--- /dev/null
+++ b/libavcodec/metadec.c
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2015-2016 Erkki Seppälä <erkki.seppala.ext at nokia.com>
+ *
+ * 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 "internal.h"
+#include "libavformat/avio.h"
+
+static int meta_decode(AVCodecContext *avctx, void *data, int *got_packet_ptr, AVPacket *avpkt)
+{
+    AVFrame *metadata = data;
+
+    *got_packet_ptr = 0;
+
+    av_frame_unref(metadata);
+    if (avpkt->buf) {
+        metadata->buf[0] = av_buffer_ref(avpkt->buf);
+        if (!metadata->buf[0])
+            return AVERROR(ENOMEM);
+        metadata->buf[0]->size = avpkt->size;
+    } else {
+        metadata->buf[0] = av_buffer_alloc(avpkt->size);
+        if (!metadata->buf[0])
+            return AVERROR(ENOMEM);
+        metadata->data[0] = metadata->buf[0]->data;
+        memcpy(metadata->data[0], avpkt->data, avpkt->size);
+    }
+
+    metadata->nb_samples = avpkt->size;
+    metadata->pts = avpkt->pts;
+    metadata->pkt_pts = avpkt->pts;
+    metadata->pkt_dts = avpkt->dts;
+    *got_packet_ptr = 1;
+
+    return 0;
+}
+
+AVCodec ff_meta_decoder = {
+    .name           = "meta",
+    .long_name      = NULL_IF_CONFIG_SMALL("Timed Metadata Decoder"),
+    .type           = AVMEDIA_TYPE_DATA,
+    .id             = AV_CODEC_ID_META,
+    .decode         = meta_decode,
+};
diff --git a/libavcodec/metaenc.c b/libavcodec/metaenc.c
new file mode 100644
index 0000000..58c9c39
--- /dev/null
+++ b/libavcodec/metaenc.c
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2015 Erkki Seppälä <erkki.seppala.ext at nokia.com>
+ *
+ * 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/intreadwrite.h"
+#include "internal.h"
+#include "libavutil/opt.h"
+#include "libavformat/avio.h"
+
+static int meta_encode(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame,
+                           int *got_packet_ptr)
+{
+    *got_packet_ptr = 0;
+
+    av_packet_unref(avpkt);
+    if (frame->buf) {
+        avpkt->buf = av_buffer_ref(frame->buf[0]);
+        if (!avpkt->buf)
+          return AVERROR(ENOMEM);
+        avpkt->data = frame->data[0];
+    } else {
+        avpkt->buf = av_buffer_alloc(frame->nb_samples);
+        if (!avpkt->buf)
+          return AVERROR(ENOMEM);
+        avpkt->data = avpkt->buf->data;
+        memcpy(avpkt->data, frame->data[0], frame->nb_samples);
+    }
+    avpkt->size = frame->nb_samples;
+    avpkt->pts = frame->pts;
+    avpkt->dts = frame->pts;
+    *got_packet_ptr = 1;
+
+    return 0;
+}
+
+AVCodec ff_meta_encoder = {
+    .name           = "meta",
+    .long_name      = NULL_IF_CONFIG_SMALL("Timed Metadata Encoder"),
+    .type           = AVMEDIA_TYPE_DATA,
+    .id             = AV_CODEC_ID_META,
+    .encode2        = meta_encode,
+};
-- 
2.7.4



More information about the ffmpeg-devel mailing list