2010-07-26 23:12:28 +00:00
|
|
|
/*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* misc parsing utilities for libavcore
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "parseutils.h"
|
|
|
|
#include "libavutil/avutil.h"
|
2010-10-04 13:41:04 +00:00
|
|
|
#include "libavutil/eval.h"
|
2010-07-26 23:12:28 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
const char *abbr;
|
|
|
|
int width, height;
|
2010-07-26 23:12:41 +00:00
|
|
|
} VideoSizeAbbr;
|
2010-07-26 23:12:28 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
const char *abbr;
|
2010-07-26 23:12:45 +00:00
|
|
|
AVRational rate;
|
2010-07-26 23:12:41 +00:00
|
|
|
} VideoRateAbbr;
|
2010-07-26 23:12:28 +00:00
|
|
|
|
2010-07-26 23:12:41 +00:00
|
|
|
static const VideoSizeAbbr video_size_abbrs[] = {
|
2010-07-26 23:12:28 +00:00
|
|
|
{ "ntsc", 720, 480 },
|
|
|
|
{ "pal", 720, 576 },
|
|
|
|
{ "qntsc", 352, 240 }, /* VCD compliant NTSC */
|
|
|
|
{ "qpal", 352, 288 }, /* VCD compliant PAL */
|
|
|
|
{ "sntsc", 640, 480 }, /* square pixel NTSC */
|
|
|
|
{ "spal", 768, 576 }, /* square pixel PAL */
|
|
|
|
{ "film", 352, 240 },
|
|
|
|
{ "ntsc-film", 352, 240 },
|
|
|
|
{ "sqcif", 128, 96 },
|
|
|
|
{ "qcif", 176, 144 },
|
|
|
|
{ "cif", 352, 288 },
|
|
|
|
{ "4cif", 704, 576 },
|
|
|
|
{ "16cif", 1408,1152 },
|
|
|
|
{ "qqvga", 160, 120 },
|
|
|
|
{ "qvga", 320, 240 },
|
|
|
|
{ "vga", 640, 480 },
|
|
|
|
{ "svga", 800, 600 },
|
|
|
|
{ "xga", 1024, 768 },
|
|
|
|
{ "uxga", 1600,1200 },
|
|
|
|
{ "qxga", 2048,1536 },
|
|
|
|
{ "sxga", 1280,1024 },
|
|
|
|
{ "qsxga", 2560,2048 },
|
|
|
|
{ "hsxga", 5120,4096 },
|
|
|
|
{ "wvga", 852, 480 },
|
|
|
|
{ "wxga", 1366, 768 },
|
|
|
|
{ "wsxga", 1600,1024 },
|
|
|
|
{ "wuxga", 1920,1200 },
|
|
|
|
{ "woxga", 2560,1600 },
|
|
|
|
{ "wqsxga", 3200,2048 },
|
|
|
|
{ "wquxga", 3840,2400 },
|
|
|
|
{ "whsxga", 6400,4096 },
|
|
|
|
{ "whuxga", 7680,4800 },
|
|
|
|
{ "cga", 320, 200 },
|
|
|
|
{ "ega", 640, 350 },
|
|
|
|
{ "hd480", 852, 480 },
|
|
|
|
{ "hd720", 1280, 720 },
|
|
|
|
{ "hd1080", 1920,1080 },
|
|
|
|
};
|
|
|
|
|
2010-07-26 23:12:41 +00:00
|
|
|
static const VideoRateAbbr video_rate_abbrs[]= {
|
2010-07-26 23:12:45 +00:00
|
|
|
{ "ntsc", { 30000, 1001 } },
|
|
|
|
{ "pal", { 25, 1 } },
|
|
|
|
{ "qntsc", { 30000, 1001 } }, /* VCD compliant NTSC */
|
|
|
|
{ "qpal", { 25, 1 } }, /* VCD compliant PAL */
|
|
|
|
{ "sntsc", { 30000, 1001 } }, /* square pixel NTSC */
|
|
|
|
{ "spal", { 25, 1 } }, /* square pixel PAL */
|
|
|
|
{ "film", { 24, 1 } },
|
|
|
|
{ "ntsc-film", { 24000, 1001 } },
|
2010-07-26 23:12:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str)
|
|
|
|
{
|
|
|
|
int i;
|
2010-07-26 23:12:41 +00:00
|
|
|
int n = FF_ARRAY_ELEMS(video_size_abbrs);
|
2010-07-26 23:12:28 +00:00
|
|
|
char *p;
|
2010-07-26 23:12:41 +00:00
|
|
|
int width = 0, height = 0;
|
2010-07-26 23:12:28 +00:00
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
2010-07-26 23:12:41 +00:00
|
|
|
if (!strcmp(video_size_abbrs[i].abbr, str)) {
|
|
|
|
width = video_size_abbrs[i].width;
|
|
|
|
height = video_size_abbrs[i].height;
|
2010-07-26 23:12:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == n) {
|
|
|
|
p = str;
|
2010-07-26 23:12:41 +00:00
|
|
|
width = strtol(p, &p, 10);
|
2010-07-26 23:12:28 +00:00
|
|
|
if (*p)
|
|
|
|
p++;
|
2010-07-26 23:12:41 +00:00
|
|
|
height = strtol(p, &p, 10);
|
2010-07-26 23:12:28 +00:00
|
|
|
}
|
2010-07-26 23:12:41 +00:00
|
|
|
if (width <= 0 || height <= 0)
|
2010-07-26 23:12:38 +00:00
|
|
|
return AVERROR(EINVAL);
|
2010-07-26 23:12:41 +00:00
|
|
|
*width_ptr = width;
|
|
|
|
*height_ptr = height;
|
2010-07-26 23:12:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-07-26 23:12:41 +00:00
|
|
|
int av_parse_video_rate(AVRational *rate, const char *arg)
|
2010-07-26 23:12:28 +00:00
|
|
|
{
|
2010-10-04 13:41:04 +00:00
|
|
|
int i, ret;
|
2010-07-26 23:12:41 +00:00
|
|
|
int n = FF_ARRAY_ELEMS(video_rate_abbrs);
|
2010-10-04 13:41:04 +00:00
|
|
|
double res;
|
2010-07-26 23:12:28 +00:00
|
|
|
|
|
|
|
/* First, we check our abbreviation table */
|
|
|
|
for (i = 0; i < n; ++i)
|
2010-10-01 16:02:10 +00:00
|
|
|
if (!strcmp(video_rate_abbrs[i].abbr, arg)) {
|
|
|
|
*rate = video_rate_abbrs[i].rate;
|
|
|
|
return 0;
|
|
|
|
}
|
2010-07-26 23:12:28 +00:00
|
|
|
|
|
|
|
/* Then, we try to parse it as fraction */
|
2010-10-04 13:41:04 +00:00
|
|
|
if ((ret = av_parse_and_eval_expr(&res, arg, NULL, NULL, NULL, NULL, NULL, NULL,
|
|
|
|
NULL, 0, NULL)) < 0)
|
|
|
|
return ret;
|
|
|
|
*rate = av_d2q(res, 1001000);
|
2010-07-26 23:12:41 +00:00
|
|
|
if (rate->num <= 0 || rate->den <= 0)
|
2010-07-26 23:12:38 +00:00
|
|
|
return AVERROR(EINVAL);
|
2010-07-26 23:12:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2010-10-04 13:41:06 +00:00
|
|
|
|
|
|
|
#ifdef TEST
|
|
|
|
|
|
|
|
#undef printf
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
printf("Testing av_parse_video_rate()\n");
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
const char *rates[] = {
|
|
|
|
"-inf",
|
|
|
|
"inf",
|
|
|
|
"nan",
|
|
|
|
"123/0",
|
|
|
|
"-123 / 0",
|
|
|
|
"",
|
|
|
|
"/",
|
|
|
|
" 123 / 321",
|
|
|
|
"foo/foo",
|
|
|
|
"foo/1",
|
|
|
|
"1/foo",
|
|
|
|
"0/0",
|
|
|
|
"/0",
|
|
|
|
"1/",
|
|
|
|
"1",
|
|
|
|
"0",
|
|
|
|
"-123/123",
|
|
|
|
"-foo",
|
|
|
|
"123.23",
|
|
|
|
".23",
|
|
|
|
"-.23",
|
|
|
|
"-0.234",
|
|
|
|
"-0.0000001",
|
|
|
|
" 21332.2324 ",
|
|
|
|
" -21332.2324 ",
|
|
|
|
};
|
|
|
|
|
|
|
|
for (i = 0; i < FF_ARRAY_ELEMS(rates); i++) {
|
|
|
|
int ret;
|
|
|
|
AVRational q = (AVRational){0, 0};
|
|
|
|
ret = av_parse_video_rate(&q, rates[i]),
|
|
|
|
printf("'%s' -> %d/%d ret:%d\n",
|
|
|
|
rates[i], q.num, q.den, ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* TEST */
|