2 * This file is part of FFmpeg.
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 * misc parsing utilities for libavcore
24 #include "parseutils.h"
25 #include "libavutil/avutil.h"
37 static const VideoSizeAbbr video_size_abbrs[] = {
40 { "qntsc", 352, 240 }, /* VCD compliant NTSC */
41 { "qpal", 352, 288 }, /* VCD compliant PAL */
42 { "sntsc", 640, 480 }, /* square pixel NTSC */
43 { "spal", 768, 576 }, /* square pixel PAL */
45 { "ntsc-film", 352, 240 },
50 { "16cif", 1408,1152 },
51 { "qqvga", 160, 120 },
56 { "uxga", 1600,1200 },
57 { "qxga", 2048,1536 },
58 { "sxga", 1280,1024 },
59 { "qsxga", 2560,2048 },
60 { "hsxga", 5120,4096 },
62 { "wxga", 1366, 768 },
63 { "wsxga", 1600,1024 },
64 { "wuxga", 1920,1200 },
65 { "woxga", 2560,1600 },
66 { "wqsxga", 3200,2048 },
67 { "wquxga", 3840,2400 },
68 { "whsxga", 6400,4096 },
69 { "whuxga", 7680,4800 },
72 { "hd480", 852, 480 },
73 { "hd720", 1280, 720 },
74 { "hd1080", 1920,1080 },
77 static const VideoRateAbbr video_rate_abbrs[]= {
78 { "ntsc", { 30000, 1001 } },
80 { "qntsc", { 30000, 1001 } }, /* VCD compliant NTSC */
81 { "qpal", { 25, 1 } }, /* VCD compliant PAL */
82 { "sntsc", { 30000, 1001 } }, /* square pixel NTSC */
83 { "spal", { 25, 1 } }, /* square pixel PAL */
84 { "film", { 24, 1 } },
85 { "ntsc-film", { 24000, 1001 } },
88 int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str)
91 int n = FF_ARRAY_ELEMS(video_size_abbrs);
93 int width = 0, height = 0;
95 for (i = 0; i < n; i++) {
96 if (!strcmp(video_size_abbrs[i].abbr, str)) {
97 width = video_size_abbrs[i].width;
98 height = video_size_abbrs[i].height;
104 width = strtol(p, &p, 10);
107 height = strtol(p, &p, 10);
109 if (width <= 0 || height <= 0)
110 return AVERROR(EINVAL);
112 *height_ptr = height;
116 int av_parse_video_rate(AVRational *rate, const char *arg)
119 int n = FF_ARRAY_ELEMS(video_rate_abbrs);
122 /* First, we check our abbreviation table */
123 for (i = 0; i < n; ++i)
124 if (!strcmp(video_rate_abbrs[i].abbr, arg)) {
125 *rate = video_rate_abbrs[i].rate;
129 /* Then, we try to parse it as fraction */
130 cp = strchr(arg, '/');
132 cp = strchr(arg, ':');
135 rate->num = strtol(arg, &cpp, 10);
136 if (cpp != arg || cpp == cp)
137 rate->den = strtol(cp+1, &cpp, 10);
141 /* Finally we give up and parse it as double */
142 *rate = av_d2q(strtod(arg, 0), 1001000);
144 if (rate->num <= 0 || rate->den <= 0)
145 return AVERROR(EINVAL);