55 #if HAVE_SYS_RESOURCE_H
57 #include <sys/resource.h>
97 vfprintf(stdout, fmt, vl);
104 static int print_prefix = 1;
130 double min,
double max)
136 error =
"Expected number for %s but found: %s\n";
137 else if (d < min || d > max)
138 error =
"The value for %s was %s which is not within %f - %f\n";
139 else if (type ==
OPT_INT64 && (int64_t)d != d)
140 error =
"Expected int64 for %s but found %s\n";
141 else if (type ==
OPT_INT && (
int)d != d)
142 error =
"Expected int for %s but found %s\n";
156 is_duration ?
"duration" :
"date", context, timestr);
163 int rej_flags,
int alt_flags)
169 for (po = options; po->
name != NULL; po++) {
172 if (((po->
flags & req_flags) != req_flags) ||
173 (alt_flags && !(po->
flags & alt_flags)) ||
174 (po->
flags & rej_flags))
186 printf(
"-%-17s %s\n", buf, po->
help);
205 const char *p = strchr(name,
':');
206 int len = p ? p - name : strlen(name);
208 while (po->
name != NULL) {
209 if (!strncmp(name, po->
name, len) && strlen(po->
name) == len)
216 #if HAVE_COMMANDLINETOARGVW
218 #include <shellapi.h>
220 static char** win32_argv_utf8 = NULL;
221 static int win32_argc = 0;
234 int i, buffsize = 0,
offset = 0;
236 if (win32_argv_utf8) {
237 *argc_ptr = win32_argc;
238 *argv_ptr = win32_argv_utf8;
243 argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc);
244 if (win32_argc <= 0 || !argv_w)
248 for (i = 0; i < win32_argc; i++)
249 buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
250 NULL, 0, NULL, NULL);
252 win32_argv_utf8 =
av_mallocz(
sizeof(
char *) * (win32_argc + 1) + buffsize);
253 argstr_flat = (
char *)win32_argv_utf8 +
sizeof(
char *) * (win32_argc + 1);
254 if (win32_argv_utf8 == NULL) {
259 for (i = 0; i < win32_argc; i++) {
260 win32_argv_utf8[i] = &argstr_flat[
offset];
261 offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
263 buffsize - offset, NULL, NULL);
265 win32_argv_utf8[i] = NULL;
268 *argc_ptr = win32_argc;
269 *argv_ptr = win32_argv_utf8;
289 char *p = strchr(opt,
':');
291 dstcount = (
int *)(so + 1);
292 *so =
grow_array(*so,
sizeof(**so), dstcount, *dstcount + 1);
293 (*so)[*dstcount - 1].specifier =
av_strdup(p ? p + 1 :
"");
294 dst = &(*so)[*dstcount - 1].u;
316 "Failed to set value '%s' for option '%s': %s\n",
334 if (!po->
name && opt[0] ==
'n' && opt[1] ==
'o') {
361 void (*parse_arg_function)(
void *,
const char*))
364 int optindex, handleoptions = 1,
ret;
371 while (optindex < argc) {
372 opt = argv[optindex++];
374 if (handleoptions && opt[0] ==
'-' && opt[1] !=
'\0') {
375 if (opt[1] ==
'-' && opt[2] ==
'\0') {
385 if (parse_arg_function)
386 parse_arg_function(optctx, opt);
398 for (i = 0; i < g->
nb_opts; i++) {
404 "%s %s -- you are trying to apply an input option to an "
405 "output file or vice versa. Move this option before the "
406 "file it belongs to.\n", o->
key, o->
opt->
help,
430 for (i = 1; i < argc; i++) {
431 const char *cur_opt = argv[i];
433 if (*cur_opt++ !=
'-')
437 if (!po->
name && cur_opt[0] ==
'n' && cur_opt[1] ==
'o')
440 if ((!po->
name && !strcmp(cur_opt, optname)) ||
441 (po->
name && !strcmp(optname, po->
name)))
452 const unsigned char *p;
455 if (!((*p >=
'+' && *p <=
':') || (*p >=
'@' && *p <=
'Z') ||
456 *p ==
'_' || (*p >=
'a' && *p <=
'z')))
463 for (p = a; *p; p++) {
464 if (*p ==
'\\' || *p ==
'"' || *p ==
'$' || *p ==
'`')
466 else if (*p < ' ' || *p >
'~')
480 if (idx && argv[idx + 1])
483 if ((env = getenv(
"FFREPORT")) || idx) {
488 for (i = 0; i < argc; i++) {
497 #define FLAGS (o->type == AV_OPT_TYPE_FLAGS) ? AV_DICT_APPEND : 0
502 char opt_stripped[128];
505 #if CONFIG_AVRESAMPLE
510 if (!strcmp(opt,
"debug") || !strcmp(opt,
"fdebug"))
513 if (!(p = strchr(opt,
':')))
514 p = opt + strlen(opt);
515 av_strlcpy(opt_stripped, opt,
FFMIN(
sizeof(opt_stripped), p - opt + 1));
519 ((opt[0] ==
'v' || opt[0] ==
'a' || opt[0] ==
's') &&
544 #if CONFIG_SWRESAMPLE
546 if (!consumed && (o=
av_opt_find(&swr_class, opt, NULL, 0,
559 #if CONFIG_AVRESAMPLE
582 for (i = 0; i < nb_groups; i++) {
584 if (p->
sep && !strcmp(p->
sep, opt))
619 resample_opts = NULL;
633 const char *key,
const char *
val)
650 memset(octx, 0,
sizeof(*octx));
706 while (optindex < argc) {
707 const char *opt = argv[optindex++], *
arg;
713 if (opt[0] ==
'-' && opt[1] ==
'-' && !opt[2]) {
718 if (opt[0] !=
'-' || !opt[1] || dashdash+1 == optindex) {
725 #define GET_ARG(arg) \
727 arg = argv[optindex++]; \
729 av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'.\n", opt);\
730 return AVERROR(EINVAL); \
739 groups[ret].
name, arg);
748 arg = argv[optindex++];
757 "argument '%s'.\n", po->
name, po->
help, arg);
762 if (argv[optindex]) {
766 "argument '%s'.\n", opt, argv[optindex]);
771 "with argument '%s'.\n", opt, argv[optindex]);
777 if (opt[0] ==
'n' && opt[1] ==
'o' &&
782 "argument 0.\n", po->
name, po->
help);
801 const struct {
const char *
name;
int level; } log_levels[] = {
815 tail = strstr(arg,
"repeat");
818 arg += 6 + (arg[6]==
'+');
823 if (!strcmp(log_levels[i].
name, arg)) {
829 level = strtol(arg, &tail, 10);
832 "Possible levels are numbers or:\n", arg);
846 while ((c = *(
template++))) {
848 if (!(c = *(
template++)))
856 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
857 tm->tm_hour, tm->tm_min, tm->tm_sec);
871 char *filename_template = NULL;
881 tm = localtime(&now);
883 while (env && *env) {
887 "Failed to parse FFREPORT environment variable: %s\n",
894 if (!strcmp(key,
"file")) {
896 filename_template =
val;
917 filename.str, strerror(errno));
922 "%s started on %04d-%02d-%02d at %02d:%02d:%02d\n"
923 "Report written to \"%s\"\n",
925 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
926 tm->tm_hour, tm->tm_min, tm->tm_sec,
942 max = strtol(arg, &tail, 10);
967 struct rlimit rl = { lim, lim + 1 };
968 if (setrlimit(RLIMIT_CPU, &rl))
977 int opt_opencl(
void *optctx,
const char *opt,
const char *
arg)
980 const char *opts =
arg;
999 const char *errbuf_ptr = errbuf;
1009 #define SHOW_VERSION 2
1010 #define SHOW_CONFIG 4
1011 #define SHOW_COPYRIGHT 8
1013 #define PRINT_LIB_INFO(libname, LIBNAME, flags, level) \
1014 if (CONFIG_##LIBNAME) { \
1015 const char *indent = flags & INDENT? " " : ""; \
1016 if (flags & SHOW_VERSION) { \
1017 unsigned int version = libname##_version(); \
1018 av_log(NULL, level, \
1019 "%slib%-11s %2d.%3d.%3d / %2d.%3d.%3d\n", \
1021 LIB##LIBNAME##_VERSION_MAJOR, \
1022 LIB##LIBNAME##_VERSION_MINOR, \
1023 LIB##LIBNAME##_VERSION_MICRO, \
1024 version >> 16, version >> 8 & 0xff, version & 0xff); \
1026 if (flags & SHOW_CONFIG) { \
1027 const char *cfg = libname##_configuration(); \
1028 if (strcmp(FFMPEG_CONFIGURATION, cfg)) { \
1029 if (!warned_cfg) { \
1030 av_log(NULL, level, \
1031 "%sWARNING: library configuration mismatch\n", \
1035 av_log(NULL, level, "%s%-11s configuration: %s\n", \
1036 indent, #libname, cfg); \
1056 const char *indent = flags &
INDENT?
" " :
"";
1060 av_log(NULL, level,
" Copyright (c) %d-%d the FFmpeg developers",
1062 av_log(NULL, level,
"\n");
1063 av_log(NULL, level,
"%sbuilt on %s %s with %s\n",
1064 indent, __DATE__, __TIME__, CC_IDENT);
1066 av_log(NULL, level,
"%sconfiguration: " FFMPEG_CONFIGURATION
"\n", indent);
1093 "This version of %s has nonfree parts compiled in.\n"
1094 "Therefore it is not legally redistributable.\n",
1098 "%s is free software; you can redistribute it and/or modify\n"
1099 "it under the terms of the GNU General Public License as published by\n"
1100 "the Free Software Foundation; either version 3 of the License, or\n"
1101 "(at your option) any later version.\n"
1103 "%s is distributed in the hope that it will be useful,\n"
1104 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1105 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1106 "GNU General Public License for more details.\n"
1108 "You should have received a copy of the GNU General Public License\n"
1109 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
1113 "%s is free software; you can redistribute it and/or modify\n"
1114 "it under the terms of the GNU General Public License as published by\n"
1115 "the Free Software Foundation; either version 2 of the License, or\n"
1116 "(at your option) any later version.\n"
1118 "%s is distributed in the hope that it will be useful,\n"
1119 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1120 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1121 "GNU General Public License for more details.\n"
1123 "You should have received a copy of the GNU General Public License\n"
1124 "along with %s; if not, write to the Free Software\n"
1125 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
1129 "%s is free software; you can redistribute it and/or modify\n"
1130 "it under the terms of the GNU Lesser General Public License as published by\n"
1131 "the Free Software Foundation; either version 3 of the License, or\n"
1132 "(at your option) any later version.\n"
1134 "%s is distributed in the hope that it will be useful,\n"
1135 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1136 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1137 "GNU Lesser General Public License for more details.\n"
1139 "You should have received a copy of the GNU Lesser General Public License\n"
1140 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
1144 "%s is free software; you can redistribute it and/or\n"
1145 "modify it under the terms of the GNU Lesser General Public\n"
1146 "License as published by the Free Software Foundation; either\n"
1147 "version 2.1 of the License, or (at your option) any later version.\n"
1149 "%s is distributed in the hope that it will be useful,\n"
1150 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1151 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
1152 "Lesser General Public License for more details.\n"
1154 "You should have received a copy of the GNU Lesser General Public\n"
1155 "License along with %s; if not, write to the Free Software\n"
1156 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
1167 const char *last_name;
1169 printf(
"File formats:\n"
1170 " D. = Demuxing supported\n"
1171 " .E = Muxing supported\n"
1177 const char *
name = NULL;
1178 const char *long_name = NULL;
1181 if ((name == NULL || strcmp(ofmt->
name, name) < 0) &&
1182 strcmp(ofmt->
name, last_name) > 0) {
1189 if ((name == NULL || strcmp(ifmt->
name, name) < 0) &&
1190 strcmp(ifmt->
name, last_name) > 0) {
1195 if (name && strcmp(ifmt->
name, name) == 0)
1202 printf(
" %s%s %-15s %s\n",
1206 long_name ? long_name:
" ");
1211 #define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name) \
1212 if (codec->field) { \
1213 const type *p = codec->field; \
1215 printf(" Supported " list_name ":"); \
1216 while (*p != term) { \
1218 printf(" %s", name); \
1228 printf(
"%s %s [%s]:\n", encoder ?
"Encoder" :
"Decoder", c->
name,
1233 printf(
" Threading capabilities: ");
1240 default: printf(
"no");
break;
1248 printf(
" Supported framerates:");
1250 printf(
" %d/%d", fps->
num, fps->
den);
1279 default:
return '?';
1287 if (prev->
id ==
id &&
1299 return (*da)->type != (*db)->type ? (*da)->type - (*db)->type :
1300 strcmp((*da)->name, (*db)->name);
1307 unsigned nb_codecs = 0, i = 0;
1311 if (!(codecs =
av_calloc(nb_codecs,
sizeof(*codecs)))) {
1328 printf(
" (%s: ", encoder ?
"encoders" :
"decoders");
1331 printf(
"%s ", codec->
name);
1342 " D..... = Decoding supported\n"
1343 " .E.... = Encoding supported\n"
1344 " ..V... = Video codec\n"
1345 " ..A... = Audio codec\n"
1346 " ..S... = Subtitle codec\n"
1347 " ...I.. = Intra frame-only codec\n"
1348 " ....L. = Lossy compression\n"
1349 " .....S = Lossless compression\n"
1351 for (i = 0; i < nb_codecs; i++) {
1369 if (strcmp(codec->
name, desc->
name)) {
1376 if (strcmp(codec->
name, desc->
name)) {
1396 " S..... = Subtitle\n"
1397 " .F.... = Frame-level multithreading\n"
1398 " ..S... = Slice-level multithreading\n"
1399 " ...X.. = Codec is experimental\n"
1400 " ....B. = Supports draw_horiz_band\n"
1401 " .....D = Supports direct rendering method 1\n"
1403 encoder ?
"Encoders" :
"Decoders");
1404 for (i = 0; i < nb_codecs; i++) {
1417 if (strcmp(codec->
name, desc->
name))
1418 printf(
" (codec %s)", desc->
name);
1438 int show_bsfs(
void *optctx,
const char *opt,
const char *arg)
1442 printf(
"Bitstream filters:\n");
1444 printf(
"%s\n", bsf->
name);
1451 void *opaque = NULL;
1454 printf(
"Supported file protocols:\n"
1457 printf(
"%s\n", name);
1458 printf(
"Output:\n");
1460 printf(
"%s\n", name);
1467 char descr[64], *descr_cur;
1472 " T. = Timeline support\n"
1473 " .S = Slice threading\n"
1474 " A = Audio input/output\n"
1475 " V = Video input/output\n"
1476 " N = Dynamic number and/or type of input/output\n"
1477 " | = Source or sink filter\n");
1481 for (i = 0; i < 2; i++) {
1483 *(descr_cur++) =
'-';
1484 *(descr_cur++) =
'>';
1487 for (j = 0; pad && pad[j].
name; j++) {
1488 if (descr_cur >= descr +
sizeof(descr) - 4)
1497 printf(
" %c%c %-16s %-10s %s\n",
1510 printf(
"Pixel formats:\n"
1511 "I.... = Supported Input format for conversion\n"
1512 ".O... = Supported Output format for conversion\n"
1513 "..H.. = Hardware accelerated format\n"
1514 "...P. = Paletted format\n"
1515 "....B = Bitstream format\n"
1516 "FLAGS NAME NB_COMPONENTS BITS_PER_PIXEL\n"
1520 # define sws_isSupportedInput(x) 0
1521 # define sws_isSupportedOutput(x) 0
1526 printf(
"%c%c%c%c%c %-16s %d %2d\n",
1543 const char *
name, *descr;
1545 printf(
"Individual channels:\n"
1546 "NAME DESCRIPTION\n");
1547 for (i = 0; i < 63; i++) {
1552 printf(
"%-12s%s\n", name, descr);
1554 printf(
"\nStandard channel layouts:\n"
1555 "NAME DECOMPOSITION\n");
1558 printf(
"%-12s", name);
1559 for (j = 1; j; j <<= 1)
1602 "but no %s for it are available. FFmpeg might need to be "
1603 "recompiled with additional external libraries.\n",
1604 name, encoder ?
"encoders" :
"decoders");
1624 printf(
" Common extensions: %s.\n", fmt->
extensions);
1643 printf(
" Common extensions: %s.\n", fmt->
extensions);
1645 printf(
" Mime type: %s.\n", fmt->
mime_type);
1648 printf(
" Default video codec: %s.\n", desc->
name);
1652 printf(
" Default audio codec: %s.\n", desc->
name);
1656 printf(
" Default subtitle codec: %s.\n", desc->
name);
1664 static void show_help_filter(
const char *
name)
1678 printf(
"Filter %s\n", f->
name);
1683 printf(
" slice threading supported\n");
1685 printf(
" Inputs:\n");
1687 for (i = 0; i <
count; i++) {
1692 printf(
" dynamic (depending on the options)\n");
1694 printf(
" none (source filter)\n");
1696 printf(
" Outputs:\n");
1698 for (i = 0; i <
count; i++) {
1703 printf(
" dynamic (depending on the options)\n");
1705 printf(
" none (sink filter)\n");
1711 printf(
"This filter has support for timeline through the 'enable' option.\n");
1714 "can not to satisfy request\n");
1719 int show_help(
void *optctx,
const char *opt,
const char *arg)
1725 par = strchr(topic,
'=');
1731 }
else if (!strcmp(topic,
"decoder")) {
1733 }
else if (!strcmp(topic,
"encoder")) {
1735 }
else if (!strcmp(topic,
"demuxer")) {
1737 }
else if (!strcmp(topic,
"muxer")) {
1740 }
else if (!strcmp(topic,
"filter")) {
1741 show_help_filter(par);
1756 while (c !=
'\n' && c != EOF)
1765 FILE *f = fopen(filename,
"rb");
1772 fseek(f, 0, SEEK_END);
1774 fseek(f, 0, SEEK_SET);
1775 if (*size == (
size_t)-1) {
1786 ret = fread(*bufptr, 1, *size, f);
1791 filename, strerror(errno));
1797 (*bufptr)[(*size)++] =
'\0';
1805 const char *preset_name,
int is_path,
1806 const char *codec_name)
1810 const char *base[3] = { getenv(
"FFMPEG_DATADIR"),
1815 av_strlcpy(filename, preset_name, filename_size);
1816 f = fopen(filename,
"r");
1819 char datadir[MAX_PATH], *ls;
1822 if (GetModuleFileNameA(GetModuleHandleA(NULL), datadir,
sizeof(datadir) - 1))
1824 for (ls = datadir; ls < datadir + strlen(datadir); ls++)
1825 if (*ls ==
'\\') *ls =
'/';
1827 if (ls = strrchr(datadir,
'/'))
1830 strncat(datadir,
"/ffpresets",
sizeof(datadir) - 1 - strlen(datadir));
1835 for (i = 0; i < 3 && !f; i++) {
1838 snprintf(filename, filename_size,
"%s%s/%s.ffpreset", base[i],
1839 i != 1 ?
"" :
"/.ffmpeg", preset_name);
1840 f = fopen(filename,
"r");
1841 if (!f && codec_name) {
1843 "%s%s/%s-%s.ffpreset",
1844 base[i], i != 1 ?
"" :
"/.ffmpeg", codec_name,
1846 f = fopen(filename,
"r");
1892 char *p = strchr(t->
key,
':');
1897 case 1: *p = 0;
break;
1899 default:
return NULL;
1907 else if (t->
key[0] == prefix &&
1929 "Could not alloc memory for stream options.\n");
1940 if (new_size >= INT_MAX / elem_size) {
1944 if (*size < new_size) {
1950 memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);