[FFmpeg-cvslog] lavf: factor out conversion of ISO8601 string to unix time
Anton Khirnov
git at videolan.org
Thu Jul 14 02:36:47 CEST 2011
ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Wed Jul 13 11:45:17 2011 +0200| [001d668d40b5f87d19271c7d5521368b5187425b] | committer: Anton Khirnov
lavf: factor out conversion of ISO8601 string to unix time
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=001d668d40b5f87d19271c7d5521368b5187425b
---
libavformat/dvenc.c | 7 ++-----
libavformat/gxfenc.c | 8 ++------
libavformat/internal.h | 5 +++++
libavformat/movenc.c | 7 ++-----
libavformat/mxfenc.c | 7 ++-----
libavformat/utils.c | 7 +++++++
6 files changed, 20 insertions(+), 21 deletions(-)
diff --git a/libavformat/dvenc.c b/libavformat/dvenc.c
index 1e59bd9..5aab683 100644
--- a/libavformat/dvenc.c
+++ b/libavformat/dvenc.c
@@ -343,11 +343,8 @@ static DVMuxContext* dv_init_mux(AVFormatContext* s)
c->start_time = s->timestamp;
else
#endif
- if (t = av_dict_get(s->metadata, "creation_time", NULL, 0)) {
- struct tm time = {0};
- strptime(t->value, "%Y - %m - %dT%T", &time);
- c->start_time = mktime(&time);
- }
+ if (t = av_dict_get(s->metadata, "creation_time", NULL, 0))
+ c->start_time = ff_iso8601_to_unix_time(t->value);
for (i=0; i < c->n_ast; i++) {
if (c->ast[i] && !(c->audio_data[i]=av_fifo_alloc(100*AVCODEC_MAX_AUDIO_FRAME_SIZE))) {
diff --git a/libavformat/gxfenc.c b/libavformat/gxfenc.c
index 2d4136a..99bd719 100644
--- a/libavformat/gxfenc.c
+++ b/libavformat/gxfenc.c
@@ -402,12 +402,8 @@ static int gxf_write_umf_material_description(AVFormatContext *s)
timestamp = s->timestamp;
else
#endif
- if (t = av_dict_get(s->metadata, "creation_time", NULL, 0)) {
- struct tm time = {0};
- strptime(t->value, "%Y - %m - %dT%T", &time);
- timestamp = mktime(&time);
- }
-
+ if (t = av_dict_get(s->metadata, "creation_time", NULL, 0))
+ timestamp = ff_iso8601_to_unix_time(t->value);
// XXX drop frame
uint32_t timecode =
diff --git a/libavformat/internal.h b/libavformat/internal.h
index aba890d..8440e6b 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -248,4 +248,9 @@ void ff_make_absolute_url(char *buf, int size, const char *base,
enum CodecID ff_guess_image2_codec(const char *filename);
+/**
+ * Convert a date string in ISO8601 format to Unix timestamp.
+ */
+int64_t ff_iso8601_to_unix_time(const char *datestr);
+
#endif /* AVFORMAT_INTERNAL_H */
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 78e5db7..12ebef5 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -2266,11 +2266,8 @@ static int mov_write_header(AVFormatContext *s)
mov->time = s->timestamp;
else
#endif
- if (t = av_dict_get(s->metadata, "creation_time", NULL, 0)) {
- struct tm time = {0};
- strptime(t->value, "%Y - %m - %dT%T", &time);
- mov->time = mktime(&time);
- }
+ if (t = av_dict_get(s->metadata, "creation_time", NULL, 0))
+ mov->time = ff_iso8601_to_unix_time(t->value);
mov->time += 0x7C25B080; //1970 based -> 1904 based
if (mov->chapter_track)
diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
index d7cc5c1..10ba6f3 100644
--- a/libavformat/mxfenc.c
+++ b/libavformat/mxfenc.c
@@ -1519,11 +1519,8 @@ static int mxf_write_header(AVFormatContext *s)
timestamp = s->timestamp;
else
#endif
- if (t = av_dict_get(s->metadata, "creation_time", NULL, 0)) {
- struct tm time = {0};
- strptime(t->value, "%Y - %m - %dT%T", &time);
- timestamp = mktime(&time);
- }
+ if (t = av_dict_get(s->metadata, "creation_time", NULL, 0))
+ timestamp = ff_iso8601_to_unix_time(t->value);
if (timestamp)
mxf->timestamp = mxf_parse_timestamp(timestamp);
mxf->duration = -1;
diff --git a/libavformat/utils.c b/libavformat/utils.c
index bbd1b2d..bb12e24 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3884,3 +3884,10 @@ void ff_make_absolute_url(char *buf, int size, const char *base,
}
av_strlcat(buf, rel, size);
}
+
+int64_t ff_iso8601_to_unix_time(const char *datestr)
+{
+ struct tm time = {0};
+ strptime(datestr, "%Y - %m - %dT%T", &time);
+ return mktime(&time);
+}
More information about the ffmpeg-cvslog
mailing list