diff options
author | Marton Balint <cus@passwd.hu> | 2016-06-30 00:55:48 +0200 |
---|---|---|
committer | Marton Balint <cus@passwd.hu> | 2016-08-28 15:55:32 +0200 |
commit | 13b90ff2c12749aac58d22da4cb47c24b7a37b04 (patch) | |
tree | 37e6a2d24cd32a4a89f99cbaffa49bffcc1db594 | |
parent | fecf5ae9aa7499280e62f5244dfd2b65c92f532a (diff) | |
download | ffmpeg-13b90ff2c12749aac58d22da4cb47c24b7a37b04.tar.gz |
avformat: fix decoded creation_time timestamps
Use proper ISO 8601 timestamps which also signal that they are in UTC.
This changes the format of creation_time and modification_date metadata values
from 2016-06-01 22:30:00 to 2016-01-01T22:30:00.000000Z
Fixes ticket #5673.
Signed-off-by: Marton Balint <cus@passwd.hu>
-rw-r--r-- | libavformat/matroskadec.c | 7 | ||||
-rw-r--r-- | libavformat/mov.c | 9 | ||||
-rw-r--r-- | libavformat/mxfdec.c | 14 | ||||
-rw-r--r-- | libavformat/version.h | 2 |
4 files changed, 7 insertions, 25 deletions
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index d07a0920cf..77b8a5d5ed 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -1691,13 +1691,8 @@ static int matroska_aac_sri(int samplerate) static void matroska_metadata_creation_time(AVDictionary **metadata, int64_t date_utc) { - char buffer[32]; /* Convert to seconds and adjust by number of seconds between 2001-01-01 and Epoch */ - time_t creation_time = date_utc / 1000000000 + 978307200; - struct tm tmpbuf, *ptm = gmtime_r(&creation_time, &tmpbuf); - if (!ptm) return; - if (strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", ptm)) - av_dict_set(metadata, "creation_time", buffer, 0); + avpriv_dict_set_timestamp(metadata, "creation_time", date_utc / 1000 + 978307200000000LL); } static int matroska_parse_flac(AVFormatContext *s, diff --git a/libavformat/mov.c b/libavformat/mov.c index bc11fb8ce0..6282d8f409 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -1156,17 +1156,10 @@ static int mov_read_moof(MOVContext *c, AVIOContext *pb, MOVAtom atom) static void mov_metadata_creation_time(AVDictionary **metadata, int64_t time) { - char buffer[32]; if (time) { - struct tm *ptm, tmbuf; - time_t timet; if(time >= 2082844800) time -= 2082844800; /* seconds between 1904-01-01 and Epoch */ - timet = time; - ptm = gmtime_r(&timet, &tmbuf); - if (!ptm) return; - if (strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", ptm)) - av_dict_set(metadata, "creation_time", buffer, 0); + avpriv_dict_set_timestamp(metadata, "creation_time", time * 1000000); } } diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index 0affca97a2..0b16463f82 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -50,6 +50,7 @@ #include "libavutil/mathematics.h" #include "libavcodec/bytestream.h" #include "libavutil/intreadwrite.h" +#include "libavutil/parseutils.h" #include "libavutil/timecode.h" #include "avformat.h" #include "internal.h" @@ -2159,7 +2160,7 @@ fail_and_free: return ret; } -static int mxf_timestamp_to_str(uint64_t timestamp, char **str) +static int64_t mxf_timestamp_to_int64(uint64_t timestamp) { struct tm time = { 0 }; time.tm_year = (timestamp >> 48) - 1900; @@ -2178,13 +2179,7 @@ static int mxf_timestamp_to_str(uint64_t timestamp, char **str) time.tm_min = av_clip(time.tm_min, 0, 59); time.tm_sec = av_clip(time.tm_sec, 0, 59); - *str = av_mallocz(32); - if (!*str) - return AVERROR(ENOMEM); - if (!strftime(*str, 32, "%Y-%m-%d %H:%M:%S", &time)) - (*str)[0] = '\0'; - - return 0; + return (int64_t)av_timegm(&time) * 1000000; } #define SET_STR_METADATA(pb, name, str) do { \ @@ -2202,9 +2197,8 @@ static int mxf_timestamp_to_str(uint64_t timestamp, char **str) #define SET_TS_METADATA(pb, name, var, str) do { \ var = avio_rb64(pb); \ - if ((ret = mxf_timestamp_to_str(var, &str)) < 0) \ + if ((ret = avpriv_dict_set_timestamp(&s->metadata, name, mxf_timestamp_to_int64(var)) < 0)) \ return ret; \ - av_dict_set(&s->metadata, name, str, AV_DICT_DONT_STRDUP_VAL); \ } while (0) static int mxf_read_identification_metadata(void *arg, AVIOContext *pb, int tag, int size, UID _uid, int64_t klv_offset) diff --git a/libavformat/version.h b/libavformat/version.h index 88fd4cc074..f3da968928 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -33,7 +33,7 @@ // Also please add any ticket numbers that you believe might be affected here #define LIBAVFORMAT_VERSION_MAJOR 57 #define LIBAVFORMAT_VERSION_MINOR 48 -#define LIBAVFORMAT_VERSION_MICRO 100 +#define LIBAVFORMAT_VERSION_MICRO 101 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ LIBAVFORMAT_VERSION_MINOR, \ |