57 #if HAVE_SYS_RESOURCE_H
59 #include <sys/resource.h>
95 vfprintf(stdout, fmt, vl);
102 static int print_prefix = 1;
113 double min,
double max)
119 error =
"Expected number for %s but found: %s\n";
120 else if (d < min || d > max)
121 error =
"The value for %s was %s which is not within %f - %f\n";
122 else if (type ==
OPT_INT64 && (int64_t)d != d)
123 error =
"Expected int64 for %s but found %s\n";
124 else if (type ==
OPT_INT && (
int)d != d)
125 error =
"Expected int for %s but found %s\n";
139 is_duration ?
"duration" :
"date", context, timestr);
146 int rej_flags,
int alt_flags)
152 for (po = options; po->
name !=
NULL; po++) {
155 if (((po->
flags & req_flags) != req_flags) ||
156 (alt_flags && !(po->
flags & alt_flags)) ||
157 (po->
flags & rej_flags))
169 printf(
"-%-17s %s\n", buf, po->
help);
188 const char *p = strchr(name,
':');
189 int len = p ? p - name : strlen(name);
192 if (!strncmp(name, po->
name, len) && strlen(po->
name) == len)
199 #if HAVE_COMMANDLINETOARGVW
201 #include <shellapi.h>
203 static char** win32_argv_utf8 =
NULL;
204 static int win32_argc = 0;
217 int i, buffsize = 0,
offset = 0;
219 if (win32_argv_utf8) {
220 *argc_ptr = win32_argc;
221 *argv_ptr = win32_argv_utf8;
226 argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc);
227 if (win32_argc <= 0 || !argv_w)
231 for (i = 0; i < win32_argc; i++)
232 buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
235 win32_argv_utf8 =
av_mallocz(
sizeof(
char *) * (win32_argc + 1) + buffsize);
236 argstr_flat = (
char *)win32_argv_utf8 +
sizeof(
char *) * (win32_argc + 1);
237 if (win32_argv_utf8 ==
NULL) {
242 for (i = 0; i < win32_argc; i++) {
243 win32_argv_utf8[i] = &argstr_flat[
offset];
244 offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
248 win32_argv_utf8[i] =
NULL;
251 *argc_ptr = win32_argc;
252 *argv_ptr = win32_argv_utf8;
272 char *p = strchr(opt,
':');
274 dstcount = (
int *)(so + 1);
275 *so =
grow_array(*so,
sizeof(**so), dstcount, *dstcount + 1);
276 (*so)[*dstcount - 1].specifier =
av_strdup(p ? p + 1 :
"");
277 dst = &(*so)[*dstcount - 1].u;
296 int ret = po->
u.
func_arg(optctx, opt, arg);
299 "Failed to set value '%s' for option '%s'\n", arg, opt);
316 if (!po->
name && opt[0] ==
'n' && opt[1] ==
'o') {
343 void (*parse_arg_function)(
void *,
const char*))
346 int optindex, handleoptions = 1, ret;
353 while (optindex < argc) {
354 opt = argv[optindex++];
356 if (handleoptions && opt[0] ==
'-' && opt[1] !=
'\0') {
357 if (opt[1] ==
'-' && opt[2] ==
'\0') {
363 if ((ret =
parse_option(optctx, opt, argv[optindex], options)) < 0)
367 if (parse_arg_function)
368 parse_arg_function(optctx, opt);
380 for (i = 0; i < g->
nb_opts; i++) {
402 for (i = 1; i < argc; i++) {
403 const char *cur_opt = argv[i];
405 if (*cur_opt++ !=
'-')
409 if (!po->
name && cur_opt[0] ==
'n' && cur_opt[1] ==
'o')
412 if ((!po->
name && !strcmp(cur_opt, optname)) ||
413 (po->
name && !strcmp(optname, po->
name)))
424 const unsigned char *p;
427 if (!((*p >=
'+' && *p <=
':') || (*p >=
'@' && *p <=
'Z') ||
428 *p ==
'_' || (*p >=
'a' && *p <=
'z')))
435 for (p = a; *p; p++) {
436 if (*p ==
'\\' || *p ==
'"' || *p ==
'$' || *p ==
'`')
438 else if (*p < ' ' || *p >
'~')
452 if (idx && argv[idx + 1])
455 if ((env = getenv(
"FFREPORT")) || idx) {
460 for (i = 0; i < argc; i++) {
469 #define FLAGS (o->type == AV_OPT_TYPE_FLAGS) ? AV_DICT_APPEND : 0
474 char opt_stripped[128];
477 #if CONFIG_AVRESAMPLE
482 if (!strcmp(opt,
"debug") || !strcmp(opt,
"fdebug"))
485 if (!(p = strchr(opt,
':')))
486 p = opt + strlen(opt);
487 av_strlcpy(opt_stripped, opt,
FFMIN(
sizeof(opt_stripped), p - opt + 1));
491 ((opt[0] ==
'v' || opt[0] ==
'a' || opt[0] ==
's') &&
516 #if CONFIG_SWRESAMPLE
531 #if CONFIG_AVRESAMPLE
554 for (i = 0; i < nb_groups; i++) {
556 if (p->
sep && !strcmp(p->
sep, opt))
591 resample_opts =
NULL;
605 const char *key,
const char *val)
622 memset(octx, 0,
sizeof(*octx));
678 while (optindex < argc) {
679 const char *opt = argv[optindex++], *
arg;
685 if (opt[0] ==
'-' && opt[1] ==
'-' && !opt[2]) {
690 if (opt[0] !=
'-' || !opt[1] || dashdash+1 == optindex) {
697 #define GET_ARG(arg) \
699 arg = argv[optindex++]; \
701 av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'.\n", opt);\
702 return AVERROR(EINVAL); \
711 groups[ret].
name, arg);
720 arg = argv[optindex++];
729 "argument '%s'.\n", po->
name, po->
help, arg);
734 if (argv[optindex]) {
738 "argument '%s'.\n", opt, argv[optindex]);
743 "with argument '%s'.\n", opt, argv[optindex]);
749 if (opt[0] ==
'n' && opt[1] ==
'o' &&
754 "argument 0.\n", po->
name, po->
help);
773 const struct {
const char *
name;
int level; } log_levels[] = {
788 if (!strcmp(log_levels[i].
name, arg)) {
794 level = strtol(arg, &tail, 10);
797 "Possible levels are numbers or:\n", arg);
811 while ((c = *(
template++))) {
813 if (!(c = *(
template++)))
821 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
822 tm->tm_hour, tm->tm_min, tm->tm_sec);
836 char *filename_template =
NULL;
846 tm = localtime(&now);
848 while (env && *env) {
852 "Failed to parse FFREPORT environment variable: %s\n",
859 if (!strcmp(key,
"file")) {
861 filename_template = val;
882 filename.str, strerror(errno));
887 "%s started on %04d-%02d-%02d at %02d:%02d:%02d\n"
888 "Report written to \"%s\"\n",
890 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
891 tm->tm_hour, tm->tm_min, tm->tm_sec,
908 max = strtol(arg, &tail, 10);
933 struct rlimit rl = { lim, lim + 1 };
934 if (setrlimit(RLIMIT_CPU, &rl))
945 const char *errbuf_ptr = errbuf;
955 #define SHOW_VERSION 2
956 #define SHOW_CONFIG 4
957 #define SHOW_COPYRIGHT 8
959 #define PRINT_LIB_INFO(libname, LIBNAME, flags, level) \
960 if (CONFIG_##LIBNAME) { \
961 const char *indent = flags & INDENT? " " : ""; \
962 if (flags & SHOW_VERSION) { \
963 unsigned int version = libname##_version(); \
964 av_log(NULL, level, \
965 "%slib%-11s %2d.%3d.%3d / %2d.%3d.%3d\n", \
967 LIB##LIBNAME##_VERSION_MAJOR, \
968 LIB##LIBNAME##_VERSION_MINOR, \
969 LIB##LIBNAME##_VERSION_MICRO, \
970 version >> 16, version >> 8 & 0xff, version & 0xff); \
972 if (flags & SHOW_CONFIG) { \
973 const char *cfg = libname##_configuration(); \
974 if (strcmp(FFMPEG_CONFIGURATION, cfg)) { \
976 av_log(NULL, level, \
977 "%sWARNING: library configuration mismatch\n", \
981 av_log(NULL, level, "%s%-11s configuration: %s\n", \
982 indent, #libname, cfg); \
1004 const char *indent = flags &
INDENT?
" " :
"";
1008 av_log(
NULL, level,
" Copyright (c) %d-%d the FFmpeg developers",
1011 av_log(
NULL, level,
"%sbuilt on %s %s with %s\n",
1012 indent, __DATE__, __TIME__, CC_IDENT);
1014 av_log(
NULL, level,
"%sconfiguration: " FFMPEG_CONFIGURATION
"\n", indent);
1041 "This version of %s has nonfree parts compiled in.\n"
1042 "Therefore it is not legally redistributable.\n",
1046 "%s is free software; you can redistribute it and/or modify\n"
1047 "it under the terms of the GNU General Public License as published by\n"
1048 "the Free Software Foundation; either version 3 of the License, or\n"
1049 "(at your option) any later version.\n"
1051 "%s is distributed in the hope that it will be useful,\n"
1052 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1053 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1054 "GNU General Public License for more details.\n"
1056 "You should have received a copy of the GNU General Public License\n"
1057 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
1061 "%s is free software; you can redistribute it and/or modify\n"
1062 "it under the terms of the GNU General Public License as published by\n"
1063 "the Free Software Foundation; either version 2 of the License, or\n"
1064 "(at your option) any later version.\n"
1066 "%s is distributed in the hope that it will be useful,\n"
1067 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1068 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1069 "GNU General Public License for more details.\n"
1071 "You should have received a copy of the GNU General Public License\n"
1072 "along with %s; if not, write to the Free Software\n"
1073 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
1077 "%s is free software; you can redistribute it and/or modify\n"
1078 "it under the terms of the GNU Lesser General Public License as published by\n"
1079 "the Free Software Foundation; either version 3 of the License, or\n"
1080 "(at your option) any later version.\n"
1082 "%s is distributed in the hope that it will be useful,\n"
1083 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1084 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1085 "GNU Lesser General Public License for more details.\n"
1087 "You should have received a copy of the GNU Lesser General Public License\n"
1088 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
1092 "%s is free software; you can redistribute it and/or\n"
1093 "modify it under the terms of the GNU Lesser General Public\n"
1094 "License as published by the Free Software Foundation; either\n"
1095 "version 2.1 of the License, or (at your option) any later version.\n"
1097 "%s is distributed in the hope that it will be useful,\n"
1098 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1099 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
1100 "Lesser General Public License for more details.\n"
1102 "You should have received a copy of the GNU Lesser General Public\n"
1103 "License along with %s; if not, write to the Free Software\n"
1104 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
1115 const char *last_name;
1117 printf(
"File formats:\n"
1118 " D. = Demuxing supported\n"
1119 " .E = Muxing supported\n"
1126 const char *long_name =
NULL;
1129 if ((name ==
NULL || strcmp(ofmt->
name, name) < 0) &&
1130 strcmp(ofmt->
name, last_name) > 0) {
1137 if ((name ==
NULL || strcmp(ifmt->
name, name) < 0) &&
1138 strcmp(ifmt->
name, last_name) > 0) {
1143 if (name && strcmp(ifmt->
name, name) == 0)
1150 printf(
" %s%s %-15s %s\n",
1154 long_name ? long_name:
" ");
1159 #define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name) \
1160 if (codec->field) { \
1161 const type *p = codec->field; \
1163 printf(" Supported " list_name ":"); \
1164 while (*p != term) { \
1166 printf(" %s", name); \
1176 printf(
"%s %s [%s]:\n", encoder ?
"Encoder" :
"Decoder", c->
name,
1180 printf(
" Threading capabilities: ");
1187 default: printf(
"no");
break;
1195 printf(
" Supported framerates:");
1197 printf(
" %d/%d", fps->
num, fps->
den);
1226 default:
return '?';
1234 if (prev->
id ==
id &&
1246 return (*da)->type != (*db)->type ? (*da)->type - (*db)->type :
1247 strcmp((*da)->name, (*db)->name);
1254 unsigned nb_codecs = 0, i = 0;
1258 if (!(codecs =
av_calloc(nb_codecs,
sizeof(*codecs)))) {
1275 printf(
" (%s: ", encoder ?
"encoders" :
"decoders");
1278 printf(
"%s ", codec->
name);
1289 " D..... = Decoding supported\n"
1290 " .E.... = Encoding supported\n"
1291 " ..V... = Video codec\n"
1292 " ..A... = Audio codec\n"
1293 " ..S... = Subtitle codec\n"
1294 " ...I.. = Intra frame-only codec\n"
1295 " ....L. = Lossy compression\n"
1296 " .....S = Lossless compression\n"
1298 for (i = 0; i < nb_codecs; i++) {
1316 if (strcmp(codec->
name, desc->
name)) {
1323 if (strcmp(codec->
name, desc->
name)) {
1343 " S..... = Subtitle\n"
1344 " .F.... = Frame-level multithreading\n"
1345 " ..S... = Slice-level multithreading\n"
1346 " ...X.. = Codec is experimental\n"
1347 " ....B. = Supports draw_horiz_band\n"
1348 " .....D = Supports direct rendering method 1\n"
1350 encoder ?
"Encoders" :
"Decoders");
1351 for (i = 0; i < nb_codecs; i++) {
1364 if (strcmp(codec->
name, desc->
name))
1365 printf(
" (codec %s)", desc->
name);
1389 printf(
"Bitstream filters:\n");
1391 printf(
"%s\n", bsf->
name);
1398 void *opaque =
NULL;
1401 printf(
"Supported file protocols:\n"
1404 printf(
"%s\n", name);
1405 printf(
"Output:\n");
1407 printf(
"%s\n", name);
1414 char descr[64], *descr_cur;
1418 printf(
"Filters:\n");
1422 for (i = 0; i < 2; i++) {
1424 *(descr_cur++) =
'-';
1425 *(descr_cur++) =
'>';
1427 pad = i ? (*filter)->outputs : (*filter)->inputs;
1428 for (j = 0; pad && pad[j].
name; j++) {
1429 if (descr_cur >= descr +
sizeof(descr) - 4)
1434 *(descr_cur++) =
'|';
1437 printf(
"%-16s %-10s %s\n", (*filter)->name, descr, (*filter)->description);
1447 printf(
"Pixel formats:\n"
1448 "I.... = Supported Input format for conversion\n"
1449 ".O... = Supported Output format for conversion\n"
1450 "..H.. = Hardware accelerated format\n"
1451 "...P. = Paletted format\n"
1452 "....B = Bitstream format\n"
1453 "FLAGS NAME NB_COMPONENTS BITS_PER_PIXEL\n"
1457 # define sws_isSupportedInput(x) 0
1458 # define sws_isSupportedOutput(x) 0
1463 printf(
"%c%c%c%c%c %-16s %d %2d\n",
1480 const char *
name, *descr;
1482 printf(
"Individual channels:\n"
1483 "NAME DESCRIPTION\n");
1484 for (i = 0; i < 63; i++) {
1489 printf(
"%-12s%s\n", name, descr);
1491 printf(
"\nStandard channel layouts:\n"
1492 "NAME DECOMPOSITION\n");
1495 printf(
"%-12s", name);
1496 for (j = 1; j; j <<= 1)
1539 "but no %s for it are available. FFmpeg might need to be "
1540 "recompiled with additional external libraries.\n",
1541 name, encoder ?
"encoders" :
"decoders");
1561 printf(
" Common extensions: %s.\n", fmt->
extensions);
1580 printf(
" Common extensions: %s.\n", fmt->
extensions);
1582 printf(
" Mime type: %s.\n", fmt->
mime_type);
1585 printf(
" Default video codec: %s.\n", desc->
name);
1589 printf(
" Default audio codec: %s.\n", desc->
name);
1593 printf(
" Default subtitle codec: %s.\n", desc->
name);
1606 par = strchr(topic,
'=');
1612 }
else if (!strcmp(topic,
"decoder")) {
1614 }
else if (!strcmp(topic,
"encoder")) {
1616 }
else if (!strcmp(topic,
"demuxer")) {
1618 }
else if (!strcmp(topic,
"muxer")) {
1633 while (c !=
'\n' && c != EOF)
1642 FILE *f = fopen(filename,
"rb");
1649 fseek(f, 0, SEEK_END);
1651 fseek(f, 0, SEEK_SET);
1652 if (*size == (
size_t)-1) {
1663 ret = fread(*bufptr, 1, *size, f);
1668 filename, strerror(errno));
1674 (*bufptr)[(*size)++] =
'\0';
1682 const char *preset_name,
int is_path,
1683 const char *codec_name)
1687 const char *base[3] = { getenv(
"FFMPEG_DATADIR"),
1692 av_strlcpy(filename, preset_name, filename_size);
1693 f = fopen(filename,
"r");
1696 char datadir[MAX_PATH], *ls;
1699 if (GetModuleFileNameA(GetModuleHandleA(
NULL), datadir,
sizeof(datadir) - 1))
1701 for (ls = datadir; ls < datadir + strlen(datadir); ls++)
1702 if (*ls ==
'\\') *ls =
'/';
1704 if (ls = strrchr(datadir,
'/'))
1707 strncat(datadir,
"/ffpresets",
sizeof(datadir) - 1 - strlen(datadir));
1712 for (i = 0; i < 3 && !f; i++) {
1715 snprintf(filename, filename_size,
"%s%s/%s.ffpreset", base[i],
1716 i != 1 ?
"" :
"/.ffmpeg", preset_name);
1717 f = fopen(filename,
"r");
1718 if (!f && codec_name) {
1720 "%s%s/%s-%s.ffpreset",
1721 base[i], i != 1 ?
"" :
"/.ffmpeg", codec_name,
1723 f = fopen(filename,
"r");
1769 char *p = strchr(t->
key,
':');
1774 case 1: *p = 0;
break;
1776 default:
return NULL;
1784 else if (t->
key[0] == prefix &&
1806 "Could not alloc memory for stream options.\n");
1817 if (new_size >= INT_MAX / elem_size) {
1821 if (*size < new_size) {
1827 memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);
1840 int h_chroma_shift, v_chroma_shift;
1868 const int h_shift = i==0 ? 0 : h_chroma_shift;
1869 const int v_shift = i==0 ? 0 : v_chroma_shift;
1875 (pixel_size*edge >> h_shift), 32);
1933 for(tmp= *pool; tmp; tmp= tmp->
next)