[FFmpeg-devel] [PATCH] lavu: introduce av_parse_ratio() and use it in ffmpeg and lavfi/aspect
Stefano Sabatini
stefasab at gmail.com
Sat Jan 21 14:59:59 CET 2012
On date Friday 2012-01-20 17:46:58 +0100, Michael Niedermayer encoded:
> On Fri, Jan 20, 2012 at 03:44:09PM +0100, Stefano Sabatini wrote:
> [...]
> > +int av_parse_ratio(AVRational *q, const char *str, int max)
> > +{
> > + char c;
> > + int ret;
> > + int64_t gcd;
> > +
> > + if (sscanf(str, "%d:%d%c", &q->num, &q->den, &c) == 2) {
> > + if (q->num == 0 && q->den == 0)
> > + return AVERROR(EINVAL);
> [...]
> > @@ -29,6 +29,21 @@
> > */
> >
> > /**
> > + * Parse str and store the parsed ratio in q.
> > + *
> > + * Note that a ratio with infinite (1/0) or negative value is
> > + * considered valid, so you should check on the returned value if you
> > + * want to exclude those values.
>
> why is 0/0 less valid ?
>
> It seems like a pretty good choice for "not known", which could be
> used to override a known value in transcoding
In this code:
+ double d;
+ ret = av_expr_parse_and_eval(&d, str, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, 0, NULL);
+ if (ret < 0)
+ return AVERROR(EINVAL);
+ *q = av_d2q(d, max);
+ }
av_expr_parse_and_eval() is not able to distinguish between invalid
syntax and undefined value (while -+1/0 is interpreted as an infinite
value, and is not considered an error), so the only way to specify an
undefined ratio is through the "0:0" syntax, which would be then not
equivalent to "0/0".
We could let av_parse_ratio() interpret "0:0" as undefined, but we
should specify in this case that "0/0" is not valid syntax, which
would be a bit confusing.
BTW there is also the problem that right now av_expr_parse_and_eval()
is not inhibiting log printing, as alternative we could add some
additional parameters log_ctx, log_level_offset for changing the log
level and/or specifying the log context.
In this case we could have:
av_parse_ratio_l(AVRational *q, const char *str, int max, void *log_ctx, int log_level_off)
and a simple macro:
av_parse_ratio(q, str, max) -> always inhibit logging
--
FFmpeg = Fierce and Fabulous Magic Pure Elitarian Game
More information about the ffmpeg-devel
mailing list