00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00024 #include "parseutils.h"
00025 #include "libavutil/avutil.h"
00026 #include "libavutil/eval.h"
00027
00028 typedef struct {
00029 const char *abbr;
00030 int width, height;
00031 } VideoSizeAbbr;
00032
00033 typedef struct {
00034 const char *abbr;
00035 AVRational rate;
00036 } VideoRateAbbr;
00037
00038 static const VideoSizeAbbr video_size_abbrs[] = {
00039 { "ntsc", 720, 480 },
00040 { "pal", 720, 576 },
00041 { "qntsc", 352, 240 },
00042 { "qpal", 352, 288 },
00043 { "sntsc", 640, 480 },
00044 { "spal", 768, 576 },
00045 { "film", 352, 240 },
00046 { "ntsc-film", 352, 240 },
00047 { "sqcif", 128, 96 },
00048 { "qcif", 176, 144 },
00049 { "cif", 352, 288 },
00050 { "4cif", 704, 576 },
00051 { "16cif", 1408,1152 },
00052 { "qqvga", 160, 120 },
00053 { "qvga", 320, 240 },
00054 { "vga", 640, 480 },
00055 { "svga", 800, 600 },
00056 { "xga", 1024, 768 },
00057 { "uxga", 1600,1200 },
00058 { "qxga", 2048,1536 },
00059 { "sxga", 1280,1024 },
00060 { "qsxga", 2560,2048 },
00061 { "hsxga", 5120,4096 },
00062 { "wvga", 852, 480 },
00063 { "wxga", 1366, 768 },
00064 { "wsxga", 1600,1024 },
00065 { "wuxga", 1920,1200 },
00066 { "woxga", 2560,1600 },
00067 { "wqsxga", 3200,2048 },
00068 { "wquxga", 3840,2400 },
00069 { "whsxga", 6400,4096 },
00070 { "whuxga", 7680,4800 },
00071 { "cga", 320, 200 },
00072 { "ega", 640, 350 },
00073 { "hd480", 852, 480 },
00074 { "hd720", 1280, 720 },
00075 { "hd1080", 1920,1080 },
00076 };
00077
00078 static const VideoRateAbbr video_rate_abbrs[]= {
00079 { "ntsc", { 30000, 1001 } },
00080 { "pal", { 25, 1 } },
00081 { "qntsc", { 30000, 1001 } },
00082 { "qpal", { 25, 1 } },
00083 { "sntsc", { 30000, 1001 } },
00084 { "spal", { 25, 1 } },
00085 { "film", { 24, 1 } },
00086 { "ntsc-film", { 24000, 1001 } },
00087 };
00088
00089 int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str)
00090 {
00091 int i;
00092 int n = FF_ARRAY_ELEMS(video_size_abbrs);
00093 char *p;
00094 int width = 0, height = 0;
00095
00096 for (i = 0; i < n; i++) {
00097 if (!strcmp(video_size_abbrs[i].abbr, str)) {
00098 width = video_size_abbrs[i].width;
00099 height = video_size_abbrs[i].height;
00100 break;
00101 }
00102 }
00103 if (i == n) {
00104 p = str;
00105 width = strtol(p, &p, 10);
00106 if (*p)
00107 p++;
00108 height = strtol(p, &p, 10);
00109 }
00110 if (width <= 0 || height <= 0)
00111 return AVERROR(EINVAL);
00112 *width_ptr = width;
00113 *height_ptr = height;
00114 return 0;
00115 }
00116
00117 int av_parse_video_rate(AVRational *rate, const char *arg)
00118 {
00119 int i, ret;
00120 int n = FF_ARRAY_ELEMS(video_rate_abbrs);
00121 double res;
00122
00123
00124 for (i = 0; i < n; ++i)
00125 if (!strcmp(video_rate_abbrs[i].abbr, arg)) {
00126 *rate = video_rate_abbrs[i].rate;
00127 return 0;
00128 }
00129
00130
00131 if ((ret = av_expr_parse_and_eval(&res, arg, NULL, NULL, NULL, NULL, NULL, NULL,
00132 NULL, 0, NULL)) < 0)
00133 return ret;
00134 *rate = av_d2q(res, 1001000);
00135 if (rate->num <= 0 || rate->den <= 0)
00136 return AVERROR(EINVAL);
00137 return 0;
00138 }
00139
00140 #ifdef TEST
00141
00142 #undef printf
00143
00144 int main(void)
00145 {
00146 printf("Testing av_parse_video_rate()\n");
00147 {
00148 int i;
00149 const char *rates[] = {
00150 "-inf",
00151 "inf",
00152 "nan",
00153 "123/0",
00154 "-123 / 0",
00155 "",
00156 "/",
00157 " 123 / 321",
00158 "foo/foo",
00159 "foo/1",
00160 "1/foo",
00161 "0/0",
00162 "/0",
00163 "1/",
00164 "1",
00165 "0",
00166 "-123/123",
00167 "-foo",
00168 "123.23",
00169 ".23",
00170 "-.23",
00171 "-0.234",
00172 "-0.0000001",
00173 " 21332.2324 ",
00174 " -21332.2324 ",
00175 };
00176
00177 for (i = 0; i < FF_ARRAY_ELEMS(rates); i++) {
00178 int ret;
00179 AVRational q = (AVRational){0, 0};
00180 ret = av_parse_video_rate(&q, rates[i]),
00181 printf("'%s' -> %d/%d ret:%d\n",
00182 rates[i], q.num, q.den, ret);
00183 }
00184 }
00185
00186 return 0;
00187 }
00188
00189 #endif