[libav-devel] [PATCH] Set protocol-level metadata in AVFormatContext any time a packet is read.

Andrew Stone andrew at clovar.com
Fri Jun 13 19:33:21 CEST 2014

If any option named "metadata" is set inside the context, it is pulled up to
the context and then the option is cleared.

Rather than maintaining a list of metadata changes and presenting them to
an application, the application must poll the metadata it's interested in
by using av_dict_version(). Typically, since this data is only used for
display, there's no need to track what actually changes as updating displayed
metadata with identical information should be acceptable.

As promised, here is the patch, stripped to the core and only updating metadata it sees
set as an option.

 libavformat/utils.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index de66c6b..ccd5d66 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1027,6 +1027,7 @@ static int read_from_packet_buffer(AVPacketList **pkt_buffer,
 static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
     int ret = 0, i, got_packet = 0;
+    AVDictionary *metadata = NULL;


@@ -1102,6 +1103,13 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
     if (!got_packet && s->parse_queue)
         ret = read_from_packet_buffer(&s->parse_queue, &s->parse_queue_end, pkt);

+    av_opt_get_dict_val(s, "metadata", AV_OPT_SEARCH_CHILDREN, &metadata);
+    if (metadata) {
+        av_dict_copy(&s->metadata, metadata, 0);
+        av_dict_free(&metadata);
+        av_opt_set_dict_val(s, "metadata", NULL, AV_OPT_SEARCH_CHILDREN);
+    }
     if (s->debug & FF_FDEBUG_TS)
         av_log(s, AV_LOG_DEBUG,
                "read_frame_internal stream=%d, pts=%"PRId64", dts=%"PRId64", "

More information about the libav-devel mailing list