[FFmpeg-devel] [PATCH 3/3] avformat: fix decoded creation_time timestamps
Marton Balint
cus at passwd.hu
Sun Aug 14 21:24:44 EEST 2016
On Fri, 1 Jul 2016, Marton Balint wrote:
> 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.
>
I'd like to apply this soon as well. Changing the format of creation_time
and modification_time in the metadata might be considered a hostile
move against library users, so I would not mind some comments that it is
OK. Maybe an entry in API changes is enough?
Thanks,
Marton
> Signed-off-by: Marton Balint <cus at passwd.hu>
> ---
> libavformat/matroskadec.c | 7 +------
> libavformat/mov.c | 9 +--------
> libavformat/mxfdec.c | 14 ++++----------
> libavformat/version.h | 2 +-
> 4 files changed, 7 insertions(+), 25 deletions(-)
>
> diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
> index f3d701f..82ff2ba 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 485bb0b..cb9490c 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -1155,17 +1155,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 0affca9..0b16463 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 47a8afb..6e23f74 100644
> --- a/libavformat/version.h
> +++ b/libavformat/version.h
> @@ -33,7 +33,7 @@
> // Also please add any ticket numbers that you belive might be affected here
> #define LIBAVFORMAT_VERSION_MAJOR 57
> #define LIBAVFORMAT_VERSION_MINOR 41
> -#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.6
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
More information about the ffmpeg-devel
mailing list