[FFmpeg-devel] [PATCH] Make the process for uuid-xmp data faster

Chen Meng mengchen.mc at alibaba-inc.com
Wed Nov 9 11:30:57 EET 2016


---
 libavformat/mov.c | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index ca978c2..c358d17 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -4530,24 +4530,30 @@ static int mov_read_uuid(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     } else if (!memcmp(uuid, uuid_xmp, sizeof(uuid))) {
         uint8_t *buffer;
         size_t len = atom.size - sizeof(uuid);
-
-        buffer = av_mallocz(len + 1);
-        if (!buffer) {
-            return AVERROR(ENOMEM);
-        }
-        ret = avio_read(pb, buffer, len);
-        if (ret < 0) {
-            av_free(buffer);
-            return ret;
-        } else if (ret != len) {
-            av_free(buffer);
-            return AVERROR_INVALIDDATA;
-        }
+        
         if (c->export_xmp) {
+            buffer = av_mallocz(len + 1);
+            if (!buffer) {
+                return AVERROR(ENOMEM);
+            }
+            ret = avio_read(pb, buffer, len);
+            if (ret < 0) {
+                av_free(buffer);
+                return ret;
+            } else if (ret != len) {
+                av_free(buffer);
+                return AVERROR_INVALIDDATA;
+            }
             buffer[len] = '\0';
             av_dict_set(&c->fc->metadata, "xmp", buffer, 0);
+            av_free(buffer);
+        } else {
+            // skip all uuid atom, which makes it fast for long uuid-xmp file
+
+            ret = avio_seek(pb, len, SEEK_CUR);
+            if (ret < 0)
+                return ret;
         }
-        av_free(buffer);
     }
     return 0;
 }
-- 
2.10.2



More information about the ffmpeg-devel mailing list