Commit 61c97238 authored by Aurelien Jacobs's avatar Aurelien Jacobs

parseutils: add support for ms and us suffix for AV_OPT_TYPE_DURATION

supported suffixes are:
- s: seconds (default when no suffix specified)
- m or ms: milliseconds
- u or us: microseconds
parent 6ce5dd22
...@@ -590,7 +590,7 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration) ...@@ -590,7 +590,7 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration)
int64_t t, now64; int64_t t, now64;
time_t now; time_t now;
struct tm dt = { 0 }, tmbuf; struct tm dt = { 0 }, tmbuf;
int today = 0, negative = 0, microseconds = 0; int today = 0, negative = 0, microseconds = 0, suffix = 1000000;
int i; int i;
static const char * const date_fmt[] = { static const char * const date_fmt[] = {
"%Y - %m - %d", "%Y - %m - %d",
...@@ -689,6 +689,17 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration) ...@@ -689,6 +689,17 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration)
if (duration) { if (duration) {
t = dt.tm_hour * 3600 + dt.tm_min * 60 + dt.tm_sec; t = dt.tm_hour * 3600 + dt.tm_min * 60 + dt.tm_sec;
if (*q == 'm') {
suffix = 1000;
microseconds /= 1000;
q++;
} else if (*q == 'u') {
suffix = 1;
microseconds = 0;
q++;
}
if (*q == 's')
q++;
} else { } else {
int is_utc = *q == 'Z' || *q == 'z'; int is_utc = *q == 'Z' || *q == 'z';
int tzoffset = 0; int tzoffset = 0;
...@@ -724,7 +735,7 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration) ...@@ -724,7 +735,7 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration)
if (*q) if (*q)
return AVERROR(EINVAL); return AVERROR(EINVAL);
t *= 1000000; t *= suffix;
t += microseconds; t += microseconds;
*timeval = negative ? -t : t; *timeval = negative ? -t : t;
return 0; return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment