diff options
author | Marton Balint <cus@passwd.hu> | 2016-06-29 22:44:59 +0200 |
---|---|---|
committer | Marton Balint <cus@passwd.hu> | 2016-08-17 23:45:41 +0200 |
commit | b72a7b96f84e5f16dd93b60668aecfda99442c71 (patch) | |
tree | 0f51e4e5cdb3a35aad6aa1652d1554dbc93d2653 /libavutil/dict.c | |
parent | a810126fd1b922154359a84b49ae2b7b9568efae (diff) | |
download | ffmpeg-b72a7b96f84e5f16dd93b60668aecfda99442c71.tar.gz |
avformat: factorize iso 8601 timestamp writer to a dictionary avutil function
Signed-off-by: Marton Balint <cus@passwd.hu>
Diffstat (limited to 'libavutil/dict.c')
-rw-r--r-- | libavutil/dict.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/libavutil/dict.c b/libavutil/dict.c index f70c7e0051..0ea71386e5 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; + } +} |