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"
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
int i;
|
2010-07-26 23:12:41 +00:00
|
|
|
int n = FF_ARRAY_ELEMS(video_rate_abbrs);
|
2010-07-26 23:12:28 +00:00
|
|
|
char *cp;
|
|
|
|
|
|
|
|
/* First, we check our abbreviation table */
|
|
|
|
for (i = 0; i < n; ++i)
|
2010-07-26 23:12:41 +00:00
|
|
|
if (!strcmp(video_rate_abbrs[i].abbr, arg)) {
|
2010-07-26 23:12:45 +00:00
|
|
|
*rate = video_rate_abbrs[i].rate;
|
2010-07-26 23:12:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Then, we try to parse it as fraction */
|
|
|
|
cp = strchr(arg, '/');
|
|
|
|
if (!cp)
|
|
|
|
cp = strchr(arg, ':');
|
|
|
|
if (cp) {
|
|
|
|
char *cpp;
|
2010-07-26 23:12:41 +00:00
|
|
|
rate->num = strtol(arg, &cpp, 10);
|
2010-07-26 23:12:28 +00:00
|
|
|
if (cpp != arg || cpp == cp)
|
2010-07-26 23:12:41 +00:00
|
|
|
rate->den = strtol(cp+1, &cpp, 10);
|
2010-07-26 23:12:28 +00:00
|
|
|
else
|
2010-07-26 23:12:41 +00:00
|
|
|
rate->num = 0;
|
2010-07-26 23:12:28 +00:00
|
|
|
} else {
|
|
|
|
/* Finally we give up and parse it as double */
|
2010-07-26 23:12:48 +00:00
|
|
|
*rate = av_d2q(strtod(arg, 0), 1001000);
|
2010-07-26 23:12:28 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|