[FFmpeg-devel] [PATCH 1/3] avformat/mux: add a format flag which ensure parsed and standardized creation time

Marton Balint cus at passwd.hu
Thu Feb 25 02:11:00 CET 2016


This can be used for formats which write all format metadata as string to
files, therefore non-standard creation times such as 'now' will be parsed.

The standardized creation time is UTC ISO 8601 with microsecond precision.

Signed-off-by: Marton Balint <cus at passwd.hu>
---
 libavformat/avformat.h |  1 +
 libavformat/mux.c      | 24 ++++++++++++++++++++++++
 libavformat/version.h  |  2 +-
 3 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 2b6533c..ea82181 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -502,6 +502,7 @@ typedef struct AVProbeData {
                                         The user or muxer can override this through
                                         AVFormatContext.avoid_negative_ts
                                         */
+#define AVFMT_NEED_PARSED_CREATION_TIME  0x80000 /**< Format needs pre-parsed standardized creation time */
 
 #define AVFMT_SEEK_TO_PTS   0x4000000 /**< Seeking is based on PTS */
 
diff --git a/libavformat/mux.c b/libavformat/mux.c
index 789c811..9a39064 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -36,10 +36,12 @@
 #include "libavutil/mathematics.h"
 #include "libavutil/parseutils.h"
 #include "libavutil/time.h"
+#include "libavutil/time_internal.h"
 #include "riff.h"
 #include "audiointerleave.h"
 #include "url.h"
 #include <stdarg.h>
+#include <time.h>
 #if CONFIG_NETWORK
 #include "network.h"
 #endif
@@ -383,6 +385,28 @@ FF_ENABLE_DEPRECATION_WARNINGS
         }
     }
 
+    /* pre-parse creation time for formats that need it */
+    if (s->oformat->flags & AVFMT_NEED_PARSED_CREATION_TIME) {
+        int64_t timestamp;
+        if (ff_parse_creation_time_metadata(s, &timestamp, 0) == 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)) {
+                    ret = AVERROR_EXTERNAL;
+                    goto fail;
+                }
+                av_strlcatf(buf, sizeof(buf), ".%06dZ", (int)(timestamp % 1000000));
+                av_dict_set(&s->metadata, "creation_time", buf, 0);
+            } else {
+                ret = AVERROR_EXTERNAL;
+                goto fail;
+            }
+        }
+    }
+
     /* set muxer identification string */
     if (!(s->flags & AVFMT_FLAG_BITEXACT)) {
         av_dict_set(&s->metadata, "encoder", LIBAVFORMAT_IDENT, 0);
diff --git a/libavformat/version.h b/libavformat/version.h
index 82a8892..9f4ede7 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -31,7 +31,7 @@
 
 #define LIBAVFORMAT_VERSION_MAJOR  57
 #define LIBAVFORMAT_VERSION_MINOR  26
-#define LIBAVFORMAT_VERSION_MICRO 100
+#define LIBAVFORMAT_VERSION_MICRO 101
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
                                                LIBAVFORMAT_VERSION_MINOR, \
-- 
2.6.2



More information about the ffmpeg-devel mailing list