diff options
author | Stefano Sabatini <stefasab@gmail.com> | 2012-01-17 15:25:14 +0100 |
---|---|---|
committer | Stefano Sabatini <stefasab@gmail.com> | 2012-02-06 11:30:54 +0100 |
commit | 70ffda3217c58bbbfb8a7e7c58824b8ca6c56128 (patch) | |
tree | 794ed6d73cf979f1ff69ad2c85701cf5e98a24ff /ffmpeg.c | |
parent | 1ca0812d909a05e341e4c76861fb9dccc2f47112 (diff) | |
download | ffmpeg-70ffda3217c58bbbfb8a7e7c58824b8ca6c56128.tar.gz |
lavu: introduce av_parse_ratio() and use it in ffmpeg and lavfi/aspect
Factorize code and provide ratio parsing consistency.
Diffstat (limited to 'ffmpeg.c')
-rw-r--r-- | ffmpeg.c | 35 |
1 files changed, 9 insertions, 26 deletions
@@ -3141,30 +3141,6 @@ static int opt_pad(const char *opt, const char *arg) return -1; } -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"); @@ -3986,8 +3962,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); + } video_enc->bits_per_raw_sample = frame_bits_per_raw_sample; MATCH_PER_STREAM_OPT(frame_pix_fmts, str, frame_pix_fmt, oc, st); |