diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2025-03-15 22:10:44 +0100 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2025-03-28 14:33:08 -0300 |
commit | c389d9ac788a529331722f6b3f13c5894114a28c (patch) | |
tree | 1b9672f7a10043f4967d72927964017c2d8d41a4 /libavformat/utils.c | |
parent | b306683d1228b1642a0d88a29071de5bdee999ff (diff) | |
download | ffmpeg-c389d9ac788a529331722f6b3f13c5894114a28c.tar.gz |
avutil/dict: Unavpriv avpriv_dict_set_timestamp()
And move it to lavf, its only user.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavformat/utils.c')
-rw-r--r-- | libavformat/utils.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/libavformat/utils.c b/libavformat/utils.c index e892e8bde7..eee7b9e0e3 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -20,14 +20,17 @@ */ #include <stdint.h> +#include <time.h> #include "config.h" #include "libavutil/avstring.h" #include "libavutil/bprint.h" +#include "libavutil/dict.h" #include "libavutil/internal.h" #include "libavutil/mem.h" #include "libavutil/time.h" +#include "libavutil/time_internal.h" #include "libavcodec/internal.h" @@ -596,3 +599,19 @@ int ff_bprint_to_codecpar_extradata(AVCodecParameters *par, struct AVBPrint *buf par->extradata_size = buf->len; return 0; } + +int ff_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; + } +} |