[FFmpeg-devel] [PATCHv2 2/3] avformat: factorize iso 8601 timestamp writer to a dictionary avutil function

Marton Balint cus at passwd.hu
Sun Jul 3 00:10:35 CEST 2016


Signed-off-by: Marton Balint <cus at passwd.hu>
---
 libavformat/internal.h |  1 +
 libavformat/utils.c    | 16 ++--------------
 libavutil/dict.c       | 17 +++++++++++++++++
 libavutil/internal.h   | 10 ++++++++++
 4 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/libavformat/internal.h b/libavformat/internal.h
index 647ad65..3ec4b0c 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -24,6 +24,7 @@
 #include <stdint.h>
 
 #include "libavutil/bprint.h"
+#include "libavutil/internal.h"
 #include "avformat.h"
 #include "os_support.h"
 
diff --git a/libavformat/utils.c b/libavformat/utils.c
index d2a709c..0993bf9 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -5140,20 +5140,8 @@ int ff_standardize_creation_time(AVFormatContext *s)
 {
     int64_t timestamp;
     int ret = ff_parse_creation_time_metadata(s, &timestamp, 0);
-    if (ret == 1) {
-        time_t seconds = timestamp / 1000000;
-        struct tm *ptm, tmbuf;
-        ptm = gmtime_r(&seconds, &tmbuf);
-        if (ptm) {
-            char buf[32];
-            if (!strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S", ptm))
-                return AVERROR_EXTERNAL;
-            av_strlcatf(buf, sizeof(buf), ".%06dZ", (int)(timestamp % 1000000));
-            av_dict_set(&s->metadata, "creation_time", buf, 0);
-        } else {
-            return AVERROR_EXTERNAL;
-        }
-    }
+    if (ret == 1)
+        return avpriv_dict_set_timestamp(&s->metadata, "creation_time", timestamp);
     return ret;
 }
 
diff --git a/libavutil/dict.c b/libavutil/dict.c
index f70c7e0..0ea7138 100644
--- a/libavutil/dict.c
+++ b/libavutil/dict.c
@@ -24,6 +24,7 @@
 #include "dict.h"
 #include "internal.h"
 #include "mem.h"
+#include "time_internal.h"
 #include "bprint.h"
 
 struct AVDictionary {
@@ -253,3 +254,19 @@ int av_dict_get_string(const AVDictionary *m, char **buffer,
     }
     return av_bprint_finalize(&bprint, buffer);
 }
+
+int avpriv_dict_set_timestamp(AVDictionary **dict, const char *key, int64_t timestamp)
+{
+    time_t seconds = timestamp / 1000000;
+    struct tm *ptm, tmbuf;
+    ptm = gmtime_r(&seconds, &tmbuf);
+    if (ptm) {
+        char buf[32];
+        if (!strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S", ptm))
+            return AVERROR_EXTERNAL;
+        av_strlcatf(buf, sizeof(buf), ".%06dZ", (int)(timestamp % 1000000));
+        return av_dict_set(dict, key, buf, 0);
+    } else {
+        return AVERROR_EXTERNAL;
+    }
+}
diff --git a/libavutil/internal.h b/libavutil/internal.h
index 61784b5..e995af9 100644
--- a/libavutil/internal.h
+++ b/libavutil/internal.h
@@ -330,6 +330,16 @@ static av_always_inline av_const int avpriv_mirror(int x, int w)
 
 void ff_check_pixfmt_descriptors(void);
 
+/**
+ * Set a dictionary value to an ISO-8601 compliant timestamp string.
+ *
+ * @param s AVFormatContext
+ * @param key metadata key
+ * @param timestamp unix timestamp in microseconds
+ * @return <0 on error
+ */
+int avpriv_dict_set_timestamp(AVDictionary **dict, const char *key, int64_t timestamp);
+
 extern const uint8_t ff_reverse[256];
 
 #endif /* AVUTIL_INTERNAL_H */
-- 
2.6.6



More information about the ffmpeg-devel mailing list