56 #if HAVE_SYS_RESOURCE_H
58 #include <sys/resource.h>
98 vfprintf(stdout, fmt, vl);
105 static int print_prefix = 1;
131 double min,
double max)
137 error =
"Expected number for %s but found: %s\n";
138 else if (d < min || d > max)
139 error =
"The value for %s was %s which is not within %f - %f\n";
140 else if (type ==
OPT_INT64 && (int64_t)d != d)
141 error =
"Expected int64 for %s but found %s\n";
142 else if (type ==
OPT_INT && (
int)d != d)
143 error =
"Expected int for %s but found %s\n";
157 is_duration ?
"duration" :
"date", context, timestr);
164 int rej_flags,
int alt_flags)
170 for (po = options; po->
name != NULL; po++) {
173 if (((po->
flags & req_flags) != req_flags) ||
174 (alt_flags && !(po->
flags & alt_flags)) ||
175 (po->
flags & rej_flags))
187 printf(
"-%-17s %s\n", buf, po->
help);
206 const char *p = strchr(name,
':');
207 int len = p ? p - name : strlen(name);
209 while (po->
name != NULL) {
210 if (!strncmp(name, po->
name, len) && strlen(po->
name) == len)
220 #if HAVE_COMMANDLINETOARGVW && defined(_WIN32)
222 #include <shellapi.h>
224 static char** win32_argv_utf8 = NULL;
225 static int win32_argc = 0;
238 int i, buffsize = 0,
offset = 0;
240 if (win32_argv_utf8) {
241 *argc_ptr = win32_argc;
242 *argv_ptr = win32_argv_utf8;
247 argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc);
248 if (win32_argc <= 0 || !argv_w)
252 for (i = 0; i < win32_argc; i++)
253 buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
254 NULL, 0, NULL, NULL);
256 win32_argv_utf8 =
av_mallocz(
sizeof(
char *) * (win32_argc + 1) + buffsize);
257 argstr_flat = (
char *)win32_argv_utf8 +
sizeof(
char *) * (win32_argc + 1);
258 if (win32_argv_utf8 == NULL) {
263 for (i = 0; i < win32_argc; i++) {
264 win32_argv_utf8[i] = &argstr_flat[
offset];
265 offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
267 buffsize - offset, NULL, NULL);
269 win32_argv_utf8[i] = NULL;
272 *argc_ptr = win32_argc;
273 *argv_ptr = win32_argv_utf8;
293 char *p = strchr(opt,
':');
295 dstcount = (
int *)(so + 1);
296 *so =
grow_array(*so,
sizeof(**so), dstcount, *dstcount + 1);
297 (*so)[*dstcount - 1].specifier =
av_strdup(p ? p + 1 :
"");
298 dst = &(*so)[*dstcount - 1].u;
320 "Failed to set value '%s' for option '%s': %s\n",
338 if (!po->
name && opt[0] ==
'n' && opt[1] ==
'o') {
365 void (*parse_arg_function)(
void *,
const char*))
368 int optindex, handleoptions = 1,
ret;
375 while (optindex < argc) {
376 opt = argv[optindex++];
378 if (handleoptions && opt[0] ==
'-' && opt[1] !=
'\0') {
379 if (opt[1] ==
'-' && opt[2] ==
'\0') {
389 if (parse_arg_function)
390 parse_arg_function(optctx, opt);
402 for (i = 0; i < g->
nb_opts; i++) {
408 "%s %s -- you are trying to apply an input option to an "
409 "output file or vice versa. Move this option before the "
410 "file it belongs to.\n", o->
key, o->
opt->
help,
434 for (i = 1; i < argc; i++) {
435 const char *cur_opt = argv[i];
437 if (*cur_opt++ !=
'-')
441 if (!po->
name && cur_opt[0] ==
'n' && cur_opt[1] ==
'o')
444 if ((!po->
name && !strcmp(cur_opt, optname)) ||
445 (po->
name && !strcmp(optname, po->
name)))
456 const unsigned char *p;
459 if (!((*p >=
'+' && *p <=
':') || (*p >=
'@' && *p <=
'Z') ||
460 *p ==
'_' || (*p >=
'a' && *p <=
'z')))
467 for (p = a; *p; p++) {
468 if (*p ==
'\\' || *p ==
'"' || *p ==
'$' || *p ==
'`')
470 else if (*p < ' ' || *p >
'~')
484 if (idx && argv[idx + 1])
487 if ((env = getenv(
"FFREPORT")) || idx) {
492 for (i = 0; i < argc; i++) {
502 int opt_flags,
int search_flags)
510 #define FLAGS (o->type == AV_OPT_TYPE_FLAGS) ? AV_DICT_APPEND : 0
515 char opt_stripped[128];
518 #if CONFIG_AVRESAMPLE
523 if (!strcmp(opt,
"debug") || !strcmp(opt,
"fdebug"))
526 if (!(p = strchr(opt,
':')))
527 p = opt + strlen(opt);
528 av_strlcpy(opt_stripped, opt,
FFMIN(
sizeof(opt_stripped), p - opt + 1));
530 if ((o =
opt_find(&cc, opt_stripped, NULL, 0,
532 ((opt[0] ==
'v' || opt[0] ==
'a' || opt[0] ==
's') &&
546 if (!consumed &&
opt_find(&sc, opt, NULL, 0,
557 #if CONFIG_SWRESAMPLE
559 if (!consumed && (o=
opt_find(&swr_class, opt, NULL, 0,
572 #if CONFIG_AVRESAMPLE
595 for (i = 0; i < nb_groups; i++) {
597 if (p->
sep && !strcmp(p->
sep, opt))
632 resample_opts = NULL;
646 const char *key,
const char *
val)
663 memset(octx, 0,
sizeof(*octx));
719 while (optindex < argc) {
720 const char *opt = argv[optindex++], *
arg;
726 if (opt[0] ==
'-' && opt[1] ==
'-' && !opt[2]) {
731 if (opt[0] !=
'-' || !opt[1] || dashdash+1 == optindex) {
738 #define GET_ARG(arg) \
740 arg = argv[optindex++]; \
742 av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'.\n", opt);\
743 return AVERROR(EINVAL); \
752 groups[ret].
name, arg);
761 arg = argv[optindex++];
770 "argument '%s'.\n", po->
name, po->
help, arg);
775 if (argv[optindex]) {
779 "argument '%s'.\n", opt, argv[optindex]);
784 "with argument '%s'.\n", opt, argv[optindex]);
790 if (opt[0] ==
'n' && opt[1] ==
'o' &&
795 "argument 0.\n", po->
name, po->
help);
826 const struct {
const char *
name;
int level; } log_levels[] = {
840 tail = strstr(arg,
"repeat");
843 arg += 6 + (arg[6]==
'+');
848 if (!strcmp(log_levels[i].
name, arg)) {
854 level = strtol(arg, &tail, 10);
857 "Possible levels are numbers or:\n", arg);
871 while ((c = *(
template++))) {
873 if (!(c = *(
template++)))
881 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
882 tm->tm_hour, tm->tm_min, tm->tm_sec);
896 char *filename_template = NULL;
906 tm = localtime(&now);
908 while (env && *env) {
912 "Failed to parse FFREPORT environment variable: %s\n",
919 if (!strcmp(key,
"file")) {
921 filename_template =
val;
942 filename.str, strerror(errno));
947 "%s started on %04d-%02d-%02d at %02d:%02d:%02d\n"
948 "Report written to \"%s\"\n",
950 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
951 tm->tm_hour, tm->tm_min, tm->tm_sec,
967 max = strtol(arg, &tail, 10);
980 struct rlimit rl = { lim, lim + 1 };
981 if (setrlimit(RLIMIT_CPU, &rl))
990 int opt_opencl(
void *optctx,
const char *opt,
const char *
arg)
993 const char *opts =
arg;
1012 const char *errbuf_ptr = errbuf;
1022 #define SHOW_VERSION 2
1023 #define SHOW_CONFIG 4
1024 #define SHOW_COPYRIGHT 8
1026 #define PRINT_LIB_INFO(libname, LIBNAME, flags, level) \
1027 if (CONFIG_##LIBNAME) { \
1028 const char *indent = flags & INDENT? " " : ""; \
1029 if (flags & SHOW_VERSION) { \
1030 unsigned int version = libname##_version(); \
1031 av_log(NULL, level, \
1032 "%slib%-11s %2d.%3d.%3d / %2d.%3d.%3d\n", \
1034 LIB##LIBNAME##_VERSION_MAJOR, \
1035 LIB##LIBNAME##_VERSION_MINOR, \
1036 LIB##LIBNAME##_VERSION_MICRO, \
1037 version >> 16, version >> 8 & 0xff, version & 0xff); \
1039 if (flags & SHOW_CONFIG) { \
1040 const char *cfg = libname##_configuration(); \
1041 if (strcmp(FFMPEG_CONFIGURATION, cfg)) { \
1042 if (!warned_cfg) { \
1043 av_log(NULL, level, \
1044 "%sWARNING: library configuration mismatch\n", \
1048 av_log(NULL, level, "%s%-11s configuration: %s\n", \
1049 indent, #libname, cfg); \
1069 const char *indent = flags &
INDENT?
" " :
"";
1073 av_log(NULL, level,
" Copyright (c) %d-%d the FFmpeg developers",
1075 av_log(NULL, level,
"\n");
1076 av_log(NULL, level,
"%sbuilt on %s %s with %s\n",
1077 indent, __DATE__, __TIME__, CC_IDENT);
1079 av_log(NULL, level,
"%sconfiguration: " FFMPEG_CONFIGURATION
"\n", indent);
1106 "This version of %s has nonfree parts compiled in.\n"
1107 "Therefore it is not legally redistributable.\n",
1111 "%s is free software; you can redistribute it and/or modify\n"
1112 "it under the terms of the GNU General Public License as published by\n"
1113 "the Free Software Foundation; either version 3 of the License, or\n"
1114 "(at your option) any later version.\n"
1116 "%s is distributed in the hope that it will be useful,\n"
1117 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1118 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1119 "GNU General Public License for more details.\n"
1121 "You should have received a copy of the GNU General Public License\n"
1122 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
1126 "%s is free software; you can redistribute it and/or modify\n"
1127 "it under the terms of the GNU General Public License as published by\n"
1128 "the Free Software Foundation; either version 2 of the License, or\n"
1129 "(at your option) any later version.\n"
1131 "%s is distributed in the hope that it will be useful,\n"
1132 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1133 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1134 "GNU General Public License for more details.\n"
1136 "You should have received a copy of the GNU General Public License\n"
1137 "along with %s; if not, write to the Free Software\n"
1138 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
1142 "%s is free software; you can redistribute it and/or modify\n"
1143 "it under the terms of the GNU Lesser General Public License as published by\n"
1144 "the Free Software Foundation; either version 3 of the License, or\n"
1145 "(at your option) any later version.\n"
1147 "%s is distributed in the hope that it will be useful,\n"
1148 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1149 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1150 "GNU Lesser General Public License for more details.\n"
1152 "You should have received a copy of the GNU Lesser General Public License\n"
1153 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
1157 "%s is free software; you can redistribute it and/or\n"
1158 "modify it under the terms of the GNU Lesser General Public\n"
1159 "License as published by the Free Software Foundation; either\n"
1160 "version 2.1 of the License, or (at your option) any later version.\n"
1162 "%s is distributed in the hope that it will be useful,\n"
1163 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1164 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
1165 "Lesser General Public License for more details.\n"
1167 "You should have received a copy of the GNU Lesser General Public\n"
1168 "License along with %s; if not, write to the Free Software\n"
1169 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
1180 const char *last_name;
1182 printf(
"File formats:\n"
1183 " D. = Demuxing supported\n"
1184 " .E = Muxing supported\n"
1190 const char *
name = NULL;
1191 const char *long_name = NULL;
1194 if ((name == NULL || strcmp(ofmt->
name, name) < 0) &&
1195 strcmp(ofmt->
name, last_name) > 0) {
1202 if ((name == NULL || strcmp(ifmt->
name, name) < 0) &&
1203 strcmp(ifmt->
name, last_name) > 0) {
1208 if (name && strcmp(ifmt->
name, name) == 0)
1215 printf(
" %s%s %-15s %s\n",
1219 long_name ? long_name:
" ");
1224 #define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name) \
1225 if (codec->field) { \
1226 const type *p = codec->field; \
1228 printf(" Supported " list_name ":"); \
1229 while (*p != term) { \
1231 printf(" %s", name); \
1241 printf(
"%s %s [%s]:\n", encoder ?
"Encoder" :
"Decoder", c->
name,
1246 printf(
" Threading capabilities: ");
1253 default: printf(
"no");
break;
1261 printf(
" Supported framerates:");
1263 printf(
" %d/%d", fps->
num, fps->
den);
1292 default:
return '?';
1300 if (prev->
id ==
id &&
1312 return (*da)->type != (*db)->type ? (*da)->type - (*db)->type :
1313 strcmp((*da)->name, (*db)->name);
1320 unsigned nb_codecs = 0, i = 0;
1324 if (!(codecs =
av_calloc(nb_codecs,
sizeof(*codecs)))) {
1341 printf(
" (%s: ", encoder ?
"encoders" :
"decoders");
1344 printf(
"%s ", codec->
name);
1355 " D..... = Decoding supported\n"
1356 " .E.... = Encoding supported\n"
1357 " ..V... = Video codec\n"
1358 " ..A... = Audio codec\n"
1359 " ..S... = Subtitle codec\n"
1360 " ...I.. = Intra frame-only codec\n"
1361 " ....L. = Lossy compression\n"
1362 " .....S = Lossless compression\n"
1364 for (i = 0; i < nb_codecs; i++) {
1382 if (strcmp(codec->
name, desc->
name)) {
1389 if (strcmp(codec->
name, desc->
name)) {
1409 " S..... = Subtitle\n"
1410 " .F.... = Frame-level multithreading\n"
1411 " ..S... = Slice-level multithreading\n"
1412 " ...X.. = Codec is experimental\n"
1413 " ....B. = Supports draw_horiz_band\n"
1414 " .....D = Supports direct rendering method 1\n"
1416 encoder ?
"Encoders" :
"Decoders");
1417 for (i = 0; i < nb_codecs; i++) {
1430 if (strcmp(codec->
name, desc->
name))
1431 printf(
" (codec %s)", desc->
name);
1451 int show_bsfs(
void *optctx,
const char *opt,
const char *arg)
1455 printf(
"Bitstream filters:\n");
1457 printf(
"%s\n", bsf->
name);
1464 void *opaque = NULL;
1467 printf(
"Supported file protocols:\n"
1470 printf(
"%s\n", name);
1471 printf(
"Output:\n");
1473 printf(
"%s\n", name);
1480 char descr[64], *descr_cur;
1485 " T.. = Timeline support\n"
1486 " .S. = Slice threading\n"
1487 " ..C = Commmand support\n"
1488 " A = Audio input/output\n"
1489 " V = Video input/output\n"
1490 " N = Dynamic number and/or type of input/output\n"
1491 " | = Source or sink filter\n");
1495 for (i = 0; i < 2; i++) {
1497 *(descr_cur++) =
'-';
1498 *(descr_cur++) =
'>';
1501 for (j = 0; pad && pad[j].
name; j++) {
1502 if (descr_cur >= descr +
sizeof(descr) - 4)
1511 printf(
" %c%c%c %-16s %-10s %s\n",
1514 filter->process_command ?
'C' :
'.',
1527 printf(
"%-32s #RRGGBB\n",
"name");
1530 printf(
"%-32s #%02x%02x%02x\n", name, rgb[0], rgb[1], rgb[2]);
1537 printf(
"Pixel formats:\n"
1538 "I.... = Supported Input format for conversion\n"
1539 ".O... = Supported Output format for conversion\n"
1540 "..H.. = Hardware accelerated format\n"
1541 "...P. = Paletted format\n"
1542 "....B = Bitstream format\n"
1543 "FLAGS NAME NB_COMPONENTS BITS_PER_PIXEL\n"
1547 # define sws_isSupportedInput(x) 0
1548 # define sws_isSupportedOutput(x) 0
1553 printf(
"%c%c%c%c%c %-16s %d %2d\n",
1570 const char *
name, *descr;
1572 printf(
"Individual channels:\n"
1573 "NAME DESCRIPTION\n");
1574 for (i = 0; i < 63; i++) {
1579 printf(
"%-12s%s\n", name, descr);
1581 printf(
"\nStandard channel layouts:\n"
1582 "NAME DECOMPOSITION\n");
1585 printf(
"%-12s", name);
1586 for (j = 1; j; j <<= 1)
1629 "but no %s for it are available. FFmpeg might need to be "
1630 "recompiled with additional external libraries.\n",
1631 name, encoder ?
"encoders" :
"decoders");
1651 printf(
" Common extensions: %s.\n", fmt->
extensions);
1670 printf(
" Common extensions: %s.\n", fmt->
extensions);
1672 printf(
" Mime type: %s.\n", fmt->
mime_type);
1675 printf(
" Default video codec: %s.\n", desc->
name);
1679 printf(
" Default audio codec: %s.\n", desc->
name);
1683 printf(
" Default subtitle codec: %s.\n", desc->
name);
1691 static void show_help_filter(
const char *
name)
1705 printf(
"Filter %s\n", f->
name);
1710 printf(
" slice threading supported\n");
1712 printf(
" Inputs:\n");
1714 for (i = 0; i <
count; i++) {
1719 printf(
" dynamic (depending on the options)\n");
1721 printf(
" none (source filter)\n");
1723 printf(
" Outputs:\n");
1725 for (i = 0; i <
count; i++) {
1730 printf(
" dynamic (depending on the options)\n");
1732 printf(
" none (sink filter)\n");
1738 printf(
"This filter has support for timeline through the 'enable' option.\n");
1741 "can not to satisfy request\n");
1746 int show_help(
void *optctx,
const char *opt,
const char *arg)
1752 par = strchr(topic,
'=');
1758 }
else if (!strcmp(topic,
"decoder")) {
1760 }
else if (!strcmp(topic,
"encoder")) {
1762 }
else if (!strcmp(topic,
"demuxer")) {
1764 }
else if (!strcmp(topic,
"muxer")) {
1767 }
else if (!strcmp(topic,
"filter")) {
1768 show_help_filter(par);
1783 while (c !=
'\n' && c != EOF)
1792 FILE *f = fopen(filename,
"rb");
1799 fseek(f, 0, SEEK_END);
1801 fseek(f, 0, SEEK_SET);
1802 if (*size == (
size_t)-1) {
1813 ret = fread(*bufptr, 1, *size, f);
1818 filename, strerror(errno));
1824 (*bufptr)[(*size)++] =
'\0';
1832 const char *preset_name,
int is_path,
1833 const char *codec_name)
1837 const char *base[3] = { getenv(
"FFMPEG_DATADIR"),
1842 av_strlcpy(filename, preset_name, filename_size);
1843 f = fopen(filename,
"r");
1846 char datadir[MAX_PATH], *ls;
1849 if (GetModuleFileNameA(GetModuleHandleA(NULL), datadir,
sizeof(datadir) - 1))
1851 for (ls = datadir; ls < datadir + strlen(datadir); ls++)
1852 if (*ls ==
'\\') *ls =
'/';
1854 if (ls = strrchr(datadir,
'/'))
1857 strncat(datadir,
"/ffpresets",
sizeof(datadir) - 1 - strlen(datadir));
1862 for (i = 0; i < 3 && !f; i++) {
1865 snprintf(filename, filename_size,
"%s%s/%s.ffpreset", base[i],
1866 i != 1 ?
"" :
"/.ffmpeg", preset_name);
1867 f = fopen(filename,
"r");
1868 if (!f && codec_name) {
1870 "%s%s/%s-%s.ffpreset",
1871 base[i], i != 1 ?
"" :
"/.ffmpeg", codec_name,
1873 f = fopen(filename,
"r");
1919 char *p = strchr(t->
key,
':');
1924 case 1: *p = 0;
break;
1926 default:
return NULL;
1934 else if (t->
key[0] == prefix &&
1956 "Could not alloc memory for stream options.\n");
1967 if (new_size >= INT_MAX / elem_size) {
1971 if (*size < new_size) {
1977 memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);