[FFmpeg-cvslog] avformat/utils: add ff_parse_creation_time_metadata

Marton Balint git at videolan.org
Sun Feb 14 02:50:11 CET 2016


ffmpeg | branch: master | Marton Balint <cus at passwd.hu> | Thu Feb  4 03:28:19 2016 +0100| [e942454daf050047142147f75743d1bb6b98d911] | committer: Marton Balint

avformat/utils: add ff_parse_creation_time_metadata

Signed-off-by: Marton Balint <cus at passwd.hu>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e942454daf050047142147f75743d1bb6b98d911
---

 libavformat/internal.h |   11 +++++++++++
 libavformat/utils.c    |   17 +++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/libavformat/internal.h b/libavformat/internal.h
index 8e71805..dc76f2c 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -554,4 +554,15 @@ int ffio_open2_wrapper(struct AVFormatContext *s, AVIOContext **pb, const char *
  */
 void ff_format_io_close(AVFormatContext *s, AVIOContext **pb);
 
+/**
+ * Parse creation_time in AVFormatContext metadata if exists and warn if the
+ * parsing fails.
+ *
+ * @param s AVFormatContext
+ * @param timestamp parsed timestamp in microseconds, only set on successful parsing
+ * @param return_seconds set this to get the number of seconds in timestamp instead of microseconds
+ * @return 1 if OK, 0 if the metadata was not present, AVERROR(EINVAL) on parse error
+ */
+int ff_parse_creation_time_metadata(AVFormatContext *s, int64_t *timestamp, int return_seconds);
+
 #endif /* AVFORMAT_INTERNAL_H */
diff --git a/libavformat/utils.c b/libavformat/utils.c
index ef9ea93..cf4124a 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -4751,3 +4751,20 @@ void ff_format_io_close(AVFormatContext *s, AVIOContext **pb)
         s->io_close(s, *pb);
     *pb = NULL;
 }
+
+int ff_parse_creation_time_metadata(AVFormatContext *s, int64_t *timestamp, int return_seconds)
+{
+    AVDictionaryEntry *entry;
+    int64_t parsed_timestamp;
+    int ret;
+    if ((entry = av_dict_get(s->metadata, "creation_time", NULL, 0))) {
+        if ((ret = av_parse_time(&parsed_timestamp, entry->value, 0)) >= 0) {
+            *timestamp = return_seconds ? parsed_timestamp / 1000000 : parsed_timestamp;
+            return 1;
+        } else {
+            av_log(s, AV_LOG_WARNING, "Failed to parse creation_time %s\n", entry->value);
+            return ret;
+        }
+    }
+    return 0;
+}



More information about the ffmpeg-cvslog mailing list