X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavutil%2Fparseutils.c;h=7127afee8e726a3129d4301bf11b5904b30cb1f6;hb=d40ff29cacf9b8ffa1061392a0e9b3056c4882ea;hp=2649e3b2bcec3a55cd168d33c880686c027580ae;hpb=dd3ca3ea15392da8636c06764e2da31e6ca700f0;p=ffmpeg diff --git a/libavutil/parseutils.c b/libavutil/parseutils.c index 2649e3b2bce..7127afee8e7 100644 --- a/libavutil/parseutils.c +++ b/libavutil/parseutils.c @@ -31,6 +31,32 @@ #include "random_seed.h" #include "parseutils.h" +int av_parse_ratio(AVRational *q, const char *str, int max, + int log_offset, void *log_ctx) +{ + char c; + int ret; + int64_t gcd; + + if (sscanf(str, "%d:%d%c", &q->num, &q->den, &c) != 2) { + double d; + ret = av_expr_parse_and_eval(&d, str, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, log_offset, log_ctx); + if (ret < 0) + return ret; + *q = av_d2q(d, max); + } + + gcd = av_gcd(FFABS(q->num), FFABS(q->den)); + if (gcd) { + q->num /= gcd; + q->den /= gcd; + } + + return 0; +} + typedef struct { const char *abbr; int width, height; @@ -124,7 +150,6 @@ int av_parse_video_rate(AVRational *rate, const char *arg) { int i, ret; int n = FF_ARRAY_ELEMS(video_rate_abbrs); - double res; /* First, we check our abbreviation table */ for (i = 0; i < n; ++i) @@ -134,10 +159,8 @@ int av_parse_video_rate(AVRational *rate, const char *arg) } /* Then, we try to parse it as fraction */ - if ((ret = av_expr_parse_and_eval(&res, arg, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, 0, NULL)) < 0) + if ((ret = av_parse_ratio_quiet(rate, arg, 1001000)) < 0) return ret; - *rate = av_d2q(res, 1001000); if (rate->num <= 0 || rate->den <= 0) return AVERROR(EINVAL); return 0; @@ -494,7 +517,7 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration) { const char *p; int64_t t; - struct tm dt; + struct tm dt = { 0 }; int i; static const char * const date_fmt[] = { "%Y-%m-%d", @@ -519,8 +542,6 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration) lastch = '\0'; is_utc = (lastch == 'z' || lastch == 'Z'); - memset(&dt, 0, sizeof(dt)); - p = timestr; q = NULL; if (!duration) {