aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAurelien Jacobs <aurel@gnuage.org>2018-03-01 19:30:42 +0100
committerAurelien Jacobs <aurel@gnuage.org>2018-03-02 22:57:08 +0100
commit61c972384d311508d07f9360d196909e27195655 (patch)
treef780fca2c2b005e0ac6631853d2317a6adf8787a
parent6ce5dd228c40159c774543425dd1f94a5d670542 (diff)
downloadffmpeg-61c972384d311508d07f9360d196909e27195655.tar.gz
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
-rw-r--r--libavutil/parseutils.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/libavutil/parseutils.c b/libavutil/parseutils.c
index 7ca07b37a1..44c845577a 100644
--- a/libavutil/parseutils.c
+++ b/libavutil/parseutils.c
@@ -590,7 +590,7 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration)
int64_t t, now64;
time_t now;
struct tm dt = { 0 }, tmbuf;
- int today = 0, negative = 0, microseconds = 0;
+ int today = 0, negative = 0, microseconds = 0, suffix = 1000000;
int i;
static const char * const date_fmt[] = {
"%Y - %m - %d",
@@ -689,6 +689,17 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration)
if (duration) {
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 {
int is_utc = *q == 'Z' || *q == 'z';
int tzoffset = 0;
@@ -724,7 +735,7 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration)
if (*q)
return AVERROR(EINVAL);
- t *= 1000000;
+ t *= suffix;
t += microseconds;
*timeval = negative ? -t : t;
return 0;