1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-01-08 13:22:53 +02:00

lavf: factor out conversion of ISO8601 string to unix time

This commit is contained in:
Anton Khirnov 2011-07-13 11:45:17 +02:00
parent b21e6b707f
commit 001d668d40
6 changed files with 20 additions and 21 deletions

View File

@ -343,11 +343,8 @@ static DVMuxContext* dv_init_mux(AVFormatContext* s)
c->start_time = s->timestamp; c->start_time = s->timestamp;
else else
#endif #endif
if (t = av_dict_get(s->metadata, "creation_time", NULL, 0)) { if (t = av_dict_get(s->metadata, "creation_time", NULL, 0))
struct tm time = {0}; c->start_time = ff_iso8601_to_unix_time(t->value);
strptime(t->value, "%Y - %m - %dT%T", &time);
c->start_time = mktime(&time);
}
for (i=0; i < c->n_ast; i++) { 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))) { if (c->ast[i] && !(c->audio_data[i]=av_fifo_alloc(100*AVCODEC_MAX_AUDIO_FRAME_SIZE))) {

View File

@ -402,12 +402,8 @@ static int gxf_write_umf_material_description(AVFormatContext *s)
timestamp = s->timestamp; timestamp = s->timestamp;
else else
#endif #endif
if (t = av_dict_get(s->metadata, "creation_time", NULL, 0)) { if (t = av_dict_get(s->metadata, "creation_time", NULL, 0))
struct tm time = {0}; timestamp = ff_iso8601_to_unix_time(t->value);
strptime(t->value, "%Y - %m - %dT%T", &time);
timestamp = mktime(&time);
}
// XXX drop frame // XXX drop frame
uint32_t timecode = uint32_t timecode =

View File

@ -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); 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 */ #endif /* AVFORMAT_INTERNAL_H */

View File

@ -2266,11 +2266,8 @@ static int mov_write_header(AVFormatContext *s)
mov->time = s->timestamp; mov->time = s->timestamp;
else else
#endif #endif
if (t = av_dict_get(s->metadata, "creation_time", NULL, 0)) { if (t = av_dict_get(s->metadata, "creation_time", NULL, 0))
struct tm time = {0}; mov->time = ff_iso8601_to_unix_time(t->value);
strptime(t->value, "%Y - %m - %dT%T", &time);
mov->time = mktime(&time);
}
mov->time += 0x7C25B080; //1970 based -> 1904 based mov->time += 0x7C25B080; //1970 based -> 1904 based
if (mov->chapter_track) if (mov->chapter_track)

View File

@ -1519,11 +1519,8 @@ static int mxf_write_header(AVFormatContext *s)
timestamp = s->timestamp; timestamp = s->timestamp;
else else
#endif #endif
if (t = av_dict_get(s->metadata, "creation_time", NULL, 0)) { if (t = av_dict_get(s->metadata, "creation_time", NULL, 0))
struct tm time = {0}; timestamp = ff_iso8601_to_unix_time(t->value);
strptime(t->value, "%Y - %m - %dT%T", &time);
timestamp = mktime(&time);
}
if (timestamp) if (timestamp)
mxf->timestamp = mxf_parse_timestamp(timestamp); mxf->timestamp = mxf_parse_timestamp(timestamp);
mxf->duration = -1; mxf->duration = -1;

View File

@ -3884,3 +3884,10 @@ void ff_make_absolute_url(char *buf, int size, const char *base,
} }
av_strlcat(buf, rel, size); 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);
}