52 #include "libavutil/ffversion.h"
57 #if HAVE_SYS_RESOURCE_H
59 #include <sys/resource.h>
94 vfprintf(stdout, fmt, vl);
101 static int print_prefix = 1;
127 double min,
double max)
133 error =
"Expected number for %s but found: %s\n";
134 else if (d < min || d > max)
135 error =
"The value for %s was %s which is not within %f - %f\n";
136 else if (type ==
OPT_INT64 && (int64_t)d != d)
137 error =
"Expected int64 for %s but found %s\n";
138 else if (type ==
OPT_INT && (
int)d != d)
139 error =
"Expected int for %s but found %s\n";
153 is_duration ?
"duration" :
"date", context, timestr);
160 int rej_flags,
int alt_flags)
166 for (po = options; po->
name != NULL; po++) {
169 if (((po->
flags & req_flags) != req_flags) ||
170 (alt_flags && !(po->
flags & alt_flags)) ||
171 (po->
flags & rej_flags))
183 printf(
"-%-17s %s\n", buf, po->
help);
202 const char *p = strchr(name,
':');
203 int len = p ? p - name : strlen(name);
205 while (po->
name != NULL) {
206 if (!strncmp(name, po->
name, len) && strlen(po->
name) == len)
216 #if HAVE_COMMANDLINETOARGVW && defined(_WIN32)
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++) {
501 int opt_flags,
int search_flags)
509 #define FLAGS (o->type == AV_OPT_TYPE_FLAGS) ? AV_DICT_APPEND : 0
514 char opt_stripped[128];
517 #if CONFIG_AVRESAMPLE
522 if (!strcmp(opt,
"debug") || !strcmp(opt,
"fdebug"))
525 if (!(p = strchr(opt,
':')))
526 p = opt + strlen(opt);
527 av_strlcpy(opt_stripped, opt,
FFMIN(
sizeof(opt_stripped), p - opt + 1));
529 if ((o =
opt_find(&cc, opt_stripped, NULL, 0,
531 ((opt[0] ==
'v' || opt[0] ==
'a' || opt[0] ==
's') &&
545 if (!consumed &&
opt_find(&sc, opt, NULL, 0,
556 #if CONFIG_SWRESAMPLE
558 if (!consumed && (o=
opt_find(&swr_class, opt, NULL, 0,
571 #if CONFIG_AVRESAMPLE
594 for (i = 0; i < nb_groups; i++) {
596 if (p->
sep && !strcmp(p->
sep, opt))
631 resample_opts = NULL;
645 const char *key,
const char *
val)
662 memset(octx, 0,
sizeof(*octx));
718 while (optindex < argc) {
719 const char *opt = argv[optindex++], *
arg;
725 if (opt[0] ==
'-' && opt[1] ==
'-' && !opt[2]) {
730 if (opt[0] !=
'-' || !opt[1] || dashdash+1 == optindex) {
737 #define GET_ARG(arg) \
739 arg = argv[optindex++]; \
741 av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'.\n", opt);\
742 return AVERROR(EINVAL); \
751 groups[ret].
name, arg);
760 arg = argv[optindex++];
769 "argument '%s'.\n", po->
name, po->
help, arg);
774 if (argv[optindex]) {
778 "argument '%s'.\n", opt, argv[optindex]);
783 "with argument '%s'.\n", opt, argv[optindex]);
789 if (opt[0] ==
'n' && opt[1] ==
'o' &&
794 "argument 0.\n", po->
name, po->
help);
825 const struct {
const char *
name;
int level; } log_levels[] = {
839 tail = strstr(arg,
"repeat");
842 arg += 6 + (arg[6]==
'+');
847 if (!strcmp(log_levels[i].
name, arg)) {
853 level = strtol(arg, &tail, 10);
856 "Possible levels are numbers or:\n", arg);
870 while ((c = *(
template++))) {
872 if (!(c = *(
template++)))
880 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
881 tm->tm_hour, tm->tm_min, tm->tm_sec);
895 char *filename_template = NULL;
905 tm = localtime(&now);
907 while (env && *env) {
911 "Failed to parse FFREPORT environment variable: %s\n",
918 if (!strcmp(key,
"file")) {
920 filename_template =
val;
941 filename.str, strerror(errno));
946 "%s started on %04d-%02d-%02d at %02d:%02d:%02d\n"
947 "Report written to \"%s\"\n",
949 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
950 tm->tm_hour, tm->tm_min, tm->tm_sec,
966 max = strtol(arg, &tail, 10);
979 struct rlimit rl = { lim, lim + 1 };
980 if (setrlimit(RLIMIT_CPU, &rl))
991 const char *errbuf_ptr = errbuf;
1001 #define SHOW_VERSION 2
1002 #define SHOW_CONFIG 4
1003 #define SHOW_COPYRIGHT 8
1005 #define PRINT_LIB_INFO(libname, LIBNAME, flags, level) \
1006 if (CONFIG_##LIBNAME) { \
1007 const char *indent = flags & INDENT? " " : ""; \
1008 if (flags & SHOW_VERSION) { \
1009 unsigned int version = libname##_version(); \
1010 av_log(NULL, level, \
1011 "%slib%-11s %2d.%3d.%3d / %2d.%3d.%3d\n", \
1013 LIB##LIBNAME##_VERSION_MAJOR, \
1014 LIB##LIBNAME##_VERSION_MINOR, \
1015 LIB##LIBNAME##_VERSION_MICRO, \
1016 version >> 16, version >> 8 & 0xff, version & 0xff); \
1018 if (flags & SHOW_CONFIG) { \
1019 const char *cfg = libname##_configuration(); \
1020 if (strcmp(FFMPEG_CONFIGURATION, cfg)) { \
1021 if (!warned_cfg) { \
1022 av_log(NULL, level, \
1023 "%sWARNING: library configuration mismatch\n", \
1027 av_log(NULL, level, "%s%-11s configuration: %s\n", \
1028 indent, #libname, cfg); \
1048 const char *indent = flags &
INDENT?
" " :
"";
1052 av_log(NULL, level,
" Copyright (c) %d-%d the FFmpeg developers",
1054 av_log(NULL, level,
"\n");
1055 av_log(NULL, level,
"%sbuilt on %s %s with %s\n",
1056 indent, __DATE__, __TIME__, CC_IDENT);
1058 av_log(NULL, level,
"%sconfiguration: " FFMPEG_CONFIGURATION
"\n", indent);
1063 const char *indent = flags &
INDENT ?
" " :
"";
1064 char str[] = { FFMPEG_CONFIGURATION };
1065 char *conflist, *remove_tilde, *splitconf;
1069 while ((conflist = strstr(str,
" --")) != NULL) {
1070 strncpy(conflist,
"~--", 3);
1075 while ((remove_tilde = strstr(str,
"pkg-config~")) != NULL) {
1076 strncpy(remove_tilde,
"pkg-config ", 11);
1079 splitconf = strtok(str,
"~");
1080 av_log(NULL, level,
"\n%sconfiguration:\n", indent);
1081 while (splitconf != NULL) {
1082 av_log(NULL, level,
"%s%s%s\n", indent, indent, splitconf);
1083 splitconf = strtok(NULL,
"~");
1119 "This version of %s has nonfree parts compiled in.\n"
1120 "Therefore it is not legally redistributable.\n",
1124 "%s is free software; you can redistribute it and/or modify\n"
1125 "it under the terms of the GNU General Public License as published by\n"
1126 "the Free Software Foundation; either version 3 of the License, or\n"
1127 "(at your option) any later version.\n"
1129 "%s is distributed in the hope that it will be useful,\n"
1130 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1131 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1132 "GNU General Public License for more details.\n"
1134 "You should have received a copy of the GNU General Public License\n"
1135 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
1139 "%s is free software; you can redistribute it and/or modify\n"
1140 "it under the terms of the GNU General Public License as published by\n"
1141 "the Free Software Foundation; either version 2 of the License, or\n"
1142 "(at your option) any later version.\n"
1144 "%s is distributed in the hope that it will be useful,\n"
1145 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1146 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1147 "GNU General Public License for more details.\n"
1149 "You should have received a copy of the GNU General Public License\n"
1150 "along with %s; if not, write to the Free Software\n"
1151 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
1155 "%s is free software; you can redistribute it and/or modify\n"
1156 "it under the terms of the GNU Lesser General Public License as published by\n"
1157 "the Free Software Foundation; either version 3 of the License, or\n"
1158 "(at your option) any later version.\n"
1160 "%s is distributed in the hope that it will be useful,\n"
1161 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1162 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
1163 "GNU Lesser General Public License for more details.\n"
1165 "You should have received a copy of the GNU Lesser General Public License\n"
1166 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
1170 "%s is free software; you can redistribute it and/or\n"
1171 "modify it under the terms of the GNU Lesser General Public\n"
1172 "License as published by the Free Software Foundation; either\n"
1173 "version 2.1 of the License, or (at your option) any later version.\n"
1175 "%s is distributed in the hope that it will be useful,\n"
1176 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
1177 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
1178 "Lesser General Public License for more details.\n"
1180 "You should have received a copy of the GNU Lesser General Public\n"
1181 "License along with %s; if not, write to the Free Software\n"
1182 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
1193 const char *last_name;
1195 printf(
"File formats:\n"
1196 " D. = Demuxing supported\n"
1197 " .E = Muxing supported\n"
1203 const char *
name = NULL;
1204 const char *long_name = NULL;
1207 if ((name == NULL || strcmp(ofmt->
name, name) < 0) &&
1208 strcmp(ofmt->
name, last_name) > 0) {
1215 if ((name == NULL || strcmp(ifmt->
name, name) < 0) &&
1216 strcmp(ifmt->
name, last_name) > 0) {
1221 if (name && strcmp(ifmt->
name, name) == 0)
1228 printf(
" %s%s %-15s %s\n",
1232 long_name ? long_name:
" ");
1237 #define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name) \
1238 if (codec->field) { \
1239 const type *p = codec->field; \
1241 printf(" Supported " list_name ":"); \
1242 while (*p != term) { \
1244 printf(" %s", name); \
1254 printf(
"%s %s [%s]:\n", encoder ?
"Encoder" :
"Decoder", c->
name,
1259 printf(
" Threading capabilities: ");
1266 default: printf(
"no");
break;
1274 printf(
" Supported framerates:");
1276 printf(
" %d/%d", fps->
num, fps->
den);
1305 default:
return '?';
1313 if (prev->
id ==
id &&
1325 return (*da)->type != (*db)->type ? (*da)->type - (*db)->type :
1326 strcmp((*da)->name, (*db)->name);
1333 unsigned nb_codecs = 0, i = 0;
1337 if (!(codecs =
av_calloc(nb_codecs,
sizeof(*codecs)))) {
1354 printf(
" (%s: ", encoder ?
"encoders" :
"decoders");
1357 printf(
"%s ", codec->
name);
1368 " D..... = Decoding supported\n"
1369 " .E.... = Encoding supported\n"
1370 " ..V... = Video codec\n"
1371 " ..A... = Audio codec\n"
1372 " ..S... = Subtitle codec\n"
1373 " ...I.. = Intra frame-only codec\n"
1374 " ....L. = Lossy compression\n"
1375 " .....S = Lossless compression\n"
1377 for (i = 0; i < nb_codecs; i++) {
1395 if (strcmp(codec->
name, desc->
name)) {
1402 if (strcmp(codec->
name, desc->
name)) {
1422 " S..... = Subtitle\n"
1423 " .F.... = Frame-level multithreading\n"
1424 " ..S... = Slice-level multithreading\n"
1425 " ...X.. = Codec is experimental\n"
1426 " ....B. = Supports draw_horiz_band\n"
1427 " .....D = Supports direct rendering method 1\n"
1429 encoder ?
"Encoders" :
"Decoders");
1430 for (i = 0; i < nb_codecs; i++) {
1443 if (strcmp(codec->
name, desc->
name))
1444 printf(
" (codec %s)", desc->
name);
1468 printf(
"Bitstream filters:\n");
1470 printf(
"%s\n", bsf->
name);
1477 void *opaque = NULL;
1480 printf(
"Supported file protocols:\n"
1483 printf(
"%s\n", name);
1484 printf(
"Output:\n");
1486 printf(
"%s\n", name);
1493 char descr[64], *descr_cur;
1498 " T.. = Timeline support\n"
1499 " .S. = Slice threading\n"
1500 " ..C = Commmand support\n"
1501 " A = Audio input/output\n"
1502 " V = Video input/output\n"
1503 " N = Dynamic number and/or type of input/output\n"
1504 " | = Source or sink filter\n");
1508 for (i = 0; i < 2; i++) {
1510 *(descr_cur++) =
'-';
1511 *(descr_cur++) =
'>';
1514 for (j = 0; pad && pad[j].
name; j++) {
1515 if (descr_cur >= descr +
sizeof(descr) - 4)
1524 printf(
" %c%c%c %-16s %-10s %s\n",
1527 filter->process_command ?
'C' :
'.',
1540 printf(
"%-32s #RRGGBB\n",
"name");
1543 printf(
"%-32s #%02x%02x%02x\n", name, rgb[0], rgb[1], rgb[2]);
1552 printf(
"Pixel formats:\n"
1553 "I.... = Supported Input format for conversion\n"
1554 ".O... = Supported Output format for conversion\n"
1555 "..H.. = Hardware accelerated format\n"
1556 "...P. = Paletted format\n"
1557 "....B = Bitstream format\n"
1558 "FLAGS NAME NB_COMPONENTS BITS_PER_PIXEL\n"
1562 # define sws_isSupportedInput(x) 0
1563 # define sws_isSupportedOutput(x) 0
1568 printf(
"%c%c%c%c%c %-16s %d %2d\n",
1585 const char *
name, *descr;
1587 printf(
"Individual channels:\n"
1588 "NAME DESCRIPTION\n");
1589 for (i = 0; i < 63; i++) {
1594 printf(
"%-12s%s\n", name, descr);
1596 printf(
"\nStandard channel layouts:\n"
1597 "NAME DECOMPOSITION\n");
1600 printf(
"%-12s", name);
1601 for (j = 1; j; j <<= 1)
1644 "but no %s for it are available. FFmpeg might need to be "
1645 "recompiled with additional external libraries.\n",
1646 name, encoder ?
"encoders" :
"decoders");
1666 printf(
" Common extensions: %s.\n", fmt->
extensions);
1685 printf(
" Common extensions: %s.\n", fmt->
extensions);
1687 printf(
" Mime type: %s.\n", fmt->
mime_type);
1690 printf(
" Default video codec: %s.\n", desc->
name);
1694 printf(
" Default audio codec: %s.\n", desc->
name);
1698 printf(
" Default subtitle codec: %s.\n", desc->
name);
1706 static void show_help_filter(
const char *
name)
1720 printf(
"Filter %s\n", f->
name);
1725 printf(
" slice threading supported\n");
1727 printf(
" Inputs:\n");
1729 for (i = 0; i <
count; i++) {
1734 printf(
" dynamic (depending on the options)\n");
1736 printf(
" none (source filter)\n");
1738 printf(
" Outputs:\n");
1740 for (i = 0; i <
count; i++) {
1745 printf(
" dynamic (depending on the options)\n");
1747 printf(
" none (sink filter)\n");
1753 printf(
"This filter has support for timeline through the 'enable' option.\n");
1756 "can not to satisfy request\n");
1767 par = strchr(topic,
'=');
1773 }
else if (!strcmp(topic,
"decoder")) {
1775 }
else if (!strcmp(topic,
"encoder")) {
1777 }
else if (!strcmp(topic,
"demuxer")) {
1779 }
else if (!strcmp(topic,
"muxer")) {
1782 }
else if (!strcmp(topic,
"filter")) {
1783 show_help_filter(par);
1798 while (c !=
'\n' && c != EOF)
1814 fseek(f, 0, SEEK_END);
1816 fseek(f, 0, SEEK_SET);
1817 if (*size == (
size_t)-1) {
1828 ret = fread(*bufptr, 1, *size, f);
1833 filename, strerror(errno));
1839 (*bufptr)[(*size)++] =
'\0';
1847 const char *preset_name,
int is_path,
1848 const char *codec_name)
1852 const char *base[3] = { getenv(
"FFMPEG_DATADIR"),
1857 av_strlcpy(filename, preset_name, filename_size);
1858 f = fopen(filename,
"r");
1861 char datadir[MAX_PATH], *ls;
1864 if (GetModuleFileNameA(GetModuleHandleA(NULL), datadir,
sizeof(datadir) - 1))
1866 for (ls = datadir; ls < datadir + strlen(datadir); ls++)
1867 if (*ls ==
'\\') *ls =
'/';
1869 if (ls = strrchr(datadir,
'/'))
1872 strncat(datadir,
"/ffpresets",
sizeof(datadir) - 1 - strlen(datadir));
1877 for (i = 0; i < 3 && !f; i++) {
1880 snprintf(filename, filename_size,
"%s%s/%s.ffpreset", base[i],
1881 i != 1 ?
"" :
"/.ffmpeg", preset_name);
1882 f = fopen(filename,
"r");
1883 if (!f && codec_name) {
1885 "%s%s/%s-%s.ffpreset",
1886 base[i], i != 1 ?
"" :
"/.ffmpeg", codec_name,
1888 f = fopen(filename,
"r");
1934 char *p = strchr(t->
key,
':');
1939 case 1: *p = 0;
break;
1941 default:
return NULL;
1949 else if (t->
key[0] == prefix &&
1971 "Could not alloc memory for stream options.\n");
1982 if (new_size >= INT_MAX / elem_size) {
1986 if (*size < new_size) {
1992 memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);