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

Stefano Sabatini stefasab at gmail.com
Fri Jan 27 22:51:25 CET 2012


On date Friday 2012-01-27 19:58:16 +0100, Michael Niedermayer encoded:
> On Fri, Jan 27, 2012 at 12:53:44PM +0100, Stefano Sabatini wrote:
[...]
> > -static double parse_frame_aspect_ratio(const char *arg)
> > -{
> > -    int x = 0, y = 0;
> > -    double ar = 0;
> > -    const char *p;
> > -    char *end;
> > -
> > -    p = strchr(arg, ':');
> > -    if (p) {
> > -        x = strtol(arg, &end, 10);
> > -        if (end == p)
> > -            y = strtol(end + 1, &end, 10);
> > -        if (x > 0 && y > 0)
> > -            ar = (double)x / (double)y;
> > -    } else
> > -        ar = strtod(arg, NULL);
> > -
> > -    if (!ar) {
> > -        av_log(NULL, AV_LOG_FATAL, "Incorrect aspect ratio specification.\n");
> > -        exit_program(1);
> > -    }
> > -    return ar;
> > -}
> > -
> >  static int opt_video_channel(const char *opt, const char *arg)
> >  {
> >      av_log(NULL, AV_LOG_WARNING, "This option is deprecated, use -channel.\n");
> > @@ -3998,8 +3974,15 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc)
> >          }
> >  
> >          MATCH_PER_STREAM_OPT(frame_aspect_ratios, str, frame_aspect_ratio, oc, st);
> > -        if (frame_aspect_ratio)
> > -            ost->frame_aspect_ratio = parse_frame_aspect_ratio(frame_aspect_ratio);
> > +        if (frame_aspect_ratio) {
> > +            AVRational q;
> > +            if (av_parse_ratio(&q, frame_aspect_ratio, 255, 0, NULL) < 0 ||
> > +                q.num <= 0 || q.den <= 0) {
> > +                av_log(NULL, AV_LOG_FATAL, "Invalid aspect ratio: %s\n", frame_aspect_ratio);
> > +                exit_program(1);
> > +            }
> > +            ost->frame_aspect_ratio = av_q2d(q);
> > +        }
> 
> how can a undefined aspect be specified ?
> (use case would be a few files with wrong but unknown aspect as input)

Currently you can't (num > 0 && den > 0 or fail), and I don't want to
change the behavior with this patch.
-- 
FFmpeg = Frenzy and Freak Minimalistic Powerful Elitist Ghost


More information about the ffmpeg-devel mailing list