[FFmpeg-devel] [PATCH] lavu: introduce av_parse_ratio() and use it in ffmpeg and lavfi/aspect

Michael Niedermayer michaelni at gmx.at
Mon Jan 23 19:42:17 CET 2012


On Sat, Jan 21, 2012 at 02:59:59PM +0100, Stefano Sabatini wrote:
> 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.

hmmm
i thought that the return code would be >= 0 with 0/0 and the value NAN

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

During times of universal deceit, telling the truth becomes a
revolutionary act. -- George Orwell
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120123/10b97319/attachment.asc>


More information about the ffmpeg-devel mailing list