Some muxers produce mp4s with a udta (user data) atom nested within a
trak atom. The nested udta atoms typically contain stream information
such as the title. ffmpeg should treat nested udta atoms as applicable
to the stream instead of globally.

Signed-off-by: Nik Johnson <n...@nikjohnson.net>
---
 libavformat/mov.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index f2a540ad50..b434802207 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -306,6 +306,8 @@ static int mov_read_udta_string(MOVContext *c, AVIOContext 
*pb, MOVAtom atom)
     int (*parse)(MOVContext*, AVIOContext*, unsigned, const char*) = NULL;
     int raw = 0;
     int num = 0;
+    AVStream *st;
+    AVDictionary **metadata;
 
     switch (atom.type) {
     case MKTAG( '@','P','R','M'): key = "premiere_version"; raw = 1; break;
@@ -514,12 +516,23 @@ retry:
             }
             str[str_size] = 0;
         }
-        c->fc->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED;
-        av_dict_set(&c->fc->metadata, key, str, 0);
+
+        // A udta atom may occur inside a trak atom when specifying trak
+        // specific user data. For example, some muxers define a trak name.
+        if (c->fc->nb_streams > 0 && c->trak_index != -1) {
+            st = c->fc->streams[c->fc->nb_streams-1];
+            st->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED;
+            metadata = &st->metadata;
+        } else {
+            c->fc->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED;
+            metadata = &c->fc->metadata;
+        }
+        av_dict_set(metadata, key, str, 0);
         if (*language && strcmp(language, "und")) {
             snprintf(key2, sizeof(key2), "%s-%s", key, language);
-            av_dict_set(&c->fc->metadata, key2, str, 0);
+            av_dict_set(metadata, key2, str, 0);
         }
+
         if (!strcmp(key, "encoder")) {
             int major, minor, micro;
             if (sscanf(str, "HandBrake %d.%d.%d", &major, &minor, &micro) == 
3) {
-- 
2.17.0.windows.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to