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"
34 int rate_num, rate_den;
37 static const VideoFrameSizeAbbr video_frame_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 VideoFrameRateAbbr video_frame_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 */
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_frame_size_abbrs);
93 int frame_width = 0, frame_height = 0;
95 for (i = 0; i < n; i++) {
96 if (!strcmp(video_frame_size_abbrs[i].abbr, str)) {
97 frame_width = video_frame_size_abbrs[i].width;
98 frame_height = video_frame_size_abbrs[i].height;
104 frame_width = strtol(p, &p, 10);
107 frame_height = strtol(p, &p, 10);
109 if (frame_width <= 0 || frame_height <= 0)
111 *width_ptr = frame_width;
112 *height_ptr = frame_height;
116 int av_parse_video_rate(AVRational *frame_rate, const char *arg)
119 int n = FF_ARRAY_ELEMS(video_frame_rate_abbrs);
122 /* First, we check our abbreviation table */
123 for (i = 0; i < n; ++i)
124 if (!strcmp(video_frame_rate_abbrs[i].abbr, arg)) {
125 frame_rate->num = video_frame_rate_abbrs[i].rate_num;
126 frame_rate->den = video_frame_rate_abbrs[i].rate_den;
130 /* Then, we try to parse it as fraction */
131 cp = strchr(arg, '/');
133 cp = strchr(arg, ':');
136 frame_rate->num = strtol(arg, &cpp, 10);
137 if (cpp != arg || cpp == cp)
138 frame_rate->den = strtol(cp+1, &cpp, 10);
142 /* Finally we give up and parse it as double */
143 AVRational time_base = av_d2q(strtod(arg, 0), 1001000);
144 frame_rate->den = time_base.den;
145 frame_rate->num = time_base.num;
147 if (frame_rate->num <= 0 || frame_rate->den <= 0)