summaryrefslogtreecommitdiff
path: root/libavfilter
diff options
context:
space:
mode:
authorStefano Sabatini <stefasab@gmail.com>2012-01-17 15:25:14 +0100
committerStefano Sabatini <stefasab@gmail.com>2012-02-06 11:30:54 +0100
commit70ffda3217c58bbbfb8a7e7c58824b8ca6c56128 (patch)
tree794ed6d73cf979f1ff69ad2c85701cf5e98a24ff /libavfilter
parent1ca0812d909a05e341e4c76861fb9dccc2f47112 (diff)
lavu: introduce av_parse_ratio() and use it in ffmpeg and lavfi/aspect
Factorize code and provide ratio parsing consistency.
Diffstat (limited to 'libavfilter')
-rw-r--r--libavfilter/vf_aspect.c25
1 files changed, 6 insertions, 19 deletions
diff --git a/libavfilter/vf_aspect.c b/libavfilter/vf_aspect.c
index f92ed1f231..cced6bde8e 100644
--- a/libavfilter/vf_aspect.c
+++ b/libavfilter/vf_aspect.c
@@ -24,6 +24,7 @@
*/
#include "libavutil/mathematics.h"
+#include "libavutil/parseutils.h"
#include "avfilter.h"
typedef struct {
@@ -33,32 +34,18 @@ typedef struct {
static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
{
AspectContext *aspect = ctx->priv;
- double ratio;
- int64_t gcd;
- char c = 0;
+ int ret;
if (args) {
- if (sscanf(args, "%d:%d%c", &aspect->aspect.num, &aspect->aspect.den, &c) != 2)
- if (sscanf(args, "%lf%c", &ratio, &c) == 1)
- aspect->aspect = av_d2q(ratio, 100);
-
- if (c || aspect->aspect.num <= 0 || aspect->aspect.den <= 0) {
+ if ((ret = av_parse_ratio(&aspect->aspect, args, 100, 0, ctx)) < 0 ||
+ aspect->aspect.num < 0 || aspect->aspect.den <= 0) {
av_log(ctx, AV_LOG_ERROR,
"Invalid string '%s' for aspect ratio.\n", args);
- return AVERROR(EINVAL);
+ return ret;
}
- gcd = av_gcd(FFABS(aspect->aspect.num), FFABS(aspect->aspect.den));
- if (gcd) {
- aspect->aspect.num /= gcd;
- aspect->aspect.den /= gcd;
- }
+ av_log(ctx, AV_LOG_INFO, "a:%d/%d\n", aspect->aspect.num, aspect->aspect.den);
}
-
- if (aspect->aspect.den == 0)
- aspect->aspect = (AVRational) {0, 1};
-
- av_log(ctx, AV_LOG_INFO, "a:%d/%d\n", aspect->aspect.num, aspect->aspect.den);
return 0;
}